当前位置:首页 > 代码 > 正文

制作五子棋的代码(五子棋游戏算法代码)

admin 发布:2022-12-19 23:58 134


今天给各位分享制作五子棋的代码的知识,其中也会对五子棋游戏算法代码进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

找五子棋源代码c++

#include "iostream"

#include iomanip

using namespace std;

const int M=20;

const int N=20;

int main()

{

char weizhi[M][N];

int k,i,j,x,y,flag=0;

cout"欢迎使用简易双人对战五子棋游戏"endl;

cout"五子棋棋谱如下:"endl;

for(k=0;k=N;k++)

coutsetw(3)setfill(' ')k;

coutendl;

for(i=1;i=M;i++)

{

coutsetw(3)setfill(' ')i;

for(j=1;j=N;j++)

{

weizhi[i][j]='-';

coutsetw(3)setfill(' ')weizhi[i][j];

}

coutendl;

}

while(flag==0)

{

//红方落子

cout"请红方输入落子位置:"endl;

loop1:

cout"请输入落子的行数:";

cinx;

cout"请输入落子的列数:";

ciny;

if(weizhi[x][y]=='-')

{

weizhi[x][y]='*';

for(k=0;k=N;k++)

coutsetw(3)setfill(' ')k;

coutendl;

for(i=1;i=M;i++)

{

coutsetw(3)setfill(' ')i;

for(j=1;j=N;j++)

coutsetw(3)setfill(' ')weizhi[i][j];

coutendl;

}

}

else

{

cout"你不能在这落子,请重新选择落子位置:"endl;

goto loop1;

}

//判断胜利

for(i=1;i=M-4;i++)

{

for(j=1;j=N-4;j++)

{

if(weizhi[i][j]=='*' weizhi[i][j+1]=='*' weizhi[i][j+2]=='*' weizhi[i][j+3]=='*' weizhi[i][j+4]=='*')

{

cout"恭喜红方获得简易双人对战五子棋的胜利!耶~~~"endl;

flag=1;

break;

}

if(weizhi[i][j]=='*' weizhi[i+1][j]=='*' weizhi[i+2][j]=='*' weizhi[i+3][j]=='*' weizhi[i+4][j]=='*')

{

cout"恭喜红方获得简易双人对战五子棋的胜利!耶~~~"endl;

flag=1;

break;

}

if(weizhi[i][j]=='*' weizhi[i+1][j+1]=='*' weizhi[i+2][j+2]=='*' weizhi[i+3][j+3]=='*' weizhi[i+4][j+4]=='*')

{

cout"恭喜红方获得简易双人对战五子棋的胜利!耶~~~"endl;

flag=1;

break;

}

if(flag==1)

break;

}

}

//蓝方落子

cout"请蓝方输入落子位置:"endl;

loop2:

cout"请输入落子的行数:";

cinx;

cout"请输入落子的列数:";

ciny;

if(weizhi[x][y]=='-')

{

weizhi[x][y]='#';

for(k=0;k=N;k++)

coutsetw(3)setfill(' ')k;

coutendl;

for(i=1;i=M;i++)

{

coutsetw(3)setfill(' ')i;

for(j=1;j=N;j++)

coutsetw(3)setfill(' ')weizhi[i][j];

coutendl;

}

}

else

{

cout"你不能在这落子,请重新选择落子位置:";

goto loop2;

}

//判断胜利

for(i=1;i=M-4;i++)

{

for(j=1;j=N-4;j++)

{

if(weizhi[i][j]=='#' weizhi[i][j+1]=='#' weizhi[i][j+2]=='#' weizhi[i][j+3]=='#' weizhi[i][j+4]=='#')

{

cout"恭喜蓝方获得简易双人对战五子棋的胜利!耶~~~"endl;

flag=1;

break;

}

if(weizhi[i][j]=='#' weizhi[i+1][j]=='#' weizhi[i+2][j]=='#' weizhi[i+3][j]=='#' weizhi[i+4][j]=='#')

{

cout"恭喜蓝方获得简易双人对战五子棋的胜利!耶~~~"endl;

flag=1;

break;

}

if(weizhi[i][j]=='#' weizhi[i+1][j+1]=='#' weizhi[i+2][j+2]=='#' weizhi[i+3][j+3]=='#' weizhi[i+4][j+4]=='#')

{

cout"恭喜蓝方获得简易双人对战五子棋的胜利!耶~~~"endl;

flag=1;

break;

}

if(flag==1)

break;

}

}

}

return 0;

}

我运行过,没有错误.

求一个编写的五子棋小游戏python的代码,求借鉴啊!!急急急。。。

#五子棋import appuifw,e32,key_codes

from graphics import *def cn(x):return x.decode('utf-8')

def quit(): _quit=1

global running

running=1

def redraw(rect): canvas.blit(img)def default():

 global con,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"Sans MT 936_S60"def initial():

 global img,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=[]

 for i in range(con["n"]*con["n"]):

  pos.append(0)def paint_back():

 global img,color,font

 #img.text((90,25),cn('欢乐五子棋'),color["fg"],font)

 for i in range(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"])

 for i in range(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"])

 

def paint_cur(x,y,sh):

 global img,con,color,pos1,pos2,running

 if running1:return

 ax=con["x"]+con["l"]*x

 ay=con["y"]+con["l"]*y

 b=con["l"]/2

 if sh0:

  c=color["p"+str(sh)]

  if rp((x,y))0:

   c=color["w"]

 if sh==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(())def paint_q(x,y,z):

 global img,con,color

 ax=con["x"]+con["l"]*x

 ay=con["y"]+con["l"]*y

 b=con["l"]/2

 if z==0:

  c=color["bg"]

 else:

  c=color["p"+str(z)]

 img.point((ax,ay),c,width=con["r"],fill=c)

 redraw(())

 if z==0:

  img.line((ax-b,ay,ax+b,ay),c)

  img.line((ax,ay-b,ax,ay+b),c)

  

def k_up():

 global cur_x,cur_y,con,turn

 paint_cur(cur_x,cur_y,0)

 cur_y=cur_y-1

 if cur_y==-1:

  cur_y=con["n"]-1

 paint_cur(cur_x,cur_y,turn)def k_down():

 global cur_x,cur_y,con,turn

 paint_cur(cur_x,cur_y,0)

 cur_y=cur_y+1

 if cur_y==con["n"]:

  cur_y=0

 paint_cur(cur_x,cur_y,turn)def k_left():

 global cur_x,cur_y,con,turn

 paint_cur(cur_x,cur_y,0)

 cur_x=cur_x-1

 if cur_x==-1:

  cur_x=con["n"]-1

 paint_cur(cur_x,cur_y,turn)def k_right():

 global cur_x,cur_y,con,turn

 paint_cur(cur_x,cur_y,0)

 cur_x=cur_x+1

 if cur_x==con["n"]:

  cur_x=0

 paint_cur(cur_x,cur_y,turn)def rp(x):

 global con,pos

 if (x[0]0 or x[0]=con["n"] or x[1]0 or x[1]=con["n"]):return 0

 #print x,pos[x[0]*con["n"]+x[1]]

 return pos[x[0]*con["n"]+x[1]]def wp(x,y):

 global con,pos

 pos[x[0]*con["n"]+x[1]]=y

  

def win():

 for i in pos1:

  k=0

  for j in range(0,6):

   if rp((i[0]+j,i[1]))==1:

    k=k+1

   else:

    break

  if k=5:

   return 1

  k=0

  for j in range(0,6):

   if rp((i[0],i[1]+j))==1:

    k=k+1

   else:

    break

  if k=5:

   return 1

  k=0

  for j in range(0,6):

   if rp((i[0]+j,i[1]+j))==1:

    k=k+1

   else:

    break

  if k=5:

   return 1

  k=0

  for j in range(0,6):

   if rp((i[0]+j,i[1]-j))==1:

    k=k+1

   else:

    break

  if k=5:

   return 1 for i in pos2:

  k=0

  for j in range(0,6):

   if rp((i[0]+j,i[1]))==2:

    k=k+1

   else:

    break

  if k=5:

   return 2

  k=0

  for j in range(0,6):

   if rp((i[0],i[1]+j))==2:

    k=k+1

   else:

    break

  if k=5:

   return 2

  k=0

  for j in range(0,6):

   if rp((i[0]+j,i[1]+j))==2:

    k=k+1

   else:

    break

  if k=5:

   return 2

  k=0

  for j in range(0,6):

   if rp((i[0]+j,i[1]-j))==2:

    k=k+1

   else:

    break

  if k=5:

   return 2

 return 0

 

def k_enter():

 global cur_x,cur_y,turn,pos1,pos2,con,color,font,running

 if running1:return

 if rp((cur_x,cur_y))==0:

  if turn==1:

   pos1.append((cur_x,cur_y))

   img.rectangle((35,255,100,272),color["bg"])

   img.rectangle((135,255,200,272),color["p2"])

  if turn==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)

  if win()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)def bindkey():

 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(())

跪求 五子棋vb代码

代码如下:

Option Explicit

Const SubWidth = 400 '定义画五子棋表格的每格长度和宽度

Private P2PlayColor As Integer '实现黑白棋子的交替进行

Private MyColor As Integer '标记黑白双方棋子颜色

Private IfSucceed As Boolean '表示是否胜利

Const pi = 3.14159 '定义字符常量pi=3.14159

Private centerx As Single

Private centery As Single

Private radius As Single

Private DataArray(14, 14) As Integer '保存棋盘中棋子的位置信息(空子=3 黑棋=1 白棋=0)

Private sumtime As Integer '记录总时间来判断谁超时

Private ifStarteasy As Boolean '标记简单难度下计时功能是否可以开启 (ifStarteasy=true时 每落子一次计时开启一次)

Private ifStartnormal As Boolean '标记中等难度下计时功能是否可以开启 (ifStartnormal=true时 每落子一次计时开启一次)

Private ifStarthard As Boolean '标记困难难度下计时功能是否可以开启 (ifStarthard=true时 每落子一次计时开启一次)

'单击命令按钮"退出"退出

Private Sub CmdExit_Click()

End

End Sub

Private Sub CmdStart_Click()

Dim i As Integer

Dim m As Integer

Dim n As Integer

'绘制棋盘

PicQiPan.Cls

PicQiPan.ForeColor = vbBlack

For i = 1 To 14

PicQiPan.Line (SubWidth, SubWidth * i)-(SubWidth * 14, _

SubWidth * i)

PicQiPan.Line (SubWidth * i, SubWidth)-(SubWidth * i, _

SubWidth * 14)

Next i

'棋盘落点信息初始化

For m = 0 To 14

For n = 0 To 14

DataArray(m, n) = 3

Next n

Next m

'主要标记信息初始化

P2PlayColor = 0

MyColor = 0

IfSucceed = False

ifStarteasy = False

ifStartnormal = False

ifStarthard = False

Timer2.Enabled = False

Timer3.Enabled = False

Timer4.Enabled = False

FrmMain.Cls

sumtime = -1

End Sub

'简单难度

Private Sub fileeasy_Click()

ifStarteasy = True

sumtime = -1

MsgBox "双方下每步棋的思考时间最多20秒,否则超时清盘"

End Sub

'通过文件"退出"退出

Private Sub fileexit_Click()

End

End Sub

'困难难度

Private Sub filehard_Click()

ifStarthard = True

sumtime = -1

MsgBox "双方下每步棋的思考时间最多5秒,否则超时清盘"

End Sub

'中等难度

Private Sub filenormal_Click()

ifStartnormal = True

sumtime = -1

FrmMain.Cls

MsgBox "双方下每步棋的思考时间最多10秒,否则超时清盘"

End Sub

'通过文件"重新开始"实现棋盘初始化

Private Sub filerestart_Click()

Call CmdStart_Click

End Sub

Private Sub Form_Load()

Dim i As Integer

Dim m As Integer

Dim n As Integer

'绘制棋盘

PicQiPan.Cls

PicQiPan.ForeColor = vbBlack

For i = 1 To 14

PicQiPan.Line (SubWidth, SubWidth * i)-(SubWidth * 14, _

SubWidth * i)

PicQiPan.Line (SubWidth * i, SubWidth)-(SubWidth * i, _

SubWidth * 14)

Next i

'棋盘落点信息初始化

For m = 0 To 14

For n = 0 To 14

DataArray(m, n) = 3

Next n

Next m

Print

'确定表针位置的基本参量

centerx = Pictime.Width / 2

centery = Pictime.Height / 2

radius = Pictime.Height / 2 * 0.9

Pictime.PSet (centerx, centery)

Pictime.Circle (centerx, centery), radius

End Sub

'棋子落点判断(出界和重子情况)

Private Sub PicQipan_MouseDown(Button As Integer, Shift As Integer, X As Single, y As Single)

Dim x0 As Integer

Dim y0 As Integer

Dim i As Integer

Dim j As Integer

If X SubWidth Or X 14.5 * SubWidth Or y SubWidth Or y 14.5 * SubWidth Then

MsgBox "超出棋盘界限,请重新下!"

Exit Sub

End If

If Abs(Int(X / SubWidth) - X / SubWidth) 0.5 Then

x0 = Int(X / SubWidth)

Else

x0 = Int(X / SubWidth) + 1

End If

If Abs(Int(y / SubWidth) - y / SubWidth) 0.5 Then

y0 = Int(y / SubWidth)

Else

y0 = Int(y / SubWidth) + 1

End If

If DataArray(x0, y0) 3 Then

'当前位置已经有棋子了,

MsgBox "当前位置已经有棋子了,请重新走!", vbCritical, "NOTE!"

Exit Sub

End If

sumtime = -1

Call DrawPill(x0, y0) '画棋子

Call RemenberCrossData(x0, y0) '记录棋子信息

Call WhoWin '判断谁赢

'判断是否开启相应难度计时功能

If ifStarteasy = True Then

Timer2.Enabled = True

End If

If ifStartnormal = True Then

Timer3.Enabled = True

End If

If ifStarthard = True Then

Timer4.Enabled = True

End If

End Sub

'画棋子

Private Sub DrawPill(xx0 As Integer, yy0 As Integer)

If P2PlayColor Then

PicQiPan.ForeColor = vbWhite

DoEvents

PicQiPan.FillColor = vbWhite

PicQiPan.FillStyle = 0

MyColor = 0

Else

PicQiPan.ForeColor = vbBlack

DoEvents

PicQiPan.FillColor = vbBlack

PicQiPan.FillStyle = 0

MyColor = 1

End If

P2PlayColor = Not P2PlayColor

PicQiPan.Circle (xx0 * SubWidth, yy0 * SubWidth), SubWidth * 0.5

End Sub

'以下A B C 三个事件共同实现下棋的同时听音乐功能

'A

Private Sub Dir1_Change()

File1.Path = Dir1.Path

End Sub

'B

Private Sub Drv_Change()

Dir1.Path = Drv.Drive

End Sub

'C

Private Sub File1_Click()

mp3.URL = File1.Path "\" File1.FileName

End Sub

'棋盘皮肤

Private Sub qipanstylefurA_Click()

PicQiPan.BackColor = HC0FFFF

Call CmdStart_Click

End Sub

Private Sub qipanstylefurB_Click()

PicQiPan.BackColor = HC0C000

Call CmdStart_Click

End Sub

Private Sub qipanstylefurC_Click()

PicQiPan.BackColor = HE0E0E0

Call CmdStart_Click

End Sub

Private Sub qipanstylefurD_Click()

PicQiPan.BackColor = H8080FF

Call CmdStart_Click

End Sub

'添加四种背景音乐

Private Sub stylemusicA_Click()

mp3.URL = App.Path "\" "music01.mp3"

End Sub

Private Sub stylemusicB_Click()

mp3.URL = App.Path "\" "music02.mp3"

End Sub

Private Sub stylemusicC_Click()

mp3.URL = App.Path "\" "music03.mp3"

End Sub

Private Sub stylemusicD_Click()

mp3.URL = App.Path "\" "music04.mp3"

End Sub

'表针走动 Timer1.Enabled=true在属性框中设定

Private Sub Timer1_Timer()

Dim s As Integer

Dim m As Integer

Dim h As Integer

Dim sngLenS As Single

Dim sngLenM As Single

Dim sngLenH As Single

Dim i As Integer

'调试几次并查询VB常用函数,最后确定应该使用Now 而不是Time(不过之前使用Time确实可以)

s = Second(Now)

m = Minute(Now)

h = Hour(Now) + m / 60

sngLenS = radius * 0.8

sngLenM = radius * 0.6

sngLenH = radius * 0.4

Pictime.Cls

Pictime.Scale (-centerx, centery)-(centerx, -centery)

Pictime.Line (0, 0)-(sngLenS * Sin(2 * pi * s / 60), sngLenS * Cos(2 * pi * s / 60)), vbGreen

Pictime.Line (0, 0)-(sngLenM * Sin(2 * pi * m / 60), sngLenM * Cos(2 * pi * m / 60)), vbGreen

If h 12 Then

h = h - 12

End If

Pictime.Line (0, 0)-(sngLenH * Sin(2 * pi * h / 12), sngLenH * Cos(2 * pi * h / 12)), vbGreen

Pictime.Circle (0, 0), radius * 0.9

For i = 1 To 12

Pictime.Circle (radius * 0.9 * 0.85 * Sin(2 * pi * i / 12), radius * 0.9 * 0.85 * Cos(2 * pi * i / 12)), radius * 0.01, vbGreen

Next i

End Sub

'判断谁赢了

Private Sub WhoWin()

Dim i As Integer

Dim j As Integer

For j = 1 To 14

For i = 1 To 14

If DataArray(i, j) = MyColor And Not IfSucceed Then

If (14 - i) = 4 And (14 - j) = 4 Then

If DataArray(i + 1, j + 1) = MyColor Then

If DataArray(i + 2, j + 2) = MyColor Then

If DataArray(i + 3, j + 3) = MyColor Then

If DataArray(i + 4, j + 4) = MyColor Then

IfSucceed = True

Exit For

Exit For

End If

End If

End If

End If

End If

If i 4 And (14 - j) = 4 Then

If DataArray(i - 1, j + 1) = MyColor Then

If DataArray(i - 2, j + 2) = MyColor Then

If DataArray(i - 3, j + 3) = MyColor Then

If DataArray(i - 4, j + 4) = MyColor Then

IfSucceed = True

Exit For

Exit For

End If

End If

End If

End If

End If

If (14 - i) = 4 Then

If DataArray(i + 1, j) = MyColor Then

If DataArray(i + 2, j) = MyColor Then

If DataArray(i + 3, j) = MyColor Then

If DataArray(i + 4, j) = MyColor Then

IfSucceed = True

Exit For

Exit For

End If

End If

End If

End If

End If

If (14 - j) = 4 Then

If DataArray(i, j + 1) = MyColor Then

If DataArray(i, j + 2) = MyColor Then

If DataArray(i, j + 3) = MyColor Then

If DataArray(i, j + 4) = MyColor Then

IfSucceed = True

Exit For

Exit For

End If

End If

End If

End If

End If

End If

Next i

Next j

If IfSucceed Then

If Not P2PlayColor Then

Timer2.Enabled = False '白方赢计时停止

Timer3.Enabled = False

Timer4.Enabled = False

MsgBox "白方胜!", vbOKOnly

CmdStart_Click

Else

Timer2.Enabled = False '黑方赢计时停止

Timer3.Enabled = False

Timer4.Enabled = False

MsgBox "黑方胜!", vbOKOnly

CmdStart_Click

End If

End If

End Sub

'分别记录黑白棋子的分布

Private Sub RemenberCrossData(x0_ As Integer, y0_ As Integer)

If MyColor Then

DataArray(x0_, y0_) = 1

Else

DataArray(x0_, y0_) = 0

End If

End Sub

'简单难度思考时间20秒

Private Sub Timer2_Timer()

Dim i As Integer

i = 1

sumtime = sumtime + i '计时

FrmMain.Cls

Print 20 - sumtime '剩余时间提示

If sumtime = 20 Then

If MyColor = 1 Then

Timer2.Enabled = False '白方超时计时停止

MsgBox "白棋超时"

Call CmdStart_Click

Else

Timer2.Enabled = False '黑方超时计时停止

MsgBox "黑棋超时"

Call CmdStart_Click

End If

End If

End Sub

'中等难度思考时间10秒

Private Sub Timer3_Timer()

Dim i As Integer

i = 1

sumtime = sumtime + i '计时

FrmMain.Cls

Print 10 - sumtime '剩余时间提示

If sumtime = 10 Then

If MyColor = 1 Then

Timer3.Enabled = False '白方超时计时停止

MsgBox "白棋超时"

Call CmdStart_Click

Else

Timer3.Enabled = False '黑方超时计时停止

MsgBox "黑棋超时"

Call CmdStart_Click

End If

End If

End Sub

'困难难度思考时间5秒

Private Sub Timer4_Timer()

Dim i As Integer

i = 1

sumtime = sumtime + i '计时

FrmMain.Cls

Print 5 - sumtime '剩余时间提示

If sumtime = 5 Then

If MyColor = 1 Then

Timer4.Enabled = False '白方超时计时停止

MsgBox "白棋超时"

Call CmdStart_Click

Else

Timer4.Enabled = False '黑方超时计时停止

MsgBox "黑棋超时"

Call CmdStart_Click

End If

End If

End Sub

五子棋源代码html

js代码:

定义canvas及黑白棋变量

font color="#2f4f4f" face="微软雅黑" size="3"var canvas;

var context;

var isWhite = true;//设置是否该轮到白棋

var isWell = false;//设置该局棋盘是否赢了,如果赢了就不能再走了

var img_b = new Image();

img_b.src = "images/b.png";//白棋图片

var img_w = new Image();

img_w.src = "images/c.png";//黑棋图片/font

为棋盘的二维数组用来保存棋盘信息

font color="#2f4f4f" face="微软雅黑" size="3" var chessData = new Array(15);//初始化0为没有走过的,1为白棋走的,2为黑棋走的

for (var x = 0; x 15; x++) {

chessData[x] = new Array(15);

for (var y = 0; y 15; y++) {

chessData[x][y] = 0;

}

}/font

绘制棋盘的线

font color="#2f4f4f" face="微软雅黑" size="3" for (var i = 0; i = 640; i += 40) {

context.beginPath();

context.moveTo(0, i);

context.lineTo(640, i);

context.closePath();

context.stroke();

context.beginPath();

context.moveTo(i, 0);

context.lineTo(i, 640);

context.closePath();

context.stroke();

}

}/font

判断该棋局的输赢

font color="#2f4f4f" face="微软雅黑" size="3" if (count1 = 5 || count2 = 5 || count3 = 5 || count4 = 5) {

if (chess == 1) {

alert("白棋赢了");

}

else {

alert("黑棋赢了");

}

isWell = true;//设置该局棋盘已经赢了,不可以再走了

}/font

html代码:

font color="#2f4f4f" face="微软雅黑" size="3"body onload="drawRect()"

div

canvas width="640" id="canvas" onmousedown="play(event)" height="640"你的浏览器不支持HTML5 canvas ,请使用 google chrome 浏览器 打开.

/canvas

/div

/body/font

制作五子棋的代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于五子棋游戏算法代码、制作五子棋的代码的信息别忘了在本站进行查找喔。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/31341.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载