骰子街是一款经典桌游。规则简单、易学。这里是规则讲解和游玩的视频。这个视频的作者桌游林吃素开了一家桌游店“小狮子桌游铺”(淘宝),我在这家桌游店买了骰子街豪华版,包含基础版和扩展。
笔者使用 Python 写了一个基于命令行的基础版的骰子街,无法添加扩展(笔者无能)。代码也少,如下:
from random import randint
from utils import *
from typing import ClassVar, Callable, Any, final
# 地标建筑
class GreatCard:
is_enable: bool
name: str
cost: int
owner: 'Player'
msg: ClassVar[str]
def __init__(self, player: 'Player'): self.owner, self.is_enable = player, False
def enable(self): ...
@final
def buy(self):
self.owner.money -= self.cost
self.open()
@final
def open(self):
self.is_enable = True
self.enable()
@classmethod
def new_great_card(cls, cls_name: str, cls_cost: int, cls_msg: str, cls_enable):
class Sub(cls):
name = cls_name
cost = cls_cost
msg = cls_msg
enable = cls_enable
return Sub
class CardMeta(type):
name: str
dice_num: tuple[int, ...]
def __str__(self): return f'card {
self.name}[{
any2str(self.dice_num)}]'
class Card(metaclass=CardMeta):
owner: 'Player'
dice_num: ClassVar[tuple[int, ...]]
name: ClassVar[str]
cost: ClassVar[int]
describe: ClassVar[list[str]] = []
def __init__(self, owner: 'Player'): self.owner = owner
def can_work(self, dice: int, player: 'Player') -> bool: ...
def work(self, now: 'Player'): ...
def set_owner(self, new: 'Player'):
raw = self.owner
self.owner = new
new.cards.append(self)
raw.cards.remove(self)
def __str__(self): return f'card {
self.name}[{
any2str(self.dice_num)}] of player {
self.owner}\'s'
def all_work(self, dice: int, now: 'Player'):
if self.can_work(dice, now):
self.work(now)
@classmethod
def new_card_cls(cls, cls_name: str, cls_dice_num: int | tuple[int, ...], cls_cost: int) -> type['Card']:
class Sub(cls):
name = cls_name
dice_num = (cls_dice_num,) if isinstance(cls_dice_num, int) else cls_dice_num
cost = cls_cost
return Sub
# 根据触发方式(当前玩家)分类
class PrivateCard(Card):
def can_work(self, dice: int, player: 'Player') -> bool: return dice in self.dice_num and player is self.owner
class PublicCard(Card):
def can_work(self, dice: int, player: 'Player') -> bool: return dice in self.dice_num
class SoldOutCard(Card):
def can_work(self, dice: int, player: 'Player') -> bool: return dice in self.dice_num and player is not self.owner
# 根据功能分类
class MoneyGetCard(Card):
one_step: ClassVar[int]
def one_make(self) -> int: ...
def work(self, now: 'Player'):
made = self.one_make()
owner = self.owner
if type(self) in affect and owner in affect_players:
made += 1
owner.money += made
@classmethod
def new_card_cls(cls, name: str, dice_num: int | tuple[int, ...], cost: int, one_step=0):
res = super().new_card_cls(name, dice_num, cost)
res.one_step = one_step
return res
class SimpleCard(MoneyGetCard):
def one_make