def board10():
from random import randint
coins = 0
board = []
charac = []
for i in range(10):
row = []
for j in range(10):
row.append('O')
charac[x][y] = 'x'
board.append(row)
def print_board(board):
for row in board:
print (" ".join(row))
print ("Let's play Treasure Hunt!")
print_board(board)
print ("Total Coins:", coins)
def random_row1(board):
return randint(O, len(board) - 1)
def random_row2(board):
return randint(O, len(board) - 1)
def random_col1(board):
return randint(O, len(board[0]) - 1)
def random_col2(board):
return randint(O, len(board[0]) - 1)
left_across1 = random_row1(board)
right_across1 = random_row2(board)
up_vertical1 = random_col1(board)
down_vetical1 = random_col2(board)
for turn in range(10):
left_across2 = int(input("How many moves LEFT of the grid would you like to go?:"))
right_across2 = int(input("How many moves RIGHT of the grid would you like to go?:"))
up_vertical2 = int(input("How many moves UP of the grid would you like to go?:"))
down_vertical2 = int(input("How many moves DOWN of the grid would you like to go?:"))
if left_across2 == left_across1 and right_across2 == right_across1 and up_vertical2 == up_vertical1 and down_vertical2 == down_vertical1:
print ("Congratulations! You landed on a Treasure Chest!")
coins + 10
break
else:
if (left_across2 < 0 or left_across2 > 8) or (right_across2 < 0 or right_across2 > 8) or (up_vertical2 < 0 or up_vertical2 > 8) or (down_vertical2 < 0 or down_vertical2 > 8):
print ("Oops, that's not even in the grid. Try Again")
else:
print ("Turn", turn + 1)
print_board(board)
print ("Total Coins:", coins)
choice = "";
while loop ==1:
print ("Menu")
print ("a.) Play the Game")
print ("b.) Quit the Game")
print ("")
choice = input("Select an option = ")
loop =0
if choice == 'a':
print("You have selected to Play the Game")
print("Select which size grid you would like to play")
print("1.) 8 x 8")
print("2.) 10 x 10")
print("3.) 12 x 12")
choice=input("Select an option = ")
if choice =='1':
board8()
elif choice == '2':
board10()
elif choice == '3':
board12()
else:
print("You've picked an invalid choice")
loop ==1
elif choice == 'b':
print("You have selected to Quit the Game")
quit()
else:
print("You've Picked an invalid Choice")
loop==1
目前我試圖讓寶島的遊戲,其中的代碼打印出10×10與(試圖讓這個先工作,然後實現大小地圖的其餘部分) X在地圖的左下角。然後用戶通知節目有多少位置要將角色向上,向左,向右和向下移動,然後移動。輸入字符到地圖
它也應該有隨機隱藏的硬幣,讓角色獲得積分。
目前我無法使用電路板上的X進行打印。因爲它現在它返回錯誤
Traceback (most recent call last):
File "*file Root*/Controlled Assessment (1).py", line 91, in <module>
board10()
File "*file Root*/Controlled Assessment (1).py", line 17, in board10
charac[x][y] = 'x'
NameError: name 'x' is not defined
任何幫助將不勝感激!
感謝大衛的迴應,非常感謝。感謝您的編輯!回答了我的問題。 –
你現在可以看看嗎。當我嘗試運行我得到這個錯誤代碼: 代碼: 從隨機進口randint 幣= 0 板對於i = [] CHARAC = [0,1,2,3,4,5] 在範圍(10): 行= [] 在範圍Ĵ(10): row.append( 'O') CHARAC [1] [1] = 'X' board.append(行) 錯誤: 文件「*文件根* /受控評估(1).py」,第91行,在 board10() 文件「*文件根* /受控評估(1)。py「,第17行,在board10 charac [1] [1] ='X' TypeError:'int'對象不支持項目分配 –
或者您是否有電子郵件我可能會從您那裏獲得一些支持? –