[Python] 纯文本查看 复制代码
from tkinter.tix import InputOnly
print("欢迎来到狼羊草过河小游戏")
print("一个农夫带一只狼、一只羊和一筐草准备过河,但")
print("因为船小,过河时每次只能带一样东西.然而老头不在的时")
print("候,狼会把羊吃掉,羊会把草吃掉.问老头怎么样过河才能")
print("使所带的东西全部带到对岸")
n=0
a=[1,1,1,1]
b=[0,0,0,0]
e=0
while n==0:
while n==0:
print( )
if a[0]==0:
print("A岸 | | B岸")
print(" | | 农夫(4)")
if a[0]==1:
print(" A岸 | | B岸")
print("农夫(4) | | ")
if a[1]==0:
print(" | | 狼(1)")
if a[1]==1:
print(" 狼(1) | | ")
if a[2]==0:
print(" | | 草(2)")
if a[2]==1:
print(" 草(2) | | ")
if a[3]==0:
print(" | | 羊(3)")
if a[3]==1:
print(" 羊(3) | | ")
print("----------分割线----------")
print( )
print("现在你将做出选择,带狼请输入1,带草请输入2,带羊请输入3,什么都不带输入4")
e=int(input("输入你的选择:"))
if a[0]==1:
if e==1:
if a[1]==1:
a[0]=a[0]-1
a[1]=a[1]-1
b[0]=b[0]+1
b[1]=b[1]+1
print("你选择了带狼")
# print("a=",a,",b=",b)
break
else:
print("狼不在此岸")
continue
elif e==2:
if a[2]==1:
a[0]=a[0]-1
b[0]=b[0]+1
a[2]=a[2]-1
b[2]=b[2]+1
print("你选择了带草")
# print("a=",a,",b=",b)
break
else:
print("草不在此岸")
continue
elif e==3:
if a[3]==1:
a[0]=a[0]-1
b[0]=b[0]+1
a[3]=a[3]-1
b[3]=b[3]+1
print("你选择了带羊")
# print("a=",a,",b=",b)
break
else:
print('羊不在此岸')
continue
elif e==4:
a[0]=a[0]-1
b[0]=b[0]+1
print("你选择了什么都不带")
# print("a=",a,",b=",b)
else :
print("< 请输入正确的数值 >")
continue
elif b[0]==1 :
if e==1:
if b[1]==1:
a[0]=a[0]+1
a[1]=a[1]+1
b[0]=b[0]-1
b[1]=b[1]-1
print("你选择了带狼")
# print("a=",a,",b=",b)
break
else:
print("狼不在此岸")
continue
elif e==2:
if b[2]==1:
a[0]=a[0]+1
b[0]=b[0]-1
a[2]=a[2]+1
b[2]=b[2]-1
print("你选择了带草")
# print("a=",a,",b=",b)
break
else:
print("草不在此岸")
continue
elif e==3:
if b[3]==1:
a[0]=a[0]+1
b[0]=b[0]-1
a[3]=a[3]+1
b[3]=b[3]-1
print("你选择了带羊")
# print("a=",a,",b=",b)
continue
else:
print("羊不在此岸")
elif e==4:
a[0]=a[0]+1
b[0]=b[0]-1
print("你选择了什么都不带")
# print("a=",a,",b=",b)
else :
print("< 请输入正确的数值 >")
if a[0]==0 and a[1]==0 and a[2]==0 and a[3]==0:#1
break
if a[0]==0 and a[1]==0 and a[2]==0 and a[3]==1:#2
continue
if a[0]==0 and a[1]==0 and a[2]==1 and a[3]==0:#3
continue
if a[0]==0 and a[1]==0 and a[2]==1 and a[3]==1:#4
print("A岸的羊把草吃了,游戏重新开始")
a=[1,1,1,1]
b=[0,0,0,0]
continue
if a[0]==0 and a[1]==1 and a[2]==0 and a[3]==0:#5
continue
if a[0]==0 and a[1]==1 and a[2]==0 and a[3]==1:#6
print("A岸的狼把羊吃了,游戏重新开始")
a=[1,1,1,1]
b=[0,0,0,0]
continue
if a[0]==0 and a[1]==1 and a[2]==1 and a[3]==0:#7
continue
if a[0]==0 and a[1]==1 and a[2]==1 and a[3]==1:#8
print("A岸的羊把草吃了,狼把羊吃了,游戏重新开始")
a=[1,1,1,1]
b=[0,0,0,0]
continue
if a[0]==1 and a[1]==0 and a[2]==0 and a[3]==0:#9
print("B岸的羊把草吃了,狼把羊吃了,游戏重新开始")
a=[1,1,1,1]
b=[0,0,0,0]
continue
if a[0]==1 and a[1]==0 and a[2]==0 and a[3]==1:#10
continue
if a[0]==1 and a[1]==0 and a[2]==1 and a[3]==0:#11
print("B岸的狼把羊吃了,游戏重新开始")
a=[1,1,1,1]
b=[0,0,0,0]
continue
if a[0]==1 and a[1]==0 and a[2]==1 and a[3]==1:#12
continue
if a[0]==1 and a[1]==1 and a[2]==0 and a[3]==0:#13
print("B岸的羊把草吃了,游戏重新开始")
a=[1,1,1,1]
b=[0,0,0,0]
continue
if a[0]==1 and a[1]==1 and a[2]==0 and a[3]==1:#14
continue
if a[0]==1 and a[1]==1 and a[2]==1 and a[3]==0:#15
continue
if a[0]==1 and a[1]==1 and a[2]==1 and a[3]==1:#16
continue
print( )
print(" (๑ŐдŐ)b")
print("恭喜你,成功渡河,游戏结束!")