-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path2048nc.c
124 lines (121 loc) · 3.04 KB
/
2048nc.c
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
122
123
124
#include "2048.h"
#include <accacia.h>
#include "2048nc.h"
void nc_printboard()
{
int i,j;
for (i = 0; i < 4; ++i)
for (j = 0; j < 4; ++j)
{
switch(board[i][j])
{
case 0:
attron(COLOR_PAIR(7)|A_DIM);
break;
case 2:
attron(COLOR_PAIR(1)|A_ITALIC);
break;
case 4:
attron(COLOR_PAIR(2)|A_ITALIC);
break;
case 8:
attron(COLOR_PAIR(3)|A_ITALIC);
break;
case 16:
attron(COLOR_PAIR(4)|A_ITALIC);
break;
case 32:
attron(COLOR_PAIR(5)|A_ITALIC);
break;
case 64:
attron(COLOR_PAIR(1)|A_BOLD|A_ITALIC);
break;
case 128:
attron(COLOR_PAIR(2)|A_BOLD|A_ITALIC);
break;
case 256:
attron(COLOR_PAIR(3)|A_BOLD|A_ITALIC);
break;
case 512:
attron(COLOR_PAIR(4)|A_BOLD|A_ITALIC);
break;
case 1024:
attron(COLOR_PAIR(5)|A_BOLD|A_ITALIC);
break;
case 2048:
attron(COLOR_PAIR(6)|A_BOLD|A_ITALIC|A_UNDERLINE);
break;
}
mvprintw(((row-9)/2) + i*2,((col-32)/2) + j*10,"%d \t",
board[i][j]);
attrset(0);
}
}
int nc_gameinit()
{
int c;
int i;
char hashi[17];
randinsertboard();
randinsertboard();
nc_printboard();
while((c=getch())!=27)
{
strcpy(hashi,hashgen());
switch(c)
{
case UP_KEY:
for(i=0;i<4;++i)
bunchcall(&board[0][i],
&board[1][i],
&board[2][i],
&board[3][i]);
break;
case DOWN_KEY:
for(i=0;i<4;++i)
bunchcall(&board[3][i],
&board[2][i],
&board[1][i],
&board[0][i]);
break;
case LEFT_KEY:
for(i=0;i<4;++i)
bunchcall(&board[i][0],
&board[i][1],
&board[i][2],
&board[i][3]);
break;
case RIGHT_KEY:
for(i=0;i<4;++i)
bunchcall(&board[i][3],
&board[i][2],
&board[i][1],
&board[i][0]);
break;
}
if (strcmp(hashi,hashgen())!=0)
randinsertboard();
nc_printboard();
switch(boardcheck())
{
case 1:
return 1;
break;/*not required*/
case -1:
return 0;
break;/*not required*/
case 0:
continue;
break;/*not required*/
}
}
return 0;
}
void nc_Winner(){
clear();
mvprintw(row/2,(col-10)/2, "WINNER! :)");
}
void nc_Loser(){
clear();
mvprintw(row/2,(col-8)/2, "LOSER :(");
}