Python

Unfinished... Coup is actually really hard to make so I kinda gave up, I was going to make an online coup like Treason Coup

fork
loading
Files
  • main.py
main.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
142
143
144
145
146
147
148
149
150
151
152
from random import sample
from time import sleep

def waitForChallenge(player, card):
  print('Waiting for challenge')

def askBlock(player):
  #do you block
  return True

class Player():
  def __init__(self, name, game):
    self.name = name
    self.cards = []
    self.coins = 2
    self.game = game
  def coup(self, player):
    self.coins -= 7
    player.dropCard()
  def forgein_aid(self):
    for player in self.game.players:
      if player != self: 
        askBlock(self, player)
    self.coins += 3
  def tax(self):
    waitForChallenge(self, Duke)
    self.coins += 3
  def assassinate(self, player):
    waitForChallenge(self, Assassin)
    if not player.block():
      self.coins -= 3
      player.dropCard()
  def steal(self, player):
    waitForChallenge(self, Capitan)
    if not player.block():
      self.coins += 2
      player.coins -= 2
  def exchange(self):
    waitForChallenge(self, Ambassador)
    #exchange
  def block(self):
    # if they block
    if askBlock(self):
      waitForChallenge(self)
      return True
    return False
    #if they dont:
  def dropCard(self):
    for cards in self.cards:
      print(cards.__class__.__name___)
    dropCard = input('Choose a card to drop: '+'')
  def turn(self):
    self.can_coup = True if self.coins >= 7 else False
    self.has_to_coup = False if self.coins < 10 else True
    if self.has_to_coup:
      print('Coup')
    choices = ['tax', 'steal', 'assasinate', 'coup', 'income', 'exchange', 'foregin aid']
    choice = input('What would you like to do?\n'+''.join([str(choices.index(i)+1)+') '+i.upper()+'\n' for i in choices]))
    if choice == '1':
      self.tax()
    elif choice == '2':
      self.steal(input('Who do you want to steal from'))
    elif choice == '3':
      self.assassinate(input('Who do you want to assassinate'))
    elif choice == '4':
      self.coup(input('Who do you want to assassinate'))
    elif choice == '5':
      self.coins += 1
    elif choice == '6':
      self.exchange()
    elif choice == '7':
      self.foregin_aid()
    else:
      print('invaild')


class Game():
  def __init__(self):
    self.isRunning = True
  def new_game(self, deck, cards, players):
    self.deck = deck
    for card in cards: card(self.deck)
    self.deck.shuffle()
    self.players = players
    for player in self.players:
      self.deck.cards[0].addPlayer(player, self.deck)
      self.deck.cards[0].addPlayer(player, self.deck)

  def run(self):
    self.players = [player for player in self.players if len(player.cards) != 0]
    while len(self.players) > 1:
      print('Cards in deck: ' + str(len(self.deck.cards)))
      print('Players: ')
      print(*[player.name for player in self.players])
      for player in self.players:
        print('It is '+player.name+'\'s turn now')
        player.turn()
      sleep(100)
    print('Winner: '+self.players[0].name+'!')

class Deck():
  def __init__(self):
    self.card_types = []
  def shuffle(self):
    self.cards = sample(self.card_types*3, len(self.card_types*3))

class Card():
  def __init__(self, deck):
    deck.card_types.append(self)
  def addPlayer(self, player, deck):
    player.cards.append(self)
    del deck.cards[0]
  def removeCard(self, player, deck):
    player.cards.remove(self)
    deck.append(self)

class Contessa(Card):
  def __init__(self, deck):
    Card.__init__(self, deck)
    self.blocks_assassination = True

class Assassin(Card):
  def __init__(self, deck):
    Card.__init__(self, deck)
    self.can_assassinate = True

class Capitan(Card):
  def __init__(self, deck):
    Card.__init__(self, deck)
    self.can_steal = True
    self.blocks_steal = True

class Duke(Card):
  def __init__(self, deck):
    Card.__init__(self, deck)
    self.can_tax = True
    self.blocks_foreign_aid = True

class Ambassador(Card):
  def __init__(self, deck):
    Card.__init__(self, deck)
    self.blocks_steal = True
    self.can_exchange = True

game = Game()
while game.isRunning:
  p1 = Player('p1', game)
  p2 = Player('p2', game)
  p3 = Player('p3', game)
  game.new_game(Deck(), [Contessa, Assassin, Capitan, Duke, Ambassador], [p1, p2, p3])
  game.run()
  game.end()