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'对象不支持项目分配 –
或者您是否有电子邮件我可能会从您那里获得一些支持? –