python3 撰写#字棋 游戏
#!/usr/bin env python3
# coding:utf-8
cont =0
map = [['[]','[]','[]'],
['[]','[]','[]'],
['[]','[]','[]']]
def maps():
for iin range(3):
print(map[i])
def player():
global x
global y
while 1:
if cont%2 ==0 :
player1x =int(input('请输入你要下的横坐标:'))
player1y =int(input('请输入你要下的纵坐标:'))
x = player1x
y = player1y
else:
player2x =int(input('请输入你要下的横坐标:'))
player2y =int(input('请输入你要下的纵坐标:'))
x = player2x
y = player2y
if map[y][x] =='[]':
pass
break
else:
print("输入有误,重新输入")
continue
def changemaps (x,y):
while 1:
if x<3 and y<3:
if cont%2 ==0:
map[y][x] ='O'
break
else:
map[y ][x] ='X'
break
else:
print("输入错误,请重新输入")
def seccessful():
if (map[0][0] == map[1][0] == map[2][0] =='X' or map[0][0] == map[0][1] == map[0][2] =='X' or map[0][2] == map[1][2] == map[2][2] =='X' or map[2][0] == map[2][1] == map[2][2] =='X' or map[0][0] == map[1][1] == map[2][2] =='X' or map[0][2] == map[1][1] == map[2][0] =='X')or (map[0][0] == map[1][0] == map[2][0] =='O' or map[0][0] == map[0][1] == map[0][2] =='O' or map[0][2] == map[1][2] == map[2][2] =='O' or map[2][0] == map[2][1] == map[2][2] =='O' or map[0][0] == map[1][1] == map[2][2] =='O' or map[0][2] == map[1][1] == map[2][0] =='O' ) :
print("seccessful!!!")
return 1
else:
return 0
maps()
while 1 :
cont +=1
player()
changemaps(x, y)
maps()
seccessful()
if seccessful() ==1:
break
网友评论