/*By Rlax*/ /*光标键控制方向,空格键落子*/ #include "Stdio.h" #include "Conio.h" #include "graphics.h" #define LEFT 0x4b00 #define RIGHT 0x4d00 #define DOWN 0x5000 #define UP 0x4800 #define ESC 0x011b #define BLANKSPACE 0x3920 #define N 400 int one_i=0,two_i=0,i,j; int signx=320,signy=240; int key=1; int turn=1; int wrong; int judgmentx[9],judgmenty[9],judgment,judgmenti,k1,k2; struct PlayOne { int x[N]; int y[N]; }one; struct PlayTwo { int x[N]; int y[N]; }two; void InitGraph(); void Gamebegin(); void DrawBackground(); void PrintPlayOnePoint(); void PrintPlayTwoPoint(); void PlayGame(); void Win(); void Win_1(); void Win_2(); void Win_3(); void Win_4(); void Resuit(); void Judgment(); void Test(); void GameOver(); void CloseGraph(); int main(void) { InitGraph(); Gamebegin(); DrawBackground(); PlayGame(); GameOver(); return 0; } void InitGraph() { int gd=DETECT,gm; initgraph(&gd,&gm,"c://tc"); cleardevice(); } void Gamebegin() { setcolor(4); settextstyle(0,0,4); outtextxy(160,100,"Five Game"); settextstyle(0,0,3); outtextxy(241,200,"By Rlax"); settextstyle(0,0,1); outtextxy(400,300,"QQ:441420519"); outtextxy(400,320,"Email:popkids@qq.com"); getch(); cleardevice(); } void DrawBackground() { setcolor(3); setlinestyle(1,0,1); for(i=0;i<=44;i+=2) { line(100,20+10*i,540,20+10*i); line(100+10*i,20,100+10*i,460); } } void PrintPlayOnePoint() { setcolor(12); setfillstyle(1,12); fillellipse(signx,signy,8,8); } void PrintPlayTwoPoint() { setcolor(9); setfillstyle(1,9); fillellipse(signx,signy,8,8); } void PlayGame() { setcolor(15-turn); circle(signx,signy,8); while(key!=ESC) { key=bioskey(0); setcolor(0); circle(signx,signy,8); switch(key) { case UP: { if(signy==20) signy=20; else signy-=20; }break; case DOWN: { if(signy==460) signy=460; else signy+=20; }break; case LEFT: { if(signx==100) signx=100; else signx-=20; }break; case RIGHT: { if(signx==540) signx=540; else signx+=20; }break; case BLANKSPACE: { for(i=0;i<one_i;i++) { if(one.x[i]==signx&&one.y[i]==signy) {wrong=1;break;} else if(two.x[i]==signx&&two.y[i]==signy) {wrong=1;break;} else wrong=2; } if(wrong!=1) { switch(turn) { case 1: { PrintPlayOnePoint(); one.x[one_i]=signx; one.y[one_i]=signy; judgmenti=one_i; Win(); turn=2; one_i++; }break; case 2: { PrintPlayTwoPoint(); two.x[two_i]=signx; two.y[two_i]=signy; judgmenti=two_i; Win(); turn=1; two_i++; }break; } } }break; } setcolor(15-turn); circle(signx,signy,8); } } void Win() { Win_1(); Win_2(); Win_3(); Win_4(); } void Win_1() { for(i=1,j=1;i<9;i++,j++) { judgmentx[i]=signx+20*j; judgmenty[i]=signy; i++; judgmentx[i]=signx-20*j; judgmenty[i]=signy; } Judgment(); } void Win_2() { for(i=1,j=1;i<9;i++,j++) { judgmentx[i]=signx; judgmenty[i]=signy+20*j; i++; judgmentx[i]=signx; judgmenty[i]=signy-20*j; } Judgment(); } void Win_3() { for(i=1,j=1;i<9;i++,j++) { judgmentx[i]=signx+20*j; judgmenty[i]=signy+20*j; i++; judgmentx[i]=signx-20*j; judgmenty[i]=signy-20*j; } Judgment(); } void Win_4() { for(i=1,j=1;i<9;i++,j++) { judgmentx[i]=signx+20*j; judgmenty[i]=signy-20*j; i++; judgmentx[i]=signx-20*j; judgmenty[i]=signy+20*j; } Judgment(); } void Judgment() { judgment=0; for(j=1;j<9;j++) if(k1==1||k2==1||j<=2) Test(); Resuit(); } void Test() { if(j%2==0) k2=0; else k1=0; for(i=0;i<=judgmenti;i++) { if(turn==1) { if(one.x[i]==judgmentx[j]&&one.y[i]==judgmenty[j]) { judgment++; if(j%2==0) k2=1; else k1=1; break; } } else if(two.x[i]==judgmentx[j]&&two.y[i]==judgmenty[j]) { judgment++; if(j%2==0) k2=1; else k1=1; break; } } } void Resuit() { if(judgment>=4&&turn==1) { setcolor(14); settextstyle(0,0,3); if(turn==1) outtextxy(128,230,"Player One Win!!"); else outtextxy(128,230,"Player Two Win!!"); key=ESC; getch(); } } void GameOver() { cleardevice(); setcolor(4); settextstyle(0,0,3); outtextxy(128,230," BYE BYE!! "); getch(); } void CloseGraph() { getch(); closegraph(); }