1024快乐!!
送给大家一个小游戏 ^v^
玩法:
开始可以选择双人或单人,然后就开始游戏。
你会摇到1~6的随机数,还会触发奖励或惩罚。
谁先到重点谁就赢。
代码:
#-*- coding: <utf-8> -*-
import random
from time import sleep as s
前 = 0
后 = 30
电前 = 0
电后 = 30
奖励 = 0
玩家 = [前 * '-' + '◆' + 后 * '-']
玩家2或电脑 = [电前 * '-' + '◇' + 电后 * '-']
色子1加 = []
色子2或电脑加 = []
玩家色子和 = []
奖判 = random.randint(1, 10)
电脑奖判 = random.randint(1, 10)
def 战况1():
print('--------------------------------------------\n战况: \n', 名字1, '--', 玩家)
print('\n', 名字2, '--', 玩家2或电脑)
def 战况2():
print('--------------------------------------------\n战况: \n', 名字, '--', 玩家)
print('\n电脑 --', 玩家2或电脑)
def 奖励1():
print('触发奖励')
print('前进 5 步. ')
s(1)
global 奖励
奖励 = 5
def 奖励4():
print('触发惩罚')
print('后退 5 步. ')
s(1)
global 奖励
奖励 = -5
def 奖励2():
print('触发奖励')
print('前进 3 步. ')
s(1)
global 奖励
奖励 = 3
def 奖励3():
print('触发惩罚')
print('后退 3 步. ')
s(1)
global 奖励
奖励 = -3
def 奖励5():
print('触发奖励')
print('前进 3 步. ')
s(1)
global 奖励
奖励 = 3
def 奖励6():
print('触发惩罚')
print('后退 1 步. ')
s(1)
global 奖励
奖励 = -1
def 啥():
print('啥都没有. ')
奖励 = 0
#--------------------------------------------------------
print('欢迎来玩摇色子, 请选择: ')
while True:
print('\n\n1. 玩家 --> 玩家\n2. 玩家 --> 电脑')
选择 = int(input('[请选择]>>> '))
if not 1 <= 选择 <= 2:
break
elif 选择 == 1:
名字1 = input('请输入玩家1的名字: ')
名字2 = input('请输入玩家2的名字: ')
s(1.5)
战况1()
while True:
print(名字1)
s(1)
input('--------------------------------------------\n请摇色子. (回车)')
色子1 = random.randint(1, 6)
print(名字1, '摇到', 色子1)
print('前进', 色子1, '步. ')
if 奖判 == 1:
奖励1()
elif 奖判 == 2:
奖励2()
elif 奖判 == 3:
奖励3()
elif 奖判 == 4:
奖励4()
elif 奖判 == 5:
奖励5()
elif 奖判 == 6:
奖励6()
else:
啥()
奖判 = random.randint(1, 10)
色子1加.append(色子1 + 奖励)
电脑奖判 = random.randint(1, 10)
前 = 前 + 色子1 + 奖励
后 = 后 - 色子1 - 奖励
玩家 = [前 * '-' + '◆' + 后 * '-']
if sum(色子1加) >= 30:
print(名字1, '胜利! ')
print('战况: \n', 名字1, '--', [30 * '-' + '◆' + 0 * '-'])
print('\n', 名字2, '--', 玩家或电脑)
前 = 0
后 = 0
电前 = 0
电后 = 0
色子1加 = []
色子2或电脑加 = []
break
s(1.5)
战况1()
print(名字2)
s(1)
input('--------------------------------------------\n请摇色子. (回车)')
色子2 = random.randint(1, 6)
print(名字2, '摇到', 色子2)
print('前进', 色子2, '步. ')
if 奖判 == 1:
奖励1()
elif 奖判 == 2:
奖励2()
elif 奖判 == 3:
奖励3()
elif 奖判 == 4:
奖励4()
elif 奖判 == 5:
奖励5()
elif 奖判 == 6:
奖励6()
else:
啥()
奖判 = random.randint(1, 10)
电脑奖判 = random.randint(1, 10)
色子2或电脑加.append(色子2 + 奖励)
电前 = 电前 + 色子2 + 奖励
电后 = 电后 - 色子2 - 奖励
玩家2或电脑 = [电前 * '-' + '◇' + 电后 * '-']
if sum(色子2或电脑加) >= 30:
print(名字2, '胜利! ')
print('--------------------------------------------\n战况: \n', 名字1, '--', 玩家)
print('\n', 名字2, '--', [30 * '-' + '◇' + 0 * '-'])
前 = 0
后 = 0
电前 = 0
电后 = 0
色子1加 = []
色子2或电脑加 = []
break
战况1()
s(1.5)
else:
print('输入你的名字: ')
名字 = input('[请输入]>>> ')
while True:
print(名字)
s(1)
input('--------------------------------------------\n请摇色子. (回车)')
s(1.5)
色子 = random.randint(1, 6)
print(名字, '摇到', 色子)
print('前进', 色子, '步. ')
if 奖判 == 1:
奖励1()
elif 奖判 == 2:
奖励2()
elif 奖判 == 3:
奖励3()
elif 奖判 == 4:
奖励4()
elif 奖判 == 5:
奖励5()
elif 奖判 == 6:
奖励6()
else:
啥()
奖判 = random.randint(1, 10)
电脑奖判 = random.randint(1, 10)
玩家色子和.append(色子 + 奖励)
前 = 前 + 色子 + 奖励
后 = 后 - 色子 - 奖励
玩家 = [前 * '-' + '◆' + 后 * '-']
奖励 = 0
if sum(玩家色子和) >= 30:
print(名字, '胜利! ')
print('--------------------------------------------\n战况: \n', 名字, '--', [30 * '-' + '◆' + 0 * '-'])
print('\n电脑 --', 玩家2或电脑)
前 = 0
后 = 0
电前 = 0
电后 = 0
玩家色子和 = []
色子2或电脑加 = []
break
战况2()
电脑 = random.randint(1, 6)
print('--------------------------------------------\n电脑摇到', 电脑)
print('前进', 电脑, '步. ')
s(1.5)
if 电脑奖判 == 1:
奖励1()
elif 电脑奖判 == 2:
奖励2()
elif 电脑奖判 == 3:
奖励3()
elif 电脑奖判 == 4:
奖励4()
elif 电脑奖判 == 5:
奖励5()
elif 电脑奖判 == 6:
奖励6()
else:
啥()
奖判 = random.randint(1, 10)
电脑奖判 = random.randint(1, 10)
电前 = 电前 + 电脑 + 奖励
电后 = 电后 - 电脑 - 奖励
玩家2或电脑 = [电前 * '-' + '◇' + 电后 * '-']
色子2或电脑加.append(电脑 + 奖励)
if sum(色子2或电脑加) >= 30:
print('电脑胜利! ')
s(1.5)
print('--------------------------------------------\n战况: \n', 名字, '--', 玩家)
print('\n电脑 --', [30 * '-' + '◇' + 0 * '-'])
前 = 0
后 = 0
电前 = 0
电后 = 0
玩家色子和 = []
色子2或电脑加 = []
break
战况2()
print(15 * '~', '感谢游玩!', 15 * '~')
希望大家喜欢~~