Exemplo n.º 1
0
def victory(char_name):
    game_data = functions.read_game_data()
    print(functions.Style.BOLD + "Congratulations " + char_name +
          "! You've defeated Red Dragon Taro!" + functions.Style.END)
    time.sleep(3)
    functions.clean_terminal()
    for char in functions.read_game_data()["characters"]:
        if char_name in char:
            reward = char[char_name]["gold"] + 100
            experience = char[char_name]["level"] + 1
            char[char_name].update(gold=reward, level=experience)
            functions.write_game_data(game_data)
    time.sleep(3)
    print("*Magic gathers around you, lifting your feet from the ground*",
          end="\r",
          flush=True)
    print(functions.Style.BOLD + "Vortigern: " + functions.Style.END +
          functions.Style.CLEAR + "Great job, " + char_name +
          ", thank you for returning with my gold!",
          end="\r",
          flush=True)
    time.sleep(3)
    print(functions.Style.BOLD + "Vortigern: " + functions.Style.END +
          functions.Style.CLEAR + "Kneel before me so that I can reward you.",
          end="\r",
          flush=True)
    time.sleep(3)
Exemplo n.º 2
0
 def load_saved_game(self):
     self.stackedWidget.setCurrentIndex(1)
     self.btnExit.setVisible(True)
     self.btnBack.setVisible(True)
     self.btnNext.setVisible(True)
     self.btnOrc.setEnabled(False)
     self.btnElf.setEnabled(False)
     self.btnGoblin.setEnabled(False)
     self.btnDwarf.setEnabled(False)
     self.btnTroll.setEnabled(False)
     self.lblOrc.setText("Empty")
     self.lblElf.setText("Empty")
     self.lblGoblin.setText("Empty")
     self.lblDwarf.setText("Empty")
     self.lblTroll.setText("Empty")
     self.lblCharacterRace.setText("Please select your character:")
     for char in functions.read_game_data()["characters"]:
         for name in char.keys():
             if char[name]["race"] == "orc":
                 self.btnOrc.setEnabled(True)
                 self.lblOrc.setText(name)
             elif char[name]["race"] == "elf":
                 self.btnElf.setEnabled(True)
                 self.lblElf.setText(name)
             elif char[name]["race"] == "goblin":
                 self.btnGoblin.setEnabled(True)
                 self.lblGoblin.setText(name)
             elif char[name]["race"] == "dwarf":
                 self.btnDwarf.setEnabled(True)
                 self.lblDwarf.setText(name)
             elif char[name]["race"] == "troll":
                 self.btnTroll.setEnabled(True)
                 self.lblTroll.setText(name)
Exemplo n.º 3
0
def load_game(char_name):
    functions.clean_terminal()
    for char in functions.read_game_data()["characters"]:
        if char_name in char:
            level = char[char_name]["level"]
            char_race = char[char_name]["race"]
            char_class = char[char_name]["class"]
            load_level(level, char_name, char_race, char_class)
Exemplo n.º 4
0
def listen(l_type, player_input, char_name):
    if l_type == "quest":
        if player_input.lower() == "a":
            functions.clean_terminal()
            print(functions.Style.BOLD +
                  "Quest Accepted: The High Lord's Gold" + functions.Style.END)
            os.system("notepad.exe data/quests/The-High-Lord's-Gold.md")
            functions.player_actions(char_name, quest=True)
            for char in functions.read_game_data()["characters"]:
                if char_name in char:
                    # health = char[char_name]["health"]
                    combat(char_name)
Exemplo n.º 5
0
def combat(char_name):
    functions.clean_terminal()
    game_data = functions.read_game_data()
    for monster in game_data["monsters"]:
        while monster["Taro"]["health"] > 0:
            health = monster["Taro"]["health"]
            hit_splat = randrange(0, 999)
            if hit_splat > health:
                hit_splat = health
            damage = health - hit_splat
            time.sleep(2)
            print("You swing your sword and hit a " + str(hit_splat) + "!")
            monster["Taro"].update(health=damage)
            functions.write_game_data(game_data)
    victory(char_name)
Exemplo n.º 6
0
 def load_game(self, character_name):
     """
     Load character stats and setup window for gameplay.
     :param character_name:
     :return:
     """
     self.fade_out(self.centralWidget())
     self.stackedWidget.setCurrentIndex(3)
     for widget in self.centralwidget.children():
         if widget.objectName() in self.widgets_list:
             if widget.objectName() == "btnBack":
                 widget.setVisible(False)
             else:
                 widget.setVisible(True)
     for char in functions.read_game_data()["characters"]:
         if character_name in char:
             gold = char[character_name]["gold"]
             level = char[character_name]["level"]
             char_race = char[character_name]["race"]
             health = char[character_name]["health"]
             self.lblGP.setText(str(gold) + " GP")
             self.lblName.setText(character_name)
             self.lblLevel.setText("LVL " + str(level))
             self.lblHP.setText(str(health) + " HP")
             if char_race == "orc":
                 self.btnCharacter.setIcon(QIcon("images/orc-head-color.png"))
             elif char_race == "elf":
                 self.btnCharacter.setIcon(QIcon("images/woman-elf-face-color.png"))
             elif char_race == "goblin":
                 self.btnCharacter.setIcon(QIcon("images/goblin-face-color.png"))
             elif char_race == "dwarf":
                 self.btnCharacter.setIcon(QIcon("images/dwarf-face-color.png"))
             elif char_race == "troll":
                 self.btnCharacter.setIcon(QIcon("images/troll-color.png"))
     volume = pygame.mixer.music.get_volume()
     while volume > 0:
         volume -= 0.000001
         pygame.mixer.music.set_volume(volume)
     pygame.mixer.music.stop()
     self.fade_in(self.centralWidget())
     load_music("music/No-More-Magic.mp3", running=True)
Exemplo n.º 7
0
def create_character(character_name, character_race):
    try:
        """
        char_name = str(input("Please enter your desired player name: ")).title()
        char_race = str(input("What race would you like to play as [Human, Elf, Orc, Troll]: ")).title()
        char_class = str(input("What class would you like to master [Warrior, Mage, Archer, Monk]: ")).title()
        """
        game_data = functions.read_game_data()
        for char in game_data["characters"]:
            if character_name in char:
                return KeyError
        game_data["characters"].append({
            character_name: {
                "race": character_race,
                "level": 1,
                "health": 100,
                "gold": 25
            }
        })
        functions.write_game_data(game_data)
        # load_game(char_name)
    except ValueError:
        sys.exit(1)
Exemplo n.º 8
0
 def turn_page(self, action):
     """
     Get current index of QStackedWidget and switch accordingly.
     :param action:
     :return:
     """
     index = self.stackedWidget.currentIndex()
     if action == "next":
         if index == 0:
             self.btnOrc.setStyleSheet(styles.normal_style)
             self.btnElf.setStyleSheet(styles.normal_style)
             self.btnGoblin.setStyleSheet(styles.normal_style)
             self.btnDwarf.setStyleSheet(styles.normal_style)
             self.btnTroll.setStyleSheet(styles.normal_style)
         elif index == 1:
             if self.character_name:
                 self.load_game(self.character_name)
             else:
                 self.stackedWidget.setCurrentIndex(2)
             """
             try:
                 data = functions.read_game_data()
                 for char in data["characters"]:
                     if character_name in char:
                         char[character_name].update(race=self.character_race)
                         functions.write_game_data(data)
             except (KeyError, ValueError):
                 self.setup_ui()
             """
         elif index == 2:
             character_name = self.txtCharacterName.toPlainText().title()
             if len(character_name) == 0 or len(character_name) > 10:
                 self.txtCharacterName.setStyleSheet(
                     "background: transparent;"
                     "border: 2px solid;"
                     "border-color: red;"
                     "color: rgb(0, 0, 0);"
                 )
                 return
             else:
                 data = functions.read_game_data()
                 for char in data["characters"]:
                     if character_name in char:
                         self.lblWarning.setText("That character already exists!")
                         self.txtCharacterName.setStyleSheet(
                             "background: transparent;"
                             "border: 2px solid;"
                             "border-color: red;"
                             "color: rgb(0, 0, 0);"
                         )
                         return
                 data["characters"].append(
                     {
                         character_name: {
                             "race": self.character_race,
                             "level": 1,
                             "health": 100,
                             "gold": 25
                         }
                     }
                 )
                 functions.write_game_data(data)
                 self.load_game(character_name)
     elif action == "back":
         if index == 1:
             self.setup_ui()
         elif index == 4:
             self.setup_ui()
         else:
             self.stackedWidget.setCurrentIndex(index - 1)
     play_sound("music/sounds/page-turning.wav")