Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

are there any kind people who can help me with this task?I'm stuck with this one! use the card and deck classes to make a

are there any kind people who can help me with this task?I'm stuck with this one!

use the card and deck classes to make a simple solitaire card.The program should print the state of print statements and enter commands from the user with input statements.The solitaire card has the following rules: -You have 9 seats.The solitaire card starts with drawing a card from the deck for each slot and placing it on this slot.-For each round you can lay two or three cards, in different slots, with the following rules: oTo lay two cards, the sum of the value must be the cards that are already in the two slots must be 11.

To lay three cards, the cards that are already in all three slots must be picture cards (jack, queen and / or king)

-The solitaire card goes up when you have used up the deck.If you have no places you can legally lay, the solitaire card does not go up.

a) Import the classes Card and Deck from my examples

b) Create a class for the game itself. This class should have instance variables for the deck and the 9 slots.

c) The designer of the game class must make a new deck, make the 9 slots, draw cards from the deck and place them on the 9 slots

d) Create a method write_condition that prints what is in the 9 places and how many cards are left in the deck

e) Create a method that checks if the game is finished. It must returnTrue if the deck is empty and False otherwise

f) Create a method for placing two cards. The method must take the numbers of the two places as parameters. The method must check that this is a legal location. If it is a legal placement, the method must draw two new cards from the deck and place them on the two slots .

g) Create a method for placing three cards similar to the one for two cards

h) Create a code that allows the user to play the solitaire card using the class and methods from the previous sub-tasks. This can either be a method in the game class or part of the if __name__ == __main__ block. The solitaire card must end when the deck is empty with a message that the solitaire card has gone up. It is not mandatory to check that there are no legal places to post.

i) Create an if __name__ == __main__ block that starts the game.

we will use the code below to answer the question above :

the code for the classes is below:

import random

class Card:

def __init __ (self, type, value):

self.type = type

self.value = value

# String representation for the user

def __str __ (self): if self.value> = 1 and self.value <= 10:

return f "{self.type} {self.verdi}"

if self.verdi == 11:

return f "{self.type} Knekt"

if self.verdi == 12:

return f "{self.type} Dame"

if self.value == 13:

return f "{self.type} King"

return "invalid card"

class Deck:

def __init __ (self):

self.cards = []

for i in range (1, 14):

self.cards.append (Short ("Save", i))

self.cards.append (Short ("Routes", i))

self.cards.append (Short ("Clover", i))

self.cards.append (Short ("Hearts", i))

def stick (self):

random.shuffle (self.cards)

def move (self):

card = self.cards [-1]

share self.cards [-1]

return card

def __str __ (self):

result = "deck \ n"

for cards in the self.cards:

result + = str (card) + "\ n"

return result

def __len __ (self):

return len (self.cards)

class Player:

def __init __ (self, name, card):

self.name = name

self.card = kort

if __name__ == "__main__":

number_players = int (input ("Number of players:"))

players = []

deck = deck ()

deck .stock ()

for i in range (number_players):

name = input (f "Name of player {i}:")

card = deck.draw ()

player = Player (name, card)

players.append (player)

print ( "Status:")

for player in players:

print (f "Player {player.name} has {player.card}")

winner = players [0]

for player in players:

if player.card.value> winner.card. value:

winner = player

print (f "Winner is {winner.name} with {winner.card}")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago