Ejemplo n.º 1
0
def main():
    state = game_start(MAX_HP, SPEED_UP_TEXT)
    turns = 0

    while True:
        '''
        Anatomy of a Turn (Loop)
        1. Clear the screen
        2. Re-render the heads up display (HUD)
        3. Check to see if we're in combat, if we are, complete the combat
        4. If not in combat, let the user know what directions are available
           and ask them what they want to do.
        5. Check the new "square" to see if there's loot or a monster there
        6. If there's loot, pick it up. If it's a monster, enter combat.
        '''
        clear()
        render_hud(state, MAX_HP)
        
        if state["combat"]:
            # TODO: write combat code
            pass

        print(message("Which direction do you go?"))
        print(state["coords"])
        if. cmd.lower(). =="up":
            (x, y). =. state["coords"]
            next_square. =. (x, y-1)
            next_square.append(state["coords"])
        elif. cmd.lower(). =="down":
            
        cmd = run_cmd(input("> "))
Ejemplo n.º 2
0
def display_thread():

    message_list = []
    server = simple_socket.connect_as_server()
    clear()
    if server:
        running = True
        while running:
            new_message = server.receive()
            if new_message is not False:
                new_message = str(new_message).replace("\r", "").replace("\n", "")
                message_list.append(new_message)
                clear()
                for line in message_list:
                    print("You wrote: " + line)
Ejemplo n.º 3
0
def game_start(max_hp, fast):
    clear()
    print(
        message(
            "You awake cold and hungry. Everywhere you look is nothing but dark."
        ))
    sleep(0 if fast else 5)

    clear()
    print(
        message(
            "How did you get here? The memories of it come in flashes and fits. Were you thrown down here or did you fall?"
        ))
    sleep(0 if fast else 5)

    clear()
    print(
        message(
            "You struggle to your feet and try to get your bearings. Try to even remember your own name. What is your name?"
        ))
    sleep(0 if fast else 3)

    name = input("> ")
    uppercased_name = "{}{}".format(name[0].upper(), name[1:])

    state = init_state(uppercased_name, max_hp)

    clear()
    render_hud(state, max_hp)
    print(
        message(
            "Of course! \"{} the {},\" that is what they used to call you.".
            format((state["player"]["name"]), state["player"]["title"])))
    sleep(0 if fast else 5)

    clear()
    render_hud(state, max_hp)
    pick = get_player_action(
        "You have no shield, but you quickly realize you've got a weapon hanging by your side. Do you remember what it is?",
        ["Sword", "Axe", "Spear"],
    )

    chosen_weapon = weapons[str(pick + 2)]
    state = equip_weapon(state, chosen_weapon)

    return state
Ejemplo n.º 4
0
def loading_screen():
    """example for using the function to refresh the screen

    no tests, because this just prints to the screen
    """
    # function for pausing the code
    from time import sleep
    # init loading string
    loading = "Loading "
    # initial screan clearing to avoid conflicts later
    clear()

    # add a dot every second
    for i in range(10):
        loading += ". "
        print(loading)
        sleep(1)
        clear()

    # loading finished
    print("Finished")
Ejemplo n.º 5
0
def main():
    state = game_start(MAX_HP)
    turns = 0

    while True:
        '''
        Anatomy of a Turn (Loop)
        1. Clear the screen
        2. Re-render the heads up display (HUD)
        3. Check to see if we're in combat, if we are, complete the combat
        4. If not in combat, let the user know what directions are available
           and ask them what they want to do.
        5. Check the new "square" to see if there's loot or a monster there
        6. If there's loot, pick it up. If it's a monster, enter combat.
        '''
        clear()
        render_hud(state, MAX_HP)
        
        if state["combat"]:
            # TODO: write combat code
            pass

        # TODO: let the player know which directions are available
        cmd = run_cmd(input("> "))
Ejemplo n.º 6
0
           and ask them what they want to do.
        5. Check the new "square" to see if there's loot or a monster there
        6. If there's loot, pick it up. If it's a monster, enter combat.
        '''
        clear()
        render_hud(state, MAX_HP)
        
        if state["combat"]:
            # TODO: write combat code
            pass

        print(message("Which direction do you go?"))
        print(state["coords"])
        if. cmd.lower(). =="up":
            (x, y). =. state["coords"]
            next_square. =. (x, y-1)
            next_square.append(state["coords"])
        elif. cmd.lower(). =="down":
            
        cmd = run_cmd(input("> "))

        # TODO: move the player based on their "cmd"


if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        clear()
        print("Goodbye!")
Ejemplo n.º 7
0
 def render_and_message(msg):
     clear()
     render_hud(state, MAX_HP)
     print(message(msg))
Ejemplo n.º 8
0
def main():
    state = game_start(MAX_HP, SPEED_UP_TEXT)
    turns = 0

    def render_and_message(msg):
        clear()
        render_hud(state, MAX_HP)
        print(message(msg))

    while True:
        '''
        Anatomy of a Turn (Loop)
        1. Clear the screen
        2. Re-render the heads up display (HUD)
        3. Check to see if we're in combat, if we are, complete the combat
        4. If not in combat, let the user know what directions are available
           and ask them what they want to do.
        5. Check the new "square" to see if there's loot or a monster there
        6. If there's loot, pick it up. If it's a monster, enter combat.
        '''
        clear()
        render_hud(state, MAX_HP)

        if state["combat"]:
            monster = get_random_monster()

            render_and_message("A " + monster["name"].upper() +
                               " has been provoked.")
            sleep(1.5)

            mon_dmg = monster_attack(state, monster)
            render_and_message("The " + monster["name"].upper() + " deals you " + str(mon_dmg) \
                + " damage. You have " + str(state["player"]["hp"]) + " HP remaining.")

            # Combat loop
            while True:
                cmd = input("Do you attack? (Y/n) ")

                if cmd.lower() is not "n":
                    dmg = player_attack(state["player"], monster)
                    render_and_message("You deal " + str(dmg) + " damange with your " + state["player"]["equipped_weapon"]["name"].upper()\
                        + " the " + monster["name"].upper() + " has " + str(monster["hp"]) + " HP remaining.")
                    sleep(2)

                    if state["player"]["hp"] <= 0:
                        render_and_message("The " + monster["name"].upper() +
                                           " dances over your lifeless body.")
                        sleep(2)
                        render_and_message("GAME OVER")
                        sleep(1)
                        sys.exit()

                    if monster["hp"] <= 0:
                        render_and_message(
                            "You've defeated the " + monster["name"].upper() +
                            ". You burn its corpse so it doesn't attract others."
                        )
                        sleep(2.7)
                        state["combat"] = False
                        break

                    mon_dmg = monster_attack(state, monster)
                    render_and_message("The " + monster["name"].upper() + " deals you " + str(mon_dmg) \
                        + " damage. You have " + str(state["player"]["hp"]) + " HP remaining.")
                    sleep(1.5)
                else:
                    render_and_message("You attempt to flee but are thwarted")

                if state["player"]["hp"] <= 0:
                    render_and_message("The " + monster["name"].upper() +
                                       " dances over your lifeless body.")
                    sleep(2)
                    render_and_message("GAME OVER")
                    sleep(1)
                    sys.exit()

        render_and_message("Which direction do you go?")
        print(state["coords"])
        cmd = run_cmd(input("> "))

        # Step 2: Error Handling
        if cmd.lower() not in DIRECTIONS:
            clear()
            render_hud(state, MAX_HP)
            print(
                message(
                    "Hmm... that doesn't sound like any direction I've heard of before"
                ))
            print("> ")
            sleep(1)
            continue

        # Step 1: Update state
        if cmd.lower() == "up":
            (x, y) = state["coords"]
            next_square = (x, y - 1)
        elif cmd.lower() == "down":
            (x, y) = state["coords"]
            next_square = (x, y + 1)
        elif cmd.lower() == "left":
            (x, y) = state["coords"]
            next_square = (x - 1, y)
        elif cmd.lower() == "right":
            (x, y) = state["coords"]
            next_square = (x + 1, y)

        # Step 3: Check if square exists
        if not square_exists(state, next_square):
            render_and_message("Where you're trying to go is no place at all.")
            print("> ")
            sleep(1)
            continue

        (x, y) = next_square

        # Step 4: Find the exit
        if state["dungeon"][y][x] == 3:
            # TODO: make the victory more enjoyable
            print(message("You did it! you made it out alive!"))
            break

        # Step 5: collision logics
        if state["dungeon"][y][x] == 1:
            render_and_message(
                "Looks like you hit a wall there bud. Maybe try a different direction."
            )
            print("> ")
            sleep(1)
            continue

        state["coords"] = next_square
        state["visited"].append(state["coords"])
        # TODO: check square
        if d(1, 20) > 10:
            state["combat"] = True
            render_and_message("There's something in the dark!")
        else:
            state["combat"] = False
Ejemplo n.º 9
0
def exit():
    clear()
    print("Goodbye!")
    sys.exit()
Ejemplo n.º 10
0
def start(max_wrong_letters):
    """starts a hangman game"""
    max_wrong_letters -= 1
    # initial screen clearing
    clear()
    # run the game until the user cancels it
    while True:
        # ask for a word from the user until he types a correct one
        while True:
            # get a word
            orig_word = get_word()
            # if the word is valid convert it into a list and leave the loop
            if check_word(orig_word):
                word = list(orig_word)
                break
            else:
                # tell the user that his input was wrong
                clear()
                print("Invalid word, please try again")

        # empty the correct and wrong letters from last game
        correct_letters = []
        wrong_letters = []
        # initial screen render
        clear()
        render(orig_word, word, correct_letters, wrong_letters, -1,
               max_wrong_letters)

        # we got a valid word now, so start a guessing round
        while True:
            # get a letter
            letter = get_letter()
            # clear the screen
            clear()
            action = -1

            # only continue with the main code if the input is valid
            if input_correct(letter):
                # check if the letter is in the word
                if replace_letter(letter, word, correct_letters,
                                  wrong_letters):
                    action = 1
                # the letter wasn't in the word
                else:
                    action = 0
            # check if the user wants to quit the game
            elif letter == 'quit':
                # clean up
                clear()
                # and quit
                return
            # refresh the screen
            render(orig_word, word, correct_letters, wrong_letters, action,
                   max_wrong_letters)

            # if the word is correct, then we are done
            if word_solved(word):
                print("Congratulations! You won!")
                # give the player time to enjoy his victory
                sleep(5)
                # clean up and start a new game
                clear()
                break
            # if too many wrong letters have been guessed the game ends
            elif len(wrong_letters) > max_wrong_letters:
                print("Game over! Too many wrong letters!")
                # print the correct word
                print("The word was:", orig_word)
                # give the player time to look at the word
                sleep(5)
                # clean up and start a new game
                clear()
                break