掷筛子游戏的基本规则是:开始都有100金币,掷出1,2,3的扣除相应的金币,掷出4,5,6加上相应的金币。如果前两次都掷出1的话游戏直接算输,前两次都掷出6的话游戏直接算胜利。除此之外,游戏金币扣光算输,游戏金币超过200算赢,一共最多十次投掷机会。
游戏运行结果如图:
下面是基本代码:
# -*- coding: utf-8 -*-
import random
import sys
def 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." % 100
def Dice_rolling():
point = random.randint(1, 6)
print "the point is: ", point
return point
def Dice_one(golds):
print "So bad, your golds will be less 40."
golds -=40
print "Your golds now are: ", golds
return golds
def Dice_two(golds):
print "Not so lucky, your golds will be less 30."
golds -= 30
print "Your golds now are: ", golds
return golds
def Dice_three(golds):
print "Ok, your golds will be less 10."
golds -= 10
print "Your golds now are: ", golds
return golds
def Dice_four(golds):
print "Good, your gold will be more 10."
golds += 10
print "Your golds now are: ", golds
return golds
def Dice_five(golds):
print "Great, your gold will be more 30."
golds += 30
print "Your golds now are: ", golds
return golds
def Dice_six(golds):
print "So lucky! your golds will be more 50."
golds += 50
print "Your golds now are: ", golds
return golds
def 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 golds
start()
golds = 100
print "第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 = 3
while 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