-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
88 lines (77 loc) · 1.35 KB
/
main.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <vector>
#include <iostream>
#include <windows.h>
#include <conio.h>
#include "src/level.cpp"
using namespace std;
int main(int argc, char *argv[])
{
string usage = "Usage: Sokoban.exe <height> <width> <box-count> [play] [json] [debug]";
if (argc <= 3)
{
cout << usage;
return 1;
}
SokobanLevel level(stoi(argv[1]), stoi(argv[2]), stoi(argv[3]));
if (argc > 4)
{
if (string(argv[4]) == "debug")
{
for (int k = 0;; k++)
{
for (int l = 0; l < (int)((k / 10) + 1); l++)
cout << "\b";
cout << k;
level.Generate();
}
return 0;
}
if (string(argv[4]) == "json")
{
level.Generate();
level.ShowJson();
return 0;
}
if (string(argv[4]) == "play")
{
level.Generate();
char input;
for (;;)
{
level.Show();
cout << "Move with WASD, R to regenerate, E to exit" << endl;
input = getch();
switch (input)
{
case 'w':
level.PlayerMove(UP);
break;
case 'a':
level.PlayerMove(LEFT);
break;
case 's':
level.PlayerMove(DOWN);
break;
case 'd':
level.PlayerMove(RIGHT);
break;
case 'r':
system("cls");
level.Generate();
break;
case 'e':
return 0;
default:
continue;
}
system("cls");
}
return 0;
}
cout << usage;
return 1;
}
level.Generate();
level.Show();
return 0;
}