黑白棋c语言程序(OthelloClanguageprogram)

举报
资源描述
黑白棋 c 语 言 程 序(O t h e l l o C l a n g u a g e p r o g r a m)#include graphics,h 图形系统头文件/*/#define left 0 x4b00 光标左键值/*/#define right 0 x4d00 光标右键值/*/#define down 0 x5000 光标下键值/*/#define the ip 0 x4800 光标上键值/*/#define esc 0 x01 lb esc 键值/*/#define enter OxlcOd 回车键值/*/int a 8 8=0,key,scorel,score2 具体分数以及按键与存放棋子的变量;/*/char playone 3,pl ay two 3;/*两个人的得分转换成字符串输 出*/playtoplay void(void);/*人人对战函数*/drawqp void(void);/*画棋盘函数*/void setplaycolor(int x);/*设置棋子第一次的颜色*/void movecolor(int x,int y);/*恢复原来棋盘状态*/int qpchange(int x,int y,int z);/*判断棋盘的变化*/doscore void(void);/*处理分数*/void printscore(int n);/*输出成绩*/playwin void(void);/*输出胜利者信息*/*主函数*/void main(void)(int dg=detect,gr;initgraph(&dg,&gr,c:tc);/*初始化图形系统*drawqp();/*画棋盘*/playtoplay();/*人人对战*/getch();closegraph();/*关闭图形系统*/void drawqp()/*画棋盘*/int i,j;scorel=score2=0;/*棋手一开始得分都为0*/setbkcolor(blue);for(i=100;in=64-scorel-score2)/*if you try to exceed the numberof spaces will stop.(MoveColor(x,y);Fillellipse(x,y,15,15);Break;ElseContinue;/*/if the key is invalid(DoScore);/*/doscoreBreak;/*board changes,then go round each other.Else/*has a piece is key to.Continue;)Else four/*/determine the direction keyIf(key=LEFT&x120)/*/left arrow(MoveColor(x,y);F illellipse(x,y,15,15);SetPlayColor(t);X-=40;F illellipse(x,y,15,15);ElseIf(key=RIGHT&x80)/*/right arrow(MoveColor(x,y);F illellipse(x,y,15,15);SetPlayColor(t);X+=40;F illellipse(x,y,15,15);ElseIf(key=UP&y120)/*/on the direction key(MoveColor(x,y);F illellipse(x,y,15,15);SetPlayColor(t);Y-=40;F illellipse(x,y,15,15);)ElseIf(key=D0WN&y400)/*/under the direction key(MoveColor(x,y);F illellipse(x,y,15,15);SetPlayColor(t);Y+=40;F illellipse(x,y,15,15);)If(key=ESC)/*/the end of the gameBreak;If(scorel+score2)=641scorel=0|score2=0)/*latticehas been filled with one or 0 pieces to judge the outcome.(playWin);/*/output end resultBreak;)T=t%2+1;/*party left,change the color of each other go/round piecesCc=0;/*count recovery for 0*/*endwhile*/Void SetPlayColor(int t)/*/color set pieces(If(t%2=l)Setfillstyle(SOLID_FILL,15);/*/whiteElseSetfillstyle(SOLIDFILL,8);/*/grayVoid M oveColor(int x,int y)the original state grid recovery/*/take a step backIf(y100)/*if it is from a starting point on the restorationof the blue.S etfillstyle(S OLID一FILL,BLU E);Else/*other circumstances if it is 1 on the restoration of awhite pawn,2 black or blue back piece,recovery board*/S witch(a(x-120)/40(y-120)/40)(Case 1:S etfillstyle(S OLID_FILL,15);break;/*/whiteCase 2:S etfillstyle(S OLID_FILL,8);break;/*/BlackDefault:S etfillstyle(S OLID_FILL,BLU E);/*/blueInt QpChange(int x,int y,int t)/*/board of the changeof judgment(Int,I,J,K,KK,II,JJ,yes;Yes=0;1=(x-120)/40;/*/subscript array elements for calculationJ=(y-120)/40;/*/column subscript array elementcalculationS etP layColor(T);/*/color change set pieces8/*began to determine the direction of change.If(j6)/*/to the right.(For(k=j+l;j.j.*120+40,15,15);i f (i i.=+1)y e s =1;)返回是否改变过棋子颜色的标记r e t u r n y e s;/*)v o i d d o s c o r e 处 理 分 数()/*/(i n t i,j;s c o r e 1 =s c o r e 2 =0;/*重新开始计分数*/f o r (i =0;i 8;i +)f o r (j =0,j s c o r e l开始判断最后的结果)/*o u t t e x t x y (1 0 0,5 0,“b l a c k w i n!”)e l s ei f (s c o r e 2#d e f i n e l e f t 0 x 4 b 0 0#d e f i n e r i g h t 0 x 4 d 0 0#d e f i n e d o w n 0 x 5 0 0 0#d e f i n e u p 0 x 4 8 0 0#d e f i n e e s c 0 x 0 1 l b#d e f i n e s p a c e 0 x 3 9 2 0#d e f i n e s t a b l e 2 0#d e f i n e j z 4#d e f i n e j s 3#d e f i n e n 1 9i n t b o x n n ;i n t s t e p s t e p _ _ _ x,y;i n t k e y;i n t f l a g =1;v o i d d r a w ();_ b o xv o i d d r a w _ c i c l e (i n t x,i n t y,i n t c o l o r);v o i d c h a n g e ();v o i d j u d g e w h o (i n t x,i n t y)v o i d j u d g e k e y ();i n t j u d g e r e s u l t (i n t x,i n t y)v o i d a t t e n t o i n ();v o i d a t t e n t i o n ()(c h a r c h;w i n d o w (1,1,8 0,2 5);t e x t b a c k g r o u n d (l i g h t b l u e);t e x t c o l o r (y e l l o w).c l r s c r ();g o t o x y (1 5.2).p r i n t f (游戏操作规则:”);g o t o x y (1 5.4).p r i n t f (p l a y r u l e s ).g o t o x y (1 5.6).p r i n t f (1、按左右上下方向键移动棋子”);gotoxy(15.8).printf(1.press left,right,up,down key to move the piece);gotoxy(15.10).printf(2、按空格确定落棋子);gotoxy(15,12);printf(2.press space to place the piece);gotoxy(15,14);printf(3、禁止在棋盘外按空格);gotoxy(15,16);printf(3.do not press the space outside of the chessboard);gotoxy(15.18);printf(你是否接受上述的游戏规则(y/n);gotoxy(3.20).printf(do you accept the above playing rules?y/n:);w h i l e g o t o x y (6 0,2 0);C H =g e t c h e ();如 果(C H =Y|C H =Y)打破;如 果(C H =n|C H =n)(窗口(1,1,8 0,2 5);设置文本的背景颜色(黑色);文字颜色(浅灰色);c l r s c r ();出口(0);g o t o x y (5 1,1 2);p r i n t f (”);无效 draw box()(int XI,X2,Yl,Y2;setbkcolor(浅蓝色);设置颜色(黄色);gotoxy(7,2);printf(“左,右,上,下键移动,空间放,ES C退出。);为(xl=1 =1,Yl,Y2=18;XI =18;XI+)线(XI+JZ)*比 莉(Y1+JS)*比 莉(XI+JZ)*比 莉(Y2+JS)*BILD;为(xl=1,Yl=1,X2=18;Y1 =18;Y1+)线(XI+JZ)*比 莉(Y1+JS)*比 莉(x2+JZ)*比 莉(Y1+JS)*BILI);对 于(XI=1;XI =18;XI+)对 于(Y 1=1;Y 1 =18;Y 1+)盒 =0 xl y l;无效 d r a w _ c ir c l e(x,y,in t 的颜色)(设置颜色(颜色);set l i
展开阅读全文
温馨提示:
金锄头文库所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
相关搜索

当前位置:首页 > 商业/管理/HR > 营销创新


电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号