def real_nextturn(): """Hidden method to really move on.""" global phase, selected if selected is not None: riskgui.drawterritory(selected, 0) selected = None if currentplayer.conqueredTerritory == 1: if len(allcards) != 0: #too bad otherwise handcard = random.choice(allcards) currentplayer.cards.append(handcard) risknetwork.add_card(handcard, currentplayer) allcards.remove(handcard) currentplayer.conqueredTerritory = 0 rotateplayers() riskgui.set_status("It is now " + currentplayer.name + "'s turn.") currentplayer.freeArmies += max(3, len(currentplayer.territories()) // 3) for c in continents: existing = [x for x in territories.values() if x.continent == c[0]] unowned = [x for x in existing if x.player != currentplayer] if len(existing) != 0 and len(unowned) == 0: currentplayer.freeArmies += c[1] riskgui.set_armies(currentplayer.freeArmies) setphase("Place")
def real_nextturn(): """Hidden method to really move on.""" global phase, selected if selected is not None: riskgui.drawterritory(selected, 0) selected = None if currentplayer.conqueredTerritory == 1: if len(allcards) != 0: #too bad otherwise handcard = random.choice(allcards) currentplayer.cards.append(handcard) risknetwork.add_card(handcard, currentplayer) allcards.remove(handcard) currentplayer.conqueredTerritory = 0 rotateplayers() riskgui.set_status("It is now " + currentplayer.name + "'s turn.") currentplayer.freeArmies += max(3, len(currentplayer.territories()) // 3) for c in continents: existing = [x for x in territories.values() if x.continent == c[0]] unowned = [x for x in existing if x.player != currentplayer] if len(existing) != 0 and len(unowned) == 0 : currentplayer.freeArmies += c[1] riskgui.set_armies(currentplayer.freeArmies) setphase("Place")
def removeplayer(player, conqueror): """Remove a dead player from the game.""" global currentplayernum, playerorder for card in player.cards: risknetwork.add_card(card, conqueror) risknetwork.remove_card(card, player) conqueror.cards += player.cards if currentplayernum >= playerorder.index(player): currentplayernum -= 1 riskgui.removeplayer(player.name) risknetwork.removeplayer(player.name) playerorder.remove(player) del players[player.name] if len(players) == 1: #game over riskgui.won_game(players.values()[0].name) setphase("PostGame")
def load_game(filename): """Load a previously-saved game.""" global currentplayer, phase, currentcard, currentplayernum if phase != "Pregame": riskgui.set_status("You have already started a game") return savefile = open(filename) while savefile.readline() == "player\n": plname = savefile.readline().strip() plarmies = int(savefile.readline().strip()) plconquered = int(savefile.readline().strip()) cards = [] currentline = savefile.readline() while currentline != "endplayer\n" and currentline != "ai\n": nline = savefile.readline().strip() cards.append(Card(currentline.strip(), nline)) currentline = savefile.readline() ainame = None if currentline == "ai\n": ainame = savefile.readline().strip() aidatalen = int(savefile.readline().strip()) aidata = savefile.read(aidatalen) savefile.readline() if not players.has_key(plname): if ainame and not os.path.exists(ainame): riskgui.set_status("AI " + ainame + " nonexistent") ainame = None riskgui.makeplayercolors(makeplayer(plname, ainame)) if ainame: players[plname].ai.loaddata(aidata) players[plname].freeArmies = plarmies players[plname].conqueredTerritory = plconquered players[plname].cards = cards for card in cards: risknetwork.add_card(card, players[plname]) playerorder.append(players[plname]) riskgui.relistplayers(playerorder) currentplayer = players[savefile.readline().strip()] currentplayernum = playerorder.index(currentplayer) riskgui.set_armies(currentplayer.freeArmies) riskgui.playersturn(currentplayer.name) setphase(savefile.readline().strip()) currentcard = int(savefile.readline().strip()) while savefile.readline().strip() == "territory": tname = savefile.readline().strip() tplayer = savefile.readline().strip() if tplayer == "None": tplayer = None else: tplayer = players[tplayer] territories[tname].player = tplayer territories[tname].armies = int(savefile.readline().strip()) riskgui.drawterritory(territories[tname], 0) savefile.readline() while 1: cardterr = savefile.readline().strip() if not cardterr: break allcards.append(Card(cardterr, savefile.readline().strip())) savefile.close()
def load_game(filename): """Load a previously-saved game.""" global currentplayer, phase, currentcard, currentplayernum if phase != "Pregame": riskgui.set_status("You have already started a game") return savefile = open(filename) while savefile.readline() == "player\n": plname = savefile.readline().strip() plarmies = int(savefile.readline().strip()) plconquered = int(savefile.readline().strip()) cards = [] currentline = savefile.readline() while currentline != "endplayer\n" and currentline != "ai\n": nline = savefile.readline().strip() cards.append(Card(currentline.strip(),nline)) currentline = savefile.readline() ainame = None if currentline == "ai\n": ainame = savefile.readline().strip() aidatalen = int(savefile.readline().strip()) aidata = savefile.read(aidatalen) savefile.readline() if not players.has_key(plname): if ainame and not os.path.exists(ainame): riskgui.set_status("AI " + ainame + " nonexistent") ainame = None riskgui.makeplayercolors(makeplayer(plname, ainame)) if ainame: players[plname].ai.loaddata(aidata) players[plname].freeArmies = plarmies players[plname].conqueredTerritory = plconquered players[plname].cards = cards for card in cards: risknetwork.add_card(card, players[plname]) playerorder.append(players[plname]) riskgui.relistplayers(playerorder) currentplayer = players[savefile.readline().strip()] currentplayernum = playerorder.index(currentplayer) riskgui.set_armies(currentplayer.freeArmies) riskgui.playersturn(currentplayer.name) setphase(savefile.readline().strip()) currentcard = int(savefile.readline().strip()) while savefile.readline().strip() == "territory": tname = savefile.readline().strip() tplayer = savefile.readline().strip() if tplayer == "None": tplayer = None else: tplayer = players[tplayer] territories[tname].player = tplayer territories[tname].armies = int(savefile.readline().strip()) riskgui.drawterritory(territories[tname], 0) savefile.readline() while 1: cardterr = savefile.readline().strip() if not cardterr: break allcards.append(Card(cardterr,savefile.readline().strip())) savefile.close()