# Module GM: Game Master # Defines a class handling several players for a # text-based D&D style game. # Author: Dana Vrajitoru # Class: C463/B551/I400 Fall 2025 from Player import * class GM: # constructor with a number of players. It generates a list # containing references to the players and stores it in # self.players. The first nhuman players are assumed to be human # and the others are NPCs. def __init__(self, nplayers = 5, nhuman = 1): self.players = [] for i in range(nhuman): self.players.append(Player(True)) # human player for i in range(nplayers - nhuman): self.players.append(Player(False)) # NPC self.nplayers = nplayers self.nhuman = nhuman self.quit = False def display(self): print("Situation:") for i in range(len(self.players)): print(i, self.players[i]) # Main function of the game that has a loop continuing while the user # still wants to play. def play(self): self.display() while not self.quit: for player in self.players: player.play(self.players) self.display() answer = input("Another round? [y/n] ") if 'n' in answer or 'N' in answer: self.quit = True print("Bye!") # main part of the program in place of a main function. # Testing code for the game. if __name__ == '__main__': gm = GM() gm.play() # Formatting a string" # s = "Strength: %d Intelligence %d Home: %d." %(4 5 6) # SyntaxError: invalid syntax. Perhaps you forgot a comma? # s = "Strength: %d Intelligence %d Home: %d." %(4, 5, 6) # s # 'Strength: 4 Intelligence 5 Home: 6.'