Add files via upload

Added functionality for cellar, moat, and militia.
This commit is contained in:
Brad Stein 2017-12-27 02:12:43 -06:00 committed by GitHub
parent 1102ad7de1
commit b90b70f118
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 73 additions and 16 deletions

View File

@ -10,6 +10,8 @@ class Card:
Victory = auto()
Curse = auto()
prevent_attack = False
def __init__(self, name, cost, cardtype, value, coin, action, buy, draw, owner):
self.__name = name
self.__cost = cost

31
cellar.py Normal file
View File

@ -0,0 +1,31 @@
from card import Card
class Cellar(Card):
def effect(self):
hand_index = 0
cards_discarded = 0
have_not_run_yet = True
while self._Card__owner.get_hand().get_remaining() >= 0 and \
0 <= hand_index < self._Card__owner.get_hand().get_remaining() and \
(hand_index != self._Card__owner.get_hand().get_supply().index(self) or have_not_run_yet):
hand_index = int(input("Player " + str(self._Card__owner.get_table().get_players().index(self._Card__owner))
+ ", input the index from your hand to discard that card and gain an action, or "
" input an impossible index to end discard selection: "))
if 0 <= hand_index < self._Card__owner.get_hand().get_remaining() and \
hand_index != self._Card__owner.get_hand().get_supply().index(self):
self._Card__owner.discard_from_hand(hand_index)
self._Card__owner.print_hand()
cards_discarded += 1
# in case last card is discarded as that will kill loop & set to itself
hand_index = self.__get_last_non_cellar_card()
have_not_run_yet = False
self._Card__owner.add_actions(cards_discarded)
def __get_last_non_cellar_card(self):
result = -1
for c in self._Card__owner.get_hand().get_supply():
if "Cellar" not in type(c).__name__:
result = self._Card__owner.get_hand().get_supply().index(c)
return result

34
game.py
View File

@ -2,6 +2,8 @@ from table import Table
from player import Player
from card import Card
from militia import Militia
from moat import Moat
from cellar import Cellar
def main():
@ -11,10 +13,15 @@ def main():
play_game(game[0])
def play_game(game_table):
game_table.play()
# place holder setup for testing until frontend constructed
def setup_new_game(game_list, parameter, card_info):
t = Table()
humans = parameter[0]
bots = parameter[1]
# bots = parameter[1]
index = 0
for p in parameter[2:]:
@ -35,22 +42,18 @@ def setup_new_game(game_list, parameter, card_info):
human.draw_hand()
t.add_player(human)
for i in range(bots):
bot = Player(False, t)
bot.draw_deck(t, get_starting_deck())
bot.draw_hand()
t.add_player(bot)
# for i in range(bots):
# bot = Player(False, t)
# bot.draw_deck(t, get_starting_deck())
# bot.draw_hand()
# t.add_player(bot)
game_list.append(t)
def play_game(game_table):
game_table.play()
def get_game_parameters():
# humans, bots, card #1, card #2, ... etc
return [1, 1, True, True, True, True, True, True, False, True, True, True, True, True, True, True, True, True, True]
return [2, 1, True, True, True, True, True, True, False, True, True, True, True, True, True, True, True, True, True]
def get_card_info():
@ -63,12 +66,12 @@ def get_card_info():
["Dutchy", 5, Card.CardType.Victory, 3, 0, 0, 0, 0, Card, 12], # 5
["Province", 8, Card.CardType.Victory, 6, 0, 0, 0, 0, Card, 12], # 6
["Curse", 0, Card.CardType.Curse, -1, 0, 0, 0, 0, Card, 30], # 7
["Cellar", 2, Card.CardType.Action, 0, 0, 1, 0, 0, Card, 10], # 8*
["Cellar", 2, Card.CardType.Action, 0, 0, 1, 0, 0, Cellar, 10], # 8
["Market", 5, Card.CardType.Action, 0, 1, 1, 1, 1, Card, 10], # 9
["Merchant", 3, Card.CardType.Action, 0, 0, 1, 0, 1, Card, 10], # 10*
["Militia", 4, Card.CardType.Attack, 0, 2, 0, 0, 0, Militia, 10], # 11
["Mine", 5, Card.CardType.Action, 0, 0, 0, 0, 0, Card, 10], # 12*
["Moat", 2, Card.CardType.Reaction, 0, 0, 0, 0, 2, Card, 10], # 13*
["Moat", 2, Card.CardType.Reaction, 0, 0, 0, 0, 2, Moat, 10], # 13
["Remodel", 4, Card.CardType.Action, 0, 0, 0, 0, 0, Card, 10], # 14*
["Smithy", 4, Card.CardType.Action, 0, 0, 0, 0, 3, Card, 10], # 15
["Village", 3, Card.CardType.Action, 0, 0, 2, 0, 1, Card, 10], # 16
@ -78,6 +81,7 @@ def get_card_info():
def get_starting_deck():
# return [["Copper", 7], ["Estate", 3]]
# return [["Market", 2], ["Merchant", 2], ["Smithy", 2], ["Village", 2], ["Moat", 2]]
return [["Militia", 4], ["Village", 3], ["Smithy", 3]]
return [["Militia", 4], ["Cellar", 3], ["Moat", 3]]
main()
main()

15
hand.py
View File

@ -18,6 +18,21 @@ class Hand(Supply):
result += 1
return result
def blocks_attack(self, what_attack):
yes_no = False
found_at = -1
for c in self._Supply__card:
if c.prevent_attack:
found_at = self._Supply__card.index(c)
if found_at >= 0:
yes_no = "Y" == input("Player " + str(self._Supply__card[found_at].get_owner().get_table().get_players().
index(self._Supply__card[found_at].get_owner()))
+ ", enter 'Y' if you'd like to reveal " + self._Supply__card[found_at].get_name()
+ " to block the " + what_attack + " attack: ")
return yes_no
def __get_unique_types(self):
unique_type = list()

View File

@ -5,7 +5,7 @@ from random import randint
class Militia(Card):
def effect(self):
for player in self._Card__owner.get_table().get_players():
if self._Card__owner != player:
if self._Card__owner != player and not player.get_hand().blocks_attack(self.get_name()):
player.print_hand()
print("Player " + str(self._Card__owner.get_table().get_players().index(player)) + ", you MUST discard "
"down to 3 cards.")

5
moat.py Normal file
View File

@ -0,0 +1,5 @@
from card import Card
class Moat(Card):
prevent_attack = True