Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to fix it?
#1
import os
import random
import time
import datetime 
from subprocess import call

var_0 = 'w'
var_1 = 's'
var_2 = 'a'
var_3 = 'd'

choice_0 = 'y'
choice_1 = 'n'

user_input = ""
menu_input = ""

action = "You woke up in the woods."
direction = ""

#player
hp = 100
hunger = 0
energy = 100
thirst = 0

time = datetime.time(7,00)

random_0 = (random.randint(0, 49))
random_1 = (random.randint(1, 20))

def screen_clear():
    os.system('cls' if os.name=='nt' else 'clear')

equipment = ["apple(15)", "water(45)", "sandwich(30)"]

def menu():
    print("COMMAND - SURVIVAL")
    print()
    print("W - Play")
    print("S - Exit")
    print()
    menu_input = input("> ")

def game():
    screen_clear()
    
    global hp
    global energy
    global hunger
    global thirst
    global equipment
    global time
    global random
    
    print("===================================================")
    print()
    print("-Player Stats-")
    print()
    print("HP:" + str(hp))
    print("ENERGY:" + str(energy))
    print("HUNGER:" + str(hunger))
    print("THIRST:" + str(thirst))
    print("EQUIPMENT: " + str(equipment))
    print("TIME: " + str(time))
    print()
    print(action)
    print()
    print("W - Go Somewhere")
    print("S - Use Item")
    print("A - Craft Something")
    print("D - Look Around")
    print()
    user_input = input("> ")
    if user_input == var_0:
        print("W - East")
        print("S - West")
        print("A - North")
        print("D - South")
        print("N - I don't want go anywhere.")
        user_input == input("> ")
        if user_input == var_0:
            print("You went east.")
            direction = "east"
            energy = energy - 15
            thirst = thirst + 5
            hunger = hunger + 2.5
            if random_0 == 0:
                hp = hp - random_1
            game()
        elif user_input == var_1:
            print("You went west.")
            game()
        elif user_input == var_2:
            print("You went north.")
            game()
        elif user_input == var_3:
            print("You went South.")
            game()
    elif user_input == var_1:
        print("What do you want to use?")
        print("Enter the number of item you want to use.")
        print("EQUIPMENT: " + str(equipment))
        user_input == input("> ")
    elif user_input == var_2:
        print("What do you want to craft?")
    elif user_input == var_3:
        print("What do you want to do?")
        user_input == input("> ")

def event_0():
    print("When you used to go " + direction + "you hurt your leg.")
    game()

if user_input == var_0:
    screen_clear()
    print("Do you know how to play?")
    print("Y/N")
    user_input = input("> ")
    if user_input == choice_0:
        game()
    elif user_input == choice_1:
        screen_clear()
        print("HOW TO PLAY:")
        print()
        print("")
        print("")
        print("")
        print("")
        print("")
        print()
        print("Press enter to return to the menu.")
        input("> ")
        game()
elif menu_input == var_1:
    print()
Put it in the compiler and you will see what problem I have.
Reply
#2
Once you get to line 115, user_input is "" and var_0 is 'w'. Game never proceeds?
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020