-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnake.hpp
52 lines (43 loc) · 1.14 KB
/
Snake.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#pragma once
#include <SFML/Graphics.hpp>
#include "Textbox.hpp"
#include <vector>
struct SnakeSegment {
SnakeSegment(int x, int y) : position(x, y){}
sf::Vector2i position;
};
using SnakeContainer = std::vector<SnakeSegment>;
enum class Direction{ None, Up, Down, Left, Right };
class Snake {
public:
Snake (int l_blockSize, Textbox* l_log);
~Snake();
void SetDirection (Direction l_dir);
Direction GetDirection();
int GetSpeed();
sf::Vector2i GetPosition();
int GetLives();
int GetScore();
void IncreaseScore();
bool HasLost();
void Lose();
void ToggleLost();
Direction GetPhysicalDirection();
void Extend();
void Reset();
void Move();
void Tick();
void Cut (int l_segments);
void Render (sf::RenderWindow& l_window);
private:
void CheckCollision();
SnakeContainer m_snakeBody;
int m_size;
Direction m_dir;
int m_speed;
int m_lives;
int m_score;
bool m_lost;
sf::RectangleShape m_bodyRect;
Textbox* m_log;
};