diff --git a/Makefile b/Makefile index 300d444..d764407 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,2 @@ all: - g++ -Wall -o "nmpython" "main.cpp" -lncurses -I v:/MinGW/MinGW32/opt/include/ncursesw -I v:/MinGW/mingw32/opt/include -L v:/MinGW/mingw32/opt/lib + v:/MinGW/bin/gcc.exe -Wall -o "nmpython" "main.c" -lncurses -I v:/MinGW/include/ncursesw -I v:/MinGW/include -L v:/MinGW/lib diff --git a/main.cpp b/main.c similarity index 93% rename from main.cpp rename to main.c index f2cf0fb..11c64ea 100644 --- a/main.cpp +++ b/main.c @@ -1,5 +1,6 @@ +#include +#include #include -#include // Пока оно true - будем крутиться в игре, // если станет false - выходим. @@ -48,8 +49,7 @@ struct coord int y; }; -// Массив для координат тела - определение -static coord * python; +struct coord *python; // Тут мы инициализируем все что надо void InitGame() @@ -94,7 +94,12 @@ void InitGame() maxPythonSize = (termWidth - 2) * (termHeight - 2); // Инициализируем массив под координаты частей тела - python = new coord[maxPythonSize](); + python = (struct coord*)malloc(maxPythonSize * sizeof(struct coord)); + if (python == NULL) { + // Обработка ошибки выделения памяти + printf("Memory allocation failed\n"); + exit(1); + } // Задаем начальные координаты python[0].x = playerX; @@ -256,12 +261,13 @@ void DrawGameOver() int winHeight = 7; int winX = (termWidth - winWidth) / 2; int winY = (termHeight - winHeight) / 2; - WINDOW * gameOverWin = newwin(winHeight, winWidth, winY, winX); + WINDOW *gameOverWin = newwin(winHeight, winWidth, winY, winX); box(gameOverWin, 0, 0); - std::string str1 = "GAME OVER!"; - std::string str2 = "Score: " + std::to_string(score); - mvwprintw(gameOverWin, 2, (winWidth - (int)str1.length()) / 2, str1.c_str()); - mvwprintw(gameOverWin, 4, (winWidth - (int)str2.length()) / 2, str2.c_str()); + char str1[] = "GAME OVER!"; + char str2[50]; + sprintf(str2, "Score: %d", score); + mvwprintw(gameOverWin, 2, (winWidth - (int)strlen(str1)) / 2, str1); + mvwprintw(gameOverWin, 4, (winWidth - (int)strlen(str2)) / 2, str2); wrefresh(gameOverWin); notimeout(gameOverWin, TRUE); wgetch(gameOverWin);