Как исправить ошибку
Вот ошибка. Сборка начата в 10:51...
1>------ Сборка начата: проект: ConsoleApplication1, Конфигурация: Debug x64 ------
1>MSVCRTD.lib(exe_main.obj): error LNK2019: ссылка на неразрешенный внешний символ main в функции «int __cdecl invoke_main(void)» (?invoke_main@@YAHXZ).
1>C:\Users\Lenovo\Desktop\Snake for PC\ConsoleApplication1\x64\Debug\ConsoleApplication1.exe: fatal error LNK1120: неразрешенных внешних элементов: 1
1>Сборка проекта «ConsoleApplication1.vcxproj» завершена с ошибкой.
========== Сборка: успешно выполнено — 0, со сбоем — 1, в актуальном состоянии — 0, пропущено — 0 ==========
========== Сборка завершено в 10:51 и заняло 04,989 с ==========
КОД: #include <iostream>
#include <conio.h>
#include <windows.h>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <algorithm>
using namespace std;
const int width = 20;
const int height = 20;
const int baseSpeed = 100;
const int boostedSpeed = 50;
#ifdef _WIN32
#define COLOR_RED 12
#define COLOR_GREEN 10
#define COLOR_YELLOW 14
#define COLOR_RESET 7
void SetColor(int color) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
}
#else
#define COLOR_RED ""
#define COLOR_GREEN ""
#define COLOR_YELLOW ""
#define COLOR_RESET ""
void SetColor(int) {}
#endif
// Состояние игры
struct GameState {
bool gameOver;
bool isPaused;
bool isBoosted;
int x, y;
int fruitX, fruitY;
int score;
vector<pair<int, int>> snake;
enum eDirection { STOP = 0, LEFT, RIGHT, UP, DOWN } dir;
};
void Setup(GameState& state) {
state.gameOver = false;
state.isPaused = false;
state.isBoosted = false;
state.dir = GameState::STOP;
state.x = width / 2;
state.y = height / 2;
state.score = 0;
state.snake.clear();
state.snake.push_back({ state.x, state.y });
do {
state.fruitX = rand() % width;
state.fruitY = rand() % height;
} while (find(state.snake.begin(), state.snake.end(), make_pair(state.fruitX, state.fruitY)) != state.snake.end());
}
// Отрисовка поля
void Draw(const GameState& state) {
system(«cls»); // Для простоты (можно заменить на более плавный вариант)
// Верхняя граница
for (int i = 0; i < width + 2; i++) cout << "#";
cout << endl;
// Поле
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
if (j == 0) cout << "#";
// Отрисовка объектов
if (i == state.y && j == state.x) {
SetColor(COLOR_GREEN);
cout << «O»;
SetColor(COLOR_RESET);
}
else if (i == state.fruitY && j == state.fruitX) {
SetColor(COLOR_RED);
cout << «F»;
SetColor(COLOR_RESET);
}
else {
bool isTail = false;
for (const auto& segment: state.snake) {
if (segment.first == j && segment.second == i) {
SetColor(COLOR_YELLOW);
cout << «o»;
SetColor(COLOR_RESET);
isTail = true;
break;
}
}
if (!isTail) cout << " ";
}
if (j == width — 1) cout << "#";
}
cout << endl;
}
for (int i = 0; i < width + 2; i++) cout << "#";
cout << endl;
// Статус
cout << «Score: » << state.score << " | ";
cout << «Speed: » << (state.isBoosted? «Boosted»: «Normal») << " | ";
cout << (state.isPaused? "[PAUSED]": "") << endl;
if (state.gameOver) cout << «GAME OVER! Press R to restart» << endl;
}
void Input(GameState& state) {
if (_kbhit()) {
switch (_getch()) {
case 'a': if (state.dir != GameState::RIGHT) state.dir = GameState::LEFT; break;
case 'd': if (state.dir != GameState::LEFT) state.dir = GameState::RIGHT; break;
case 'w': if (state.dir != GameState::DOWN) state.dir = GameState::UP; break;
case 's': if (state.dir != GameState::UP) state.dir = GameState::DOWN; break;
case ' ': state.isBoosted = !state.isBoosted; break;
case 'p': state.isPaused = !state.isPaused; break;
case 'r': if (state.gameOver) Setup(state); break;
case 'x': state.gameOver = true; break;
}
}
}
void Logic(GameState& state) {
if (state.isPaused || state.gameOver) return;
// Движение головы
int prevX = state.snake[0].first;
int prevY = state.snake[0].second;
switch (state.dir) {
case GameState::LEFT: state.x--; break;
case GameState::RIGHT: state.x++; break;
case GameState::UP: state.y--; break;
case GameState::DOWN: state.y++; break;
default: break;
}
if (state.x < 0 || state.x >= width || state.y < 0 || state.y >= height) {
state.gameOver = true;
return;
}
if (state.x == state.fruitX && state.y == state.fruitY) {
state.score += 10;
do {
state.fruitX = rand() % width;
state.fruitY = rand() % height;
} while (find(state.snake.begin(), state.snake.end(), make_pair(state.fruitX, state.fruitY)) != state.snake.end());
state.snake.push_back({ -1, -1 });
}
for (size_t i = 1; i < state.snake.size(); i++) {
swap(state.snake[i].first, prevX);
swap(state.snake[i].second, prevY);
}
// Обновление головы
state.snake[0].first = state.x;
state.snake[0].second = state.y;
// Проверка столкновения с хвостом
for (size_t i = 1; i < state.snake.size(); i++) {
if (state.snake[i].first == state.x && state.snake[i].second == state.y) {
state.gameOver = true;
break;
}
}
}
int main() {
srand(time(0));
GameState game;
Setup(game);
while (true) {
Draw(game);
Input(game);
Logic(game);
Sleep(game.isBoosted? boostedSpeed: baseSpeed);
}
return 0;


