初学python, 自己编的掷筛子小游戏
来源:互联网 发布:xp仿mac苹果系统 编辑:程序博客网 时间:2024/04/27 15:48
掷筛子游戏的基本规则是:开始都有100金币,掷出1,2,3的扣除相应的金币,掷出4,5,6加上相应的金币。如果前两次都掷出1的话游戏直接算输,前两次都掷出6的话游戏直接算胜利。除此之外,游戏金币扣光算输,游戏金币超过200算赢,一共最多十次投掷机会。
游戏运行结果如图:
下面是基本代码:
# -*- coding: utf-8 -*-import randomimport sysdef start(): print "Welcome to the exciting game of \'Dice or Dies\'!" print "Here, nothings counts but luck." print "Now, let's play!" print "Everyone has %d golds at first." % 100def Dice_rolling(): point = random.randint(1, 6) print "the point is: ", point return pointdef Dice_one(golds): print "So bad, your golds will be less 40." golds -=40 print "Your golds now are: ", golds return goldsdef Dice_two(golds): print "Not so lucky, your golds will be less 30." golds -= 30 print "Your golds now are: ", golds return goldsdef Dice_three(golds): print "Ok, your golds will be less 10." golds -= 10 print "Your golds now are: ", golds return goldsdef Dice_four(golds): print "Good, your gold will be more 10." golds += 10 print "Your golds now are: ", golds return goldsdef Dice_five(golds): print "Great, your gold will be more 30." golds += 30 print "Your golds now are: ", golds return goldsdef Dice_six(golds): print "So lucky! your golds will be more 50." golds += 50 print "Your golds now are: ", golds return goldsdef Decide_rule(point, golds): if point == 1: golds = Dice_one(golds) elif point == 2: golds = Dice_two(golds) elif point == 3: golds = Dice_three(golds) elif point == 4: golds = Dice_four(golds) elif point == 5: golds = Dice_five(golds) else: golds = Dice_six(golds) return goldsstart()golds = 100print "第1次投掷:".decode('utf-8').encode('gbk')number = Dice_rolling()if number == 1: current_golds = Decide_rule(number, golds) print "You will be out of the game, if your next point is still 1." print "第2次投掷: ".decode('utf-8').encode('gbk') number_sec = Dice_rolling() if number_sec == 1: print "Game over!" exit(0) else: current_golds = Decide_rule(number_sec, current_golds)elif number == 6: current_golds = Decide_rule(number, golds) print "You will win, if your next point is still 6." print "第2次投掷: ".decode('utf-8').encode('gbk') number_sec = Dice_rolling() if number_sec == 6: print "You win!" exit(0) else: current_golds = Decide_rule(number_sec, current_golds)else: current_golds = Decide_rule(number, golds) print "第2次投掷: ".decode('utf-8').encode('gbk') number_sec = Dice_rolling() current_golds = Decide_rule(number_sec, current_golds)count_rolling = 3while count_rolling < 11: print "第 %d 次投掷: ".decode('utf-8').encode('gbk') % count_rolling number = Dice_rolling() current_golds = Decide_rule(number, current_golds) if current_golds < 0: print "Game over!" exit(0) elif current_golds > 200: print "You win!" print "Totally, you throwed %d times." % count_rolling exit(0) else: count_rolling += 1
0 0
- 初学python, 自己编的掷筛子小游戏
- jquery实现掷筛子小游戏
- java 编的老虎机 掷筛子 面向过程!
- 自己编的猜数字小游戏
- 一个自己编的小游戏——猜数
- 初学Python之发布自己的模块
- #Python 初学之二编写一个小游戏#
- 求质数的筛子
- 无形的筛子
- 实现“挨拉托色尼的筛子”
- 掷筛子问题
- 自己写的小游戏,玩玩
- 筛子
- 绘制简单的条形图(使用pygal掷筛子)
- 初学c语言所编的程序
- 初学java:Map集合的编历
- 自己编的分页模块
- 写给自己的第一编
- 常用的servlet包
- C学习笔记——冒泡排序
- WEB入门之十八 动画特效
- 对于摄像机采集交错视频来说,偶场和奇场是并非由同一帧分拆得来
- QT 调试
- 初学python, 自己编的掷筛子小游戏
- HashMap提高篇(2)--HashMap的存取方法的源码实现
- php输出控制函数汇总
- android 加入FLAG_ACTIVITY_NEW_TASK
- android 实现 bilili 动画播放效果
- 简单的约瑟夫环
- HDU3067 小t的游戏
- D
- Day2 数据处理