使用python制作一款能够随时添加新游戏和切换游戏的小游戏盒子
设计一个小游戏盒子
(举例如将猜拳游戏,和骰子猜点数大小)运用于同一个游戏盒子中,用户可以键入关键字来实现选择游戏,进行游戏,切换游戏,退出程序等功能,同时该游戏盒子呈开放状态,随时都可以添加新游戏,并互相不影响,即可模拟现实中软件更新,游戏上新!

现给出示例代码如下(可直接用于小游戏程序设计期末大作业)
代码可更换,可创新,如有需要可直接复制
游戏盒子加载模块,模拟真实的APP开启界面,代替直接显示菜单,给予用户真实感!
def youxihezi():
import time
t = 500
for n in range(t+1):
loading = round(n/t*100)
print(f"r游戏盒子加载中.... {loading}%",end="")
time.sleep(0.0001)
print("n")
time.sleep(1)
caidan()
def caidan():
print('小游戏盒子'.center(50, '*'))
print('*'.ljust(53,' '), '*')
print('*', end='')
print("1.猜拳游戏".center(49), end='')
print('*')
print('n')
print('*', end='')
print("2.猜大小 ".center(49), end='')
print(' *')
print('*'.ljust(53,' '), '*')
print('*' * 54)
s = int(input("n请选择一个游戏(输入0退出小游戏盒子T_T):"))
if s == 2:
print('-----猜大小-----')
caidaxiao()
elif s == 1:
print('---猜拳游戏----')
caiquan()
else:
print('即将退出游戏盒子,欢迎下次游玩!')
exit()
def caiquan():
import time
t = 100
for n in range(t+1):
loading = round(n/t*100)
print(f"r加载中{loading}%",end="")
time.sleep(0.01)
print('n--------------猜拳游戏----------------nn')
import random
ying = 0
shu = 0
while True:
if shu == 2:
print('nn三局两胜 你输了!n游戏结束!')
youxi()
elif ying == 2:
print('nn三局两胜 你赢了!n游戏结束!')
youxi()
user = int(input('请出拳 0(石头) 1(剪刀) 2(布):'))
if user > 2:
print('没有这个手势哦!请重新输入!')
else:
data = ['石头', '剪刀', '布']
com = random.randint(0, 2)
print('您出的是',data[user],'电脑出的是',data[com])
if user == com:
print('平局')
continue
elif (user == 0 and com == 1) or (user == 1 and com == 2) or (user == 2 and com == 0):
print('你赢了')
ying += 1
else:
print('你输了')
shu += 1
def youxi():
q = int(input('是否继续游戏?n键入0退出该游戏,返回游戏盒子n键入1开始新游戏n键入2直接退出整个游戏盒子n'))
if q == 0:
caidan()
elif q == 1:
caiquan()
elif q == 2:
print('n即将退出游戏盒子,欢迎下次游玩!n')
exit()
def youxi1():
q = int(input('是否继续游戏?n键入0退出该游戏,返回游戏盒子n键入1开始新游戏n键入2直接退出整个游戏盒子n'))
if q == 0:
caidan()
elif q == 1:
caidaxiao()
elif q == 2:
print('n即将退出游戏盒子,欢迎下次游玩!n')
exit()
def caidaxiao():
import time
import random
name = input('请填写用户名:')
age = int(input('您好,请输入您年龄:'))
user_info = {'name': name, 'age': age}
user_properties = ['X3 x1-5']
properties = ['X3 (250G)', 'X1-5 (300G)']
if 10 < user_info['age'] < 18:
glod = 1000
elif 18 <= user_info['age'] <= 30:
glod = 1100
else:
glod = 500
user_info['glod'] = glod
print("{}您好,欢迎游玩本游戏,您的初始金币为:{}".format(user_info['name'], user_info['glod']))
print("n")
time.sleep(1)
print('游戏说明'.center(50, '*'))
print('*'.ljust(53,' '), '*')
print('*', end='')
print("电脑每次投掷三枚骰子,总点数>=10为大,否则为小".center(32), end='')
print('*')
print('*'.ljust(53,' '), '*')
print('*' * 54)
print("n")
result = input('是否开始游戏 yes or no : ')
if (result.lower() == 'yes'):
while True:
dices = []
for i in range(0, 3):
dices.append(random.randint(1, 6))
total = sum(dices)
user_input = input('请输入big OR small : ')
u_input = user_input.strip().lower()
time.sleep(1)
print('骰子点数为:{}'.format(dices), end=' ')
if (total >= 10 and u_input == 'big') or (total < 10 and u_input == 'small'):
print('您赢了!!!')
multi = 1
if len(user_properties) > 0:
use_pro = input('是否使用道具: ')
if use_pro.lower() == 'yes':
use_pro = int(input('请选择使用第几个道具{} :'.format(user_properties)))
use_pro -= 1
if user_properties[use_pro] == 'X 3':
multi = 3
print('奖金翻3倍')
elif user_properties[use_pro] == 'X 1-5':
multi = random.randint(1, 5)
print('奖金翻{}倍'.format(multi))
user_properties.remove(user_properties[use_pro])
user_info['glod'] += 100 * multi;
else:
print('您输了!')
user_info['glod'] -= 100;
if (user_info['glod'] <= 0):
print('您的金币已经用完,感谢您的游玩')
break
if user_info['glod'] % 1000 == 0:
shop = input('您现在有金币:{},是否购买道具 yes or no: '.format(user_info['glod']))
if shop.lower() == 'yes':
good_num = int(input('请选择要购买第几个道具 {}'.format(properties)))
if good_num == 1:
user_properties.append('X 3')
user_info['glod'] -= 250
print('购买成功!消耗金币250')
elif good_num == 2:
user_properties.append('X 1-5')
user_info['glod'] -= 300
print('购买成功!消耗金币300')
else:
print('没有该道具,您失去了这次机会')
else:
print('您现在有金币:{} '.format(user_info['glod']))
else:
youxi1()
youxihezi()