-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameCode.py
141 lines (107 loc) · 4.59 KB
/
GameCode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
from random import shuffle
class Card :
suits = {" ", "Red", "Green", "Blue", "Yellow", "Trump"}
values = {"Switch", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"}
def __init__(self, suit, value) :
self.suit = suit
self.value = value
def show(self):
print ("The {} of {}".format(self.value, self.suit))
class Deck :
def __init__(self) :
self.cards = []
for suit in ["Red", "Green", "Blue", "Yellow"] :
for value in range(1, 16) :
self.cards.append(Card(suit, value))
for value in range(1,9) :
self.cards.append(Card("Trump", value))
for i in range(0, 4) :
self.cards.append(Card(" ", "Switch"))
shuffle(self.cards)
def show(self) :
for card in self.cards :
card.show()
def shuffle(self) :
import random
random.shuffle(self.cards)
def drawCard(self) :
return self.cards.pop()
def drawCards(self, n) :
cards = []
for i in range(0, n) :
cards.append(self.drawCard())
return cards
class Player :
def __init__(self, name) :
self.name = name
self.hand = []
self.score = 0
def draw(self, deck) :
self.hand.append(deck.drawCard())
def drawCards(self, deck, n) :
for i in range(0, n) :
self.draw(deck)
def showHand(self) :
for card in self.hand :
card.show()
def playCard(self, card) :
self.hand.remove(card) #TODO: check if card is in hand (error handling)
return card.value
def showScore(self) :
print ("{} has {} points".format(self.name, self.score))
class Game :
def __init__(self) :
self.deck = Deck()
self.players = []
self.turn = 0
self.current_hand = []
self.player_clockwise_order = []
def addPlayer(self, player) :
self.players.append(player)
self.player_clockwise_order.append(player) # Set the order that the players are supposedly 'sitting;
def play(self) :
if len(self.players) == 0 :
print("There are no players") # How can you play a game without players?
elif len(self.players) == 1 :
print("There is only one player") # How can you play a game with only one player?
elif len(self.players) == 2 :
print("There are two players, 20 cards are removed") # 20 cards are removed from the deck when there are only two players
self.deck.drawCards(20)
num_cards_pp = 13
elif len(self.players) == 3 :
print("There are three players") # No cards are removed from the deck when there are three players - each player receives 12 cards
num_cards_pp = 12
elif len(self.players) == 4 :
print("There are four players") # No cards are removed from the deck when there are four players - each player receives 9 cards
num_cards_pp = 9
elif len(self.players) == 5 :
print("There are five players") # 2 cards are removed from the deck when there are five players - each player receives 7 cards
num_cards_pp = 7
elif len(self.players) == 6 :
print("There are six players") # No cards are removed from the deck when there are six players - each player receives 6 cards
num_cards_pp = 6
else :
print("There are more than six players") # The limit on the number of players is six
for player in self.players : # Each player draws cards from the deck until they have the right number of cards
player.drawCards(self.deck, num_cards_pp)
self.deck.drawCard() # The deck is shuffled and the first card is shown to all players TODO--> gonna need to make this work visually
# class AIPlayer :
# def __init__(self, name) :
# self.name = name
# self.hand = []
# self.score = 0
# def draw(self, deck) :
# self.hand.append(deck.drawCard())
# def showHand(self) :
# for card in self.hand :
# card.show()
# def playCard(self, card) :
# self.hand.remove(card)
# return card.value
# def showScore(self) :
# print ("{} has {} points".format(self.name, self.score))
# def play(self, game) :
# self.drawCards(game.deck, num_cards_pp)
# self.showHand()
# card = self.playCard(self.hand[0]) #TODO: decide how to play a card
# return card