def main(): #建立商店 Prepare.PrepareShop() #建立玩家以及与玩家有关的地点 Prepare.PreparePlayer() #开启循环 Turn = 0 while (True): Turn += 1 #随机胜负,统计步数 Prepare.PrepareStep() if (base.RoundActionStep == 0 or base.RoundActionStep == base.alivePlayerNum): Turn -= 1 continue #回合优先级判断 Prepare.PreparePriority() #更新玩家的回合信息 Game.UpdatePlayerTurnInfo() #游戏进程 for i in range(0, base.playerNum): #base.RoundActionStep是当前回合行动力 nowID = base.playerActionOrder[i] nowPlayer = base.playerList[nowID] if (nowPlayer.hp <= 0 or base.playerDiceList[nowID] == 0): continue for step in range(0, base.RoundActionStep): Print.PrintInfo(Turn) print('Player%d: %s, it\'s your turn.' % (nowID + 1, base.playerList[nowID].name)) print('You have %d step(s) left.' % (base.RoundActionStep - step)) NothingID = Game.GameDecision(nowPlayer) CommandIn = int(input('Your option:')) if (CommandIn == NothingID): break Game.GameDecision(nowPlayer, CommandIn) base.alivePlayerNum = Game.CountAlive() base.playerList[i].leftstep -= 1 #游戏结束判断 if (Game.GameEndCheck()): break
def main(): #建立商店 base.marketList.append(Market('shop')) base.marketList.append(Market('supermarket')) base.marketList.append(Market('retail department')) base.marketList.append(Market('shopping mall')) base.bmarketList.append(BlackMarket()) #建立玩家以及与玩家有关的地点 base.playerNum = int(input('Number of players:')) base.alivePlayerNum = base.playerNum for i in range(0, base.playerNum): playerName = str(input('Please input the Player%d\'s name:' % (i + 1))) base.playerList.append(Player(playerName, i, base.bmarketList[0])) nowPlayer = base.playerList[i] base.homeList.append(Home(nowPlayer)) nowPlayer.plc = base.homeList[i] base.outhomeList.append(OutsideHome(nowPlayer)) base.cellarList.append(Cellar(nowPlayer)) base.carList.append(Car(nowPlayer)) base.outcarList.append(OutsideCar(nowPlayer)) base.ambushList.append(AmbushPoint(base.homeList[i], nowPlayer)) base.playerPriorityList.append(-1) base.playerDiceList.append(0) base.playerActionOrder.append(-1) #开启循环 running = True Turn = 0 while running: Turn += 1 base.RoundActionStep = 0 for i in range(0, base.playerNum): tempDouble = random.random()*2 tempInt = math.floor(tempDouble) base.playerDiceList[i] = tempInt if (tempInt == 0 and base.playerList[i].hp > 0): base.RoundActionStep += 1 if (base.RoundActionStep == 0 or base.RoundActionStep == base.alivePlayerNum): Turn -= 1 continue #回合优先级判断 for i in range(0, base.playerNum): base.playerPriorityList[i] = -1 tempCount = 0 while tempCount < base.playerNum: tempDouble = random.random()*base.playerNum tempInt = math.floor(tempDouble) if (base.playerPriorityList[tempInt] == -1): base.playerPriorityList[tempInt] = tempCount base.playerActionOrder[tempCount] = tempInt tempCount += 1 for i in range(0, base.playerNum): nowID = base.playerActionOrder[i] nowPlayer = base.playerList[nowID] if (nowPlayer.hp <= 0 or base.playerDiceList[nowID] == 0): continue #base.playerActionOrder[i]是当前玩家的ID #base.RoundActionStep是当前行动力 for step in range(0, base.RoundActionStep): Print.PrintInfo(Turn) print('Player%d: %s, it\'s your turn.' % (nowID + 1, base.playerList[nowID].name)) print('You have %d step(s) left.' % (base.RoundActionStep - step)) Game.GameDecision(nowID) CommandIn = int(input('Your option:')) Game.GameDecision(nowID, CommandIn) base.alivePlayerNum = Game.CountAlive() if (base.alivePlayerNum == 1): for plr in base.playerList: if (plr.hp > 0): print('Winner: ', end = '') plr.PrintName() input() break