This repository has been archived by the owner on Jul 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
C1.0.0.5.5.cpp
266 lines (266 loc) · 6.85 KB
/
C1.0.0.5.5.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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#include<bits/stdc++.h>
#include<conio.h>
#include<windows.h>
using namespace std;
int ma[103][103],who=1,have,map_size=0,people;
map<string,int>id;
map<char,int>gox;
map<char,int>goy;
string col[13]={"white","blue","red","green","cyan"};
string icon[23]={" ","1","o","2","x","3","@","4","+"};
struct peo{
int x,y,cnt;
string name;
}a[5];
void gotoxy(int x, int y){
COORD pos;
pos.X=x;
pos.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void hidecursor(){
CONSOLE_CURSOR_INFO cursor_info={1,0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
}
void initkeyboard(){
goy['a']=0;
goy['d']=0;
goy['w']=-1;
goy['s']=1;
gox['w']=0;
gox['s']=0;
gox['a']=-1;
gox['d']=1;
}
void ccolor(string str,string color){
if(color=="white")
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN | FOREGROUND_BLUE);
if(color=="red")
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
if(color=="green")
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
if(color=="blue")
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);
if(color=="yellow")
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN);
if(color=="pink")
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_BLUE);
if(color=="cyan")
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |FOREGROUND_BLUE);
cout<<str;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);
}
void tocolor(int a){
switch(a){
case 1:
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);
break;
case 2:
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
break;
case 3:
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
break;
case 4:
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN |FOREGROUND_BLUE);
break;
case 5:
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN | FOREGROUND_BLUE);
break;
}
}
char scanc(){
char ch='\0';
ch=getch();
switch(ch){
case 'w':
return 'w';
case 'a':
return 'a';
case 'd':
return 'd';
case 's':
return 's';
case -32:
char ch2;
ch2=getch();
switch(ch2){
case 72:
return 'w';
case 75:
return 'a';
case 77:
return 'd';
case 80:
return 's';
}
break;
case 13:
return 13;
}
}
int selectwhat(string title,string titlecolor,string selectcolor,string text[],int textcount,string textcolor,string tipscolor){
int select=0;
ccolor(title+"\n",titlecolor);
for(int i=0;i<textcount;i++)
ccolor("\n "+text[i]+"\n",textcolor);
cout<<"\n";
ccolor("'w'、's'或上下键进行选择,enter、右键或'd'进行确定",tipscolor);
while(1){
gotoxy(0,2*select+1);
for(int i=0;i<=text[select].size()+1;i++)
ccolor("-",selectcolor);
ccolor("\n|",selectcolor);
gotoxy(text[select].size()+1,2*select+2);
ccolor("|\n",selectcolor);
for(int i=0;i<=text[select].size()+1;i++)
ccolor("-",selectcolor);
switch(scanc()){
case 'w':
if(select!=0){
gotoxy(0,2*select+1);
for(int i=0;i<=text[select].size()+1;i++)
ccolor(" ",selectcolor);
ccolor("\n ",selectcolor);
gotoxy(text[select].size()+1,2*select+2);
ccolor(" \n",selectcolor);
for(int i=0;i<=text[select].size()+1;i++)
ccolor(" ",selectcolor);
select--;
}
break;
case 's':
if(select<textcount-1){
gotoxy(0,2*select+1);
for(int i=0;i<=text[select].size()+1;i++)
ccolor(" ",selectcolor);
ccolor("\n ",selectcolor);
gotoxy(text[select].size()+1,2*select+2);
ccolor(" \n",selectcolor);
for(int i=0;i<=text[select].size()+1;i++)
ccolor(" ",selectcolor);
select++;
}
break;
case 'd':
return select;
case 13:
return select;
}
}
}
bool cmp(peo a,peo b){
return a.cnt>b.cnt;
}
void initmap(){
for(int i=0;i<=map_size+1;i++)
ccolor("-","pink");
cout<<endl;
for(int i=1;i<=map_size;i++){
ccolor("|","pink");
for(int j=1;j<=map_size;j++)
cout<<" ";
ccolor("|\n","pink");
}
for(int i=0;i<=map_size+1;i++)
ccolor("-","pink");
cout<<endl;
cout<<"\n\n\n";
for(int i=1;i<=people;i++)
ccolor(icon[i*2-1]+":"+a[i].name+"在的位置 ",col[i]);
cout<<endl;
for(int i=1;i<=people;i++)
ccolor(icon[i*2]+":"+a[i].name+"占的格子 ",col[i]);
for(int i=1;i<=people;i++){
gotoxy(a[i].x,a[i].y);
ccolor(icon[i*2-1],col[i]);
}
}
int main(){
hidecursor();
initkeyboard();
memset(ma,0,sizeof(ma));
string peop[5]={"双人","四人"};
people=selectwhat("请选择人数","red","blue",peop,2,"green","white");
people=(people+1)*2;
system("cls");
for(int i=1;i<=people;i++){
tocolor(5);
cout<<"请输入玩家"<<i<<"的名字:";
tocolor(i);
cin>>a[i].name;
id[a[i].name]=i;
}
system("cls");
tocolor(5);
cout<<"请输入地图大小(N*N)(2~37):";
cin>>map_size;
for(int i=1;i<=people;i++)
a[i].cnt=1;
a[1].x=1;
a[1].y=1;
a[2].x=map_size;
a[2].y=map_size;
ma[1][1]=1;
ma[map_size][map_size]=3;
if(people==4){
a[3].x=map_size;
a[3].y=1;
a[4].x=1;
a[4].y=map_size;
ma[map_size][1]=5;
ma[1][map_size]=7;
}
have=map_size*map_size-people;
system("cls");
initmap();
while(have){
gotoxy(0,map_size+2);
for(int i=1;i<=people;i++){
tocolor(i);
cout<<a[i].name<<"占格数:"<<a[i].cnt<<" ";
}
tocolor(5);
cout<<" \n剩余格数:"<<have<<" \n该";
ccolor(a[who].name,col[who]);
tocolor(5);
cout<<"了 ";
char ch=scanc();
int nx=a[who].x+gox[ch],ny=a[who].y+goy[ch];
if(nx>=1&&nx<=map_size&&ny>=1&&ny<=map_size&&(ma[nx][ny]==who*2||ma[nx][ny]==0)){
if(!ma[nx][ny]){
a[who].cnt++;
have--;
}
ma[a[who].x][a[who].y]=who*2;
gotoxy(a[who].x,a[who].y);
ccolor(icon[who*2],col[who]);
a[who].x=nx;
a[who].y=ny;
ma[a[who].x][a[who].y]=who*2-1;
gotoxy(a[who].x,a[who].y);
ccolor(icon[who*2-1],col[who]);
}
if(who<people)
who++;
else
who=1;
}
system("cls");
sort(a+1,a+1+people,cmp);
ccolor("排名\n名次 名字 占格数\n","white");
int ct=1;
for(int i=1;i<=people;i++){
tocolor(id[a[i].name]);
if(a[i].cnt==a[ct].cnt)
cout<<ct;
else{
cout<<i;
ct=i;
}
cout<<" "<<a[i].name<<" "<<a[i].cnt<<endl;
}
ccolor("按任意键退出","white");
getch();
return 0;
}