-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoard.cpp
More file actions
121 lines (113 loc) · 1.9 KB
/
Board.cpp
File metadata and controls
121 lines (113 loc) · 1.9 KB
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
#include "Board.h"
Board::Board(int boardSize)
{
_maze = new Maze(boardSize);
_size = _maze->GetSize();
_isGameEnd = false;
ResetBoard();
_gun = new Gun(_maze->GetTile(), _player->GetPosp(), _player->GetDir());
}
void Board::RenderBoard()
{
// const char** const tile = _maze->GetTile(); À̰Š¿Ö ¾ÈµÊ?
char** const tile = _maze->GetTile();
for (int y = 0; y < *_size; y++)
{
for (int x = 0; x < *_size; x++)
{
if (IsPOINTEqual(_player->GetPos(), intToPoint(x,y)))
{
_player->PrtPlayer();
}
else
{
switch (tile[y][x])
{
case Empty:
cout << "¡à";
break;
case Wall:
cout << "¡á";
break;
case Goal:
cout << "¢Ã";
break;
default:
perror("Wrong Value");
break;
}
}
}
cout << endl;
}
}
void Board::ResetBoard()
{
_maze->GenerateByBinaryTree();
_player = new Player(_maze->GetStartPos());
}
void Board::InputCommend(char input)
{
LetterIntegrate(input);
switch (input)
{
case ESC:
ExitGame();
break;
case UpArrow:
MovePlayer(Direction::UP);
break;
case DownArrow:
MovePlayer(Direction::DOWN);
break;
case LeftArrow:
MovePlayer(Direction::LEFT);
break;
case RightArrow:
MovePlayer(Direction::RIGHT);
break;
case A:
_gun->Fire();
break;
default:
break;
}
}
void Board::ExitGame()
{
system("cls");
_isGameEnd = true;
exit(0);
}
void Board::MovePlayer(Direction dir)
{
_player->Move(dir);
if(CheckNextBlock(_player->GetPos().x, _player->GetPos().y) == TileState::CANNOTMOVE)
{
_player->Back();
}
}
TileState Board::CheckNextBlock(int x, int y)
{
switch (_maze->GetTile()[y][x])
{
case Empty:
return TileState::CANMOVE;
break;
case Wall:
return TileState::CANNOTMOVE;
break;
case Goal:
_isGameEnd = true;
return TileState::CANMOVE;
break;
default:
perror("Block not found");
return TileState::CANNOTMOVE;
break;
}
}
bool Board::GetIsGameEnd()
{
return _isGameEnd;
}