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


Python Resource.buy_resource方法代碼示例

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


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

示例1: main

# 需要導入模塊: import Resource [as 別名]
# 或者: from Resource import buy_resource [as 別名]
    def main(self):

        # TODO Load the map blocked need map object

        # init turns
        # TODO
        self.initializePlayerTurns()
        for player in reversed(self.players):
            while len(player.get_PowerPlants()) == 0:
                auction = Auction.Auction(
                    self.Table.getDeck(), self.Table.getCardsForAuction() + self.Table.getFutureCardsForAuction()
                )
                # TODO Anandh add auction stuff

        while not self.gameover:
            print("buy resources")
            # PHASE 2 bid for resources
            for player in self.players:
                request = {}
                request[Resource.COAL] = player.getCoalRequest()
                request[Resource.OIL] = player.getOilRequest()
                request[Resource.GARBAGE] = player.getGarbageRequest()
                request[Resource.URANIUM] = player.getUraniumRequest()
                cost = Resource.buy_resource(request)
                if cost == 0:
                    player.warn(NOT_ENOUGH_RESOURCES)
                elif cost <= player.f_b_get_money():
                    player.pay(cost)
                    player.add_coal(request[Resource.COAL])
                    player.add_oil(request[Resource.OIL])
                    player.add_garbage(request[Resource.GARBAGE])
                    player.add_uranium(request[Resource.URANIUM])
                else:
                    # This case there is not enough money
                    player.warn(NOT_ENOUGH_MONEY)
            self.ResourceMarket.restore_resources()

            # PHASE 3 buy cities
            # TODO Blocked no map available

            # PHASE 4 power cities
            for player in self.players:
                player.powerCities()
                # TODO check game end

                # PHASE 5 pay the players
            for player in self.players:
                player.addMoney(payday.pay(player.get_cities_powered))

                # Check if advance to 2
            if self.currentPhase == 1:
                self.checkAdvancePhaseTwo()

            for player in self.players:
                if player.get_cities() >= self.GAMEEND[self.numPlayers]:
                    self.gameover = True
                    # PHASE 1 bid for power plants
            self.players = calculateTurns()
            availableCards = self.Table.getCardsForAuction()
            futureCards = self.Table.getFutureCardsForAuction()
            self.checkAdvancePhaseThree(availableCards)
            # Pass to players
            # TODO Auction
            print("Bid for power plants")
            auction = Auction.Auction(self.Table.getDeck(), availableCards + futureCards)
開發者ID:straemer,項目名稱:PowerGrid,代碼行數:67,代碼來源:gamemaster.py


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