This repository has been archived by the owner on Nov 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Classes.h
85 lines (71 loc) · 2.07 KB
/
Classes.h
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef CLASSES_H_INCLUDED
#define CLASSES_H_INCLUDED
#include "Declaration.h"
#include <vector>
using namespace std;
enum SnakeDirection {UP, DOWN, LEFT, RIGHT}; //{0, 1, 2, 3}
struct point{
int x, y;
};
class Snake{
public:
Snake(int _x, int _y);
Snake(point _pos);
~Snake();
void setPosition(int _x, int _y);
void setPosition(point _pos);
point getPosition();
void setTailLen(int _len);
int getTailLen();
void setDirection(SnakeDirection _direction, bool _antiReverse = true);
SnakeDirection getDirection();
void insertTails(point _tailPos);
vector<point> getTails();
void popTails(); //NEED SET ZONE TO 0
void move();
void saveTails();
vector<point> tails;
private:
point pos;
int tailLen = 0; //length of Tails; .
SnakeDirection direction = RIGHT; //default direction
};
class SnakeGame{
public:
SnakeGame(); // construction
~SnakeGame(); //destruction
void setZone(int _x, int _y, int _val);
void setZone(point _pos, int _val);
int getZone(int _x, int _y);
int getZone(point _pos);
int getScore();
int setGameSpeed(int _gameSpeed);
int getGameSpeed();
void loadMap(char *_dir);
void beginGame();
private:
bool gameOver = true;
int zone[playZoneH+1][playZoneW+1] = { {0} };
int score = 0;
int gameSpeed = 70;
Snake *snake = new Snake(playZoneW/2, playZoneH/2);
//
void setSecureKey(int _val);
//~~
int secureKey;
//~~ FUNCTION
void setScore(int _score);
void getKey2ChangeDirection(); //getkey and auto change direction
void snakeMove(); //change position depending on direction
void drawPoint(int x, int y);
void drawScreen(); // draw Zone to GameScreen
void drawBorder(); // draw border
void drawScoreBoard(); // draw Scoreboard
void drawScoreValue(); // draw score in Scoreboard
void gameThread(); // main game thread
void logic();
void foodSpawn();
void saveTail(point newTail);
void makeTail();
};
#endif // CLASSES_H_INCLUDED