Перевел на C ибо нефиг

This commit is contained in:
2024-09-16 22:01:06 +04:00
parent 080ac8abb8
commit c4793ede4c
2 changed files with 16 additions and 10 deletions

View File

@@ -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

View File

@@ -1,5 +1,6 @@
#include <stdlib.h>
#include <string.h>
#include <ncurses.h>
#include <string>
// Пока оно 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;
@@ -258,10 +263,11 @@ void DrawGameOver()
int winY = (termHeight - winHeight) / 2;
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);