-3

我正在制作 4 名玩家的宫殿纸牌游戏,我不确定我应该如何确定轮到谁来扔牌?我应该使用像柜台这样的东西还是什么?

4

2 回答 2

1

使用简单的计数器模数玩家人数。

class Game(object):
    def __init__(self):
        self.count = 4
        self.current_player = 0

    def next_turn(self):
        self.current_player += 1
        self.current_player %= self.count
于 2013-08-22T12:37:14.977 回答
0

由于不同的牌可能会导致不同的玩家有下一回合,以及游戏在顺时针和逆时针之间切换,我建议你把决定权留给卡片对象。

from abc import ABCMeta, abstractmethod

class Card(object):
    __metaclass__ = ABCMeta
    def __init__(self, color, value):
        """
        Color is either "r", "b", "g", or "y". Value is 0-9.
        """
        self.color = color
        self.value = value

    def is_valid(self, color, value=None):
        return color in self.color or value == self.value

    @abstractmethod
    def card_effect(self, game):
        pass

所有卡片的这个基类是一个类必须履行才能被视为卡片的“契约”。因为我们不打算实例化这个类,所以我们把它变成一个抽象类。

class Normal(Card):
    def card_effect(self, game):
        game.increment_player_index(1)

class Skip(Card):
    def __init__(self, color):
        super(Skip, self).__init__(color, "skip")

    def card_effect(self, game):
        game.increment_player_index(2)

class Turn(Card):
    def __init__(self, color):
        super(Turn, self).__init__(color, "turn")

    def card_effect(self, game):
        game.toggle_direction()
        game.increment_player_index(2)

class PlusTwo(Card):
    def __init__(self, color):
        super(PlusTwo, self).__init__(color, "+2")

    def card_effect(self, game):
        game.increment_player_index(1)
        game.current_player().punish(2)
        game.increment_player_index(1)

对于黑卡,我们这样做:

class PlusFour(Card):
    def __init__(self):
        super(PlusFour, self).__init__("rbgy", "+4")

    def card_effect(self, game):
        color = game.current_player().choose_color()
        game.set_color(color)
        game.increment_player_index(1)
        game.current_player().punish(4)
        game.increment_player_index(1)
于 2013-08-22T12:54:04.070 回答