我要做的是将坐标(网格[0][0])标记为“A1”,(网格[0][1])标记为“A2”,(网格[1][0])标记为“B1”,(网格[1][1])标记为“B2”,依此类推。我正在创建一个游戏,玩家必须选择坐标,以便在游戏开始前删除其中的内容。你知道吗
B W B W A1 A2 A3 A4 W B W B I want to access like this B1 B2 B3 B4 B W B W C1 C2 C3 C4
现在,我正在询问用户他们想要删除哪一个片段(“B”或“W”)(可以是他们自己的片段)。我希望他们能够为左上方的“B”键入“A1”。你知道吗
removeB = input("BLACK, remove one of your pieces by typing in it's coordinates")
我不知道如何将A1,A2,B1,B2‘变量’分配到指定的坐标。我希望能够做到:
if(removeB == A1): grid[row -1][col -1].append('-') # '-' = empty
如果有帮助,我将代码附在下面:
import random numrows = 3 numcols = 4 def initial(): grid = [] count = 0 y = 2 for x in range(numrows)s grid.append([]) for y in range(numcols): if ((x + y)%2): grid[x].append('W') else: grid[x].append('B') for x in grid: print(*x, sep=' ',end="\n") print("") color = input("Press 'Enter' to see which color you will be playing") print("") rand=random.randrange(1,3) if(rand == 1): print("Player1 you will be playing as BLACK") print("Player2 you will be playing as WHITE") else: print("Player1 you will be playing as WHITE") print("Player2 you will be playing as BLACK") print("") print(" The game board can be navigated as if it were: ") print("") example = '''\ A1 A2 A3 A4 B W B W B1 B2 B3 B4 = W B W B C1 C2 C3 C4 B W B W ''' print(example) print("and so on.....") print("") if(rand == 1): removeB = input("~BLACK Player, remove one of your pieces by typing in the coordinates: ") removeW = input("~WHITE Player, remove one of your pieces by typing in the coordinates: ") else: removeW = input("~WHITE Player, remove one of your pieces by typing in the coordinates: ") removeB = input("~BLACK Player, remove one of your pieces by typing in the coordinates: ")
提前感谢您花时间和精力回答我的问题。你知道吗
顺便说一下,我知道我的代码很难理解。我对python只有3个星期的了解,哈哈。我还没有完成代码,只是挂断了这部分。。。。你知道吗
至于标记网格坐标,我发现我可以在if语句中使用变量'removeB'(存储的用户输入)。因此,如果(removeB==“1”),则将网格[0][0]的坐标从“B”设置为“-”(空)
这是我的简历:
输出:
我并没有包括我在上面使用的几个函数,但是它们的操作与它们的名称一样。如果你对我在这里所涉及的内容有任何疑问,我很乐意分享我的发现的其他方面。你知道吗
相关问题 更多 >
编程相关推荐