《python二维游戏编程》项目一:杠子老虎鸡虫

V0.0.2.20210629


项目简介

《python二维游戏编程》课后项目1

适用于中国农业出版社,张太红主编,2015版本

本人不慎丢失了该书的光盘,怀疑第二章往后的模板在光盘中,如果你有光盘或者有本书的第二个项目往后的模板,我需要你的帮助

题目要求简介

源代码

import randomgustures = ['虫子', '鸡', '老虎', '杠子']def name_to_number(name):if name in gustures:return gustures.index(name)else:return -1def number_to_name(num):if num < gustures.__len__():return gustures[num]else:return '所喊无效!'def shut_out(name):if name == '随机':return random.randint(0, 3)else:return name_to_number(name)def play_one_round(player1_name, player1_code, player2_name, player2_code, print_msg=True):""":param player1_name::param player2_name::param player1_code::param player2_code::param print_msg:"""if player1_code >= gustures.__len__():if print_msg:print(player1_name + '玩家所喊无效!')return -1if player2_code >= gustures.__len__():if print_msg:print(player2_name + '玩家所喊无效!')return -1code_res = player1_code - player2_codeif code_res == 1 or code_res == -3:res = 1elif code_res == -1 or code_res == 3:res = 2else:res = 0if print_msg:print(player1_name + '喊的为:' + number_to_name(player1_code))print(player2_name + '喊的为:' + number_to_name(player2_code))if res == 0:print(player1_name + '和' + player2_name + '打成平手!')elif res == 1:print(player1_name + '获胜!')else:print(player2_name + '获胜!')return resdef probability_calculate():i = 0player_win = [0, 0, 0]while i < 128:play_res = play_one_round('甲', shut_out('随机'), '乙', shut_out('随机'), print_msg=False)player_win[play_res] += 1i += 1print('甲、乙随机比赛128次,验证对决结果的概率为')print('甲方获胜的概率为:%f' % (float(player_win[1] / (player_win[0] + player_win[1] + player_win[1]))))print('双方平局的概率为:%f' % (float(player_win[0] / (player_win[0] + player_win[1] + player_win[1]))))print('甲方失败的概率为:%f' % (float(player_win[2] / (player_win[0] + player_win[1] + player_win[1]))))random.seed()
probability_calculate()

使用说明

环境依赖:python3

维护说明

注意

关于作者

Autho: KiraSkyler
Email: kiraskyler@outlook.com / kiraskyler@qq.com

贡献者/贡献组织

鸣谢

版权信息

该项目签署了GPL 授权许可,详情请参阅官网

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see https://www.gnu.org/licenses/.

更新日志

  • V0.0.0.20210101

杠子老虎鸡虫 《python二维游戏编程》课后项目一相关推荐

  1. python二维游戏编程 超级大脑_超级大脑教练 - 主页

    ${content} 你输入的邮件地址曾经通过${type}激活了本站帐号,请使用${type}帐号直接登录. 课程习题 : 提示 请选择一个答案 提交 查看正确答案 下一题 ${option}: $ ...

  2. python项目之杠子老虎鸡虫

    python项目之杠子老虎鸡虫 本项目我们尝试用Python语言设计一个计算机程序来模拟"杠子老虎鸡虫"游戏.程序的文件名称为HitChopsticks.py,程序将使用impor ...

  3. python二维游戏示例_Python实现的井字棋(Tic Tac Toe)游戏示例

    本文实例讲述了Python实现的井字棋(Tic Tac Toe)游戏.分享给大家供大家参考,具体如下: 说明 用python实现了井字棋,整个框架是本人自己构思的,自认为比较满意.另外,90%+的代码 ...

  4. python二维游戏示例_Python 扫雷游戏的简单例子

    使用python的tkinter做gui,由于没考虑可用性问题,因此UI比较难看,pygame更有趣更强大更好看,做这些小游戏更合适. python扫雷游戏的完整代码: 代码示例: #!/usr/bi ...

  5. python 二维列表_python二维列表

    广告关闭 腾讯云11.11云上盛惠 ,精选热门产品助力上云,云服务器首年88元起,买的越多返的越多,最高返5000元! 方法一:使用 lambda 关键词辅助对二维列表进行排序,lambda的使用方法 ...

  6. python怎么安装myqr模块-python二维码操作:对QRCode和MyQR入门详解

    python是所有编程语言中模块最丰富的 生活中常见的二维码功能在使用python第三方库来生成十分容易 三个大矩形是定位图案,用于标记二维码的大小.这三个定位图案有白边,通过这三个矩形就可以标识一个 ...

  7. python画二维散点图-基于python 二维数组及画图的实例详解

    1.二维数组取值 注:不管是二维数组,还是一维数组,数组里的数据类型要一模一样,即若是数值型,全为数值型 #二维数组 import numpy as np list1=[[1.73,1.68,1.71 ...

  8. 专属自己的二维游戏引擎【二】

    我给客户制作美术素材从来没有崩溃过,最近给一个客户制作二维游戏素材的时候就直接崩溃了. 次时代模型的流程虽然麻烦,但是我还没有见过比它更麻烦千倍的东西,这次算是见识了. 韩国的泡菜确实比较不太好吃.你 ...

  9. Python 二维数组

    Python数组的应用中在实际编程中是一个非常重要的应用技术,作为Python编程人员来说,必须要熟练的掌握这方面的所有应用技巧.那么,接下来,我们将会通过对Python二维数组的理解来为大家解读这方 ...

最新文章

  1. 转载-SQL Server各种导入导出数据方式的比较
  2. java 修改 request参数值,如何在HttpServletRequest中设置参数?
  3. unity3d iPhone文件目录介绍
  4. C++ void类型指针的使用
  5. Android的Style的使用
  6. 如何选择数据结构和算法(转)
  7. Oracle导入程序Imp的使用详解
  8. 拼多多开始卖车了!3.49万秒杀五菱宏光...
  9. python中argsparse_Python中argparse库的基本使用(示例)
  10. Unicode字符串和非Unicode字符串
  11. 新益华基层医疗系统使用方法_家中更换新路由器了,但不知道如何替换?可以尝试使用这种方法...
  12. 出租车计费java_java算法_出租车计费
  13. DC-DC电路中自举电容和自举电阻是什么?
  14. Scikit-Learn机器学习(knn算法)
  15. 15家银行信用卡积分含金量大比拼
  16. CSS3基础一篇完结(豪豪的备忘录)
  17. 定制自己的xDoclet标签
  18. 什么软件能测试电脑能不能玩lol,怎么判断自己的电脑能不能玩lol_电脑配置检测的方法 - 驱动管家...
  19. ubuntu下 qt xxx.run 安装步骤
  20. 【探究网络安全与网络安全文化及网络安全防范】计算机网络安全现状

热门文章

  1. 程序员做外包,真的没地位没出路吗
  2. 线上nginx偶尔出现502错误
  3. CF1324D Pair of Topics 题解
  4. 2018最佳计算机配置,2018年主流的组装电脑配置是什么样的?
  5. C#调用第三方dll生成exe被dep拦截
  6. 英语如此简单(转贴)
  7. 防抖为什么要使用闭包
  8. 年轻人说“接受自己的平庸”,八成是自欺欺人
  9. 7.3.1 B树及其基本操作
  10. 云计算、社交网络和移动互联网------转自月光博客