擲篩子遊戲的基本規則是:開始都有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
初學者 用python寫的擲幣遊戲練習
擲色子 學習python 第三天的小白,做個記錄 import random print 30 print t歡迎進入擲幣遊戲 print 30 uesername input 輸入使用者名稱 money 0answer input 確定進入遊戲嗎 是 否 if answer 是 p判斷遊戲幣是否充...
自己編的分頁模組
因為要做個文字資料庫搜尋系統,順便寫了這個,加了點 美化 美工太差 讀資料時候可以用fread函式和implode結合,例如 msg implode fread data.txt filesize data.txt msg是乙個陣列 廢話 配合for i 0 i mline i 來讀取檔案,mlin...
用crosstool ng構建自己的交叉編譯工具鏈
交叉編譯器是編譯器的一種,它執行在一種平台下卻生成另一種平台執行的二進位制檔案。當前構建交叉編譯器的方法有很多,這裡介紹一種方便快捷的方式 使用crosstool ng 1.從crosstool ng cd crosstool ng 1.21.0 3.執行編譯三步曲 configure prefix...