日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python文字游戏循环3次_Python寻宝游戏中的无限循环

發布時間:2023/12/16 python 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python文字游戏循环3次_Python寻宝游戏中的无限循环 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

所以我創造了一個簡單的尋寶游戲,你可以在一個棋盤上尋找三個寶藏。但在猜了6次之后,我陷入了困境!X代表你搜索過的區域,$符號是你找到的寶藏。請幫忙!!!!在import random

def hide_treasure(board):

treasures=0

while treasures<=3:

random_row=random.randrange(0,5)

random_col=random.randrange(0,5)

if(0<=random_row<5) and(0<=random_col<5) and (board[random_row] [random_col]==" "):

board[random_row][random_col]="T"

treasures+=1

def display_board(board,show_treasure=False):

for col in range(5):

print " %d " %col,

print

for row in range(5):

print " %d:" %(row)," | ".join(board[row]).replace("T"," ")

print " ---+---+---+---+---"

if show_treasure==True:

" ".replace(" ","T")

def make_user_move(board):

valid_move=False

while not valid_move:

try:

ask_row=input("What row would you like to search (0-4): ")

ask_col=input("What col would you like to search (0-4): ")

if board[ask_row][ask_col]=="T":

board[ask_row][ask_col]="$"

print

print"YES! You found a treasure."

return True

elif board[ask_row][ask_col]=="$" or board[ask_row][ask_col]=="X":

print

print"You already tried there, please pick again."

else:

board[ask_row][ask_col]="X"

print

print"Nothing there."

break

except ValueError:

print"Integers only for row and column values. Please try again!"

continue

except IndexError:

print

print"Sorry invalid location. Please try again!"

def main():

board=[[" "," "," "," "," "],[" "," "," "," "," "],[" ", " "," "," "," ",],[" "," "," "," "," "],[" "," "," "," "," "]]

print"WELCOME TO TREASURE HUNT!"

guess=10

treasures=0

while guess!=0 and treasures!=3:

print

print"You have",guess,"guesses left and have found",treasures,"/3 treasures"

hide_treasure(board)

display_board(board)

guess-=1

if make_user_move(board):

treasures+=1

if guess==0 and treasures!=3:

display_board(show_treasure=True)

print"OH NO! You only found %d"%treasures,"/3 treasures."

print

print"*** GAME OVER ***"

elif treasures==3:

display_board(board)

print"CONGRATULATIONS! You found ALL of the hidden treasure."

print

print"*** GAME OVER ***"

main()

總結

以上是生活随笔為你收集整理的python文字游戏循环3次_Python寻宝游戏中的无限循环的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。