当前正在使用python开发存储卡游戏。那里有一块有文字的纸牌。
两张卡片包含相同的单词,您尝试收集成对的具有相同单词的卡片。
例如,如果板上有10张卡,则有5个单词。您可以通过连续翻转具有相同单词的两张牌来配对。如果弄错了,两张卡都会向后翻转。该游戏让人想起this游戏,但我的版本使用文字代替。
我当前的代码一团糟,但我只是一个初学者。我目前陷入困境,不知道如何继续。如果有人可以帮助我,将不胜感激。
class Playingboard:
def __init__(self, points):
self.points = points
def randomCard(self):
for row in range(1, 5);:
for column in range(1, 5):
print (i*j, end " ")
print()
class Cards:
def __init__(self, ShowCard = False, word):
#
self.ShowCard = ShowCard
self.word = word
def ShowCard(self):
#Shows the word
def __lt__ (self):
#Compares the cards to see if it's the same word
wordlist =[car, computer, house, speaker, piano, drums]
cardlist = []
amount_word = 6
for i in amount_word:
card = Card(wordlist[i])
cardlist.append(card)
cardlist.append(card)
答案 0 :(得分:1)
要做的第一件事是运行您的代码。当Python引发错误时,请修复程序的该部分,以免引起错误。然后,重复该过程,直到整个过程运行无误。
您发布的代码中有很多错误。以下是代码的副本,该代码将无任何错误地运行。我建议您将其与您的版本进行比较,以便您可以查看出错的地方。
class Playingboard:
def __init__(self, points):
self.points = points
def randomCard(self):
for row in range(1, 5):
for column in range(1, 5):
print (i*j, end = " ")
print()
class Cards:
def __init__(self, word, ShowCard = False):
#
self.ShowCard = ShowCard
self.word = word
def ShowCard(self):
pass
#Shows the word
def __lt__ (self):
pass
#Compares the cards to see if it's the same word
wordlist =['car', 'computer', 'house', 'speaker', 'piano', 'drums']
cardlist = []
for word in wordlist :
card = Cards(word)
cardlist.append(card)
cardlist.append(card)