-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
73 lines (65 loc) · 1.66 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
#include <iostream>
#include <ctime>
#include <ncurses.h>
#include <cstring>
#include "board.hpp"
int main(int argc, char *argv[])
{
if (!term_test())
{
std::cout << "At least 24 x 119 terminal required" << std::endl;
return 1;
}
srand(static_cast<unsigned>(time(NULL)));
std::string name{""};
bool hl = true;
if (argc > 1)
{
for (int i = 1 ; i < argc ; i++)
{
char * temp = argv[i];
int len = strlen(temp);
if (strncmp(temp, "--name", len) == 0 || strncmp(temp, "--n", len) == 0)
{
if (i+1 < argc)
{
// name = argv[++i];
while(i+1 < argc && argv[i+1][0] != '-')
name = name + argv[++i] + ' ';
name.pop_back();
}
else
{
std::cout << "Invalid name";
return 1;
}
}
else if (strncmp(temp, "--highlight=false", len) == 0 || strncmp(temp, "--hl=f", len) == 0)
hl = false;
else if (strncmp(temp, "help", len) == 0)
{
help();
return 0;
}
else if (strncmp(temp, "-s", len) == 0)
{
scoreboard();
return 0;
}
}
}
if (name.empty())
{
std::cout << "What's your name? ";
std::cin >> name;
}
ncwrap nc;
bool play = true;
Board board(name, hl);
while(play)
{
board.draw();
play = board.move();
}
board.wait();
}