changes
This commit is contained in:
+55
-40
@@ -9,51 +9,66 @@
|
||||
#include "globals.hpp"
|
||||
#include "input.hpp"
|
||||
|
||||
Snake snake {1};
|
||||
Window window;
|
||||
Input input;
|
||||
Fruit fruit;
|
||||
|
||||
int main() {
|
||||
int score = 0;
|
||||
std::array<std::array<char, COL>, ROW> &board = window.m_board;
|
||||
bool update = true;
|
||||
int row = 0, col = 0;
|
||||
Snake snake {1};
|
||||
Window window;
|
||||
Input input;
|
||||
Fruit fruit;
|
||||
|
||||
Point previous {row,col};
|
||||
fruit.create_point();
|
||||
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;
|
||||
|
||||
if(fruit.m_row == row && fruit.m_col == col) {
|
||||
fruit.reset(board);
|
||||
++score;
|
||||
int x = 5;
|
||||
int y = 5;
|
||||
for(int i = 0; i <= x; i++) {
|
||||
for(int a = 0; a <= y; a++) {
|
||||
snake.create_tail(i, a);
|
||||
}
|
||||
std::tie(row, col) = previous.get_point(snake.get_direction(), row, col);
|
||||
|
||||
board[row][col] = '*';
|
||||
board[fruit.m_row][fruit.m_col] = '*';
|
||||
std::cout << "Score: " << score << std::endl;
|
||||
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.
|
||||
*
|
||||
*/
|
||||
for(int i = 0; i < snake.m_tails.size(); i++) {
|
||||
std::cout << &snake.m_tails.at(i) << std::endl;
|
||||
}
|
||||
std::cout << snake.m_tails.size() << std::endl;
|
||||
|
||||
|
||||
// int score = 0;
|
||||
// int row = 0, col = 0;
|
||||
// int fps = 5;
|
||||
// bool running = true;
|
||||
//
|
||||
// Point previous {row,col}; // Creating initial snake head position
|
||||
// fruit.create_point(); // Creating initial fruit object
|
||||
// std::array<std::array<char, COL>, ROW> &board = window.m_board;
|
||||
// std::thread input_thread(&Input::get_input, &input);
|
||||
// while(running) {
|
||||
// switch (input.m_current_key) {
|
||||
// case 's':
|
||||
// snake.m_direction = 1;
|
||||
// break;
|
||||
// case 'w':
|
||||
// snake.m_direction = 2;
|
||||
// break;
|
||||
// case 'a':
|
||||
// snake.m_direction = 3;
|
||||
// break;
|
||||
// case 'd':
|
||||
// snake.m_direction = 4;
|
||||
// break;
|
||||
// case 'q':
|
||||
// running = false;
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// fruit.reset(board, row, col, score);
|
||||
// std::tie(row, col) = previous.get_point(snake.m_direction, row, col);
|
||||
//
|
||||
// board[row][col] = '*';
|
||||
// board[fruit.m_row][fruit.m_col] = '*';
|
||||
// std::cout << "Score: " << score << std::endl;
|
||||
// previous.clear(board); // Clear old previous point
|
||||
// previous = Point {row, col}; // Set new previous point
|
||||
// window.update_loop(fps); // Update loop to clear board, tick and redisplay board
|
||||
// }
|
||||
//
|
||||
// input_thread.join();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user