Ⅰ 求五子棋C源代码
这个是稍微好一点的了,以前没事试过
/*
五子棋
*/
#include<stdio.h>
#include<stdlib.h>
#include<graphics.h>
#include<bios.h>
#include<conio.h>
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b
#define SPACE 0x3920
#define BILI 20
#define JZ 4
#define JS 3
#define N 19
int box[N][N];
int step_x,step_y ;
int key ;
int flag=1 ;
void draw_box();
void draw_cicle(int x,int y,int color);
void change();
void judgewho(int x,int y);
void judgekey();
int judgeresult(int x,int y);
void attentoin();
void attention()
{
char ch ;
window(1,1,80,25);
textbackground(LIGHTBLUE);
textcolor(YELLOW);
clrscr();
gotoxy(15,2);
printf("游戏操作规则:");
gotoxy(15,4);
printf("Play Rules:");
gotoxy(15,6);
printf("1、按左右上下方向键移动棋子");
gotoxy(15,8);
printf("1. Press Left,Right,Up,Down Key to move 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 Space outside of the chessboard");
gotoxy(15,18);
printf("你是否接受上述的游戏规则(Y/N)");
gotoxy(15,20);
printf("Do you accept the above Playing Rules? [Y/N]:");
while(1)
{
gotoxy(60,20);
ch=getche();
if(ch=='Y'||ch=='y')
break ;
else if(ch=='N'||ch=='n')
{
window(1,1,80,25);
textbackground(BLACK);
textcolor(LIGHTGRAY);
clrscr();
exit(0);
}
gotoxy(51,12);
printf(" ");
}
}
void draw_box()
{
int x1,x2,y1,y2 ;
setbkcolor(LIGHTBLUE);
setcolor(YELLOW);
gotoxy(7,2);
printf("Left, Right, Up, Down KEY to move, Space to put, ESC-quit.");
for(x1=1,y1=1,y2=18;x1<=18;x1++)
line((x1+JZ)*BILI,(y1+JS)*BILI,(x1+JZ)*BILI,(y2+JS)*BILI);
for(x1=1,y1=1,x2=18;y1<=18;y1++)
line((x1+JZ)*BILI,(y1+JS)*BILI,(x2+JZ)*BILI,(y1+JS)*BILI);
for(x1=1;x1<=18;x1++)
for(y1=1;y1<=18;y1++)
box[x1][y1]=0 ;
}
void draw_circle(int x,int y,int color)
{
setcolor(color);
setlinestyle(SOLID_LINE,0,1);
x=(x+JZ)*BILI ;
y=(y+JS)*BILI ;
circle(x,y,8);
}
void judgekey()
{
int i ;
int j ;
switch(key)
{
case LEFT :
if(step_x-1<0)
break ;
else
{
for(i=step_x-1,j=step_y;i>=1;i--)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(i<1)break ;
step_x=i ;
judgewho(step_x,step_y);
break ;
}
case RIGHT :
if(step_x+1>18)
break ;
else
{
for(i=step_x+1,j=step_y;i<=18;i++)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(i>18)break ;
step_x=i ;
judgewho(step_x,step_y);
break ;
}
case DOWN :
if((step_y+1)>18)
break ;
else
{
for(i=step_x,j=step_y+1;j<=18;j++)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(j>18)break ;
step_y=j ;
judgewho(step_x,step_y);
break ;
}
case UP :
if((step_y-1)<0)
break ;
else
{
for(i=step_x,j=step_y-1;j>=1;j--)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(j<1)break ;
step_y=j ;
judgewho(step_x,step_y);
break ;
}
case ESC :
break ;
case SPACE :
if(step_x>=1&&step_x<=18&&step_y>=1&&step_y<=18)
{
if(box[step_x][step_y]==0)
{
box[step_x][step_y]=flag ;
if(judgeresult(step_x,step_y)==1)
{
sound(1000);
delay(1000);
nosound();
gotoxy(30,4);
if(flag==1)
{
setbkcolor(BLUE);
cleardevice();
setviewport(100,100,540,380,1);
/*定义一个图形窗口*/
setfillstyle(1,2);
/*绿色以实填充*/
setcolor(YELLOW);
rectangle(0,0,439,279);
floodfill(50,50,14);
setcolor(12);
settextstyle(1,0,5);
/*三重笔划字体, 水平放?5倍*/
outtextxy(20,20,"The White Win !");
setcolor(15);
settextstyle(3,0,5);
/*无衬笔划字体, 水平放大5倍*/
outtextxy(120,120,"The White Win !");
setcolor(14);
settextstyle(2,0,8);
getch();
closegraph();
exit(0);
}
if(flag==2)
{
setbkcolor(BLUE);
cleardevice();
setviewport(100,100,540,380,1);
/*定义一个图形窗口*/
setfillstyle(1,2);
/*绿色以实填充*/
setcolor(YELLOW);
rectangle(0,0,439,279);
floodfill(50,50,14);
setcolor(12);
settextstyle(1,0,8);
/*三重笔划字体, 水平放大8倍*/
outtextxy(20,20,"The Red Win !");
setcolor(15);
settextstyle(3,0,5);
/*无衬笔划字体, 水平放大5倍*/
outtextxy(120,120,"The Red Win !");
setcolor(14);
settextstyle(2,0,8);
getch();
closegraph();
exit(0);
}
}
change();
break ;
}
}
else
break ;
}
}
void change()
{
if(flag==1)
flag=2 ;
else
flag=1 ;
}
void judgewho(int x,int y)
{
if(flag==1)
draw_circle(x,y,15);
if(flag==2)
draw_circle(x,y,4);
}
int judgeresult(int x,int y)
{
int j,k,n1,n2 ;
while(1)
{
n1=0 ;
n2=0 ;
/*水平向左数*/
for(j=x,k=y;j>=1;j--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*水平向右数*/
for(j=x,k=y;j<=18;j++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}
/*垂直向上数*/
n1=0 ;
n2=0 ;
for(j=x,k=y;k>=1;k--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*垂直向下数*/
for(j=x,k=y;k<=18;k++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}
/*向左上方数*/
n1=0 ;
n2=0 ;
for(j=x,k=y;j>=1,k>=1;j--,k--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*向右下方数*/
for(j=x,k=y;j<=18,k<=18;j++,k++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}
/*向右上方数*/
n1=0 ;
n2=0 ;
for(j=x,k=y;j<=18,k>=1;j++,k--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*向左下方数*/
for(j=x,k=y;j>=1,k<=18;j--,k++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}
return(0);
break ;
}
}
void main()
{
int gdriver=VGA,gmode=VGAHI;
clrscr();
attention();
initgraph(&gdriver,&gmode,"c:\\tc");
/* setwritemode(XOR_PUT);*/
flag=1 ;
draw_box();
do
{
step_x=0 ;
step_y=0 ;
/*draw_circle(step_x,step_y,8); */
judgewho(step_x-1,step_y-1);
do
{
while(bioskey(1)==0);
key=bioskey(0);
judgekey();
}
while(key!=SPACE&&key!=ESC);
}
while(key!=ESC);
closegraph();
}
Ⅱ 求一个c++实现人机对战,人人对战的五子棋游戏源代码,急用,谢谢
五子棋范例的源程序:目录renju下的内容
程序在附件中,需要请免费下载
renju.dsw
renju.dsp
这两个是项目文件。包含整个项目的文件配置等信息
RESOURCE.H
renju.rc
这是整个工程中使用的Windows资源列表。包括置于res子目录下的图标,
位图以及光标等内容。
Renju.h
这是应用程序的主头文件。包含了通用于工程的其他头文件。以及
CRenjuApp类的声明。
renju.cpp
这是应用程序的主源程序。包含整个程序的入口点。CRenjuApp类的实现。
StdAfx.h
StdAfx.cpp
这对文件由用于将一些预编译信息纳入程序。编译后将产生stdafx.obj
define.h
这是一个包含程序中的数据表示的定义的头文件。
NewGame.h
NewGame.cpp
这一对文件定义并实现用于新游戏的设置的对话框。
renjuDlg.h
renjuDlg.cpp
这一对文件定义并实现了,五子棋的主界面。
Eveluation.h
Eveluation.cpp
这一对文件定义并实现了估值核心类。
MoveGenerator.h
MoveGenerator.cpp
这一对文件定义并实现了走法产生器。
SearchEngine.h
SearchEngine.cpp
这一对文件定义了搜索引擎接口。
HistoryHeuristic.h
HistoryHeuristic.cpp
这一对文件定义并实现历史启发类。
TranspositionTable.h
TranspositionTable.cpp
这一对文件定义并实现置换表类。
NegaScout_TT_HH.h
NegaScout_TT_HH.cpp
这一对文件定义并实现历史启发和置换表增强的NegaScout搜索引擎。
Directory of renju es
chess.rc2//资源文件
chess.ico//图标文件
若满意请及时采纳,谢谢
Ⅲ 找五子棋源代码c++
网上下载一个,再改改
Ⅳ 急求:五子棋的源代码(数据结构),每一步都要有解释的!!!
#include<iostream.h>#include<stdlib.h>#define Num 15//********************************************************//类class T//定义类用来封装所有相关函数和变量{ char board[Num][Num];//用数组board[Num][Num]来定义棋盘public: void PrintMenu(); //打印菜单 说明游戏规则和方法 void PrintBoard(); //打印棋盘 void GameStart(char*,int &,int &,char); //下棋 int whichwin(int,int,char); //判断那个选手赢 void Choice(char &); //是否再玩 void Setboard(); //重置棋盘};//****************************************************************//main主函数void main ()//主函数{ T s;//说明类的一个对象s s.PrintMenu();//通过s调用PrintMenu函数提示如何游戏 char player1[20],player2[20];//玩家姓名 int FirstWin=0,SecondWin=0,Draws=0,x,y,N;//说明变量,赋初值为0以待计算输赢结果 char choice='Y'; cin.ignore(20,'\n');//输入输出流,前面如果有输入把输入行所有字符取空,以便后面的输入从新的一行开始 cout<<"请输入第一个玩家姓名:"; cin.getline(player1,20);//连续读取数据 cout<<"请输入第二个玩家姓名:"; cin.getline(player2,20); while(choice=='Y'||choice=='y')//条件成立,执行 { s.Setboard();//调用Setboard函数 N=0; while(N<=(Num*Num)) { s.PrintBoard();//打印棋盘 s.GameStart(player1,x,y,'O'); N++;//记录已下棋子数 if(s.whichwin(x-1,y-1,'O'))//返回值不为0则条件成立 { s.PrintBoard(); cout<<player1<<"赢了。"<<endl; FirstWin++;//记录赢局数 break;//终止本次循环 } s.PrintBoard();//同上 s.GameStart(player2,x,y,'X'); N++; if(s.whichwin(x-1,y-1,'X')) { s.PrintBoard(); cout<<player2<<"赢了。"<<endl; SecondWin++; break; } if(N==(Num*Num)) { cout<<"和棋!"; Draws++;//记录平局数 break; } } s.Choice(choice);//给玩家提供一次选择是否再玩的机会 } //输出游戏输赢次数 cout<<player1<<"赢了"<<FirstWin<<"次"<<endl; cout<<player2<<"赢了"<<SecondWin<<"次"<<endl; cout<<"和"<<Draws<<"次"<<endl; cout<<"谢谢使用。"<<endl; cout<<"任意键继续。"<<endl; cin.get();//很必要的,目的是空度换行字符}//*******************************************************************//定义公有成员函数void T::PrintMenu(){ cout<<"欢迎进入五子棋游戏!\n"; cout<<"******************************************"<<endl; cout<<"\t游戏说明:"<<endl<<endl; cout<<"1.第一个玩家用O第二个玩家用X;"<<endl; cout<<"2.请根据提示输入所要走的行和列;"<<endl; cout<<"3.按<Enter>下棋。"<<endl; cout<<"
Ⅳ 求一个编写的五子棋小游戏python的代码,求借鉴啊!!急急急。。。
#五子棋importappuifw,e32,key_codes
fromgraphicsimport*defcn(x):returnx.decode('utf-8')
defquit():_quit=1
globalrunning
running=1
defredraw(rect):canvas.blit(img)defdefault():
globalcon,color,font
con={"l":15,"x":15,"y":33,"r":13,"n":15}
color={"bg":0x7777bb,"fg":0x333333,"p1":0x000000,"p2":0xffffff,"w":0xff0000}
font=u"SansMT936_S60"definitial():
globalimg,canvas,con,color,cur_x,cur_y,turn,pos1,pos2,pos
appuifw.app.screen='full'
appuifw.app.body=canvas=appuifw.Canvas()
img=Image.new((240,320))
img.clear(color["bg"])
cur_x=7
cur_y=7
turn=1
pos1=[]
pos2=[]
pos=[]
foriinrange(con["n"]*con["n"]):
pos.append(0)defpaint_back():
globalimg,color,font
#img.text((90,25),cn('欢乐五子棋'),color["fg"],font)
foriinrange(con["x"],con["x"]+con["l"]*con["n"]-1,con["l"]):
img.line((i,con["y"],i,con["y"]+con["l"]*(con["n"]-1)),color["fg"])
foriinrange(con["y"],con["y"]+con["l"]*con["n"]-1,con["l"]):
img.line((con["x"],i,con["x"]+con["l"]*(con["n"]-1),i),color["fg"])
img.text((40,270),cn('玩家1'),color["p1"],font)
img.text((160,270),cn('玩家2'),color["p2"],font)
img.point((90,263),color["p1"],width=con["r"],fill=color["p1"])
img.point((144,263),color["p2"],width=con["r"],fill=color["p2"])
defpaint_cur(x,y,sh):
globalimg,con,color,pos1,pos2,running
ifrunning<>1:return
ax=con["x"]+con["l"]*x
ay=con["y"]+con["l"]*y
b=con["l"]/2
ifsh<>0:
c=color["p"+str(sh)]
ifrp((x,y))<>0:
c=color["w"]
ifsh==0:
c=color["bg"]
img.line((ax-b,ay-2,ax-b,ay-b,ax-2,ay-b),c)
img.line((ax-b,ay+2,ax-b,ay+b,ax-2,ay+b),c)
img.line((ax+b,ay-2,ax+b,ay-b,ax+2,ay-b),c)
img.line((ax+b,ay+2,ax+b,ay+b,ax+2,ay+b),c)
redraw(())defpaint_q(x,y,z):
globalimg,con,color
ax=con["x"]+con["l"]*x
ay=con["y"]+con["l"]*y
b=con["l"]/2
ifz==0:
c=color["bg"]
else:
c=color["p"+str(z)]
img.point((ax,ay),c,width=con["r"],fill=c)
redraw(())
ifz==0:
img.line((ax-b,ay,ax+b,ay),c)
img.line((ax,ay-b,ax,ay+b),c)
defk_up():
globalcur_x,cur_y,con,turn
paint_cur(cur_x,cur_y,0)
cur_y=cur_y-1
ifcur_y==-1:
cur_y=con["n"]-1
paint_cur(cur_x,cur_y,turn)defk_down():
globalcur_x,cur_y,con,turn
paint_cur(cur_x,cur_y,0)
cur_y=cur_y+1
ifcur_y==con["n"]:
cur_y=0
paint_cur(cur_x,cur_y,turn)defk_left():
globalcur_x,cur_y,con,turn
paint_cur(cur_x,cur_y,0)
cur_x=cur_x-1
ifcur_x==-1:
cur_x=con["n"]-1
paint_cur(cur_x,cur_y,turn)defk_right():
globalcur_x,cur_y,con,turn
paint_cur(cur_x,cur_y,0)
cur_x=cur_x+1
ifcur_x==con["n"]:
cur_x=0
paint_cur(cur_x,cur_y,turn)defrp(x):
globalcon,pos
if(x[0]<0orx[0]>=con["n"]orx[1]<0orx[1]>=con["n"]):return0
#printx,pos[x[0]*con["n"]+x[1]]
returnpos[x[0]*con["n"]+x[1]]defwp(x,y):
globalcon,pos
pos[x[0]*con["n"]+x[1]]=y
defwin():
foriinpos1:
k=0
forjinrange(0,6):
ifrp((i[0]+j,i[1]))==1:
k=k+1
else:
break
ifk>=5:
return1
k=0
forjinrange(0,6):
ifrp((i[0],i[1]+j))==1:
k=k+1
else:
break
ifk>=5:
return1
k=0
forjinrange(0,6):
ifrp((i[0]+j,i[1]+j))==1:
k=k+1
else:
break
ifk>=5:
return1
k=0
forjinrange(0,6):
ifrp((i[0]+j,i[1]-j))==1:
k=k+1
else:
break
ifk>=5:
return1foriinpos2:
k=0
forjinrange(0,6):
ifrp((i[0]+j,i[1]))==2:
k=k+1
else:
break
ifk>=5:
return2
k=0
forjinrange(0,6):
ifrp((i[0],i[1]+j))==2:
k=k+1
else:
break
ifk>=5:
return2
k=0
forjinrange(0,6):
ifrp((i[0]+j,i[1]+j))==2:
k=k+1
else:
break
ifk>=5:
return2
k=0
forjinrange(0,6):
ifrp((i[0]+j,i[1]-j))==2:
k=k+1
else:
break
ifk>=5:
return2
return0
defk_enter():
globalcur_x,cur_y,turn,pos1,pos2,con,color,font,running
ifrunning<>1:return
ifrp((cur_x,cur_y))==0:
ifturn==1:
pos1.append((cur_x,cur_y))
img.rectangle((35,255,100,272),color["bg"])
img.rectangle((135,255,200,272),color["p2"])
ifturn==2:
pos2.append((cur_x,cur_y))
img.rectangle((35,255,100,272),color["p1"])
img.rectangle((135,255,200,272),color["bg"])
paint_q(cur_x,cur_y,turn)
wp((cur_x,cur_y),turn)
ifwin()<>0:
#img.text((80,300),cn('玩家')+str(turn)+cn("获胜!"),color["fg"],font)
img.rectangle((35,255,100,272),color["bg"])
img.rectangle((135,255,200,272),color["bg"])
paint_cur(cur_x,cur_y,0)
running=2
turn=3-turn
paint_cur(cur_x,cur_y,turn)defbindkey():
canvas.bind(key_codes.EKeyUpArrow,k_up)
canvas.bind(key_codes.EKeyDownArrow,k_down)
canvas.bind(key_codes.EKeyLeftArrow,k_left)
canvas.bind(key_codes.EKeyRightArrow,k_right)
canvas.bind(key_codes.EKeySelect,k_enter)default()
initial()
paint_back()
paint_cur(cur_x,cur_y,1)
img.rectangle((35,255,100,272),color["p1"])
bindkey()redraw(())
appuifw.app.exit_key_handler=quit()
_quit=0
while(1-_quit):
e32.ao_sleep(0.2)
redraw(())
Ⅵ 五子棋C语言代码
五子棋C语言代码如下:
#include <stdio.h>
#include <bios.h>
#include <ctype.h>
#include <conio.h>
#include <dos.h>
#define CROSSRU 0xbf /*右上角点*/
#define CROSSLU 0xda /*左上角点*/
#define CROSSLD 0xc0 /*左下角点*/
#define CROSSRD 0xd9 /*右下角点*/
#define CROSSL 0xc3 /*左边*/
#define CROSSR 0xb4 /*右边*/
#define CROSSU 0xc2 /*上边*/
#define CROSSD 0xc1 /*下边*/
#define CROSS 0xc5 /*十字交叉点*/
/*定义棋盘左上角点在屏幕上的位置*/
#define MAPXOFT 5
#define MAPYOFT 2
/*定义1号玩家的操作键键码*/
#define PLAY1UP 0x1157/*上移--'W'*/
#define PLAY1DOWN 0x1f53/*下移--'S'*/
#define PLAY1LEFT 0x1e41/*左移--'A'*/
#define PLAY1RIGHT 0x2044/*右移--'D'*/
#define PLAY1DO 0x3920/*落子--空格键*/
/*定义2号玩家的操作键键码*/
#define PLAY2UP 0x4800/*上移--方向键up*/
#define PLAY2DOWN 0x5000/*下移--方向键down*/
#define PLAY2LEFT 0x4b00/*左移--方向键left*/
#define PLAY2RIGHT 0x4d00/*右移--方向键right*/
#define PLAY2DO 0x1c0d/*落子--回车键Enter*/
/*若想在游戏中途退出, 可按 Esc 键*/
#define ESCAPE 0x011b
/*定义棋盘上交叉点的状态, 即该点有无棋子 */
/*若有棋子, 还应能指出是哪个玩家的棋子 */
#define CHESSNULL 0 /*没有棋子*/
#define CHESS1 'O'/*一号玩家的棋子*/
#define CHESS2 'X'/*二号玩家的棋子*/
/*定义按键类别*/
#define KEYEX99v 0/*退出键*/
#define KEYFALLCHESS 1/*落子键*/
#define KEYMOVECURSOR 2/*光标移动键*/
#define KEYINVALID 3/*无效键*/
/*定义符号常量: 真, 假 --- 真为1, 假为0 */
#define TRUE 1
#define FALSE 0
/**********************************************************/
/* 定义数据结构 */
/*棋盘交叉点坐标的数据结构*/
struct point
{
int x,y;
};
或者下面这个:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#define N 15
#define B 7
#define STOP -10000
#define OK 1
#define NO 0
#define UP 328
#define DOWN 336
#define LEFT 331
#define RIGHT 333
int a[N+1][N+1];
int zx,zy;
int write=1,biaoji=0;
struct zn{
long sum;
int y;
int x;
}w[N+1][N+1],max,max1;
void cbar(int i,int x,int y,int r);
void map(int a[][]);
int getkey();
int key();
void zuobiao(int x,int y,int i);
int tu(int a[][],int write);
int wtu(int a[][],int write);
int neng(int a[][]);
int zh5(int y,int x,int a[][]);
long zzh5(int b[][],int i);
main()
{
int i,j;
int gdriver=DETECT;
int gmode;
initgraph(&gdriver,&gmode,"");
zx=(N+1)/2;
zy=(N+1)/2;
for(i=1;i<=N;i++)
for(j=1;j<=N;j++)
a[i][j]=0;
map(a);
i=1;
while(i)
{
int k,n;
k=wtu(a,write);
if(k==STOP) goto end;
map(a);
n=neng(a);
if(n==STOP) goto end;
map(a);
}
end:
;
}
int neng(int a[N+1][N+1])
{
int i,j;
int k;
max.sum=-1;
for(i=0;i<=N;i++)
for(j=0;j<+N;j++)
{
w[i][j].sum=0;
w[i][j].x=i;
w[i][j].y=j;
}
for(i=1;i<=N-4;i++)
for(j=1;j<=N-4;j++)
{
k=zh5(i,j,a);
if(k==STOP) return (STOP);
}
for(i=1;i<=N;i++)
for(j=1;j<=N;j++)
{
if(max.sum<w[i][j].sum)
{
max.sum=w[i][j].sum;
max.y=i;
max.x=j;
}
else if(max.sum==w[i][j].sum)
{
if(((max.y-zy)*(max.y-zy)+(max.x-zx)*(max.x-zx))>((i-zy)*(i-zy)+(j-zx)*(j-zx)))
max.sum=w[i][j].sum;
max.y=i;
max.x=j;
}
}
if(a[max.y][max.x]==0)
{
a[max.y][max.x]=-1;
zy=max.y;
zx=max.x;
}
}
int zh5(int y,int x,int a[N+1][N+1])
{
int i,j;
int b[6][6];
long c[13];
long d[6][6];
long temp;
for(i=y;i<=y+4;i++)
for(j=x;j<=x+4;j++)
b[i+1-y][j+1-x]=a[i][j];
c[1]=b[1][1]+b[1][2]+b[1][3]+b[1][4]+b[1][5];
c[2]=b[2][1]+b[2][2]+b[2][3]+b[2][4]+b[2][5];
c[3]=b[3][1]+b[3][2]+b[3][3]+b[3][4]+b[3][5];
c[4]=b[4][1]+b[4][2]+b[4][3]+b[4][4]+b[4][5];
c[5]=b[5][1]+b[5][2]+b[5][3]+b[5][4]+b[5][5];
c[6]=b[1][1]+b[2][1]+b[3][1]+b[4][1]+b[5][1];
c[7]=b[1][2]+b[2][2]+b[3][2]+b[4][2]+b[5][2];
c[8]=b[1][3]+b[2][3]+b[3][3]+b[4][3]+b[5][3];
c[9]=b[1][4]+b[2][4]+b[3][4]+b[4][4]+b[5][4];
c[10]=b[1][5]+b[2][5]+b[3][5]+b[4][5]+b[5][5];
c[11]=b[1][1]+b[2][2]+b[3][3]+b[4][4]+b[5][5];
c[12]=b[1][5]+b[2][4]+b[3][3]+b[4][2]+b[5][1];
for(i=1;i<=12;i++)
{
switch(c[i])
{
case 5:biaoji=1;return(STOP);
case -5:biaoji=-1;return(STOP);
case -4:c[i]=100000;break;
case 4:c[i]=100000;break;
case -3:c[i]=150;break;
case 3:c[i]=150;break;
case -2:c[i]=120;break;
case 2:c[i]=100;break;
case -1:c[i]=1;break;
case 1:c[i]=1;break;
default: c[i]=0;
}
}
for(i=1;i<=12;i++)
{
if(c[i]==150)
c[i]+=zzh5(b,i);
}
for(i=1;i<=5;i++)
for(j=1;j<=5;j++)
d[i][j]=0;
for(i=1;i<=5;i++)
for(j=1;j<=5;j++)
{
if(i==j) d[i][j]+=c[11];
if((i+j)==6) d[i][j]+=c[12];
d[i][j]+=c[i]+c[j+5];
}
for(i=1;i<=5;i++)
for(j=1;j<=5;j++)
{
if(b[i][j]!=0)
d[i][j]=-2;
}
max1.sum=-1;
max1.y=0;
max1.x=0;
for(i=1;i<=5;i++)
for(j=1;j<=5;j++)
{
if(max1.sum<d[i][j])
{
max1.sum=d[i][j];
max1.y=i;
max1.x=j;
w[i+y-1][j+x-1].sum+=max1.sum;
}
else if(max1.sum==d[i][j])
{
if(((i+y-1-zy)*(i+y-1-zy)+(j+x-1-zx)*(j+x-1-zx))>((max1.y+y-1-zy)*(max1.y+y-1-zy)+(max1.x+x-1-zx)*(max1.x+x-1-zx)))
{
max1.sum=d[i][j];
max1.y=i;
max1.x=j;
}
}
}
}
long zzh5(int b[6][6],int n)
{
int i,j,k,l,m;
switch(n)
{
case 1:i=b[1][1];j=b[1][2];k=b[1][3];l=b[1][4];m=b[1][5];break;
case 2:i=b[2][1];j=b[2][2];k=b[2][3];l=b[2][4];m=b[2][5];break;
case 3:i=b[3][1];j=b[3][2];k=b[3][3];l=b[3][4];m=b[3][5];break;
case 4:i=b[4][1];j=b[4][2];k=b[4][3];l=b[4][4];m=b[4][5];break;
case 5:i=b[5][1];j=b[5][2];k=b[5][3];l=b[5][4];m=b[5][5];break;
case 6:i=b[1][1];j=b[2][1];k=b[3][1];l=b[4][1];m=b[5][1];break;
case 7:i=b[1][2];j=b[2][2];k=b[3][2];l=b[4][2];m=b[5][2];break;
case 8:i=b[1][3];j=b[2][3];k=b[3][3];l=b[4][3];m=b[5][3];break;
case 9:i=b[1][4];j=b[2][4];k=b[3][4];l=b[4][4];m=b[5][4];break;
case 10:i=b[1][5];j=b[2][5];k=b[3][5];l=b[4][5];m=b[5][5];break;
case 11:i=b[1][1];j=b[2][2];k=b[3][3];l=b[4][4];m=b[5][5];break;
case 12:i=b[1][5];j=b[2][4];k=b[3][3];l=b[4][2];m=b[5][1];break;
}
if((i==0&&j==1&&k==1&&l==1&&m==0))
return (900);
if((i==0&&j==-1&&k==-1&&l==-1&&m==0))
return(1000);
if((i==0&&j==0&&k==1&&l==1&&m==1)||(i==1&&j==1&&k==1&&l==0&&m==0))
return(20);
if((i==0&&j==0&&k==-1&&l==-1&&m==-1)||(i==-1&&j==-1&&k==-1&&l==0&&m==0))
return(20);
if((i==-1&&j==1&&k==1&&l==1&&m==1)||(i==1&&j==-1&&k==1&&l==1&&m==1)||(i==1&&j==1&&k==-1&&l==1&&m==1)||(i==1&&j==1&&k==1&&l==-1&&m==1)||(i==1&&j==1&&k==1&&l==1&&m==-1))
return(-60);
if((i==1&&j==-1&&k==-1&&l==-1&&m==-1)||(i==-1&&j==1&&k==-1&&l==-1&&m==-1)||(i==-1&&j==1&&k==-1&&l==-1&&m==-1)||(i==-1&&j==-1&&k==-1&&l==1&&m==-1)||(i==-1&&j==-1&&k==-1&&l==-1&&m==1))
return(-60);
}
int wtu(int a[N+1][N+1],int write)
{
int i=1;
map(a);
zuobiao(zx,zy,1);
while(i)
{
int k;
k=tu(a,write);
if(k==OK) i=0;
if(k==STOP) return (STOP);
}
}
int getkey()
{
int key,lo,hi;
key=bioskey(0);
lo=key&0x00ff;
hi=(key&0xff00)>>8;
return((lo==0) ? hi+256:lo);
}
int key()
{
int k;
k=getkey();
switch(k)
{
case 27: return (STOP);
case 13:
case ' ': return (OK);
case 328: return (UP);
case 336: return (DOWN);
case 331: return (LEFT);
case 333: return (RIGHT);
default: return (NO);
}
}
void zuobiao(int x,int y,int i)
{
int r;
if(i!=0)
{
setcolor(GREEN);
for(r=1;r<=5;r++)
circle(75+25*x,25+25*y,r);
}
else
{
if(a[zy][zx]==1)
{
setcolor(8);
for(r=1;r<=5;r++)
circle(75+25*x,25+25*y,r);
}
else if(a[zy][zx]==-1)
{
setcolor(WHITE);
for(r=1;r<=5;r++)
circle(75+25*x,25+25*y,r);
}
else
{
setcolor(B);
for(r=1;r<=5;r++)
circle(75+25*x,25+25*y,r);
setcolor(RED); line(75+25*zx-5,25+25*zy,75+25*x+5,25+25*zy);
line(75+25*zx,25+25*zy-5,75+25*zx,25+25*zy+5);
}
}
}
int tu(int a[N+1][N+1],int write)
{
int k;
re:
k=key();
if(k==OK)
{
if(a[zy][zx]==0)
{
a[zy][zx]=write;
}
else
goto re;
}
if(k==STOP) return(STOP);
if(k==NO) goto re;
if(k==UP)
{
int i,j;
if(zy==1) j=zy;
else j=zy-1;
zuobiao(zx,zy,0);
zuobiao(zx,j,1);
zy=j;
goto re;
}
if(k==DOWN)
{
int i,j;
if(zy==N) j=zy;
else j=zy+1;
zuobiao(zx,zy,0);
zuobiao(zx,j,1);
zy=j;
goto re;
}
if(k==LEFT)
{
int i,j;
if(zx==1) i=zx;
else i=zx-1;
zuobiao(zx,zy,0);
zuobiao(i,zy,1);
zx=i;
goto re;
}
if(k==RIGHT)
{
int i,j;
if(zx==N) i=zx;
else i=zx+1;
zuobiao(zx,zy,0);
zuobiao(i,zy,1);
zx=i;
goto re;
}
}
void cbar(int i,int x,int y,int r)
{
if(i!=0)
{
if(i==1)
setcolor(8);
else if(i==-1)
setcolor(WHITE);
for(i=1;i<=r;i++)
{
circle(x,y,i);
}
}
}
void map(int a[N+1][N+1])
{
int i,j;
cleardevice();
setbkcolor(B);
setcolor(RED);
for(i=0;i<N;i++)
{
line(100,50+25*i,75+N*25,50+25*i);
line(100+25*i,50,100+25*i,25+N*25);
}
for(i=1;i<=N;i++)
for(j=1;j<=N;j++)
cbar(a[i][j],75+25*j,25+25*i,10);
}
Ⅶ 求一个安卓开发小游戏源代码,临时交作业用
package com.fiveChess;
import android.app.Activity;
import android.os.Bundle;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;
public class MainActivity extends Activity {
GameView gameView = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
Display display = this.getWindowManager().getDefaultDisplay();
gameView = new GameView(this,display.getWidth(),display.getHeight());
setContentView(gameView);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add("重新开始").setIcon(android.R.drawable.ic_menu_myplaces);
menu.add("退出");
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getTitle().equals("重新开始")){
gameView.canPlay = true;
gameView.chess = new int[gameView.row][gameView.col];
gameView.invalidate();
}else if(item.getTitle().equals("退出")){
finish();
}
return super.onOptionsItemSelected(item);
}
}
package com.fiveChess;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.view.MotionEvent;
import android.view.View;
public class GameView extends View {
Context context = null;
int screenWidth,screenHeight;
String message = "";//提示轮到哪个玩家
int row,col; //划线的行数和列数
int stepLength = 30;//棋盘每格间距
int[][] chess = null;//0代表没有棋子,1代表是黑棋,2代表白旗
boolean isBlack = true;
boolean canPlay = true;
public GameView(Context context,int screenWidth,int screenHeight) {
super(context);
this.context = context;
this.screenWidth = screenWidth;
this.screenHeight = screenHeight;
this.message = "黑棋先行";
row = (screenHeight-50)/stepLength+1;
col = (screenWidth-10)/stepLength+1;
chess = new int[row][col];
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
paint.setColor(Color.WHITE);
canvas.drawRect(0, 0, screenWidth, screenHeight, paint);//画背景
paint.setColor(Color.BLUE);
paint.setTextSize(25);
canvas.drawText(message, (screenWidth-100)/2, 30, paint);//画最顶层的字
paint.setColor(Color.BLACK);
//画棋盘
for(int i=0;i<row;i++){
canvas.drawLine(10, 50+i*stepLength, 10+(col-1)*stepLength, 50+i*stepLength, paint);
}
for(int i=0;i<col;i++){
canvas.drawLine(10+i*stepLength,50,10+i*stepLength,50+(row-1)*stepLength, paint);
}
for(int r=0;r<row;r++){
for(int c=0;c<col;c++){
if(chess[r][c] == 1){
paint.setColor(Color.BLACK);
paint.setStyle(Style.FILL);
canvas.drawCircle(10+c*stepLength, 50+r*stepLength, 10, paint);
}else if(chess[r][c] == 2){
//画白棋
paint.setColor(Color.WHITE);
paint.setStyle(Style.FILL);
canvas.drawCircle(10+c*stepLength, 50+r*stepLength, 10, paint);
paint.setColor(Color.BLACK);
paint.setStyle(Style.STROKE);
canvas.drawCircle(10+c*stepLength, 50+r*stepLength, 10, paint);
}
}
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if(!canPlay){return false;}
float x = event.getX();
float y = event.getY();
int r = Math.round((y-50)/stepLength);
int c = Math.round((x-10)/stepLength);
if(r<0 || r>row-1 || c<0 || c>col-1){return false;}
if(chess[r][c]!=0){return false;}//若有棋子则不再画棋子了
if(isBlack){
chess[r][c] = 1;
isBlack = false;
message = "轮到白棋";
}else{
chess[r][c] = 2;
isBlack = true;
message = "轮到黑棋";
}
invalidate();
if(judge(r, c,0,1)) return false;
if(judge(r, c,1,0)) return false ;
if(judge(r, c,1,1)) return false;
if(judge(r, c,1,-1)) return false;
return super.onTouchEvent(event);
}
private boolean judge(int r, int c,int x,int y) {//r,c表示行和列,x表示在y方向上的偏移,y表示在x方向上的偏移
int count = 1;
int a = r;
int b = c;
while(r>=0 && r<row && c>=0 && c<col && r+x>=0 && r+x<row && c+y>=0 && c+y<col && chess[r][c] == chess[r+x][c+y]){
count++;
if(y>0){
c++;
}else if(y<0){
c--;
}
if(x>0){
r++;
}else if(x<0){
r--;
}
}
while(a>=0 && a<row && b>=0 && b<col && a-x>=0 && a-x<row && b-y>=0 && b-y<col && chess[a][b] == chess[a-x][b-y]){
count++;
if(y>0){
b--;
}else if(y<0){
b++;
}
if(x>0){
a--;
}else if(x<0){
a++;
}
}
if(count>=5){
String str = "";
if(isBlack){
str = "白棋胜利";
}else{
str = "黑棋胜利";
}
new AlertDialog.Builder(context).setTitle("游戏结束").setMessage(str).setPositiveButton("重新开始", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
chess = new int[row][col];
invalidate();
}
}).setNegativeButton("观看棋局", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
canPlay = false;
}
}).show();
return true;
}
return false;
}
}
PS:五子棋,无需图片,直接在程序里画出来的。注意我发的是两个文件,一个activity,一个类文件,别把它当成一个文件了
Ⅷ 跪求C++五子棋程序源代码
#include "iostream"
#include <iomanip>
using namespace std;
const int M=20;
const int N=20;
int main()
{
char wei[M][N];
int k,i,j,x,y,flag=0;
cout<<"欢迎使用简易双人对战五子棋游戏"<<endl;
cout<<"五子棋棋谱如下:"<<endl;
for(k=0;k<=N;k++)
cout<<setw(3)<<setfill(' ')<<k;
cout<<endl;
for(i=1;i<=M;i++)
{
cout<<setw(3)<<setfill(' ')<<i;
for(j=1;j<=N;j++)
{
wei[i][j]='-';
cout<<setw(3)<<setfill(' ')<<wei[i][j];
}
cout<<endl;
}
while(flag==0)
{
//红方落子
cout<<"请红方输入落子位置:"<<endl;
loop1:
cout<<"请输入落子的行数:";
cin>>x;
cout<<"请输入落子的列数:";
cin>>y;
if(wei[x][y]=='-')
{
wei[x][y]='*';
for(k=0;k<=N;k++)
cout<<setw(3)<<setfill(' ')<<k;
cout<<endl;
for(i=1;i<=M;i++)
{
cout<<setw(3)<<setfill(' ')<<i;
for(j=1;j<=N;j++)
cout<<setw(3)<<setfill(' ')<<wei[i][j];
cout<<endl;
}
}
else
{
cout<<"你不能在这落子,请重新选择落子位置:"<<endl;
goto loop1;
}
//判断胜利
for(i=1;i<=M-4;i++)
{
for(j=1;j<=N-4;j++)
{
if(wei[i][j]=='*' && wei[i][j+1]=='*' && wei[i][j+2]=='*' && wei[i][j+3]=='*' && wei[i][j+4]=='*')
{
cout<<"恭喜红方获得简易双人对战五子棋的胜利!耶~~~"<<endl;
flag=1;
break;
}
if(wei[i][j]=='*' && wei[i+1][j]=='*' && wei[i+2][j]=='*' && wei[i+3][j]=='*' && wei[i+4][j]=='*')
{
cout<<"恭喜红方获得简易双人对战五子棋的胜利!耶~~~"<<endl;
flag=1;
break;
}
if(wei[i][j]=='*' && wei[i+1][j+1]=='*' && wei[i+2][j+2]=='*' && wei[i+3][j+3]=='*' && wei[i+4][j+4]=='*')
{
cout<<"恭喜红方获得简易双人对战五子棋的胜利!耶~~~"<<endl;
flag=1;
break;
}
if(flag==1)
break;
}
}
//蓝方落子
cout<<"请蓝方输入落子位置:"<<endl;
loop2:
cout<<"请输入落子的行数:";
cin>>x;
cout<<"请输入落子的列数:";
cin>>y;
if(wei[x][y]=='-')
{
wei[x][y]='#';
for(k=0;k<=N;k++)
cout<<setw(3)<<setfill(' ')<<k;
cout<<endl;
for(i=1;i<=M;i++)
{
cout<<setw(3)<<setfill(' ')<<i;
for(j=1;j<=N;j++)
cout<<setw(3)<<setfill(' ')<<wei[i][j];
cout<<endl;
}
}
else
{
cout<<"你不能在这落子,请重新选择落子位置:";
goto loop2;
}
//判断胜利
for(i=1;i<=M-4;i++)
{
for(j=1;j<=N-4;j++)
{
if(wei[i][j]=='#' && wei[i][j+1]=='#' && wei[i][j+2]=='#' && wei[i][j+3]=='#' && wei[i][j+4]=='#')
{
cout<<"恭喜蓝方获得简易双人对战五子棋的胜利!耶~~~"<<endl;
flag=1;
break;
}
if(wei[i][j]=='#' && wei[i+1][j]=='#' && wei[i+2][j]=='#' && wei[i+3][j]=='#' && wei[i+4][j]=='#')
{
cout<<"恭喜蓝方获得简易双人对战五子棋的胜利!耶~~~"<<endl;
flag=1;
break;
}
if(wei[i][j]=='#' && wei[i+1][j+1]=='#' && wei[i+2][j+2]=='#' && wei[i+3][j+3]=='#' && wei[i+4][j+4]=='#')
{
cout<<"恭喜蓝方获得简易双人对战五子棋的胜利!耶~~~"<<endl;
flag=1;
break;
}
if(flag==1)
break;
}
}
}
return 0;
}
二人对弈五子棋游戏,棋子分为黑白两种;当同一种颜色的棋子实现五子连珠时即为获胜;通过按下棋盘上的状态键,用以标示该黑子落子还是白子落子;
运行成功;你可以在这基础上修改一下
Ⅸ 急求五子棋源代码
/*
五子棋
*/
#include<stdio.h>
#include<stdlib.h>
#include<graphics.h>
#include<bios.h>
#include<conio.h>
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b
#define SPACE 0x3920
#define BILI 20
#define JZ 4
#define JS 3
#define N 19
int box[N][N];
int step_x,step_y ;
int key ;
int flag=1 ;
void draw_box();
void draw_cicle(int x,int y,int color);
void change();
void judgewho(int x,int y);
void judgekey();
int judgeresult(int x,int y);
void attentoin();
void attention()
{
char ch ;
window(1,1,80,25);
textbackground(LIGHTBLUE);
textcolor(YELLOW);
clrscr();
gotoxy(15,2);
printf("游戏操作规则:");
gotoxy(15,4);
printf("Play Rules:");
gotoxy(15,6);
printf("1、按左右上下方向键移动棋子");
gotoxy(15,8);
printf("1. Press Left,Right,Up,Down Key to move 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 Space outside of the chessboard");
gotoxy(15,18);
printf("你是否接受上述的游戏规则(Y/N)");
gotoxy(15,20);
printf("Do you accept the above Playing Rules? [Y/N]:");
while(1)
{
gotoxy(60,20);
ch=getche();
if(ch=='Y'||ch=='y')
break ;
else if(ch=='N'||ch=='n')
{
window(1,1,80,25);
textbackground(BLACK);
textcolor(LIGHTGRAY);
clrscr();
exit(0);
}
gotoxy(51,12);
printf(" ");
}
}
void draw_box()
{
int x1,x2,y1,y2 ;
setbkcolor(LIGHTBLUE);
setcolor(YELLOW);
gotoxy(7,2);
printf("Left, Right, Up, Down KEY to move, Space to put, ESC-quit.");
for(x1=1,y1=1,y2=18;x1<=18;x1++)
line((x1+JZ)*BILI,(y1+JS)*BILI,(x1+JZ)*BILI,(y2+JS)*BILI);
for(x1=1,y1=1,x2=18;y1<=18;y1++)
line((x1+JZ)*BILI,(y1+JS)*BILI,(x2+JZ)*BILI,(y1+JS)*BILI);
for(x1=1;x1<=18;x1++)
for(y1=1;y1<=18;y1++)
box[x1][y1]=0 ;
}
void draw_circle(int x,int y,int color)
{
setcolor(color);
setlinestyle(SOLID_LINE,0,1);
x=(x+JZ)*BILI ;
y=(y+JS)*BILI ;
circle(x,y,8);
}
void judgekey()
{
int i ;
int j ;
switch(key)
{
case LEFT :
if(step_x-1<0)
break ;
else
{
for(i=step_x-1,j=step_y;i>=1;i--)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(i<1)break ;
step_x=i ;
judgewho(step_x,step_y);
break ;
}
case RIGHT :
if(step_x+1>18)
break ;
else
{
for(i=step_x+1,j=step_y;i<=18;i++)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(i>18)break ;
step_x=i ;
judgewho(step_x,step_y);
break ;
}
case DOWN :
if((step_y+1)>18)
break ;
else
{
for(i=step_x,j=step_y+1;j<=18;j++)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(j>18)break ;
step_y=j ;
judgewho(step_x,step_y);
break ;
}
case UP :
if((step_y-1)<0)
break ;
else
{
for(i=step_x,j=step_y-1;j>=1;j--)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(j<1)break ;
step_y=j ;
judgewho(step_x,step_y);
break ;
}
case ESC :
break ;
case SPACE :
if(step_x>=1&&step_x<=18&&step_y>=1&&step_y<=18)
{
if(box[step_x][step_y]==0)
{
box[step_x][step_y]=flag ;
if(judgeresult(step_x,step_y)==1)
{
sound(1000);
delay(1000);
nosound();
gotoxy(30,4);
if(flag==1)
{
setbkcolor(BLUE);
cleardevice();
setviewport(100,100,540,380,1);
/*定义一个图形窗口*/
setfillstyle(1,2);
/*绿色以实填充*/
setcolor(YELLOW);
rectangle(0,0,439,279);
floodfill(50,50,14);
setcolor(12);
settextstyle(1,0,5);
/*三重笔划字体, 水平放?5倍*/
outtextxy(20,20,"The White Win !");
setcolor(15);
settextstyle(3,0,5);
/*无衬笔划字体, 水平放大5倍*/
outtextxy(120,120,"The White Win !");
setcolor(14);
settextstyle(2,0,8);
getch();
closegraph();
exit(0);
}
if(flag==2)
{
setbkcolor(BLUE);
cleardevice();
setviewport(100,100,540,380,1);
/*定义一个图形窗口*/
setfillstyle(1,2);
/*绿色以实填充*/
setcolor(YELLOW);
rectangle(0,0,439,279);
floodfill(50,50,14);
setcolor(12);
settextstyle(1,0,8);
/*三重笔划字体, 水平放大8倍*/
outtextxy(20,20,"The Red Win !");
setcolor(15);
settextstyle(3,0,5);
/*无衬笔划字体, 水平放大5倍*/
outtextxy(120,120,"The Red Win !");
setcolor(14);
settextstyle(2,0,8);
getch();
closegraph();
exit(0);
}
}
change();
break ;
}
}
else
break ;
}
}
void change()
{
if(flag==1)
flag=2 ;
else
flag=1 ;
}
void judgewho(int x,int y)
{
if(flag==1)
draw_circle(x,y,15);
if(flag==2)
draw_circle(x,y,4);
}
int judgeresult(int x,int y)
{
int j,k,n1,n2 ;
while(1)
{
n1=0 ;
n2=0 ;
/*水平向左数*/
for(j=x,k=y;j>=1;j--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*水平向右数*/
for(j=x,k=y;j<=18;j++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}
/*垂直向上数*/
n1=0 ;
n2=0 ;
for(j=x,k=y;k>=1;k--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*垂直向下数*/
for(j=x,k=y;k<=18;k++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}
/*向左上方数*/
n1=0 ;
n2=0 ;
for(j=x,k=y;j>=1,k>=1;j--,k--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*向右下方数*/
for(j=x,k=y;j<=18,k<=18;j++,k++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}
/*向右上方数*/
n1=0 ;
n2=0 ;
for(j=x,k=y;j<=18,k>=1;j++,k--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*向左下方数*/
for(j=x,k=y;j>=1,k<=18;j--,k++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}
return(0);
break ;
}
}
void main()
{
int gdriver=VGA,gmode=VGAHI;
clrscr();
attention();
initgraph(&gdriver,&gmode,"c:\\tc");
/* setwritemode(XOR_PUT);*/
flag=1 ;
draw_box();
do
{
step_x=0 ;
step_y=0 ;
/*draw_circle(step_x,step_y,8); */
judgewho(step_x-1,step_y-1);
do
{
while(bioskey(1)==0);
key=bioskey(0);
judgekey();
}
while(key!=SPACE&&key!=ESC);
}
while(key!=ESC);
closegraph();
}