Summoner Wars

Simulate Dice Roll

  • 🗡️: 0 🏹: 0 ⚡: 0
  • # Purpose: Summoner Wars Dice Roller
    # %------------------------------------------ Packages -------------------------------------------% #
    import random
    
    # %------------------------------------------ Classes ------------------------------------------% #
    class SummonerWars():
        def __init__(self) -> None:
            """
                * Summoner Wars Dice Faces:
                M = Melee | R = Range | S = Lightning
                (M, R, S) = (bool, bool, bool)
                1) MR : (True, True, False) 
                2) MR : (True, True, False)
                3) MR : (True, True, False)
                4) MS : (True, False, True)
                5) RS : (False, True, True)
                6) M  : (True, False, False)
            """
            self.dice_symbol_map = {
                (True, True, False):  "🗡️  | 🏹",
                (True, False, True):  "🗡️  | ⚡",
                (False, True, True):  "🏹 | ⚡",
                (True, False, False): "🗡️"
            }
            
            self.dice_faces = [(True,  True,  False),
                               (True,  True,  False),
                               (True,  True,  False),
                               (True,  False, True),
                               (False, True,  True),
                               (True,  False, False)]
            
            self.game_stats = {'M': 0, 'R': 0, 'S': 0}
            
        # Purpose: Roll n dice and return the results
        def play(self):
            while True:
                # Get user input
                user_input = input("Enter the number of dice to roll (or 'q' to quit): ")
    
                # Check if the user wants to quit
                if user_input.lower() == 'q':
                    print("Game over!")
                    break
                
                # Check if the user wants to quit
                n = int(user_input)
                if n < 1:
                    print("Please enter a positive integer.")
                    continue
                
                # Roll the dice
                result = self.roll_n_dice(n)
                SummonerWars.print_result(result)
                
            # Print the final game stats
            print(f'{"Final Game Stats":-^{50}}')
            SummonerWars.print_result(self.game_stats)
    
        # Purpose: Roll n dice
        def roll_n_dice(self, n):
            result = {'M': 0, 'R': 0, 'S': 0}
            
            for _ in range(n):
                face = random.choice(self.dice_faces)
                print(f" - {self.dice_symbol_map.get(face, '')}")
                if face[0]:
                    result['M'] += 1
                    self.game_stats['M'] += 1
                if face[1]:
                    result['R'] += 1
                    self.game_stats['R'] += 1
                if face[2]:
                    result['S'] += 1
                    self.game_stats['S'] += 1
            return result
        
        @staticmethod
        def print_result(result):
            print(f"Total Melee: {result['M']},\nTotal Range: {result['R']},\nTotal Lightning: {result['S']}\n")
    
    # %-------------------------------------------- Main ---------------------------------------------% #
    def main():
        game = SummonerWars()
        game.play()
    
    # %--------------------------------------------- Run ---------------------------------------------% #
    if __name__ == '__main__':
        print(f'{"Start":-^{50}}')
        main()
        print(f'{"End":-^{50}}')