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
コードはANと(この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 ボード私のために= [] CHARAC = [0,1,2,3,4,5] を範囲内(10): 行範囲内のjに対する= [] (10): row.append( 'O') CHARAC [1] [1] = 'X' board.append(行) エラー: ファイル "* File Root */Controlled Assessment(1).py"、行91、 board10() ファイル "*ファイルルート* /制御評価(1)。"int"オブジェクトは項目割り当てをサポートしていません –
また、あなたからのサポートを得ることができる電子メールがありますか? –