-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.cpp
More file actions
95 lines (82 loc) · 1.27 KB
/
Game.cpp
File metadata and controls
95 lines (82 loc) · 1.27 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
#include "Game.h"
Game::Game()
{
}
Game::~Game()
{
}
void Game::Play()
{
b.setSize();
b.Scramble();
char input;
do
{
system("cls");
b.Print();
cout << endl << "Moves: " << player.getMoves();
Input();
} while (!b.CheckIfSolved());
cout << "Congratulations! You won in " << player.getMoves() << "!" << endl;
}
void Game::Input()
{
char input;
input = _getch();
int playerPos = player.getPos();
int size = b.getSize();
// Move
switch (input)
{
case ('w') :
if (playerPos - size >= 0)
{
player.setPos(playerPos - size);
b.Swap(playerPos - size, playerPos);
player.addMove();
}
break;
case ('s') :
if (playerPos + size < size*size)
{
player.setPos(playerPos + size);
b.Swap(playerPos + size, playerPos);
player.addMove();
}
break;
case ('a') :
if (playerPos % size != 0)
{
player.setPos(playerPos - 1);
b.Swap(playerPos - 1, playerPos);
player.addMove();
}
break;
case ('d') :
if ((playerPos + 1) % size != 0)
{
player.setPos(playerPos + 1);
b.Swap(playerPos + 1, playerPos);
player.addMove();
}
break;
case ('r') :
Reset();
break;
case('q') :
Quit();
break;
default:
break;
}
}
void Game::Reset()
{
int input;
system("cls");
b.Reset();
player.Reset();
}
void Game::Quit()
{
}