3个适合新手练习的python小游戏

这篇文章主要分析的是3个适合新手练习的python小游戏,初学者嘛就应该多练手,下文分享的python小游戏欢迎大家来玩,需要的小伙伴也可以参考一下

学Python之前我们先来几个简单的小游戏练练手,这三个小游戏一个比一个复杂,建议新手慢慢来:

1.猜拳

import random  #导入随机模块   num = 1 yin_num = 0 shu_num = 0 while num <= 3:     if shu_num == 2 or yin_num == 2:         break     user = int(input('请出拳 0(石头) 1(剪刀) 2(布)'))     if user > 2:         print('不能出大于2的值')     else:         data = ['石头', '剪刀', '布']         com = random.randint(0, 2)         print("您出的是{},电脑出的是{}".format(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('你赢了')             yin_num += 1         else:             print('你输了')             shu_num += 1     num += 1

2.数字炸弹

import random import time   bomb = random.randint(1, 99) print(bomb) start = 0 end = 99 while 1 == 1:       people = int(input('请输入{}到{}之间的数:'.format(start, end)))     if people > bomb:         print('大了')         end = people     elif people  bomb:         print('大了')         end = com     elif com 

3.赌大小

import time import random # 让用户注册 name = input('请填写用户名:') age = input("{}您好,请输入您的年龄 : ".format(name)) user_info = {'name': name, 'age': int(age)}  # 用户信息 user_properties = ['X 1-5']  # 用于存放用户道具 默认道具 properties = ['X3 (250G)', 'X1-5 (300G)']  # 道具列表 显示用   # 根据用户年龄 给与不同的初始金币 if 10 =10为大,否则为小".center(32), end='') print('*') print('*'.ljust(53), '*') print('*' * 54) print("\n")   #             开始游戏 result = input('是否开始游戏 yes or no :  ') go = True if (result.lower() == 'yes'):     while go:         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;  # 错误 用户金币减 100           # 判断用户金币 是否够下次玩 不够则退出程序         if (user_info['glod'] <= 0):             print('您的金币已经用完,感谢您的游玩')             break           if user_info['glod'] % 1000 == 0:  # 用户金币 是1000的倍数是 可购买道具             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  # 用户金币减 300                     print('购买成功!消耗金币300')                 else:                     print('没有该道具,您失去了这次机会')         else:             #  一直提示 太烦             # conti = input('您现在有金币:{},是否继续游玩,yes or no: '.format(user_info['glod']))             print('您现在有金币:{} '.format(user_info['glod'])) else:     print('欢迎下次游玩,再见!')

到此这篇关于3个适合新手练习的python小游戏的文章就介绍到这了,更多相关python小游戏练习内容请搜索0133技术站以前的文章或继续浏览下面的相关文章希望大家以后多多支持0133技术站!

以上就是3个适合新手练习的python小游戏的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » python