add cattletruck
This commit is contained in:
parent
db98f88db0
commit
344b7cc043
@ -129,9 +129,9 @@ class Deck:
|
||||
def peek(self, n_cards: int) -> list:
|
||||
return self.cards[:n_cards]
|
||||
|
||||
def peek_scrap_pile(self) -> cs.Card:
|
||||
def peek_scrap_pile(self, n_cards: int=1) -> List[cs.Card]:
|
||||
if len(self.scrap_pile) > 0:
|
||||
return self.scrap_pile[-1]
|
||||
return self.scrap_pile[-n_cards:]
|
||||
else:
|
||||
return None
|
||||
|
||||
|
@ -139,7 +139,20 @@ class CattleTruck(TrainCard):
|
||||
super().__init__("Cattle Truck")
|
||||
self.icon = "🚋🐄"
|
||||
|
||||
def choose_card_callback(self, player: 'Player', card_index):
|
||||
chosen_card = player.available_cards.pop(card_index)
|
||||
player.game.deck.scrap_pile.pop(-card_index)
|
||||
player.hand.append(chosen_card)
|
||||
player.pending_action = PendingAction.PLAY
|
||||
player.notify_self()
|
||||
|
||||
def play_card(self, player, against=None, _with=None) -> bool:
|
||||
drawn_cards = player.game.deck.peek_scrap_pile(n_cards=3)
|
||||
player.set_choose_action(
|
||||
"choose_cattle_truck",
|
||||
drawn_cards,
|
||||
self.choose_card_callback,
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
|
@ -942,7 +942,7 @@ class Game:
|
||||
print(f"{self.name}: scrap")
|
||||
room = self.name if sid is None else sid
|
||||
if self.deck.peek_scrap_pile():
|
||||
G.sio.emit("scrap", room=room, data=self.deck.peek_scrap_pile().__dict__)
|
||||
G.sio.emit("scrap", room=room, data=self.deck.peek_scrap_pile()[0].__dict__)
|
||||
else:
|
||||
G.sio.emit("scrap", room=room, data=None)
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
from typing import Any, List
|
||||
import pytest
|
||||
from bang.characters import Character
|
||||
from bang.game import Game
|
||||
@ -8,7 +9,7 @@ from globals import G
|
||||
G.sio = DummySocket()
|
||||
|
||||
|
||||
def started_game(expansions, players=4, character=Character("test_char", 4)):
|
||||
def started_game(expansions=[], players=4, character=Character("test_char", 4)) -> Game:
|
||||
g = Game("test")
|
||||
g.expansions = expansions
|
||||
ps = [Player(f"p{i}", f"p{i}") for i in range(players)]
|
||||
@ -23,19 +24,19 @@ def started_game(expansions, players=4, character=Character("test_char", 4)):
|
||||
return g
|
||||
|
||||
|
||||
def set_events(g: Game, event_cards):
|
||||
def set_events(g: Game, event_cards) -> None:
|
||||
g.deck.event_cards = event_cards
|
||||
|
||||
|
||||
def current_player(g: Game):
|
||||
def current_player(g: Game) -> Player:
|
||||
return g.players[g.turn]
|
||||
|
||||
|
||||
def next_player(g: Game):
|
||||
def next_player(g: Game) -> Player:
|
||||
return g.players[(g.turn + 1) % len(g.players)]
|
||||
|
||||
|
||||
def current_player_with_cards(g: Game, cards):
|
||||
def current_player_with_cards(g: Game, cards: List[Any]) -> Player:
|
||||
p = current_player(g)
|
||||
p.draw("")
|
||||
p.hand = cards
|
||||
|
24
backend/tests/test_trains.py
Normal file
24
backend/tests/test_trains.py
Normal file
@ -0,0 +1,24 @@
|
||||
from random import randint
|
||||
from bang.characters import Character
|
||||
from bang.expansions.train_robbery.trains import *
|
||||
from bang.deck import Deck
|
||||
from bang.game import Game
|
||||
from bang.players import Player
|
||||
import bang.cards as cs
|
||||
from globals import PendingAction
|
||||
|
||||
from tests import started_game, set_events, current_player, next_player, current_player_with_cards
|
||||
|
||||
|
||||
def test_cattle_truck():
|
||||
g = started_game()
|
||||
|
||||
g.deck.scrap_pile = [cs.CatBalou(0,1), cs.CatBalou(0,2), cs.CatBalou(0,3)]
|
||||
p = current_player_with_cards(g, [CattleTruck()])
|
||||
p.play_card(0)
|
||||
|
||||
assert p.pending_action == PendingAction.CHOOSE
|
||||
p.choose(0)
|
||||
assert p.pending_action == PendingAction.PLAY
|
||||
assert len(p.hand) == 1
|
||||
assert len(g.deck.scrap_pile) == 2
|
Loading…
Reference in New Issue
Block a user