Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is python. A common memory matching game played by young children is to sta

ID: 3671233 • Letter: T

Question

This is python.

A common memory matching game played by young children is to start with a deck of cards that contains identical pairs. For example, given six cards in the deck, two might be labeled 1, two labeled 2 and two labeled 3. The cards are shuffled and placed face down on a board. A player then selects two cards that are face down, turns them face up, and if the cards match they are left face up. If the two cards do not match, they are returned to their original face down position. The game continues until all cards are face up.

Write a program that plays the memory matching game. When it start, the program prompts the user for the number of rows and columns for the game board that contains the cards. The total number of cards must be even. Assume that the board dimensions are at most 8 by 9 or 9 by 8. Your cards must be numbered from 1 through (number of rows * number of columns) / / 2. Your program allows the player to specify the cards that she would like to select through a coordinate system as shown in the sample run below. All the cards that are face down are indicated by *. For example, in the following layout of a 4 by 4 game board

the pair of 8 which are face up are at coordinates (1,1) and (3,2). Pay attention to how the coordinates are specified: row number followed by column number, both start at index 1, not zero. A sample run of the game is as follows:

Another sample run is as follows:

A third sample run is as follows:

Design Requirments: You need to use three classes: Card, Deck and Game. Card stores both the card's value and face (a string or Boolean variable to indicate whether the card is facing up or down). Deck contains the cards needed for the game. It will contain among its methods a method to deal a card, another for shuffling the deck, and a method that returns number of cards left in the deck. These two classes are not identical to the classes Card and Deck discussed in the book but have many things in common. The class Game simulates playing a single game and represents the interaction between the user and the other classes. Its instance members store a 2D list (of card objects) representing the game board where the cards are placed, number of rows and number of columns of the game board. Among the instance methods of the Game class: play(), which simulates playing the game; isGameOver(), which checks whether or not the game is over; displayBoard(), which displays the board; populateBoard(), which creates the initial 2D list of identical pairs of cards with all the cards facing down. Most probably, you will need to write other instance methods as you see appropriate.    

Use the following test program:

The format of the output and input of your program must be the same as what is shown in the sample runs above.

Explanation / Answer

I miss the play method and the shuffling :( I can not reach the time
else works fine:

code:

class Card:
def __init__(self, card):
self.card = card
self.face = True
  
def getCard(self):
return self.card
  
def setFace(self, b):
self.face = b;
  
def getFace(self):
return self.face
  
class Deck:
def __init__(self, numberCards):
self.numberCards = numberCards
  
def getNumberCards(self):
return self.numberCards
  
class Game:
status = 'initial'
def __init__(self, rows, columns):
self.rows = rows
self.columns = columns
self.cards = []
self.populateBoard()
  
def Play():
return 0
  
def GameOver(self):
if self.status == 'gameover':
return True
else:
return False
  
def displayBoard(self):
c = ''
d = " "
cards = []
for k in range(self.columns):
d = d + str(k) + " "
print(d)
print("-----------")
for i in range(self.rows):
c = str(i)+' | '
cards = self.cards[i]
for j in range(self.columns):
if cards[j].getFace() == False:
c = c + '* ';
else:
c = c + str(cards[j].getCard()) +' ';
print (c)
  
  
def populateBoard(self):
count = 0
card = []
for i in range(self.rows):
for j in range(self.columns):
if (i+j) % 2 == 0:
count = count +1
card.append(Card(count))
card.append(Card(count))
self.cards.append(card)
card = []

def main():
while True:
# Force user to enter valid value for number of rows
while True:
rows = input("Enter number of rows ")
if rows.isdigit() and ( 1 <= int(rows) <= 9):
rows = int(rows)
break
else:
print (" ***Number of rows must be between 1 and 9! Try again.***")
# Adding *** and indenting error message makes it easier for the user to see

# Force user to enter valid value for number of columns
while True:
columns = input("Enter number of columns ")
if columns.isdigit() and ( 1 <= int(columns) <= 9):
columns = int(columns)
break
else:
print (" ***Number of columns must be between 1 and 9! Try again.***")

if rows * columns % 2 == 0:
break
else:
print (" ***The value of rows X columns must be even. Try again.***")

  
game = Game(rows, columns)
game.displayBoard()
"""game.play()"""

if __name__ == "__main__":
main()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote