-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathgame.cpp
67 lines (50 loc) · 964 Bytes
/
game.cpp
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
#include <iostream>
#include "grid.hpp"
void do_action(grid& g)
{
char action;
std::cin >> action;
if(action == 'w')
{
g.action(direction::NORTH);
return;
}
if(action == 's')
{
g.action(direction::SOUTH);
return;
}
if(action == 'a')
{
g.action(direction::WEST);
return;
}
if(action == 'd')
{
g.action(direction::EAST);
return;
}
if(action == 'g')
{
std::cout << "Cheater!" << std::endl;
g.set(0, 0, 2048);
}
}
int main()
{
std::cout << "w = north, s = south, a = west, d = east" << std::endl;
grid g;
g.print();
while(g.can_move())
{
do_action(g);
g.print();
std::cout << "Score: " << g.score() << std::endl;
if(g.largest() == 2048)
{
std::cout << "Win" << std::endl;
break;
}
}
return 0;
}