wip
This commit is contained in:
+53
-58
@@ -2,7 +2,6 @@
|
||||
#include <thread>
|
||||
#include <cstdlib>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
#include "point.hpp"
|
||||
#include "fruit.hpp"
|
||||
#include "snake.hpp"
|
||||
@@ -11,65 +10,61 @@
|
||||
#include "input.hpp"
|
||||
|
||||
int main (int argc, char *argv[]) {
|
||||
Snake snake {1};
|
||||
Window window;
|
||||
Input input;
|
||||
Fruit fruit;
|
||||
Snake snake { 1, 0, 0 };
|
||||
Window window;
|
||||
Input input;
|
||||
Fruit fruit;
|
||||
|
||||
int x = 5;
|
||||
for(int i = 0; i < x; i++) {
|
||||
snake.create_tail(i, 0);
|
||||
}
|
||||
std::thread input_thread(&Input::get_input, &input);
|
||||
bool running = true;
|
||||
int count = 0;
|
||||
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;
|
||||
}
|
||||
|
||||
int row = 0, col = 0;
|
||||
int count = 0;
|
||||
while(count < 2) {
|
||||
count++;
|
||||
for(int i = 0; i < snake.m_tails.size(); i++) {
|
||||
std::tie(row, col) = snake.get_new_point(i, 1, row, col);
|
||||
std::cout << snake.m_tails.at(i).to_string() << std::endl;
|
||||
fruit.reset(window.m_board, snake.m_head.m_row, snake.m_head.m_col, window.m_score, count);
|
||||
if (window.m_score % 2 == 0 && count > 0) {
|
||||
if (snake.m_direction == 1) {
|
||||
int r = snake.m_head.m_row;
|
||||
if (r + 1 > ROW - 1) {
|
||||
r = snake.m_head.m_row;
|
||||
}
|
||||
snake.create_tail(snake.m_head.m_row + r + 1, snake.m_head.m_col);
|
||||
++r;
|
||||
}
|
||||
count--;
|
||||
}
|
||||
|
||||
/* TODO
|
||||
* update tail positions
|
||||
* draw positions
|
||||
* clear first tail
|
||||
* repeat
|
||||
* */
|
||||
|
||||
window.m_board[snake.m_head.m_row][snake.m_head.m_col] = '*';
|
||||
window.m_board[fruit.m_row][fruit.m_col] = '*';
|
||||
window.draw_score();
|
||||
window.update_loop(FPS);
|
||||
snake.m_head.clear(window.m_board);
|
||||
snake.m_head.get_new_point(snake.m_direction);
|
||||
}
|
||||
}
|
||||
|
||||
// int score = 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;
|
||||
input_thread.join();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user