forked from MichalApanowicz/TheGameProject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.hpp
157 lines (135 loc) · 3.24 KB
/
class.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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#ifndef CLASS_HPP_INCLUDED
#define CLASS_HPP_INCLUDED
#include <curses.h>
#include <ctime>
#include <cstdlib>
using namespace std;
enum TypeOfField{NUL,TREE,CHAR_GOOD,CHAR_BAD,BONUS,BONUS2,HEART};
char symbols[]={' ', 'Y', '|', '-', 'O', '+', 'H'};
class Field{
TypeOfField type;
public:
void changeField();
};
class Player{
int positionX;
int positionY;
bool status;
public:
void setPosition(int, int);
void movePlayer(int);
void changeStatus(int);
void writeX();
void writeY();
bool getStatus();
int getX();
int getY();
};
void Player::setPosition(int x, int y){
this->status = 1;
this->positionX = x;
this->positionY = y;
}
void Player::movePlayer(int direction){
switch(direction){
case KEY_LEFT:
if(this->positionX>0) this->positionX=this->positionX-1;
break;
case KEY_UP:
if(this->positionY>0) this->positionY=this->positionY-1;
break;
case KEY_DOWN:
if(this->positionY<25-1) this->positionY=this->positionY+1;
break;
case KEY_RIGHT:
if(this->positionX<80-1) this->positionX=this->positionX+1;
break;
default:
break;
}
}
void Player::changeStatus(int stat)
{
srand(time(NULL));
if(stat==0) {
setPosition(-1,-1);
this->status = 0;
}else if(stat==1) {
setPosition(rand()%COLS,rand()%LINES);
this->status = 1;
}
}
void Player::writeX(){
printw("%d",this->positionX);
}
void Player::writeY(){
printw("%d",this->positionY);
}
int Player::getX(){
return this->positionX;
}
int Player::getY(){
return this->positionY;
}
bool Player::getStatus(){
return this->status;
}
class Stage{
int maxX;
int maxY;
//Field tab[];
public:
void setSize(int,int);
void draw(Player, Player, Player);
int getWidth();
int getHeight();
};
void Stage::setSize(int width, int height){
this->maxX = width;
this->maxY = height;
}
void Stage::draw(Player character, Player target, Player target2){
int x1 = character.getX();
int y1 = character.getY();
int x2 = target.getX();
int y2 = target.getY();
int x3 = target2.getX();
int y3 = target2.getY();
const char* white = "X";
const char* black = "O";
clear();
if(y1 != -1 && x1 !=-1) mvprintw( y1,x1, white);
if(y2 != -1 && x2 !=-1) mvprintw( y2,x2, black);
if(y3 != -1 && x3 !=-1) mvprintw( y3,x3, black);
}
int Stage::getWidth(){
return this->maxX;
}
int Stage::getHeight(){
return this->maxY;
}
void start_counting()
{
clear();
char start_msg[] = "Sterowanie strzalkami. Cel: Zlap murzynow!";
mvprintw(LINES/2,COLS/2-sizeof(start_msg)/2,"Sterowanie strzalkami. Cel: Zlap murzynow!\n\t\t\t\t Czas:20sek");
refresh();
Sleep(3000);
clear();
mvprintw(LINES/2,COLS/2,"3..");
refresh();
Sleep(1000);
clear();
mvprintw(LINES/2,COLS/2,"2..");
refresh();
Sleep(1000);
clear();
mvprintw(LINES/2,COLS/2,"1..");
refresh();
Sleep(1000);
clear();
mvprintw(LINES/2,COLS/2,"START");
refresh();
Sleep(100);
}
#endif // CLASS_HPP_INCLUDED