运行方法:

1. 打开python2 IDLE;

2. 输入 from craps import *

3. 按提示输入运行命令。例如,玩游戏就输入play();查看余额就输入check_bankroll();

自动玩看胜率就输入auto()

craps.py

import random

point_set = False

bet = 10

bankroll = 1000

sim_win = 0

sim_lose = 0

print """

Welcome to the 'Seven Star' casino!

You are playing craps now,

your started bankroll is '$1000',

the started bet is '$10',

command:

play(): "Rolling the dices"

check_bankroll(): "Checking your current balance"

all_in(): Showing "hand"

set_bet(): "Setting a new bet"

game(): "Check your game status"

auto(): "It can be played automatically for you until reach a specific bankroll"

"""

def roll():

d1 = random.randrange(1,7)

d2 = random.randrange(1,7)

print "You rolled", d1, "+", d2, "=", d1+d2

return d1 + d2

def play():

global point_set, bankroll, point

global sim_win, sim_lose

if bankroll < bet:

print "Sorry, you can't play since you don't have enough money!"

print """Do you wanna get more money?

1: Yes

2: No

"""

choice = raw_input(">>")

if choice == str(1):

money = raw_input("How much do you wanna get?")

bankroll += int(money)

print "Your current bankroll is: ", bankroll

if choice == str(2):

print "Thanks for playing! See you next time!"

else:

if not point_set:

print

print "New game. Your bet is: ", bet

# for the first roll

r = roll()

if not point_set:

if r in (7, 11):

bankroll += bet

sim_win += 1

print "Congratz! You Won! Your bankroll is: ", bankroll

elif r in (2, 3, 12):

bankroll -= bet

sim_lose += 1

print "Oops! You lost! Your bankroll is: ", bankroll

else:

point = r

point_set = True

print "Your point is", "[", point, "]"

# for subsequence rolls

elif r == 7:

bankroll -= bet

sim_lose += 1

point_set = False

print "You crapped out! Your bankroll is: ", bankroll

elif r == point:

bankroll += bet

sim_win += 1

point_set = False

print "You made your point! Your bankroll is: ", bankroll

def set_bet(inp):

global bet, bankroll, point_set

print

if point_set:

print "WARNING!"

print "The game has started, you will lose half of your bet if resetting your bet!"

prompt = raw_input("""

1: Yes, I am wanna reset my bet!

2: No, I don't wanna reset my bet!

""")

if prompt == "1":

point_set = False

bankroll -= bet/2

print "Forfeiting current bet. Your bankroll is: ", bankroll

else:

pass

bet = int(inp)

print "New bet size is: ", bet

def all_in():

set_bet(bankroll)

def check_bankroll():

global bet

print "Your current balance is: ", bankroll

def game():

total = sim_win + sim_lose

percent = float(sim_win)/total * 100

print "So far, the games that you have been playing are: ", total

print "Won ", sim_win

print "Lost ", sim_lose

print "Overall, you have %d%% to win!" %percent

def auto():

game_status = True

purpose = raw_input("How much are you gonna reach? ")

while game_status:

play()

if bankroll == int(purpose) or bankroll == 0:

game_status = False

game()

以上所述就是本文的全部内容了,希望能够对大家学习Python有所帮助。

10个易被忽视但应掌握的Python基本用法

我一辈子都在写代码,但从来没有掌握编码的精髓。大部分情况下使用VisualBasic,因为我用VB最舒服。同时还略微了解一点其他语言(R、C、JavaScript、Appl

用Python制作检测Linux运行信息的工具的教程

在这篇文章里,我们将会探索如何使用Python语言作为一个工具来检测Linux系统各种运行信息。让我们一起来学习吧。哪种Python?当我提到Python时,我一般

Python进行数据科学工作的简单入门教程

Python拥有着极其丰富且稳定的数据科学工具环境。遗憾的是,对不了解的人来说这个环境犹如丛林一般(cuesnakejoke)。在这篇文章中,我会一步一步指

使用C语言编写craps骰子游戏,Python实现国外赌场热门游戏Craps(双骰子)相关推荐

  1. 以游戏设计的角度分析热门游戏——王者荣耀

    五大类 总述 机制 规则 目标 障碍 奖励 总述 在一款游戏中大致可以分为以下5类:机制.规则.目标.障碍.奖励.[1] 机制 机制是游戏核心部分的规则.流程.数据.[2] 王者荣耀是一款MOBA类手 ...

  2. 无领导小组游戏怎样脱颖而出_3种热门游戏在市场上脱颖而出的方式

    无领导小组游戏怎样脱颖而出 What makes a game stand out in a crowded market and skyrocket to success and popularit ...

  3. 编写五子棋的完整python代码_python实现五子棋游戏(pygame版)

    本文实例为大家分享了python五子棋游戏的具体代码,供大家参考,具体内容如下 目录 简介 实现过程 结语 简介 使用python实现pygame版的五子棋游戏: 环境:Windows系统+pytho ...

  4. 编写五子棋的完整python代码_python实现五子棋游戏

    本文实例为大家分享了python实现五子棋游戏的具体代码,供大家参考,具体内容如下 话不多说,直接上代码: 全部工程文件,在GitHub:五子棋 效果预览: #!/usr/bin/env python ...

  5. python编写古诗_用Python实现古诗词填字游戏(一)

    利用古诗词做填字游戏是一项很有趣的活动,通常的填字游戏都是由几横几竖构成,如下图: 显然,横竖交叉的位置就是两句诗共有的字.那么,问题来了,如何从众多诗文中找到有共同字的句子呢? 这里Mr. PosP ...

  6. 猜数字游戏python程序_Python猜数游戏,程序随机生成一个0-100的数,猜对后退出【实例源码】...

    Python猜数字游戏: 写程序,随机生成一个0~100之间的数用变量x绑定 循环让用户输入一个数用y绑定, 输出猜数字的结果 1. 如果y等于生成的数x,则提示"您猜对了", 打 ...

  7. cs精英游戏python代码_python面向对象-cs游戏示例

    #!/usr/local/bin/python3 # -*- coding:utf-8 -*- class Role(object): n = 123 # 类变量 name = "我是类na ...

  8. ov5640帧率配置_vivo S7e游戏测试:三款热门游戏,帧率表现如何?

    距离vivo S7e发布已经有一段时间了,相信有一些小伙伴都已经用上了,不知道大家的使用感受如何呢?作为一直紧跟年轻人潮流的"蓝厂",这次带来的主打"超薄超清晰,照亮你的 ...

  9. Atari游戏公司推出两款热门游戏的“区块链版本”

    点击上方"蓝色字"可关注我们! 暴走时评:游戏公司Atari已与区块链创业公司Animoca Brands签订许可协议,制作两款流行手机游戏的区块链版本.Atari是俄罗斯方块和P ...

  10. 编写五子棋的完整python代码_python制作简单五子棋游戏

    本文实例为大家分享了python五子棋游戏的具体代码,供大家参考,具体内容如下 #五子棋 '" 矩阵做棋盘 16*16 "+" 打印棋盘 for for 游戏是否结束 开 ...

最新文章

  1. iOS progressive Web App (PWA) 技术
  2. LVM逻辑卷管理测试——创建逻辑卷
  3. 2021年春季学期-信号与系统-第十三次作业参考答案-第一小题
  4. MATLAB | Matlab 2020a/202b/2018a/2019b安装教程及资源及matlab基本案例(图像练手教程)
  5. 【论文解读】深度强化学习基石论文:函数近似的策略梯度方法
  6. python 将ipv4的格式转换
  7. android第三方应用,Android 第三方应用接入微信平台研究情况分享(一)
  8. 防止P2P终结者的方法
  9. 澳大利亚人一周发一次工资 经常月光不存钱
  10. java实用教程——组件及事件处理——对话框(颜色对话框,自定义对话框)
  11. iOS5中 UIViewController新方法的使用
  12. JVM证书制作步骤+耶鲁 CAS 配置
  13. 计算机网络课程优秀备考PPT之第一章概述(一)
  14. 详解Java中ArrayList、Vector、LinkedList三者的异同点
  15. linux添加自定义的命令!
  16. 400多个开源项目以及43个优秀的Swift开源项目-Swift编程语言资料大合集
  17. windows安装caffe
  18. 室内可见光定位matlab代码,visible-led-communication 这里给出了几个可见光通信的MATLAB程序...
  19. eclipse新建JSP页面报错:Multiple annotations found at this line解决方法
  20. C#使用iTextSharp合并pdf,添加页码

热门文章

  1. mysql中single是什么意思_single是什么意思
  2. coreutils8.32 hostid命令和源码分析
  3. 随机无梯度Frank-Wolfe方法的统一分析
  4. 最优化算法---可行方向之Frank-wolfe 方法(求解非线性规划问题)
  5. Video Caption Tutorial
  6. Windows窗口程序
  7. ssh远程重装Centos系统
  8. onenote同步速度慢
  9. 你有想过如何合适地给 JavaScript 变量命名吗?
  10. windows常用快捷命令大全总结