-
Notifications
You must be signed in to change notification settings - Fork 1
/
20164206004 刘继强 中国象棋 代码 玩家2(client).txt
1732 lines (1660 loc) · 47.7 KB
/
20164206004 刘继强 中国象棋 代码 玩家2(client).txt
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <bits/stdc++.h>
#include <winsock2.h>
#include <graphics.h>
#include <time.h>
#include <ctype.h>
#include <cmath>
#include <cstdlib>
#include <windows.h>
#include <mmsystem.h>
#pragma comment(lib,"WinMM.LIB")
#define ADDRESS "127.0.0.1"
using namespace std;
PIMAGE imgstart;
PIMAGE imgmark;
PIMAGE imgmark1;
PIMAGE imgbk;
PIMAGE imgdescription1;
PIMAGE imgdescription2;
PIMAGE imgdescription3;
PIMAGE imgqp1;
PIMAGE imgqp2;
PIMAGE imgqp3;
PIMAGE imgqp4;
PIMAGE imgqp5;
PIMAGE imgqp6;
PIMAGE imgloading;
PIMAGE imgmusicopen;
PIMAGE imgmusicclose;
PIMAGE imgcheckerboard;
PIMAGE imgcheckerboard1;
PIMAGE imgcheckerboard2;
PIMAGE imgcheckerboard3;
PIMAGE imgranking;
PIMAGE imgredche;
PIMAGE imgredma;
PIMAGE imgredpao;
PIMAGE imgredshi;
PIMAGE imgredxiang;
PIMAGE imgredshuai;
PIMAGE imgredbing;
PIMAGE imgblackche;
PIMAGE imgblackma;
PIMAGE imgblackpao;
PIMAGE imgblackshi;
PIMAGE imgblackxiang;
PIMAGE imgblackjiang;
PIMAGE imgblackzu;
PIMAGE imgfredche;
PIMAGE imgfredma;
PIMAGE imgfredpao;
PIMAGE imgfredshi;
PIMAGE imgfredxiang;
PIMAGE imgfredshuai;
PIMAGE imgfredbing;
PIMAGE imgfblackche;
PIMAGE imgfblackma;
PIMAGE imgfblackpao;
PIMAGE imgfblackshi;
PIMAGE imgfblackxiang;
PIMAGE imgfblackjiang;
PIMAGE imgfblackzu;
PIMAGE imgfbk;
int i;
int j=0;
int row,col;
int posx,posy;
MUSIC mus,mus1; //定义音乐对象
struct fd_set rfds;
struct timeval timeout = {1,0};
SOCKET sockClient;
int ret;
int Bangchess[4][8]= {0};
int cnt = 1;
int tot = 0;
int w=1;
int counter = 1;
typedef struct chess1
{
int vis;
} Chess1;
typedef struct node//显示排行榜信息的结构体
{
char name[20];
char color[10];
int Wins;
double winning_percentage;
} Node;
Node game_player[100];
int cmp(Node a,Node b)//结构体排序
{
return a.name>b.name;
}
int chart[10][9]=
{
{32,31,30,29,28,27,26,25,24},
{0,0,0,0,0,0,0,0,0},
{0,23,0,0,0,0,0,22,0},
{21,0,20,0,19,0,18,0,17},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{16,0,15,0,14,0,13,0,12},
{0,11,0,0,0,0,0,10,0},
{0,0,0,0,0,0,0,0,0},
{9,8,7,6,5,4,3,2,1}
};
//初始的二维数组
int chart1[10][9]=
{
{32,31,30,29,28,27,26,25,24},
{0,0,0,0,0,0,0,0,0},
{0,23,0,0,0,0,0,22,0},
{21,0,20,0,19,0,18,0,17},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{16,0,15,0,14,0,13,0,12},
{0,11,0,0,0,0,0,10,0},
{0,0,0,0,0,0,0,0,0},
{9,8,7,6,5,4,3,2,1}
};
////标准二维数组
//一些棋子的走棋数组
int redma[10][9]=
{
{0,1,0,1,0,1,0,1,0},
{0,1,0,1,0,1,0,1,0},
{1,0,1,0,1,0,1,0,1},
{1,0,1,0,1,0,1,0,1},
{0,1,0,1,0,1,0,1,0},
{0,1,0,1,0,1,0,1,0},
{1,0,1,0,1,0,1,0,1},
{1,0,1,0,1,0,1,0,1},
{0,1,0,1,0,1,0,1,0},
{0,1,0,1,0,1,0,1,0}
};
int blackma[10][9]=
{
{0,1,0,1,0,1,0,1,0},
{0,1,0,1,0,1,0,1,0},
{1,0,1,0,1,0,1,0,1},
{1,0,1,0,1,0,1,0,1},
{0,1,0,1,0,1,0,1,0},
{0,1,0,1,0,1,0,1,0},
{1,0,1,0,1,0,1,0,1},
{1,0,1,0,1,0,1,0,1},
{0,1,0,1,0,1,0,1,0},
{0,1,0,1,0,1,0,1,0}
};
int redxiang[10][9]=
{
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,1,0,0,0,1,0,0},
{0,0,0,0,0,0,0,0,0},
{1,0,0,0,1,0,0,0,1},
{0,0,0,0,0,0,0,0,0},
{0,0,1,0,0,0,1,0,0}
};
int blackxiang[10][9]=
{
{0,0,1,0,0,0,1,0,0},
{0,0,0,0,0,0,0,0,0},
{1,0,0,0,1,0,0,0,1},
{0,0,0,0,0,0,0,0,0},
{0,0,1,0,0,0,1,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0}
};
int redshi[10][9]=
{
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,1,0,1,0,0,0},
{0,0,0,0,1,0,0,0,0},
{0,0,0,1,0,1,0,0,0}
};
int blackshi[10][9]=
{
{0,0,0,1,0,1,0,0,0},
{0,0,0,0,1,0,0,0,0},
{0,0,0,1,0,1,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0}
};
int redshuai[10][9]=
{
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,1,1,1,0,0,0},
{0,0,0,1,1,1,0,0,0},
{0,0,0,1,1,1,0,0,0}
};
int blackjiang[10][9]=
{
{0,0,0,1,1,1,0,0,0},
{0,0,0,1,1,1,0,0,0},
{0,0,0,1,1,1,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0}
};
int redbing[10][9]=
{
{1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0}
};
int blackzu[10][9]=
{
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1}
};
void itoa(int n,char *s)//itoa函数
{
int i,j,sign;
if((sign=n)<0)//记录符号
n=-n;//使n成为正数
i=0;
do
{
s[i++]=n%10+'0';//取下一个数字
}
while ((n/=10)>0);//删除该数字
if(sign<0)
s[i++]='-';
s[i]='\0';
for(j=i; j>=0; j--) //生成的数字是逆序的,所以要逆序输出
printf("%c",s[j]);
}
int atoi(char *s)//atoi函数
{
int i,n,sign;
for(i=0; isspace(s[i]); i++) //跳过空白符;
sign=(s[i]=='-')?-1:1;
if(s[i]=='+'||s[i]==' -')//跳过符号
i++;
for(n=0; isdigit(s[i]); i++)
n=10*n+(s[i]-'0');//将数字字符转换成整型数字
return sign *n;
}
void randomBangchess()//随机翻棋数组值
{
randomize();
int num;
int a[40];
for(int i = 0; i < 32; i++)
a[i] = 0;
for(int row=0; row<4; row++)
{
for(int col=0; col<8; col++)
{
num=random(32)+1;
while(!a[num])
{
Bangchess[row][col]= num;
a[num] = 1;
}
}
}
}
void go_chess(int x,int y)//走棋
{
switch(Bangchess[x][y])
{
case 1:
case 2:
putimage_withalpha(NULL,imgfredche,52.75*x+83,53*y+148);
break;
case 3:
case 4:
putimage_withalpha(NULL,imgfredma,52.75*x+83,53*y+148);
break;
case 5:
case 6:
putimage_withalpha(NULL,imgfredxiang,52.75*x+83,53*y+148);
break;
case 7:
case 8:
putimage_withalpha(NULL,imgfredshi,52.75*x+83,53*y+148);
break;
case 9:
putimage_withalpha(NULL,imgfredshuai,52.75*x+83,53*y+148);
break;
case 10:
case 11:
putimage_withalpha(NULL,imgfredpao,52.75*x+83,53*y+148);
break;
case 12:
case 13:
case 14:
case 15:
case 16:
putimage_withalpha(NULL,imgfredbing,52.75*x+83,53*y+148);
break;
case 17:
case 18:
case 19:
case 20:
case 21:
putimage_withalpha(NULL,imgfblackzu,52.75*x+83,53*y+148);
break;
case 22:
case 23:
putimage_withalpha(NULL,imgfblackpao,52.75*x+83,53*y+148);
break;
case 24:
case 25:
putimage_withalpha(NULL,imgfblackche,52.75*x+83,53*y+148);
break;
case 26:
case 27:
putimage_withalpha(NULL,imgfblackma,52.75*x+83,53*y+148);
break;
case 28:
case 29:
putimage_withalpha(NULL,imgfblackxiang,52.75*x+83,53*y+148);
break;
case 30:
case 31:
putimage_withalpha(NULL,imgfblackshi,52.75*x+83,53*y+148);
break;
case 32:
putimage_withalpha(NULL,imgfblackjiang,52.75*x+83,53*y+148);
break;
}
}
void init_Bangchess()//初始化翻棋数组
{
for(int row=0; row<4; row++)
{
for(int col=0; col<8; col++)
{
Sleep(200);
putimage_withalpha(NULL,imgfbk,52.75*col+83,53*row+148);
}
}
}
void init_Bangchess1()
{
for(int row=0; row<4; row++)
{
for(int col=0; col<8; col++)
{
putimage_withalpha(NULL,imgfbk,52.75*col+83,53*row+148);
}
}
}
void init_chart()//初始化象棋数组
{
for(int row=0; row<10; row++)
{
for(int col=0; col<9; col++)
{
chart[row][col]=chart1[row][col];
}
}
}
void musicopen()
{
mus.OpenFile("E:\\CloudMusic\\高山流水.mp3"); // 打开音乐文件
mus.SetVolume(0.7f); // 设置音量,参数范围从 0.0f 到 1.0f
if (mus.GetPlayStatus() == MUSIC_MODE_STOP)
{
mus.Play(0);
}
}
void musicopen1()
{
mus1.OpenFile("E:\\CloudMusic\\吃棋子音效.wav"); //打开音乐文件
mus1.SetVolume(0.7f); //设置音量,参数范围从 0.0f 到 1.0f
if(mus1.GetPlayStatus() == MUSIC_MODE_STOP)
{
mus1.Play(0);
}
}
void limit_time()
{
int time_start = fclock();
int temp;
int cnt;
for(; is_run(); delay_fps(60))
{
mouse_msg msg = {0};
while(mousemsg())
{
msg = getmouse();
}
temp = fclock();
if(temp != time_start&&(30-time_start)>0)
{
time_start = temp;
setbkmode(OPAQUE);
setbkcolor(RGB(0,255,0));
//xyprintf(120, 160, "%2d:%2d:%2d",time_start/3600,(time_start-time_start/3600*3600)/60,time_start-(time_start-time_start/3600*3600)/60*60);
xyprintf(140, 210, "%d sec",30-time_start);
}
if(!(30-time_start))
{
setfont(50,0, "宋体");
setbkmode(TRANSPARENT);
setcolor(RED);
outtextxy(222,149,"时间到,你输了!");
return ;
}
if((int)msg.is_left()&&(int)msg.is_up()&&!(int)msg.is_down()
&&600<msg.x&&msg.x<640&&300<msg.y&&msg.y<320)
{
cnt++;
if(cnt%2)
{
putimage_withalpha(NULL,imgmusicopen,80,101);
musicopen();
}
else
{
putimage_withalpha(NULL,imgmusicclose,80,101);
mus.Close();//关闭音乐文件
}
system("pause");
}
}
}
void game_time()
{
int time_start = fclock();
int temp;
int cnt;
for(; is_run(); delay_fps(60))
{
mouse_msg msg = {0};
while(mousemsg())
{
msg = getmouse();
}
temp = fclock();
if(temp != time_start&&(30-time_start)>0)
{
time_start = temp;
setbkmode(OPAQUE);
setfontbkcolor(RGB(255,255,0));
xyprintf(120, 160, "%2d:%2d:%2d",time_start/3600,(time_start-time_start/3600*3600)/60,time_start-
(time_start-time_start/3600*3600)/60*60);
xyprintf(120, 210, "%d sec",30-time_start);
}
if(!(30-time_start))
{
setfont(45,0, "宋体");
setbkmode(TRANSPARENT);
setfontbkcolor(RED);
outtextxy(227,149,"时间到,你输了!");
return ;
}
if((int)msg.is_left()&&(int)msg.is_up()&&!(int)msg.is_down()
&&600<msg.x&&msg.x<640&&300<msg.y&&msg.y<320)
{
cnt++;
if(cnt%2)
{
putimage_withalpha(NULL,imgmusicopen,80,101);
musicopen();
}
else
{
putimage_withalpha(NULL,imgmusicclose,80,101);
mus.Close();//关闭音乐文件
}
system("pause");
}
}
}
void init_chess()
{
for(int row=0; row<10; row++)
{
for(int col=0; col<9; col++)
{
switch(chart1[row][col])
{
case 1:
case 9:
Sleep(200);
putimage_withalpha(NULL,imgredche,34.67*col+230,35.7*row);
break;
case 2:
case 8:
Sleep(200);
putimage_withalpha(NULL,imgredma,34.67*col+230,35.7*row);
break;
case 3:
case 7:
Sleep(200);
putimage_withalpha(NULL,imgredxiang,34.67*col+230,35.7*row);
break;
case 4:
case 6:
Sleep(200);
putimage_withalpha(NULL,imgredshi,34.67*col+230,35.7*row);
break;
case 5:
Sleep(200);
putimage_withalpha(NULL,imgredshuai,34.67*col+230,35.7*row);
break;
case 10:
case 11:
Sleep(200);
putimage_withalpha(NULL,imgredpao,34.67*col+230,35.7*row);
break;
case 12:
case 13:
case 14:
case 15:
case 16:
Sleep(200);
putimage_withalpha(NULL,imgredbing,34.67*col+230,35.7*row);
break;
case 17:
case 18:
case 19:
case 20:
case 21:
Sleep(200);
putimage_withalpha(NULL,imgblackzu,34.67*col+230,35.7*row);
break;
case 22:
case 23:
Sleep(200);
putimage_withalpha(NULL,imgblackpao,34.67*col+230,35.7*row);
break;
case 24:
case 32:
Sleep(200);
putimage_withalpha(NULL,imgblackche,34.67*col+230,35.7*row);
break;
case 25:
case 31:
Sleep(200);
putimage_withalpha(NULL,imgblackma,34.67*col+230,35.7*row);
break;
case 26:
case 30:
Sleep(200);
putimage_withalpha(NULL,imgblackxiang,34.67*col+230,35.7*row);
break;
case 27:
case 29:
Sleep(200);
putimage_withalpha(NULL,imgblackshi,34.67*col+230,35.7*row);
break;
case 28:
Sleep(200);
putimage_withalpha(NULL,imgblackjiang,34.67*col+230,35.7*row);
break;
}
}
}
}
void init_chess1()
{
for(int row=0; row<10; row++)
{
for(int col=0; col<9; col++)
{
switch(chart[row][col])
{
case 1:
case 9:
putimage_withalpha(NULL,imgredche,34.67*col+230,35.7*row);
break;
case 2:
case 8:
putimage_withalpha(NULL,imgredma,34.67*col+230,35.7*row);
break;
case 3:
case 7:
putimage_withalpha(NULL,imgredxiang,34.67*col+230,35.7*row);
break;
case 4:
case 6:
putimage_withalpha(NULL,imgredshi,34.67*col+230,35.7*row);
break;
case 5:
putimage_withalpha(NULL,imgredshuai,34.67*col+230,35.7*row);
break;
case 10:
case 11:
putimage_withalpha(NULL,imgredpao,34.67*col+230,35.7*row);
break;
case 12:
case 13:
case 14:
case 15:
case 16:
putimage_withalpha(NULL,imgredbing,34.67*col+230,35.7*row);
break;
case 17:
case 18:
case 19:
case 20:
case 21:
putimage_withalpha(NULL,imgblackzu,34.67*col+230,35.7*row);
break;
case 22:
case 23:
putimage_withalpha(NULL,imgblackpao,34.67*col+230,35.7*row);
break;
case 24:
case 32:
putimage_withalpha(NULL,imgblackche,34.67*col+230,35.7*row);
break;
case 25:
case 31:
putimage_withalpha(NULL,imgblackma,34.67*col+230,35.7*row);
break;
case 26:
case 30:
putimage_withalpha(NULL,imgblackxiang,34.67*col+230,35.7*row);
break;
case 27:
case 29:
putimage_withalpha(NULL,imgblackshi,34.67*col+230,35.7*row);
break;
case 28:
putimage_withalpha(NULL,imgblackjiang,34.67*col+230,35.7*row);
break;
}
}
}
}
void init_chess2()
{
for(int row=0; row<10; row++)
{
for(int col=0; col<9; col++)
{
switch(chart1[row][col])
{
case 1:
case 9:
putimage_withalpha(NULL,imgredche,34.67*col+230,35.7*row);
break;
case 2:
case 8:
putimage_withalpha(NULL,imgredma,34.67*col+230,35.7*row);
break;
case 3:
case 7:
putimage_withalpha(NULL,imgredxiang,34.67*col+230,35.7*row);
break;
case 4:
case 6:
putimage_withalpha(NULL,imgredshi,34.67*col+230,35.7*row);
break;
case 5:
putimage_withalpha(NULL,imgredshuai,34.67*col+230,35.7*row);
break;
case 10:
case 11:
putimage_withalpha(NULL,imgredpao,34.67*col+230,35.7*row);
break;
case 12:
case 13:
case 14:
case 15:
case 16:
putimage_withalpha(NULL,imgredbing,34.67*col+230,35.7*row);
break;
case 17:
case 18:
case 19:
case 20:
case 21:
putimage_withalpha(NULL,imgblackzu,34.67*col+230,35.7*row);
break;
case 22:
case 23:
putimage_withalpha(NULL,imgblackpao,34.67*col+230,35.7*row);
break;
case 24:
case 32:
putimage_withalpha(NULL,imgblackche,34.67*col+230,35.7*row);
break;
case 25:
case 31:
putimage_withalpha(NULL,imgblackma,34.67*col+230,35.7*row);
break;
case 26:
case 30:
putimage_withalpha(NULL,imgblackxiang,34.67*col+230,35.7*row);
break;
case 27:
case 29:
putimage_withalpha(NULL,imgblackshi,34.67*col+230,35.7*row);
break;
case 28:
putimage_withalpha(NULL,imgblackjiang,34.67*col+230,35.7*row);
break;
}
}
}
}
void init_interface()
{
initgraph(762,357);
setfont(30,0, "宋体");
putimage(0,0,imgstart);
putimage(381,0,imgbk);
setbkmode(TRANSPARENT);
setfontbkcolor(WHITE);
setcolor(WHITE);
outtextxy(260,10, "残局练习");
outtextxy(260,50, "人机对战");
outtextxy(260,100, "双人对战");
outtextxy(260,150, "游戏说明");
outtextxy(260,200, "排行榜");
outtextxy(260,250, "退出游戏");
outtextxy(260,300, "棋谱欣赏");
outtextxy(50,245, "翻棋挑战");
outtextxy(50,84, "揭棋挑战");
setfont(45,0,"宋体");
outtextxy(180,10, "中");
outtextxy(180,110, "国");
outtextxy(180,210, "象");
outtextxy(180,310, "棋");
setfont(20,0,"宋体");
outtextxy(25,300, "16级2班刘继强");
mus.Close();
}
void functional_tips1()
{
initgraph(769,599);
putimage(0,0,imgcheckerboard);
putimage_withalpha(NULL,imgmusicopen,80,100);
musicopen();
setbkmode(TRANSPARENT);
setcolor(BLACK);
setfontbkcolor(BLACK);
setfont(19,0,"宋体");
outtextxy(30,110,"音效:");
outtextxy(30,160,"对局时间:");
outtextxy(30,210,"步时:");
outtextxy(600,50,"新局");
outtextxy(600,100,"悔棋");
outtextxy(600,150,"求和");
outtextxy(600,200,"认输");
outtextxy(600,250,"返回");
outtextxy(600,300,"暂停");
init_chart();
init_chess1();
}
void functional_tips2()
{
initgraph(612,504);
setfont(30,0, "宋体");
putimage(0,0,imgcheckerboard3);
putimage(61,124,imgcheckerboard2);
setbkmode(TRANSPARENT);
setcolor(BLACK);
setfontbkcolor(BLACK);
outtextxy(140,400,"返回");
outtextxy(260,400,"新局");
outtextxy(380,400,"悔棋");
}
void restart()
{
//system("cls");
cleardevice();
functional_tips1();
mus.Close();
game_time();
}
int move_chess1(int x,int y)
{
//coordinate(x,y);
posx=(int)(x-230.0)/34.67;
posy=(int)y/35.7;
for(i=1; i<=32; i++)
{
if(i==chart[posy][posx])
break;
}
return posy;
//cout<<posy<<" "<<posx<<endl;
//cout<<chart[posy][posx]<<endl;
}
int move_chess2(int x,int y)
{
//coordinate(x,y);
posx=(int)(x-230.0)/34.67;
posy=(int)y/35.7;
for(i=1; i<=32; i++)
{
if(i==chart[posy][posx])
break;
}
return posx;
//cout<<posy<<" "<<posx<<endl;
//cout<<chart[posy][posx]<<endl;
}
int move_chess3(int x,int y)
{
//coordinate(x,y);
posx=(int)(x-230.0)/34.67;
posy=(int)y/35.7;
for(i=1; i<=32; i++)
{
if(i==chart[posy][posx])
break;
}
return chart[posy][posx];
//cout<<posy<<" "<<posx<<endl;
//cout<<chart[posy][posx]<<endl;
}
int move_chess4(int x,int y)
{
//coordinate(x,y);
posx=(int)(x-83.0)/52.75;
posy=(int)(y-148.0)/53.0;
for(i=1; i<=32; i++)
{
if(i==Bangchess[posy][posx])
break;
}
return posy;
//cout<<posy<<" "<<posx<<endl;
//cout<<Bangchess[posy][posx]<<endl;
}
int move_chess5(int x,int y)
{
//coordinate(x,y);
posx=(int)(x-83.0)/52.75;
posy=(int)(y-148.0)/53.0;
for(i=1; i<=32; i++)
{
if(i==Bangchess[posy][posx])
break;
}
return posx;
//cout<<posy<<" "<<posx<<endl;
//cout<<Bangchess[posy][posx]<<endl;
}
int move_chess6(int x,int y)
{
//coordinate(x,y);
posx=(int)(x-83.0)/52.75;
posy=(int)(y-148.0)/53.0;
for(i=1; i<=32; i++)
{
if(i==Bangchess[posy][posx])
break;
}
return Bangchess[posy][posx];
//cout<<posy<<" "<<posx<<endl;
//cout<<Bangchess[posy][posx]<<endl;
}
int start_winsock()
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 1, 1 );
err = WSAStartup(wVersionRequested, &wsaData );
if ( err != 0 )
{
return -1;
}
if (LOBYTE( wsaData.wVersion ) != 1
|| HIBYTE(wsaData.wVersion) != 1 )
{
WSACleanup( );
return -1;
}
}
int set_conn_socket(SOCKET *sock)
{
int err;
char addr[100];
*sock = socket(AF_INET, SOCK_STREAM, 0);
//设置通信地址
SOCKADDR_IN addrSrv;
printf("请输入服务器的IP地址\n");
gets(addr);
addrSrv.sin_addr.S_un.S_addr = inet_addr(addr);//本地回路地址是127.0.0.1;
addrSrv.sin_family = AF_INET;
addrSrv.sin_port = htons(6000);
//把socket与地址绑定在一起
err = connect(*sock, (SOCKADDR*)&addrSrv, sizeof(SOCKADDR));
if (err != 0)
{
return -1;
}
}
void receive(int x,int y)
{
char recvBuf[100]= {0};
FD_ZERO(&rfds); /* 清空集合 */
FD_SET(sockClient, &rfds); /* 这里是添加检测 */
ret=select(0, &rfds, NULL, NULL, &timeout);
if(ret > 0)
{
if(FD_ISSET(sockClient,&rfds)) /* 这里检测的是fp在集合中是否状态变化,即可以操作。 */
{
recv(sockClient,recvBuf, 100, 0);
chart[x][y]=atoi(recvBuf);
printf("Says: %d\n",atoi(recvBuf));//接收信息
}
}
}
void transmit(int x,int y)
{
FD_ZERO(&rfds); /* 清空集合 */
FD_SET(sockClient, &rfds); /* 这里是添加检测 */
ret=select(0, &rfds, NULL, NULL, &timeout);
char sendBuf[100]= {0};
itoa(chart[x][y],sendBuf,10);