54 lines
1.1 KiB
C++
54 lines
1.1 KiB
C++
#include <iostream>
|
|
#include <thread>
|
|
#include <cstdlib>
|
|
#include <unistd.h>
|
|
#include "point.hpp"
|
|
#include "fruit.hpp"
|
|
#include "snake.hpp"
|
|
#include "window.hpp"
|
|
#include "globals.hpp"
|
|
#include "input.hpp"
|
|
|
|
int main (int argc, char *argv[]) {
|
|
Head head { 2, 0, 0 };
|
|
Window window;
|
|
Input input;
|
|
Fruit fruit;
|
|
|
|
std::thread input_thread(&Input::get_input, &input);
|
|
bool running = true;
|
|
int count = 0;
|
|
|
|
while (running) {
|
|
switch (input.m_current_key) {
|
|
case 'a':
|
|
head.m_direction = -1;
|
|
break;
|
|
case 'd':
|
|
head.m_direction = 1;
|
|
break;
|
|
case 's':
|
|
head.m_direction = 2;
|
|
break;
|
|
case 'w':
|
|
head.m_direction = -2;
|
|
break;
|
|
case 'q':
|
|
running = false;
|
|
break;
|
|
}
|
|
|
|
fruit.reset(window.m_board, head.m_head.m_row, head.m_head.m_col, window.m_score, count);
|
|
|
|
window.m_board[head.m_head.m_row][head.m_head.m_col] = '*';
|
|
window.m_board[fruit.m_row][fruit.m_col] = 'X';
|
|
window.draw_score();
|
|
window.update_loop(FPS);
|
|
head.m_head.clear(window.m_board);
|
|
head.get_new_point(head.m_direction);
|
|
}
|
|
|
|
input_thread.join();
|
|
return 0;
|
|
}
|