I am trying to make a text based object oriented card game. Two players draw a card each from a deck of cards, and the player with the strongest card wins. I have four classes for this game: Card, Deck, Player, Game. My question is: How can i compare each players card to each other and determine the strongest one. All other suggestions about the code are welcome. Best regards HWG.
Here is my code:
Card
class Card():
values = [None, None, 2, 3, 4, 5, 6, 7, 8, 9, 10, "Jack", "Queen", "King",
"Ace"]
suits = ["hearts", "spades", "diamond", "clubs"]
def __init__(self, value, suit):
self.value = value
self.suit = suit
def __repr__(self):
return str(self.values[self.value]) + " of " + str(self.suits[self.suit])
Deck
from random import shuffle
from card import Card
class Deck():
def __init__(self):
self.cards = []
for v in range(2, 15):
for s in range(4):
self.cards.append(Card(v, s))
shuffle(self.cards)
Player
from deck import Deck
class Player():
def __init__(self, name):
self.name = name
self.card = None
self.wins = 0
Game
from player import Player
from deck import Deck
import getch
class Game():
def __init__(self):
player1_name = input("Player One Name: ")
player2_name = input("Player Two Name: ")
self.deck = Deck()
self.player1 = Player(player1_name)
self.player2 = Player(player2_name)
self.cards = self.deck.cards
def game_loop(self):
while len(self.cards) >= 2:
print("\nPress enter to draw")
getch.getch()
player1_card = self.cards.pop()
player2_card = self.cards.pop()