refactor: renamed snake to element and moved fruit to element. Removed a lot of unused functions and variables
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
#ifndef ELEMENT_HPP
|
||||
#define ELEMENT_HPP
|
||||
|
||||
#include <vector>
|
||||
#include "point.hpp"
|
||||
|
||||
struct Head {
|
||||
Head();
|
||||
Point m_head;
|
||||
Point m_previous_head;
|
||||
void get_new_pos();
|
||||
};
|
||||
|
||||
struct Tail {
|
||||
Point m_tail_pos;
|
||||
Point m_previous_tail_pos;
|
||||
};
|
||||
|
||||
struct Body {
|
||||
Body();
|
||||
std::vector<Tail> m_body;
|
||||
int m_score;
|
||||
bool m_collision;
|
||||
void clear(std::array<std::array<char, COL>, ROW> &arr);
|
||||
void add_tail();
|
||||
void get_new_points(Head &head);
|
||||
void collision(Head &head);
|
||||
};
|
||||
|
||||
struct Fruit {
|
||||
Fruit();
|
||||
Point m_point;
|
||||
void get_new_pos(std::array<std::array<char, COL>, ROW> &board, Head &head, int &score);
|
||||
};
|
||||
|
||||
#endif // ELEMENT_HPP
|
||||
@@ -1,12 +0,0 @@
|
||||
#ifndef FRUIT_HPP
|
||||
#define FRUIT_HPP
|
||||
|
||||
#include "point.hpp"
|
||||
|
||||
struct Fruit {
|
||||
Fruit();
|
||||
Point m_point;
|
||||
void reset(std::array<std::array<char, COL>, ROW> &board, int row, int col, int &score);
|
||||
};
|
||||
|
||||
#endif // FRUIT_HPP
|
||||
@@ -5,6 +5,5 @@
|
||||
|
||||
constexpr uint16_t ROW = 11;
|
||||
constexpr uint16_t COL = 11;
|
||||
constexpr uint16_t FPS = 5;
|
||||
|
||||
#endif // GLOBALS_HPP
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
struct Input {
|
||||
int m_current_key = 0;
|
||||
char m_getch = ' ';
|
||||
void get_input(int &d, bool &c, bool &r);
|
||||
void get_input(int &d, bool &r);
|
||||
};
|
||||
|
||||
#endif // INPUT_HPP
|
||||
|
||||
+2
-4
@@ -2,7 +2,6 @@
|
||||
#define POINT_HPP
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include "globals.hpp"
|
||||
|
||||
struct Point {
|
||||
@@ -13,9 +12,8 @@ struct Point {
|
||||
Point(int x, int y) : m_row(x), m_col(y) {}
|
||||
Point(int x, int y, int dir) : m_row(x), m_col(y), m_direction(dir) {}
|
||||
|
||||
std::string to_string() const;
|
||||
void clear(std::array<std::array<char, COL>, ROW> &arr) const;
|
||||
void set_new_point(int x, int y, int dir);
|
||||
void clear(std::array<std::array<char, COL>, ROW> &board) const;
|
||||
void set_new_point(int row, int col, int dir);
|
||||
};
|
||||
|
||||
#endif // POINT_HPP
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
#ifndef SNAKE_HPP
|
||||
#define SNAKE_HPP
|
||||
|
||||
#include <vector>
|
||||
#include "point.hpp"
|
||||
|
||||
struct Head {
|
||||
Head();
|
||||
Head(int default_direction, int row, int col);
|
||||
Point m_head;
|
||||
Point m_previous_head;
|
||||
void get_new_point(int direction);
|
||||
void get_previous_point();
|
||||
};
|
||||
|
||||
struct Tail {
|
||||
Tail(int follow_direction, int row, int col);
|
||||
Point m_tail_pos;
|
||||
Point m_previous_tail_pos;
|
||||
std::vector<Point> m_move_history;
|
||||
void get_previous_point();
|
||||
};
|
||||
|
||||
struct Body {
|
||||
std::vector<Tail> m_body;
|
||||
void clear(std::array<std::array<char, COL>, ROW> &arr);
|
||||
void draw(std::array<std::array<char, COL>, ROW> &arr);
|
||||
void move(Head &head);
|
||||
void get_new_points(Head &head);
|
||||
void collision(Head &head, bool &running);
|
||||
};
|
||||
|
||||
#endif
|
||||
+2
-12
@@ -2,22 +2,12 @@
|
||||
#define WINDOW_HPP
|
||||
#include <array>
|
||||
#include "globals.hpp"
|
||||
#include "fruit.hpp"
|
||||
#include "snake.hpp"
|
||||
#include "element.hpp"
|
||||
|
||||
struct Window {
|
||||
Window();
|
||||
std::array<std::array<char, COL>, ROW> m_board;
|
||||
int m_score;
|
||||
int m_reset;
|
||||
int m_previous_reset;
|
||||
|
||||
void draw_window();
|
||||
void tick(double frames_per_second);
|
||||
void kill(bool &running);
|
||||
void update_score(Fruit &fruit, Body &body);
|
||||
void update_display(int fps);
|
||||
void check_exit(bool &running, Body &body, bool &collision);
|
||||
void update_display(Fruit &fruit, Head &head, Body &body);
|
||||
};
|
||||
|
||||
#endif // WINDOW_HPP
|
||||
|
||||
Reference in New Issue
Block a user