コード例 #1
0
def test_reveal_creatures():
    now = time.time()
    game = Game.Game("g1", "p0", now, now, 2, 6)
    player = Player.Player("p0", game, 0)

    legion = Legion.Legion(
        player, "Rd01",
        Creature.n2c(["Unknown", "Unknown", "Unknown", "Unknown"]), 1)
    legion.reveal_creatures(["Ogre"])
    assert legion.creature_names == ["Ogre", "Unknown", "Unknown", "Unknown"]
    legion.reveal_creatures(["Ogre", "Ogre"])
    assert legion.creature_names == ["Ogre", "Ogre", "Unknown", "Unknown"]
    legion.reveal_creatures(["Ogre", "Ogre", "Troll"])
    assert legion.creature_names == ["Ogre", "Ogre", "Troll", "Unknown"]
    legion.reveal_creatures(["Troll"])
    assert legion.creature_names == ["Ogre", "Ogre", "Troll", "Unknown"]
    legion.reveal_creatures(["Troll", "Troll"])
    assert legion.creature_names == ["Ogre", "Ogre", "Troll", "Troll"]
    legion.add_creature_by_name("Ranger")
    legion.reveal_creatures(["Troll", "Troll", "Ranger"])
    assert legion.creature_names == [
        "Ogre", "Ogre", "Ranger", "Troll", "Troll"
    ]

    legion = Legion.Legion(
        player, "Rd01",
        Creature.n2c(["Unknown", "Unknown", "Unknown", "Unknown"]), 1)
    legion.reveal_creatures(["Centaur", "Centaur", "Lion"])
    assert legion.creature_names == ["Centaur", "Centaur", "Lion", "Unknown"]
コード例 #2
0
ファイル: SplitLegion.py プロジェクト: optionalg/Slugathon
    def __init__(self, playername, legion, def1, parent):
        gtk.Dialog.__init__(self, "SplitLegion - %s" % playername, parent)
        self.old_legion = legion
        player = legion.player
        self.deferred = def1

        self.set_icon(icon.pixbuf)
        self.set_transient_for(parent)
        self.set_destroy_with_parent(True)
        self.vbox.set_spacing(9)

        legion_name = gtk.Label("Splitting legion %s (%s) in hex %s" % (
                                legion.markerid,
                                legion.picname,
                                legion.hexlabel))
        self.vbox.pack_start(legion_name)

        old_hbox = gtk.HBox(spacing=15)
        self.vbox.pack_start(old_hbox)
        old_marker_hbox = gtk.HBox()
        old_hbox.pack_start(old_marker_hbox, expand=False)
        self.old_chits_hbox = gtk.HBox()
        old_hbox.pack_start(self.old_chits_hbox, expand=True)

        new_hbox = gtk.HBox(spacing=15)
        self.vbox.pack_start(new_hbox)
        new_marker_hbox = gtk.HBox()
        new_hbox.pack_start(new_marker_hbox, expand=False)
        self.new_chits_hbox = gtk.HBox()
        new_hbox.pack_start(self.new_chits_hbox, expand=True)

        old_marker = Marker.Marker(legion, False, scale=20)
        old_marker_hbox.pack_start(old_marker.event_box, expand=False)

        self.new_legion1 = Legion.Legion(player, legion.markerid,
                                         legion.sorted_creatures,
                                         legion.hexlabel)
        self.new_legion2 = Legion.Legion(player, player.selected_markerid,
                                         [], legion.hexlabel)
        self.new_marker = Marker.Marker(self.new_legion2, False, scale=20)
        new_marker_hbox.pack_start(self.new_marker.event_box, expand=False)

        for creature in legion.sorted_creatures:
            chit = Chit.Chit(creature, player.color, scale=20)
            self.old_chits_hbox.pack_start(chit.event_box, expand=False,
                                           fill=False)
            chit.connect("button-press-event", self.cb_click)

        self.add_button("gtk-cancel", gtk.RESPONSE_CANCEL)
        self.ok_button = self.add_button("gtk-ok", gtk.RESPONSE_OK)
        self.ok_button.set_sensitive(False)
        self.connect("response", self.cb_response)

        self.show_all()
コード例 #3
0
def test_is_legal_split():
    now = time.time()
    game = Game.Game("g1", "p0", now, now, 2, 6)
    creatures = Creature.n2c(creaturedata.starting_creature_names)
    player = Player.Player("p0", game, 0)

    parent = Legion.Legion(player, "Rd01", creatures, 1)
    child1 = Legion.Legion(player, "Rd01",
                           Creature.n2c(["Titan", "Gargoyle", "Ogre", "Ogre"]),
                           1)
    child2 = Legion.Legion(
        player, "Rd03",
        Creature.n2c(["Angel", "Gargoyle", "Centaur", "Centaur"]), 1)
    assert parent.is_legal_split(child1, child2)
    assert not parent.is_legal_split(child1, child1)

    parent2 = Legion.Legion(
        player, "Rd01",
        Creature.n2c(["Titan", "Gargoyle", "Ogre", "Troll", "Centaur"]), 1)
    child3 = Legion.Legion(
        player, "Rd01", Creature.n2c(["Titan", "Gargoyle", "Ogre", "Troll"]),
        1)
    child4 = Legion.Legion(player, "Rd03", Creature.n2c(["Centaur"]), 1)
    assert not parent2.is_legal_split(child3, child4)

    child5 = Legion.Legion(
        player, "Rd01",
        Creature.n2c(["Unknown", "Unknown", "Unknown", "Unknown"]), 1)
    child6 = Legion.Legion(
        player, "Rd03",
        Creature.n2c(["Unknown", "Unknown", "Unknown", "Unknown"]), 1)
    assert parent.is_legal_split(child5, child6)
コード例 #4
0
ファイル: Player.py プロジェクト: optionalg/Slugathon
 def split_legion(self, parent_markerid, child_markerid,
                  parent_creature_names, child_creature_names):
     logging.info("%s %s %s %s", parent_markerid, child_markerid,
                  parent_creature_names, child_creature_names)
     parent = self.markerid_to_legion.get(parent_markerid)
     if parent is None:
         return
     if child_markerid not in self.markerids_left:
         raise AssertionError("illegal marker")
     if (bag(parent.creature_names) != bag(parent_creature_names).union(
             bag(child_creature_names))
             and bag(parent_creature_names).union(bag(child_creature_names))
             != bag({"Unknown": len(parent)})):
         raise AssertionError("wrong creatures", "parent.creature_names",
                              parent.creature_names,
                              "parent_creature_names",
                              parent_creature_names, "child_creature_names",
                              child_creature_names)
     new_legion1 = Legion.Legion(self, parent_markerid,
                                 Creature.n2c(parent_creature_names),
                                 parent.hexlabel)
     new_legion2 = Legion.Legion(self, child_markerid,
                                 Creature.n2c(child_creature_names),
                                 parent.hexlabel)
     if not parent.is_legal_split(new_legion1, new_legion2):
         raise AssertionError("illegal split")
     del new_legion1
     parent.creatures = Creature.n2c(parent_creature_names)
     for creature in parent.creatures:
         creature.legion = parent
     self.take_marker(child_markerid)
     new_legion2.add_observer(self.game)
     self.markerid_to_legion[child_markerid] = new_legion2
     del parent
     # One action for our player with creature names
     action = Action.SplitLegion(self.game.name, self.name, parent_markerid,
                                 child_markerid, parent_creature_names,
                                 child_creature_names)
     logging.info(action)
     self.notify(action, names=[self.name])
     # Another action for everyone (including our player, who will
     # ignore it as a duplicate) without creature names.
     action = Action.SplitLegion(self.game.name, self.name, parent_markerid,
                                 child_markerid,
                                 len(parent_creature_names) * ["Unknown"],
                                 len(child_creature_names) * ["Unknown"])
     logging.info(action)
     self.notify(action)
コード例 #5
0
def test_any_summonable():
    creatures = Creature.n2c([
        "Archangel", "Serpent", "Centaur", "Gargoyle", "Ogre", "Ranger",
        "Minotaur"
    ])
    legion = Legion.Legion(None, "Rd01", creatures, 1)
    assert legion.any_summonable
    creatures = Creature.n2c([
        "Angel", "Serpent", "Centaur", "Gargoyle", "Ogre", "Ranger", "Minotaur"
    ])
    legion = Legion.Legion(None, "Rd01", creatures, 1)
    assert legion.any_summonable
    creatures = Creature.n2c(
        ["Serpent", "Centaur", "Gargoyle", "Ogre", "Ranger", "Minotaur"])
    legion = Legion.Legion(None, "Rd01", creatures, 1)
    assert not legion.any_summonable
コード例 #6
0
def test_remove_creature_by_name():
    now = time.time()
    game = Game.Game("g1", "p0", now, now, 2, 6)
    creatures = Creature.n2c(creaturedata.starting_creature_names)
    player = Player.Player("p0", game, 0)
    legion = Legion.Legion(player, "Rd01", creatures, 1)
    assert len(legion) == 8
    legion.remove_creature_by_name("Gargoyle")
    assert len(legion) == 7
    assert "Gargoyle" in legion.creature_names
    legion.remove_creature_by_name("Gargoyle")
    assert len(legion) == 6
    assert "Gargoyle" not in legion.creature_names
    try:
        legion.remove_creature_by_name("Gargoyle")
    except ValueError:
        pass
    else:
        assert False
    legion.remove_creature_by_name("Ogre")
    legion.remove_creature_by_name("Ogre")
    legion.remove_creature_by_name("Centaur")
    legion.remove_creature_by_name("Centaur")
    legion.remove_creature_by_name("Titan")
    assert len(legion) == 1
    assert legion
    legion.remove_creature_by_name("Angel")
    assert len(legion) == 0
    assert legion
コード例 #7
0
def test_add_creature_by_name():
    now = time.time()
    game = Game.Game("g1", "p0", now, now, 2, 6)
    creatures = Creature.n2c(creaturedata.starting_creature_names)
    player = Player.Player("p0", game, 0)
    legion = Legion.Legion(player, "Rd01", creatures, 1)
    assert len(legion) == 8
    try:
        legion.add_creature_by_name("Cyclops")
    except ValueError:
        pass
    else:
        assert False
    legion.remove_creature_by_name("Gargoyle")
    assert len(legion) == 7
    try:
        legion.add_creature_by_name("Cyclops")
    except ValueError:
        pass
    else:
        assert False
    assert "Gargoyle" in legion.creature_names
    legion.remove_creature_by_name("Gargoyle")
    assert len(legion) == 6
    assert "Gargoyle" not in legion.creature_names
    legion.add_creature_by_name("Troll")
    assert len(legion) == 7
    assert "Troll" in legion.creature_names
コード例 #8
0
def test_score():
    now = time.time()
    game = Game.Game("g1", "p0", now, now, 2, 6)
    creatures = Creature.n2c(creaturedata.starting_creature_names)
    player = Player.Player("p0", game, 0)
    legion = Legion.Legion(player, "Rd01", creatures, 1)
    assert legion.score == 120
コード例 #9
0
def test_picname():
    now = time.time()
    game = Game.Game("g1", "p0", now, now, 2, 6)
    creatures = Creature.n2c(creaturedata.starting_creature_names)
    player = Player.Player("p0", game, 0)
    legion = Legion.Legion(player, "Rd01", creatures, 1)
    assert legion.picname == "Cross"

    legion = Legion.Legion(
        player, "Rd02",
        Creature.n2c(["Titan", "Gargoyle", "Centaur", "Centaur"]), 1)
    assert legion.picname == "Eagle"

    legion = Legion.Legion(
        player, "Gr12",
        Creature.n2c(["Gargoyle", "Gargoyle", "Centaur", "Centaur"]), 1)
    assert legion.picname == "Ourobouros"
コード例 #10
0
def test_creature_names():
    now = time.time()
    game = Game.Game("g1", "p0", now, now, 2, 6)
    creatures = Creature.n2c(creaturedata.starting_creature_names)
    player = Player.Player("p0", game, 0)
    legion = Legion.Legion(player, "Rd01", creatures, 1)
    assert legion.creature_names == [
        "Angel", "Centaur", "Centaur", "Gargoyle", "Gargoyle", "Ogre", "Ogre",
        "Titan"
    ]
コード例 #11
0
def test_num_lords():
    now = time.time()
    game = Game.Game("g1", "p0", now, now, 2, 6)
    creatures = Creature.n2c(creaturedata.starting_creature_names)
    player = Player.Player("p0", game, 0)
    legion = Legion.Legion(player, "Rd01", creatures, 1)
    assert legion.num_lords == 2
    assert not legion.can_flee

    legion = Legion.Legion(
        player, "Rd02",
        Creature.n2c(["Titan", "Gargoyle", "Centaur", "Centaur"]), 1)
    assert legion.num_lords == 1
    assert not legion.can_flee

    legion = Legion.Legion(
        player, "Rd02",
        Creature.n2c(["Gargoyle", "Gargoyle", "Centaur", "Centaur"]), 1)
    assert legion.num_lords == 0
    assert legion.can_flee
コード例 #12
0
def test_engaged():
    now = time.time()
    game = Game.Game("g1", "p1", now, now, 2, 6)
    creatures = Creature.n2c(creaturedata.starting_creature_names)
    player1 = Player.Player("p1", game, 0)
    player1.color = "Red"
    game.players.append(player1)
    legion1 = Legion.Legion(player1, "Rd01", creatures, 1)
    player1.markerid_to_legion[legion1.markerid] = legion1

    player2 = Player.Player("p2", game, 1)
    player2.color = "Blue"
    game.players.append(player2)
    legion2 = Legion.Legion(player2, "Bu01", creatures, 2)
    player2.markerid_to_legion[legion2.markerid] = legion2
    assert not legion1.engaged
    assert not legion2.engaged

    legion2.move(1, False, None, 1)
    assert legion1.engaged
    assert legion2.engaged
コード例 #13
0
def test_sorted_creatures():
    creatures = Creature.n2c([
        "Archangel", "Serpent", "Centaur", "Gargoyle", "Ogre", "Ranger",
        "Minotaur"
    ])
    legion = Legion.Legion(None, "Rd01", creatures, 1)
    li = legion.sorted_creatures
    assert len(li) == len(creatures) == len(legion)
    names = [creature.name for creature in li]
    assert names == [
        "Archangel", "Serpent", "Ranger", "Minotaur", "Gargoyle", "Centaur",
        "Ogre"
    ]
コード例 #14
0
def test_find_creature():
    now = time.time()
    game = Game.Game("g1", "p0", now, now, 2, 6)
    creatures = Creature.n2c(creaturedata.starting_creature_names)
    player = Player.Player("p0", game, 0)
    legion = Legion.Legion(player, "Rd01", creatures, 1)
    assert legion.find_creature("Titan", "DEFENDER") is None
    for creature in legion.creatures:
        creature.hexlabel = "DEFENDER"
    assert legion.find_creature("Titan", "DEFENDER") is not None
    assert legion.find_creature("Ogre", "DEFENDER") is not None
    assert legion.find_creature("Titan", "ATTACKER") is None
    assert legion.find_creature("Ogre", "ATTACKER") is None
コード例 #15
0
def test_unknown():
    creatures = Creature.n2c([
        "Archangel", "Serpent", "Centaur", "Gargoyle", "Ogre", "Ranger",
        "Minotaur"
    ])
    legion = Legion.Legion(None, "Rd01", creatures, 1)
    assert not legion.any_unknown
    assert legion.all_known
    assert not legion.all_unknown

    creatures = Creature.n2c([
        "Archangel", "Serpent", "Centaur", "Gargoyle", "Ogre", "Ranger",
        "Unknown"
    ])
    legion = Legion.Legion(None, "Rd01", creatures, 1)
    assert legion.any_unknown
    assert not legion.all_known
    assert not legion.all_unknown

    creatures = Creature.n2c(8 * ["Unknown"])
    legion = Legion.Legion(None, "Rd01", creatures, 1)
    assert legion.any_unknown
    assert not legion.all_known
    assert legion.all_unknown
コード例 #16
0
def test_could_recruit():
    now = time.time()
    game = Game.Game("g1", "p0", now, now, 2, 6)
    player = Player.Player("p0", game, 0)

    legion = Legion.Legion(
        player, "Rd02",
        Creature.n2c(["Titan", "Gargoyle", "Centaur", "Centaur"]), 1)
    caretaker = Caretaker.Caretaker()

    assert not legion.could_recruit("Marsh", caretaker)
    assert not legion.could_recruit("Desert", caretaker)
    assert legion.could_recruit("Plains", caretaker)
    assert legion.could_recruit("Brush", caretaker)
    assert legion.could_recruit("Tower", caretaker)
コード例 #17
0
def test_available_recruits():
    now = time.time()
    game = Game.Game("g1", "p0", now, now, 2, 6)
    player = Player.Player("p0", game, 0)

    legion = Legion.Legion(
        player, "Rd02",
        Creature.n2c(["Titan", "Lion", "Gargoyle", "Centaur", "Centaur"]), 1)
    caretaker = Caretaker.Caretaker()

    assert legion.available_recruits("Marsh", caretaker) == []
    assert legion.available_recruits("Desert", caretaker) == ["Lion"]
    assert legion.available_recruits("Plains",
                                     caretaker) == ["Centaur", "Lion"]
    assert legion.available_recruits("Brush", caretaker) == ["Gargoyle"]
    assert legion.available_recruits(
        "Tower", caretaker) == ["Ogre", "Centaur", "Gargoyle", "Warlock"]
コード例 #18
0
def test_combat_value():
    now = time.time()
    game = Game.Game("g1", "p0", now, now, 2, 6)
    creatures = Creature.n2c(creaturedata.starting_creature_names)
    player = Player.Player("p0", game, 0)
    legion = Legion.Legion(player, "Rd01", creatures, 1)

    # No terrain
    legion.hexlabel = None
    assert legion.terrain_combat_value == legion.combat_value
    # Plains
    legion.hexlabel = 1
    assert legion.terrain_combat_value == legion.combat_value
    # Woods
    legion.hexlabel = 2
    assert legion.terrain_combat_value == legion.combat_value
    # Brush
    legion.hexlabel = 3
    assert legion.terrain_combat_value > legion.combat_value
    # Hills
    legion.hexlabel = 4
    assert legion.terrain_combat_value > legion.combat_value
    # Jungle
    legion.hexlabel = 5
    assert legion.terrain_combat_value > legion.combat_value
    # Desert
    legion.hexlabel = 7
    assert legion.terrain_combat_value == legion.combat_value
    # Marsh
    legion.hexlabel = 8
    assert legion.terrain_combat_value > legion.combat_value
    # Swamp
    legion.hexlabel = 14
    assert legion.terrain_combat_value > legion.combat_value
    # Tower
    legion.hexlabel = 100
    assert legion.terrain_combat_value > legion.combat_value
    # Mountains
    legion.hexlabel = 1000
    assert legion.terrain_combat_value == legion.combat_value
    # Tundra
    legion.hexlabel = 2000
    assert legion.terrain_combat_value == legion.combat_value
コード例 #19
0
def test_can_summon():
    now = time.time()
    game = Game.Game("g1", "p1", now, now, 2, 6)
    creatures = Creature.n2c(creaturedata.starting_creature_names)
    player1 = Player.Player("p1", game, 0)
    player1.assign_color("Red")
    game.players.append(player1)
    legion1 = Legion.Legion(player1, "Rd01", creatures, 1)
    player1.markerid_to_legion[legion1.markerid] = legion1
    assert not legion1.can_summon

    player1.split_legion("Rd01", "Rd02",
                         ["Titan", "Centaur", "Ogre", "Gargoyle"],
                         ["Angel", "Centaur", "Ogre", "Gargoyle"])
    assert legion1.can_summon
    legion2 = player1.markerid_to_legion["Rd02"]
    legion2.move(2, False, None, 1)
    assert legion1.can_summon
    assert not legion2.can_summon
コード例 #20
0
ファイル: Player.py プロジェクト: optionalg/Slugathon
 def create_starting_legion(self):
     markerid = self.selected_markerid
     if markerid is None:
         raise AssertionError("create_starting_legion without marker")
     if markerid not in self.markerids_left:
         raise AssertionError("create_starting_legion with bad marker")
     if self.markerid_to_legion:
         raise AssertionError("create_starting_legion but have a legion")
     creatures = [
         Creature.Creature(name)
         for name in creaturedata.starting_creature_names
     ]
     legion = Legion.Legion(self, self.take_marker(markerid), creatures,
                            self.starting_tower)
     self.markerid_to_legion[markerid] = legion
     legion.add_observer(self.game)
     action = Action.CreateStartingLegion(self.game.name, self.name,
                                          markerid)
     caretaker = self.game.caretaker
     for creature in creatures:
         caretaker.take_one(creature.name)
     self.created_starting_legion = True
     self.notify(action)
コード例 #21
0
def test_available_recruits_and_recruiters():
    now = time.time()
    game = Game.Game("g1", "p0", now, now, 2, 6)
    player = Player.Player("p0", game, 0)

    legion = Legion.Legion(
        player, "Rd01",
        Creature.n2c(["Titan", "Gargoyle", "Centaur", "Centaur"]), 1)
    caretaker = Caretaker.Caretaker()

    assert legion.available_recruits_and_recruiters("Marsh", caretaker) == []
    assert legion.available_recruits_and_recruiters("Desert", caretaker) == []
    assert legion.available_recruits_and_recruiters("Plains", caretaker) == [
        ("Centaur", "Centaur"), ("Lion", "Centaur", "Centaur")
    ]
    assert legion.available_recruits_and_recruiters("Brush", caretaker) == [
        ("Gargoyle", "Gargoyle")
    ]
    assert legion.available_recruits_and_recruiters("Tower", caretaker) == [
        ("Ogre", ), ("Centaur", ), ("Gargoyle", ), ("Warlock", "Titan")
    ]

    caretaker.counts["Centaur"] = 0
    assert legion.available_recruits_and_recruiters("Plains", caretaker) == [
        ("Lion", "Centaur", "Centaur")
    ]

    legion2 = Legion.Legion(
        player, "Rd02",
        Creature.n2c(["Titan", "Gargoyle", "Gargoyle", "Gargoyle"]), 1)
    assert legion2.available_recruits_and_recruiters("Tower", caretaker) == [
        ("Ogre", ), ("Gargoyle", ), ("Warlock", "Titan"),
        ("Guardian", "Gargoyle", "Gargoyle", "Gargoyle")
    ]
    assert legion2.available_recruits_and_recruiters("Brush", caretaker) == [
        ("Gargoyle", "Gargoyle"), ("Cyclops", "Gargoyle", "Gargoyle")
    ]

    legion3 = Legion.Legion(player, "Rd03", Creature.n2c(["Colossus"]), 1)
    assert legion3.available_recruits_and_recruiters("Tundra", caretaker) == [
        ("Troll", "Colossus"), ("Warbear", "Colossus"), ("Giant", "Colossus"),
        ("Colossus", "Colossus")
    ]
    assert legion3.available_recruits_and_recruiters(
        "Mountains", caretaker) == [("Lion", "Colossus"),
                                    ("Minotaur", "Colossus"),
                                    ("Dragon", "Colossus"),
                                    ("Colossus", "Colossus")]
    assert legion3.available_recruits_and_recruiters("Marsh", caretaker) == []

    legion4 = Legion.Legion(
        player, "Rd04",
        Creature.n2c(["Behemoth", "Cyclops", "Cyclops", "Cyclops"]), 1)
    assert legion4.available_recruits_and_recruiters("Brush", caretaker) == [
        ("Gargoyle", "Cyclops"), ("Cyclops", "Cyclops"),
        ("Gorgon", "Cyclops", "Cyclops")
    ]
    logging.info(legion4.available_recruits_and_recruiters(
        "Jungle", caretaker))
    assert legion4.available_recruits_and_recruiters("Jungle", caretaker) == [
        ("Gargoyle", "Cyclops"),
        ("Gargoyle", "Behemoth"),
        ("Cyclops", "Cyclops"),
        ("Cyclops", "Behemoth"),
        ("Behemoth", "Cyclops", "Cyclops", "Cyclops"),
        ("Behemoth", "Behemoth"),
    ]
コード例 #22
0
ファイル: Graveyard.py プロジェクト: optionalg/Slugathon
    def cb_destroy(confirmed):
        print "destroy"
        graveyard.destroy()
        gtk.main_quit()

    def cb_click(self, widget, event):
        if self.legion.living_creatures:
            random.choice(self.legion.living_creatures).kill()
            graveyard.update_gui()

    creatures = [
        Creature.Creature(name)
        for name in creaturedata.starting_creature_names
    ]

    playername = "test"
    player = Player.Player(playername, None, None)
    player.color = random.choice(playercolordata.colors)
    abbrev = player.color_abbrev
    index = random.randrange(1, 12 + 1)
    legion = Legion.Legion(player, "%s%02d" % (abbrev, index), creatures, 1)
    graveyard = Graveyard(legion)
    graveyard.connect("destroy", guiutils.exit)
    graveyard.connect("button-press-event", cb_click, graveyard)

    window = gtk.Window()
    window.add(graveyard)
    window.show_all()

    gtk.main()
コード例 #23
0
    now = time.time()
    playername = "test"
    game = Game.Game("g1", playername, now, now, 2, 6)
    player = Player.Player(playername, game, 0)
    player.color = "Red"
    creatures1 = [Creature.Creature(name) for name in
                  ["Titan", "Ogre", "Troll", "Ranger"]]
    creatures2 = [Creature.Creature(name) for name in
                  ["Angel", "Ogre", "Troll", "Ranger"]]
    creatures3 = [Creature.Creature(name) for name in
                  ["Archangel", "Centaur", "Lion", "Ranger"]]
    creatures4 = [Creature.Creature(name) for name in
                  ["Gargoyle", "Cyclops", "Gorgon", "Behemoth"]]
    creatures5 = [Creature.Creature(name) for name in
                  ["Angel", "Angel", "Warlock", "Guardian"]]
    legion1 = Legion.Legion(player, "Rd01", creatures1, 1)
    legion2 = Legion.Legion(player, "Rd02", creatures2, 2)
    legion3 = Legion.Legion(player, "Rd03", creatures3, 3)
    legion4 = Legion.Legion(player, "Rd04", creatures4, 4)
    legion5 = Legion.Legion(player, "Rd05", creatures5, 4)
    for legion in [legion1, legion2, legion3, legion4, legion5]:
        player.markerid_to_legion[legion.markerid] = legion

    def my_callback((legion, donor, creature)):
        logging.info("Will summon %s from %s into %s", creature, donor, legion)
        guiutils.exit()

    summonangel, def1 = new(playername, legion1, None)
    def1.addCallback(my_callback)
    summonangel.connect("destroy", guiutils.exit)
コード例 #24
0
if __name__ == "__main__":
    import time
    from slugathon.game import Creature, Legion, Player, Game

    now = time.time()
    attacker_playername = "Roar!"
    game = Game.Game("g1", attacker_playername, now, now, 2, 6)

    attacker_player = Player.Player(attacker_playername, game, 0)
    attacker_player.color = "Black"
    attacker_creature_names = [
        "Titan", "Colossus", "Serpent", "Hydra", "Archangel", "Angel",
        "Unicorn"
    ]
    attacker_creatures = Creature.n2c(attacker_creature_names)
    attacker_legion = Legion.Legion(attacker_player, "Bk01",
                                    attacker_creatures, 1)

    defender_playername = "Eek!"
    defender_player = Player.Player(defender_playername, game, 0)
    defender_player.color = "Gold"
    defender_creature_names = ["Ogre", "Centaur", "Gargoyle"]
    defender_creatures = Creature.n2c(defender_creature_names)
    defender_legion = Legion.Legion(defender_player, "Rd01",
                                    defender_creatures, 1)

    def my_callback((attacker, defender, fled)):
        logging.info("fled is %s", fled)
        reactor.stop()

    _, def1 = new(defender_playername, attacker_legion, defender_legion, None)
    def1.addCallback(my_callback)
コード例 #25
0
 def update(self, observed, action, names):
     st = None
     if isinstance(action, Action.AssignTower):
         st = "%s gets tower %d" % (action.playername, action.tower_num)
     elif isinstance(action, Action.PickedColor):
         st = "%s gets color %s" % (action.playername, action.color)
     elif isinstance(action, Action.StartSplitPhase):
         playercolor = self.game.get_player_by_name(action.playername).color
         st = "%s (%s) turn %d" % (action.playername, playercolor,
                                   action.turn)
     elif isinstance(action, Action.SplitLegion):
         st = "%s (%s) (%d) splits off %s (%s) (%d)" % (
             action.parent_markerid,
             Legion.find_picname(action.parent_markerid),
             len(action.parent_creature_names), action.child_markerid,
             Legion.find_picname(
                 action.child_markerid), len(action.child_creature_names))
     elif isinstance(action, Action.UndoSplit):
         st = "%s (%s) (%d) undoes split" % (
             action.parent_markerid,
             Legion.find_picname(action.parent_markerid),
             len(action.parent_creature_names) +
             len(action.child_creature_names))
     elif isinstance(action, Action.MergeLegions):
         st = "%s (%s) (%d) merges with splitoff" % (
             action.parent_markerid,
             Legion.find_picname(action.parent_markerid),
             len(action.parent_creature_names) +
             len(action.child_creature_names))
     elif isinstance(action, Action.RollMovement):
         playercolor = self.game.get_player_by_name(action.playername).color
         st = "%s (%s) rolls %d for movement" % (
             action.playername, playercolor, action.movement_roll)
     elif isinstance(action, Action.MoveLegion):
         st = "%s (%s) %s from %s hex %s to %s hex %s" % (
             action.markerid, Legion.find_picname(action.markerid),
             "teleports" if action.teleport else "moves",
             self.game.board.hexes[action.previous_hexlabel].terrain,
             action.previous_hexlabel,
             self.game.board.hexes[action.hexlabel].terrain,
             action.hexlabel)
     elif isinstance(action, Action.UndoMoveLegion):
         st = "%s (%s) undoes move" % (action.markerid,
                                       Legion.find_picname(action.markerid))
     elif isinstance(action, Action.RevealLegion):
         st = "%s (%s) is revealed as %s" % (
             action.markerid, Legion.find_picname(
                 action.markerid), ", ".join(action.creature_names))
     elif isinstance(action, Action.Flee):
         st = "%s (%s) in %s hex %s flees" % (
             action.markerid, Legion.find_picname(action.markerid),
             self.game.board.hexes[action.hexlabel].terrain,
             action.hexlabel)
     elif isinstance(action, Action.Concede):
         st = "%s (%s) in %s hex %s concedes" % (
             action.markerid, Legion.find_picname(action.markerid),
             self.game.board.hexes[action.hexlabel].terrain,
             action.hexlabel)
     elif isinstance(action, Action.SummonAngel):
         st = "%s (%s) summons %s from %s (%s)" % (
             action.markerid, Legion.find_picname(action.markerid),
             action.creature_name, action.donor_markerid,
             Legion.find_picname(action.donor_markerid))
     elif isinstance(action, Action.RecruitCreature):
         st = "%s (%s) recruits %s with %s" % (
             action.markerid, Legion.find_picname(action.markerid),
             action.creature_name, ", ".join(action.recruiter_names))
     elif isinstance(action, Action.UndoRecruit):
         st = "%s (%s) undoes recruit" % (
             action.markerid, Legion.find_picname(action.markerid))
     elif isinstance(action, Action.Fight):
         st = "%s (%s) fights %s (%s) in %s hex %s" % (
             action.attacker_markerid,
             Legion.find_picname(
                 action.attacker_markerid), action.defender_markerid,
             Legion.find_picname(action.defender_markerid),
             self.game.board.hexes[action.hexlabel].terrain,
             action.hexlabel)
     elif isinstance(action, Action.StartReinforceBattlePhase):
         playercolor = self.game.get_player_by_name(action.playername).color
         st = "%s (%s) starts battle turn %d" % (
             action.playername, playercolor, action.battle_turn)
     elif isinstance(action, Action.MoveCreature):
         playercolor = self.game.get_player_by_name(action.playername).color
         st = "%s (%s) moves %s in %s hex %s to %s hex %s" % (
             action.playername, playercolor, action.creature_name,
             self.game.battlemap.hexes[action.old_hexlabel].terrain,
             action.old_hexlabel,
             self.game.battlemap.hexes[action.new_hexlabel].terrain,
             action.new_hexlabel)
     elif isinstance(action, Action.UndoMoveCreature):
         st = "%s in %s hex %s undoes move" % (
             action.creature_name,
             self.game.battlemap.hexes[action.new_hexlabel].terrain,
             action.new_hexlabel)
     elif isinstance(action, Action.Strike):
         if action.carries:
             st = "%s in %s strikes %s in %s for %d %s and %s %s" % (
                 action.striker_name, action.striker_hexlabel,
                 action.target_name, action.target_hexlabel, action.hits,
                 "hit" if action.hits == 1 else "hits", action.carries,
                 "carry" if action.carries == 1 else "carries")
         else:
             st = "%s in %s strikes %s in %s for %d %s" % (
                 action.striker_name, action.striker_hexlabel,
                 action.target_name, action.target_hexlabel, action.hits,
                 "hit" if action.hits == 1 else "hits")
     elif isinstance(action, Action.Carry):
         st = "%d %s to %s in %s, leaving %d %s" % (
             action.carries, "hit carries" if action.carries == 1 else
             "hits carry", action.carry_target_name,
             action.carry_target_hexlabel, action.carries_left,
             "carry" if action.carries == 1 else "carries")
     elif isinstance(action, Action.DriftDamage):
         st = "%s in %s suffers drift damage" % (action.target_name,
                                                 action.target_hexlabel)
     elif isinstance(action, Action.BattleOver):
         if action.winner_survivors:
             st = "%s (%s) defeats %s (%s) in %s" % (
                 action.winner_markerid,
                 Legion.find_picname(
                     action.winner_markerid), action.loser_markerid,
                 Legion.find_picname(
                     action.loser_markerid), action.hexlabel)
         else:
             st = "%s (%s) and %s (%s) mutual in %s" % (
                 action.winner_markerid,
                 Legion.find_picname(
                     action.winner_markerid), action.loser_markerid,
                 Legion.find_picname(
                     action.loser_markerid), action.hexlabel)
     elif isinstance(action, Action.AcquireAngels):
         st = "%s (%s) acquires %s" % (action.markerid,
                                       Legion.find_picname(action.markerid),
                                       ", ".join(action.angel_names))
     elif isinstance(action, Action.GameOver):
         if len(action.winner_names) == 1:
             st = "%s wins!" % action.winner_names[0]
         else:
             st = "%s draw" % " and ".join(action.winner_names)
     if st and st != self.last_st:
         self.last_st = st
         label = gtk.Label(st)
         # left-align the label
         label.set_alignment(0.0, 0.5)
         self.vbox2.pack_start(label, expand=False, fill=False)
         label.show()
         upper = self.vadjustment.get_upper()
         self.vadjustment.set_value(upper)
コード例 #26
0
ファイル: TurnTrack.py プロジェクト: optionalg/Slugathon
            self.draw_turn_box(ctx, ii)
        for ii in xrange(7):
            self.draw_turn_number(ctx, ii)
        self.draw_marker(ctx)

    def repaint(self):
        self.update_gui()

    def update(self, observed, action, names):
        if isinstance(action, Action.StartReinforceBattlePhase):
            self.battle_turn = action.battle_turn
            if action.playername == self.defender.player.name:
                self.active_marker = self.defender_marker
            else:
                self.active_marker = self.attacker_marker
            self.repaint()


if __name__ == "__main__":
    from slugathon.util import guiutils
    from slugathon.game import Legion

    window = gtk.Window()
    attacker = Legion.Legion(None, "Rd01", [], 1)
    defender = Legion.Legion(None, "Bu01", [], 2)
    turntrack = TurnTrack(attacker, defender, None, 50)
    turntrack.connect("destroy", guiutils.exit)
    window.add(turntrack)
    window.show_all()
    gtk.main()
コード例 #27
0
def test_find_picname():
    assert Legion.find_picname("Rd01") == "Cross"
    assert Legion.find_picname("Rd02") == "Eagle"
    assert Legion.find_picname("Gr12") == "Ourobouros"
コード例 #28
0
ファイル: EventLog.py プロジェクト: dripton/Slugathon
 def update(self, observed, action, names):
     st = None
     if isinstance(action, Action.AssignTower):
         st = "%s gets tower %d" % (action.playername,
                                    action.tower_num)
     elif isinstance(action, Action.PickedColor):
         st = "%s gets color %s" % (action.playername,
                                    action.color)
     elif isinstance(action, Action.StartSplitPhase):
         playercolor = self.game.get_player_by_name(action.playername).color
         st = "%s (%s) turn %d" % (action.playername,
                                   playercolor, action.turn)
     elif isinstance(action, Action.SplitLegion):
         st = "%s (%s) (%d) splits off %s (%s) (%d)" % (
             action.parent_markerid,
             Legion.find_picname(action.parent_markerid),
             len(action.parent_creature_names),
             action.child_markerid,
             Legion.find_picname(action.child_markerid),
             len(action.child_creature_names))
     elif isinstance(action, Action.UndoSplit):
         st = "%s (%s) (%d) undoes split" % (
             action.parent_markerid,
             Legion.find_picname(action.parent_markerid),
             len(action.parent_creature_names) +
             len(action.child_creature_names))
     elif isinstance(action, Action.MergeLegions):
         st = "%s (%s) (%d) merges with splitoff" % (
             action.parent_markerid,
             Legion.find_picname(action.parent_markerid),
             len(action.parent_creature_names) +
             len(action.child_creature_names))
     elif isinstance(action, Action.RollMovement):
         playercolor = self.game.get_player_by_name(action.playername).color
         st = "%s (%s) rolls %d for movement" % (action.playername,
                                                 playercolor,
                                                 action.movement_roll)
     elif isinstance(action, Action.MoveLegion):
         st = "%s (%s) %s from %s hex %s to %s hex %s" % (
             action.markerid,
             Legion.find_picname(action.markerid),
             "teleports" if action.teleport else "moves",
             self.game.board.hexes[action.previous_hexlabel].terrain,
             action.previous_hexlabel,
             self.game.board.hexes[action.hexlabel].terrain,
             action.hexlabel)
     elif isinstance(action, Action.UndoMoveLegion):
         st = "%s (%s) undoes move" % (action.markerid,
                                       Legion.find_picname(action.markerid))
     elif isinstance(action, Action.RevealLegion):
         st = "%s (%s) is revealed as %s" % (
             action.markerid,
             Legion.find_picname(action.markerid),
             ", ".join(action.creature_names))
     elif isinstance(action, Action.Flee):
         st = "%s (%s) in %s hex %s flees" % (
             action.markerid,
             Legion.find_picname(action.markerid),
             self.game.board.hexes[action.hexlabel].terrain,
             action.hexlabel)
     elif isinstance(action, Action.Concede):
         st = "%s (%s) in %s hex %s concedes" % (
             action.markerid,
             Legion.find_picname(action.markerid),
             self.game.board.hexes[action.hexlabel].terrain,
             action.hexlabel)
     elif isinstance(action, Action.SummonAngel):
         st = "%s (%s) summons %s from %s (%s)" % (
             action.markerid,
             Legion.find_picname(action.markerid),
             action.creature_name,
             action.donor_markerid,
             Legion.find_picname(action.donor_markerid))
     elif isinstance(action, Action.RecruitCreature):
         st = "%s (%s) recruits %s with %s" % (
             action.markerid,
             Legion.find_picname(action.markerid),
             action.creature_name, ", ".join(action.recruiter_names))
     elif isinstance(action, Action.UndoRecruit):
         st = "%s (%s) undoes recruit" % (
             action.markerid,
             Legion.find_picname(action.markerid))
     elif isinstance(action, Action.Fight):
         st = "%s (%s) fights %s (%s) in %s hex %s" % (
             action.attacker_markerid,
             Legion.find_picname(action.attacker_markerid),
             action.defender_markerid,
             Legion.find_picname(action.defender_markerid),
             self.game.board.hexes[action.hexlabel].terrain,
             action.hexlabel)
     elif isinstance(action, Action.StartReinforceBattlePhase):
         playercolor = self.game.get_player_by_name(action.playername).color
         st = "%s (%s) starts battle turn %d" % (action.playername,
                                                 playercolor,
                                                 action.battle_turn)
     elif isinstance(action, Action.MoveCreature):
         playercolor = self.game.get_player_by_name(action.playername).color
         st = "%s (%s) moves %s in %s hex %s to %s hex %s" % (
             action.playername, playercolor, action.creature_name,
             self.game.battlemap.hexes[action.old_hexlabel].terrain,
             action.old_hexlabel,
             self.game.battlemap.hexes[action.new_hexlabel].terrain,
             action.new_hexlabel)
     elif isinstance(action, Action.UndoMoveCreature):
         st = "%s in %s hex %s undoes move" % (
             action.creature_name,
             self.game.battlemap.hexes[action.new_hexlabel].terrain,
             action.new_hexlabel)
     elif isinstance(action, Action.Strike):
         if action.carries:
             st = "%s in %s strikes %s in %s for %d %s and %s %s" % (
                 action.striker_name,
                 action.striker_hexlabel,
                 action.target_name,
                 action.target_hexlabel,
                 action.hits,
                 "hit" if action.hits == 1 else "hits",
                 action.carries,
                 "carry" if action.carries == 1 else "carries")
         else:
             st = "%s in %s strikes %s in %s for %d %s" % (
                 action.striker_name,
                 action.striker_hexlabel,
                 action.target_name,
                 action.target_hexlabel,
                 action.hits,
                 "hit" if action.hits == 1 else "hits")
     elif isinstance(action, Action.Carry):
         st = "%d %s to %s in %s, leaving %d %s" % (
             action.carries,
             "hit carries" if action.carries == 1 else "hits carry",
             action.carry_target_name,
             action.carry_target_hexlabel,
             action.carries_left,
             "carry" if action.carries == 1 else "carries")
     elif isinstance(action, Action.DriftDamage):
         st = "%s in %s suffers drift damage" % (
             action.target_name, action.target_hexlabel)
     elif isinstance(action, Action.BattleOver):
         if action.winner_survivors:
             st = "%s (%s) defeats %s (%s) in %s" % (
                 action.winner_markerid,
                 Legion.find_picname(action.winner_markerid),
                 action.loser_markerid,
                 Legion.find_picname(action.loser_markerid),
                 action.hexlabel)
         else:
             st = "%s (%s) and %s (%s) mutual in %s" % (
                 action.winner_markerid,
                 Legion.find_picname(action.winner_markerid),
                 action.loser_markerid,
                 Legion.find_picname(action.loser_markerid),
                 action.hexlabel)
     elif isinstance(action, Action.AcquireAngels):
         st = "%s (%s) acquires %s" % (action.markerid,
                                       Legion.find_picname(action.markerid),
                                       ", ".join(action.angel_names))
     elif isinstance(action, Action.GameOver):
         if len(action.winner_names) == 1:
             st = "%s wins!" % action.winner_names[0]
         else:
             st = "%s draw" % " and ".join(action.winner_names)
     if st and st != self.last_st:
         self.last_st = st
         label = gtk.Label(st)
         # left-align the label
         label.set_alignment(0.0, 0.5)
         self.vbox2.pack_start(label, expand=False, fill=False)
         label.show()
         upper = self.vadjustment.get_upper()
         self.vadjustment.set_value(upper)
コード例 #29
0
        self.deferred.callback((self.legion, None, None))
        self.destroy()


if __name__ == "__main__":
    import time
    from slugathon.game import Legion, Player, Game
    from slugathon.util import guiutils

    creature_names = ["Titan", "Dragon", "Dragon", "Minotaur", "Minotaur"]
    creatures = Creature.n2c(creature_names)

    def my_callback((legion, creature, recruiter_names)):
        logging.info("%s recruited %s %s", legion, creature, recruiter_names)
        guiutils.exit()

    now = time.time()
    playername = "p0"
    game = Game.Game("g1", "p0", now, now, 2, 6)
    player = Player.Player(playername, game, 0)
    player.color = "Red"
    legion = Legion.Legion(player, "Rd01", creatures, 1)
    legion.hexlabel = 1000
    masterhex = game.board.hexes[legion.hexlabel]
    mterrain = masterhex.terrain
    pickrecruit, def1 = new(playername, legion, mterrain, game.caretaker, None)
    def1.addCallback(my_callback)
    pickrecruit.connect("destroy", guiutils.exit)

    gtk.main()
コード例 #30
0
ファイル: test_legion.py プロジェクト: dripton/Slugathon
def test_find_picname():
    assert Legion.find_picname("Rd01") == "Cross"
    assert Legion.find_picname("Rd02") == "Eagle"
    assert Legion.find_picname("Gr12") == "Ourobouros"