當前位置: 首頁>>代碼示例>>Python>>正文


Python Rules.addUnits方法代碼示例

本文整理匯總了Python中rules.Rules.addUnits方法的典型用法代碼示例。如果您正苦於以下問題:Python Rules.addUnits方法的具體用法?Python Rules.addUnits怎麽用?Python Rules.addUnits使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rules.Rules的用法示例。


在下文中一共展示了Rules.addUnits方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from rules import Rules [as 別名]
# 或者: from rules.Rules import addUnits [as 別名]

#.........這裏部分代碼省略.........
        for bonus in self.bonuses:
            deserveBonus = True
            for country in bonus[0:-1]:
                if not self.isOwned(country,player):
                    deserveBonus = False
            if deserveBonus:
                count+=(countriesPerTroop*int(bonus[-1]))
        return max(int(count/countriesPerTroop),3)


    def player_reinforce(self,country,howMany,player):
        pass
        # check for correct turn, right time, have reinforcements, etc.
        if type(player) != type('string') and type(player) != type(u'string'):
            return False
        if self.whosTurn != player:
            return False
        if self.turnStage != 'reinforce':
            return False
        if self.reinforcementsToPlace[player]<=0:
            return False
        if type(country) != type('string') and type(country) != type(u'string'):
            return False
        if country not in self.countries:
            return False
        if not self.isOwned(country, player):
            return False
        if type(howMany) != type(1):
            return False
        if howMany>self.reinforcementsToPlace[player]:
            return False
        if howMany < 0:
            return False
        if self.rules.addUnits(country, howMany):
            self.reinforcementsToPlace[player]=self.reinforcementsToPlace[player]-howMany
            self.updateTurn()
            return True
        else:
            return False

    def player_attack(self,fromCountry,toCountry,howMany,player):
        if self.whosTurn != player:
            #raise Exception, 'player error'
            return False
        if self.turnStage != 'attacks':
            #raise Exception, 'its not in the attack stage'
            return False
        if type(fromCountry)!=type('string') and type(fromCountry) != type(u'string'):
            #raise Exception, 'from country is not a string'
            return False
        if type(toCountry)!=type('string') and type(fromCountry) != type(u'string'):
            #raise Exception, 'to country is not a string'
            return False
        if type(player)!=type('string') and type(player) != type(u'string'):
            #raise Exception, 'player is not a string'
            return False
        if type(howMany)!=type(1):
            #raise Exception, 'how many is not a number'
            return False
        if not fromCountry in self.countries:
            #raise Exception, 'from country is not a country'
            return False
        if not toCountry in self.countries:
            #raise Exception, 'to country is not a country'
            return False
        if not player in self.players:
開發者ID:thomasballinger,項目名稱:Utok,代碼行數:70,代碼來源:game.py


注:本文中的rules.Rules.addUnits方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。