feat: fruits, globals, input, snake, point, window
This commit is contained in:
+47
-51
@@ -1,60 +1,56 @@
|
||||
#include <iostream>
|
||||
#include <termios.h>
|
||||
#include <thread>
|
||||
#include <cstdlib>
|
||||
#include <unistd.h>
|
||||
#include "snake.hpp"
|
||||
#include "point.hpp"
|
||||
#include "fruit.hpp"
|
||||
#include "window.hpp"
|
||||
#include "globals.hpp"
|
||||
#include "input.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";
|
||||
}
|
||||
}
|
||||
Snake snake {1};
|
||||
Window window;
|
||||
Input input;
|
||||
Fruit fruit;
|
||||
|
||||
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;
|
||||
// int randomNum = random() % 101;
|
||||
//
|
||||
// std::cout << randomNum;
|
||||
fruit.create_point();
|
||||
std::cout << fruit.m_point.get_point() << std::endl;
|
||||
// std::array<std::array<char, COL>, ROW> &board = window.m_board;
|
||||
// bool update = true;
|
||||
// int row = 0, col = 0;
|
||||
//
|
||||
// Point previous {row,col};
|
||||
// std::thread input_thread(&Input::get_input, &input);
|
||||
// while(update) {
|
||||
// if (input.m_current_key == 's') snake.set_direction(1);
|
||||
// if (input.m_current_key == 'w') snake.set_direction(2);
|
||||
// if (input.m_current_key == 'a') snake.set_direction(3);
|
||||
// if (input.m_current_key == 'd') snake.set_direction(4);
|
||||
// if (input.m_current_key == 'q') break;
|
||||
//
|
||||
// std::tie(row, col) = previous.get_point(snake.get_direction(), row, col);
|
||||
//
|
||||
// board[row][col] = '*';
|
||||
// previous.clear(board); // Clear old point
|
||||
// previous = Point {row, col}; // Set new previous
|
||||
// window.update_loop(5); // Update loop to clear board, tick and redisplay board
|
||||
// }
|
||||
//
|
||||
// input_thread.join();
|
||||
/* First
|
||||
* Learn how to make threads,
|
||||
* for the input thread call the thread then use a while loop within the thread, DO NOT use a while loop to call the thread
|
||||
*
|
||||
* for the update display thread use a while loop within the thread, DO NOT USE a while loop to call the thread.
|
||||
*
|
||||
* the update display thread will ALSO BE YOUR GAME UPDATE THREAD. Your input thread should only be used for INPUT no other function calls should be made and it should NEVER be put to sleep.
|
||||
*
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user