当前位置: 首页>>代码示例>>Python>>正文


Python Map.createSquareMap方法代码示例

本文整理汇总了Python中Map.Map.createSquareMap方法的典型用法代码示例。如果您正苦于以下问题:Python Map.createSquareMap方法的具体用法?Python Map.createSquareMap怎么用?Python Map.createSquareMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Map.Map的用法示例。


在下文中一共展示了Map.createSquareMap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from Map import Map [as 别名]
# 或者: from Map.Map import createSquareMap [as 别名]
class Game:
    def __init__(self):
        self.map = Map()
        self.numUnits = 1
        self.numPlayers = 1
        self.playerIndex = -1 
        self.turn = 1
        self.players = []

    def __saveable__(self):
        """ Returns a saveable representation of the game. """
        d = {}

        d['players'] = map(saveable, self.players)
        d['map'] = saveable(self.map)
        d['turn'] = self.turn
        d['playerIndex'] = self.playerIndex
        d['currentPlayer'] = saveable(self.currentPlayer)

        return d

    @classmethod
    def __load__(cls, d):
        g = cls()

        g.map = load(Map, d['map'], game=g)
        g.players = map(partial(load, Player, game=g), d['players'])
        g.turn = d['turn']
        g.playerIndex = d['playerIndex']
        g.currentPlayer = load(Player, d['currentPlayer'], game=g)
        g.numUnits = len(g.map.units)
        g.numPlayers = len(g.players)

        return g

    def save(self, filename):
        d = saveable(self)

        with open(filename, 'w') as f:
            json.dump(d, f)

        print 'Game saved.'

    @classmethod
    def load(cls, filename):
        Player.loadedPlayers = {}

        with open(filename) as f:
            d = json.load(f)

        print 'Game loaded.'
        return load(cls, d)

    def start(self):
        self.players.append(HumanPlayer(self))
        for x in xrange(self.numPlayers - 1):
            self.players.append(AIPlayer(self))
        self.map.createSquareMap(self.numUnits, self.players, 10, 10, 50)
        self.numUnits *= self.numPlayers
        
    def cyclePlayers(self):
        self.playerIndex += 1
        if self.playerIndex == self.numPlayers:
            self.playerIndex = -1 
            self.currentPlayer = None # None indicates the turn is over
        else:
            self.currentPlayer = self.players[self.playerIndex]
    
    def nextPlayerAction(self):
        self.cyclePlayers()
        if self.currentPlayer:
            self.currentPlayer.doTurn()
        else:
            self.nextTurn()
    
    def nextTurn(self):
        self.save('savefile.save')
        self.resetPlayerCycle()
        self.nextPlayerAction()
        self.turn += 1
    
    def resetPlayerCycle(self):
        self.playerIndex = -1
    
    def moveAction(self, fun):
        if isinstance(self.currentPlayer, HumanPlayer):
            self.currentPlayer.currentUnit.tile.setChosenByReach(self.currentPlayer.currentUnit.moves)
            self.map.addAction(partial(self.currentPlayer.currentUnit.move, fun=fun))
            return True
        return False
    
    def nextUnitAction(self):
        if isinstance(self.currentPlayer, HumanPlayer):
            self.currentPlayer.nextUnitAction()
            return True
        return False
    
    def nextTurnAction(self):
        if isinstance(self.currentPlayer, HumanPlayer):
            self.currentPlayer.endTurn()
#.........这里部分代码省略.........
开发者ID:Temppa,项目名称:Vuoropohjainen-peli,代码行数:103,代码来源:application.py

示例2: __init__

# 需要导入模块: from Map import Map [as 别名]
# 或者: from Map.Map import createSquareMap [as 别名]
class Game:
    def __init__(self):
        self.map = Map()
        self.numUnits = 1
        self.numPlayers = 1
        self.playerIndex = -1 
        self.turn = 1
        self.players = []
        self.mode = 'single'
        self.playerNames = []
        self.singletonObject = None
        self.turnUnits = []
        self.mapSize = 0 #small

    def __saveable__(self):
        """ Returns a saveable representation of the game. """
        d = {}

        d['players'] = map(saveable, self.players)
        d['map'] = saveable(self.map)
        d['turn'] = self.turn
        d['playerIndex'] = self.playerIndex
        d['currentPlayer'] = saveable(self.currentPlayer)

        return d

    @classmethod
    def __load__(cls, d):
        g = cls()

        g.map = load(Map, d['map'], game=g)
        g.players = map(partial(load, Player, game=g), d['players'])
        g.turn = d['turn']
        g.playerIndex = d['playerIndex']
        g.currentPlayer = load(Player, d['currentPlayer'], game=g)
        g.numUnits = len(g.map.units)
        g.numPlayers = len(g.players)

        return g

    def save(self, filename):
        d = saveable(self)

        with open(filename, 'w') as f:
            json.dump(d, f)

        print 'Game saved.'

    @classmethod
    def load(cls, filename):
        Player.loadedPlayers = {}

        with open(filename) as f:
            d = json.load(f)

        print 'Game loaded.'
        return load(cls, d)

    def start(self):
        if game.mode == 'single':
            self.players.append(HumanPlayer(self))
            for x in xrange(self.numPlayers - 1):
                self.players.append(AIPlayer(self))
        else:
            for x in xrange(self.numPlayers):
                self.players.append(HumanPlayer(self))
        if self.mapSize == 0:
            self.map.createSquareMap(self.numUnits, self.players, 50, 1)
        elif self.mapSize == 1:
            self.map.createSquareMap(self.numUnits, self.players, 35, 2)
        else:
            self.map.createSquareMap(self.numUnits, self.players, 20, 3)
        self.numUnits *= self.numPlayers
        
    def cyclePlayers(self):
        self.playerIndex += 1
        if self.playerIndex == self.numPlayers:
            self.playerIndex = -1 
            self.currentPlayer = None # None indicates the turn is over
        else:
            self.currentPlayer = self.players[self.playerIndex]
            if isinstance(self.currentPlayer, HumanPlayer):
                self.turnUnits = filter(lambda x: x.owner == self.currentPlayer, self.map.units)

    def nextPlayerAction(self):
        self.cyclePlayers()
        if self.currentPlayer:
            self.currentPlayer.doTurn()
        else:
            self.nextTurn()
    
    def nextTurn(self):
        self.save('savefile.save')
        self.resetPlayerCycle()
        self.nextPlayerAction()
        self.turn += 1
    
    def resetPlayerCycle(self):
        self.playerIndex = -1
    
#.........这里部分代码省略.........
开发者ID:Odingod,项目名称:Vuoropohjainen-peli,代码行数:103,代码来源:application.py


注:本文中的Map.Map.createSquareMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。