同志们我好久没有发布Python小游戏了,
今天我更新一个啦!!!!!!
我们这次的游戏是《石头剪刀布》实际上和《斗兽棋》判断输赢的思路有点像哦;
好啦我们上代码:
import random
#玩家和 AI 的得分
human_score = 0
ai_score = 0
i = 0
#输出各自计分
print("比分: 玩家 ",human_score," vs AI ",ai_score)
while human_score < 3 and ai_score < 3:
i = i + 1
print("-----回合 ",i,"-----")
print('''请输入你的选择:
1. 石头
2. 剪刀
3. 布''')
human = input("你的选择是:")
human = int(human)
if human == 1:
print("你出的石头")
if human == 2:
print("你出的剪刀")
if human == 3:
print("你出的布")
ai = random.randint(1, 3)
if ai == 1:
print("对手 出的石头")
if ai == 2:
print("对手 出的剪刀")
if ai == 3:
print("对手 出的布")
if human == 1:
if ai == 1:
print("平局")
if ai == 2:
print("玩家胜利")
human_score = human_score + 1
if ai == 3:
print("对手 胜利")
ai_score = ai_score + 1
if human == 2:
if ai == 1:
print("对手 胜利")
ai_score = ai_score + 1
if ai == 2:
print("平局")
if ai == 3:
print("玩家胜利")
human_score = human_score + 1
if human == 3:
if ai == 1:
print("玩家 胜利")
human_score = human_score + 1
if ai == 2:
print("对手 胜利")
ai_score = ai_score + 1
if ai == 3:
print("平局")
print("比分: 玩家 ",human_score," vs 对手 ",ai_score)
print()
if human_score == 3:
print("玩家获胜!")
if ai_score == 3:
print("对手 获胜!")
同志们我们作品就分享到这里啦,拜拜
本站作者已申明原创,禁止转载!
文章内容属作者个人观点,不代表本站立场,如有侵权立删。






