我正在制作这段代码并且卡住,因为我必须随机为grid
分配值并返回它,所以在这种情况下我必须将10
单元格/网格部分分配给宝箱所以如果用户输入有宝箱的网格的网格参考,那么十个金币将被添加到玩家的整个集合中,所以这是我的code
到目前为止......
import random
def menu():
play=int(input('To play the game, press 1 and to exit, press 2'))
if play==1:
size=int(input('to play with 8x8 grid(This is the origional game), press 8, to play with 10x10 grid, press 10 and to play with 12x12 grid, press 12 '))
if size==8:
Grid=[' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '' ',' ',' ',' ',' ',' ',' ',' ',' ',' '' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ']
input('press enter when you would like to play')
def printgrid():
print(' | | | | | | | ')
print(" "+Grid[1]+" | "+Grid[2]+" | "+Grid[3]+" | "+Grid[4]+" | "+Grid[5]+" | "+Grid[6]+" | "+Grid[7]+" | "+Grid[8]+" ")
print(" | | | | | | |")
print("-----|-----|-----|-----|-----|-----|-----|-----")
print(' | | | | | | | ')
print(" "+Grid[9]+" | "+Grid[10]+" | "+Grid[11]+" | "+Grid[12]+" | "+Grid[13]+" | "+Grid[14]+" | "+Grid[15]+" | "+Grid[16]+" ")
print(" | | | | | | |")
print("-----|-----|-----|-----|-----|-----|-----|-----")
print(' | | | | | | | ')
print(" "+Grid[17]+" | "+Grid[18]+" | "+Grid[19]+" | "+Grid[20]+" | "+Grid[21]+" | "+Grid[22]+" | "+Grid[23]+" | "+Grid[24]+" ")
print(" | | | | | | |")
print("-----|-----|-----|-----|-----|-----|-----|-----")
print(' | | | | | | | ')
print(" "+Grid[25]+" | "+Grid[26]+" | "+Grid[27]+" | "+Grid[28]+" | "+Grid[29]+" | "+Grid[30]+" | "+Grid[31]+" | "+Grid[32]+" ")
print(" | | | | | | |")
print("-----|-----|-----|-----|-----|-----|-----|-----")
print(' | | | | | | | ')
print(" "+Grid[33]+" | "+Grid[34]+" | "+Grid[35]+" | "+Grid[36]+" | "+Grid[37]+" | "+Grid[38]+" | "+Grid[39]+" | "+Grid[40]+" ")
print(" | | | | | | |")
print("-----|-----|-----|-----|-----|-----|-----|-----")
print(' | | | | | | | ')
print(" "+Grid[41]+" | "+Grid[42]+" | "+Grid[43]+" | "+Grid[44]+" | "+Grid[45]+" | "+Grid[46]+" | "+Grid[47]+" | "+Grid[48]+" ")
print(" | | | | | | |")
print("-----|-----|-----|-----|-----|-----|-----|-----")
print(' | | | | | | | ')
print(" "+Grid[49]+" | "+Grid[50]+" | "+Grid[51]+" | "+Grid[52]+" | "+Grid[53]+" | "+Grid[54]+" | "+Grid[56]+" | "+Grid[57]+" ")
print(" | | | | | | |")
print("-----|-----|-----|-----|-----|-----|-----|-----")
print(' | | | | | | | ')
print(" "+Grid[57]+" | "+Grid[58]+" | "+Grid[59]+" | "+Grid[60]+" | "+Grid[61]+" | "+Grid[62]+" | "+Grid[63]+" | "+Grid[64]+" ")
print(" | | | | | | |")
print("-----|-----|-----|-----|-----|-----|-----|-----")
start=False
while not False:
printgrid()
for x in range(10):
Grid=random.randint.insert('x')
place=int(input('Grid refrene'))
if place==Grid==x:
print('Done')
elif play==2:
print('Good bye')
menu()