我正在编写一个连接4的游戏。如果你不知道规则,查一下,这是一个相对简单的游戏。我把每一行都列成一个单子。但是,它会在另一行的下面打印每一行。我想让它把每一行打印在另一行的旁边。你知道吗
#Variables that determine how close up or if the slot is full for each column
ZeroTime = 0
OneTime = 0
TwoTime = 0
ThreeTime = 0
FourTime = 0
FiveTime = 0
SixTime = 0
#Makes the List for Each Row
ListZero = ["0",".", ".", ".", ".", ".", ".", "."]
ListOne = ["1",".", ".", ".", ".", ".", ".", "."]
ListTwo = ["2",".", ".", ".", ".", ".", ".", "."]
ListThree = ["3",".", ".", ".", ".", ".", ".", "."]
ListFour = ["4",".", ".", ".", ".", ".", ".", "."]
ListFive = ["5",".", ".", ".", ".", ".", ".", "."]
ListSix = ["6",".", ".", ".", ".", ".", ".", "."]
#Asks The Players For Their Usernames
namo = str(input("Player O what is your name: "))
namx = str(input("Player X what is your name: "))
print (namo + " is using O and " + namx + " is using X")
#Prints Current Board
print ("""
The current board is:
0 1 2 3 4 5 6
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
""")
#Asks the O player for which column they are going to choose
ot = str(input(namo + ", you're O! Enter which column you choose:"))
#Adds the slot
#For Slot 0
if ot == "0":
ListZero [7 - ZeroTime] = "O"
print (ListZero [0 + ZeroTime])
ZeroTime = ZeroTime + 1
if ot == "1":
ListOne [7 - ZeroTime] = "O"
print (ListZero [0 + ZeroTime])
ZeroTime = ZeroTime + 1
if ot == "2":
ListTwo [7 - ZeroTime] = "O"
print (ListZero [0 + ZeroTime])
ZeroTime = ZeroTime + 1
if ot == "3":
ListThree [7 - ZeroTime] = "O"
print (ListZero [0 + ZeroTime])
ZeroTime = ZeroTime + 1
if ot == "4":
ListFour [7 - ZeroTime] = "O"
print (ListZero [0 + ZeroTime])
ZeroTime = ZeroTime + 1
else:
print ("""We Hit an Error!
Sorry, we don't have a slot for that. The code only allows these
slots:
0, 1, 2, 3, 4, 5, 6.
Your turn has been skipped. """) #Added turn has been skipped, I can
fix that later but we're in the prototype right now
#Prints the Board After That
print ("""
The current board is:
""")
#I was confused on printing lists with the [] and '' so I googled
online, the base code for this was found online. However, I added
ListZero, ListOne, etc.
print(*ListZero, sep='\n')
print(*ListOne, sep='\n')
print(*ListTwo, sep='\n')
print(*ListThree, sep='\n')
print(*ListFour, sep='\n')
print(*ListFive, sep='\n')
print(*ListSix, sep='\n')
下面是一个简短的片段,介绍如何垂直打印相邻的两个列表。也许你可以把它扩展到你的代码中。
zip
可以接受任何数量的支持迭代的对象。你知道吗输出:
这是你的密码对应的。。你知道吗
输出:
希望这有帮助。你知道吗
可以使用提供多维数组的numpy数组。你知道吗
您可以先遍历列表元素的位置,然后遍历列表,而不是按顺序打印列表:
不过,维尼思的解决方案更为优雅。你知道吗
相关问题 更多 >
编程相关推荐