Adding Main files

This commit is contained in:
DarthMooMancer
2025-05-08 10:24:34 -04:00
parent 7bd4f2b0ff
commit 636ebae6a3
5 changed files with 99 additions and 0 deletions
+60
View File
@@ -0,0 +1,60 @@
#include <iostream>
#include <termios.h>
#include <unistd.h>
#include "snake.hpp"
const int ROW = 10;
const int COL = 10;
char getch();
void create_board();
void draw_board();
struct {
char board[ROW][COL];
} window;
char (*g_pboard)[ROW][COL] = &window.board;
char getch() {
termios oldt, newt;
char ch;
tcgetattr(STDIN_FILENO, &oldt); // get current terminal attributes
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO); // disable canonical mode and echo
tcsetattr(STDIN_FILENO, TCSANOW, &newt); // apply new settings
read(STDIN_FILENO, &ch, 1); // read one char
tcsetattr(STDIN_FILENO, TCSANOW, &oldt); // restore original settings
return ch;
}
void create_board() {
for(int i = 0; i < ROW; i++) {
for(int a = 0; a < COL; a++) {
(*g_pboard)[i][a] = '.';
}
}
}
void draw_board() {
for(int i = 0; i < ROW; i++) {
for(int a = 0; a < COL; a++) {
std::cout << (*g_pboard)[i][a] << " ";
}
std::cout << "\n";
}
}
int main() {
create_board();
draw_board();
draw_snake();
// int count = 0;
// std::cout << "Press any key other than space or esc: " << std::endl;
// while(count < 10) {
// char ch = getch();
// std::cout << "\nYou pressed: " << ch << '\n';
// ++count;
// }
return 0;
}