Ask coding questions

← Back to all posts
Why is the change from level 2 to level 3 different than the change from 1 to 2.
ColePete (24)

Look at the change from level 1 to two. Then look at the change from two to three. Why is it different? I want them to both be like the change from level 1 to level 2. Any suggestions?

Answered by Whippingdot (158) [earned 5 cycles]
View Answer
Commentshotnewtop
ColePete (24)

@MocaCDeveloper @whippingdot I feel bad always asking ya'll for help, but, I am stuck.

Whippingdot (158)

I am thinking. Maybe the indents are wrong? @ColePete

ColePete (24)

@Whippingdot well, if the indents were wrong, I would get a red squiggly line under where the indent is messed up.

Whippingdot (158)

I am forking the repl and making it simpler. I will then paste the code here. You can find the difference by looking at the history of the repl after pasting the changed code I give you here. @ColePete

ColePete (24)

@Whippingdot thx, feel free to fix any other problems. (But please tell me what you did, so that i can know and learn from it)

ColePete (24)

Got to go see ya!

ColePete (24)

@Whippingdot how is the fork coming along? The other guy didn't fix the problem.

Whippingdot (158)

Yeah, it is coming along. It takes time, sry. I will try to solve the main problem today. You have 500 lines of code. Yesterday I finished about 120 @ColePete

ColePete (24)

@Whippingdot Lol all good sry to bother u.

Whippingdot (158)

Work on a different project, you can work on many at the same time. @ColePete

Whippingdot (158)

I am doing yours, and 3 more. @ColePete

ColePete (24)

@Whippingdot, I know that I can, I just don't know what to do.

Whippingdot (158)

Done

I finished @ColePete. I did a lot of indenting changes.

Print

Also, at the start you kept on using print one after another, instead of doing that, you can just use one print statement and whenever you want it to print a new line, type \n in the double quotes.

Input

Also, when inputing something you can type stuff in double quotes inside the input statement and that will print before asking you the input. You don't need a print statement before the input statement. Also, you can put the input statement inside int() so it changes the answer to an integer. Then you don't need to check if the number is "1", only if it is 1.

Whippingdot (158)

THE CODE

game_running = True
select_weapon = True
rnum = 1
import os
from termcolor import colored
import random
import time

weapon = {"close range": "Sword", "long range": "Bow and Arrow"}

def clear(seconds=0):
  time.sleep(seconds)
  os.system('clear')


player_moves = 0
third_level = True

monster_names = ["Brady", "Jack", "Charlie", "Jude", "Austin"]
monster_names2 = ["Brady", "Jack", "Charlie", "Jude", "Austin"]
boss_names = ["Brady", "Jack", "Charlie", "Jude", "Austin"]
monster_name = random.choice(monster_names)
while game_running == True:
  new_round = True

  clear(.1)
  random_name = random.randint(0, 4)
  monster_name1 = monster_names[random_name]
  del monster_names2[random_name]
  random_name = random.randint(0, 3)
  monster_name2 = monster_names2[random_name]
  del boss_names[random_name]
  random_name = random.randint(0, 2)
  boss_name = boss_names[random_name]

  player_name = input("---" * 7 + "\nEnter PLAYER Name: ")
  clear()
  while select_weapon == True:
    clear(1)
    player_weapon = input("---" * 7 + "\nPlease Select Weapon\n1) Sword\n2) Bow and Arrow\n")
    if player_weapon == "1":
      print("---" * 7 + "\nYou have chosen a sword as your weapon")
      player = {"attack": 14, "heal": 12, "health": 100}
      select_weapon = False
    elif player_weapon == "2":
      print("---" * 7)
      print("You have chosen a bow and arrow as your weapon")
      player = {"attack": 8, "heal": 20, "health": 100}
      select_weapon = False
    else:
      print("***" * 7)
      print("ERR: Invalid Input")
      print("***" * 7)
    monster = {"attack": 16, "health": 100, "name": random_name}
    clear(1.5)

  while new_round == True:
    player_won = False
    monster_won = False
    if player["health"] <= 25:
      os.system('clear')
      print("---" * 7 + "\n" + colored(player_name + " has " + str(player["health"]) +" health", "red") + "\n" + monster_name1 + " has " +str(monster["health"]) + " health\n" + "---" * 7 + "\nPlease Select Action\n1) Attack\n2) Heal\n3) Exit Game")

    elif player["health"] <= 50:
      os.system('clear')
      print("---" * 7 + "\n" + colored(player_name + " has " + str(player["health"]) +" health", "yellow") + "\n" + monster_name1 + " has " +  str(monster["health"]) + " health\n" + "---" * 7 +  "\nPlease Select Action\n1) Attack\n2) Heal\n3) Exit Game")

    else:
      os.system('clear')
      print("---" * 7 + "\n" + colored(player_name + " has " + str(player["health"]) +" health", "green") + "\n" + monster_name1 + " has " +  str(monster["health"]) + " health\n" + "---" * 7 +  "\nPlease Select Action\n1) Attack\n2) Heal\n3) Exit Game")
    player_choice = int(input())

    if player_choice == 1:
      ++player_moves
      monster["health"] -= player["attack"]
      if monster["health"] <= 0:
        player_won = True
      else:
        player["health"] -= monster["attack"]
        if player["health"] <= 0:
          monster_won = True
          print("---" * 7 + "\nYou Lose!\n" + "---" * 7)
          new_round = False
          player_choice = int(input("Please Select Action\n1) Restart Game\n2) Exit Game: "))
          if player_choice == 1:
            new_round = False
          elif player_choice == 2:
            print("---" * 7)
            print("Thanks for playing!!!!")
            exit()
          else:
            print("Invalid Input")
    elif player_choice == 2:
      ++player_moves
      print("Heal player")
      player["health"] = player["health"] + player["heal"]
      if player["health"] >= 100:
        player["health"] = 100
    elif player_choice == 3:
      ++player_moves
      print("---" * 7)
      print("Thanks for playing!!!!")
      exit()
    else:
      print("***" * 7)
      print("ERR: INVALID INPUT")
      print("***" * 7)
    if player_won == True and monster_won != True:
      os.system('clear')
      print("---" * 7)
      print("You defeated " + monster_name1)
      print("---" * 7)
      print("Please Select Action")
      print("1) Continue to next level")
      print("2) Exit Game")
      player_choice = input()
      if player_choice == "2":
        print("---" * 7)
        print("Thanks for playing!!!!")
        exit()
      elif player_choice == "1":
        second_level = True
        weapon_select = True
        player = {"attack": 10, "heal": 16, "health": 100}
        monster = {"attack": 20, "health": 150}
        clear()
        print("***" * 7)
        print("LEVEL TWO")
        print("***" * 7)
        clear(3)
        while second_level == True:
          new_round = True
          print("---" * 7)
          print("Enter PLAYER Name")
          player_name = input()
          clear()
          while weapon_select == True:
            clear(1)
            print("---" * 7)
            print("Please Select Weapon")
            print("1) Sword")
            print("2) Bow and Arrow\n")
            player_weapon = input()
            if player_weapon == "1":
              print("---" * 7)
              print("You have chosen a sword as your weapon")
              weapon_select = False
              second_level = False
            elif player_weapon == "2":
                print("---" * 7)
                print("You have chosen a bow and arrow as your weapon")
                player = {"attack": 8, "heal": 18, "health": 100}
                monster = {"attack": 10, "health": 100}
                weapon_select = False
                second_level = False
            else:
                  print("Invalid Input")
            clear(1.5)
            while new_round == True:
              player_won = False
              monster_won = False
              if player["health"] <= 25:
                clear()
                print("---" * 7)
                print(colored(player_name + " has " + str(player["health"]) + " health", "red"))
                print(monster_name2 + " has " + str(monster["health"]) + " health")
                print("---" * 7)
                print("Please Select Action")
                print("1) Attack")
                print("2) Heal")
                print("3) Exit Game")
              elif player["health"] <= 50:
                clear()
                print("---" * 7)
                print(colored(player_name + " has " + str(player["health"]) + " health", "yellow"))
                print(monster_name2 + " has " + str(monster["health"]) + " health")
                print("---" * 7)
                print("Please Select Action")
                print("1) Attack")
                print("2) Heal")
                print("3) Exit Game")
              else:
                clear()
                print("---" * 7)
                print(colored(player_name + " has " + str(player["health"]) + " health", "green"))
                print(monster_name2 + " has " + str(monster["health"]) + " health")
                print("---" * 7)
                print("Please Select Action")
                print("1) Attack")
                print("2) Heal")
                print("3) Exit Game")
              player_choice = input()
              if player_choice == "1":
                ++player_moves
                monster["health"] = monster["health"] - player["attack"]
                if monster["health"] <= 0:
                  player_won = True
                else:
                  player["health"] = player["health"] - monster["attack"]
                  if player["health"] <= 0:
                    monster_won = True
                    print("---" * 7)
                    print("You Lose!")
                    print("---" * 7)
                    new_round = False
                    print("Please Select Action")
                    print("1) Restart Game")
                    print("2) Exit Game")
                    player_choice = input()
                    if player_choice == "1":
                      new_round = False
                    elif player_choice == "2":
                      print("---" * 7)
                      print("Thanks for playing!!!!")
                      exit()
                    else:
                      print("Invalid Input")
              elif player_choice == "2":
                ++player_moves
                print("Heal player")
                player["health"] = player["health"] + player["heal"]
                if player["health"] >= 100:
                  player["health"] = 100
                  ++player_moves
                  print("Health is already at its maximum")
              elif player_choice == "3":
                print("---" * 7)
                print("Thanks for playing!!!!")
                exit()
              if player_won == True and monster_won != True:
                clear()
                print("---" * 7)
                print("You defeated " + monster_name2)
                print("---" * 7)
                print("Please Select Action")
                print("1) Continue to next level")
                print("2) Exit Game")
                player_choice = input()
                if player_choice == "2":
                  print("---" * 7)
                  print("Thanks for playing!!!!")
                  exit()
                elif player_choice == "1":
                  weapon_select = True
                  clear()
                  print("***" * 7)
                  print("LEVEL THREE")
                  print("***" * 7)
                  clear(3)
                  player = {"attack": 15, "heal": 18, "health": 100}
                  monster = {"attack": 25, "health": 200}
                else:
                  print("***" * 7)
                  print("ERR: INVAILID INPUT")
                  print("***" * 7)
                weapon_select = True
                while third_level == True:
                  new_round = True
                  clear()
                  while weapon_select == True:
                    os.system('clear')
                    print("---" * 7)
                    print("Please Select Weapon")
                    print("1) Sword")
                    print("2) Bow and Arrow")
                    player_weapon = input()
                    if player_weapon == "1":
                      print("---" * 7)
                      print("You have chosen a sword as your weapon")
                      weapon_select = False
                      second_level = False
                    elif player_weapon == "2":
                      print("---" * 7)
                      print("You have chosen a bow and arrow as your weapon")
                      player = {"attack": 8,"heal": 18,"health": 100}
                      monster = {"attack": 10, "health": 100}
                      weapon_select = False
                      second_level = False
                    else:
                      print("Invalid Input")
                  clear()
                  print("---" * 7)
                  print("Enter PLAYER Name")
                  player_name = input()
                  clear()
                  while new_round == True:
                    player_won = False
                    monster_won = False
                    if player["health"] <= 25:
                      os.system('clear')
                      print("---" * 7)
                      print(colored(player_name + " has " + str(player["health"]) + " health", "red"))
                      print(boss_name + " has " + str(monster["health"]) + " health")
                      print("---" * 7)
                      print("Please Select Action")
                      print("1) Attack")
                      print("2) Heal")
                      print("3) Exit Game")
                    elif player["health"] <= 50:
                      os.system('clear')
                      print("---" * 7)
                      print(colored(player_name + " has " + str(player["health"]) + " health", "yellow"))
                      print(boss_name + " has " +str(monster["health"]) + " health")
                      print("---" * 7)
                      print("Please Select Action")
                      print("1) Attack")
                      print("2) Heal")
                      print("3) Exit Game")
                    else:
                      clear()
                      print("---" * 7)
                      print(colored(player_name + " has " + str(player["health"]) + " health", "green"))
                      print(boss_name + " has " +str(monster["health"]) + " health")
                      print("---" * 7)
                      print("Please Select Action")
                      print("1) Attack")
                      print("2) Heal")
                      print("3) Exit Game")
                    player_choice = input()
                    if player_choice == "1":
                      ++player_moves
                      monster["health"] = monster["health"] - player["attack"]
                      if monster["health"] <= 0:
                        player_won = True
                      else:
                        player["health"] = player["health"] - monster["attack"]
                        if player["health"] <= 0:
                          monster_won = True
                          print("---" * 7)
                          print("You Lose!")
                          print("---" * 7)
                          new_round = False
                          print("Please Select Action")
                          print("1) Restart Game")
                          print("2) Exit Game")
                          player_choice = input()
                          if player_choice == "1":
                            new_round = False
                          elif player_choice == "2":
                            print("---" * 7)
                            print("Thanks for playing!!!!")
                            exit()
                          else:
                            print("Invalid Input")
                    elif player_choice == "2":
                      ++player_moves
                      print("Heal player")
                      player["health"] = player["health"] + player["heal"]
                      if player["health"] >= 100:
                        player["health"] = 100
                    elif player_choice == "3":
                      print("---" * 7)
                      print("Thanks for playing!!!!")
                      exit()
                    if player_won == True and monster_won != True:
                      os.system('clear')
                      print("---" * 7)
                      print("You defeated " + monster_name)
                      print("---" * 7)
                      print("Please Select Action")
                      print("1) Continue to BOSS")
                      print("2) Exit Game")
                      player_choice = input()
                      if player_choice == "2":
                        print("---" * 7)
                        print("Thanks for playing!!!!")
                        exit()
                      elif player_choice == "1":
                        boss_level = True
                        player = {"attack": 20,"heal": 28,"health": 100}
                        monster = {"attack": 24, "health": 300}
                      select_weapon = True
                      while select_weapon == True:
                        clear(1)
                        print("---" * 7)
                        print("Please Select Weapon")
                        print("1) Sword")
                        print("2) Bow and Arrow")
                        player_weapon = input()
                        if player_weapon == "1":
                          print("---" * 7)
                          print("You have chosen a sword as your weapon")
                          player = {"attack": 14,"heal": 12,"health": 100}
                          monster = {"attack": 16,"health": 100,"name": random_name}
                          select_weapon = False
                        elif player_weapon == "2":
                          print("---" * 7)
                          print("You have chosen a bow and arrow as your weapon")
                          player = {"attack": 8,"heal": 20,"health": 100}
                          monster = {"attack": 16,"health": 100,"name": random_name}
                          select_weapon = False
                        else:
                          print("***" * 7)
                          print("ERR: Invalid Input")
                          print("***" * 7)
                      clear(1.5)
                      while boss_level == True:
                        print("Please Select Action")
                        print("1) Attack")
                        print("2) Heal")
                        print("3) Exit Game")
                        player_choice = input()
                        if player_choice == "1":
                          player_moves + 1
                          monster["health"] = monster["health"] - player["attack"]
                          if monster["health"] <= 0:
                            player_won = True
                          else:
                            player["health"] = player["health"] - monster["attack"]
                            if player["health"] <= 0:
                              monster_won = True
                              print("---" * 7)
                              print("You Lose!")
                              print("---" * 7)
                              new_round = False
                              print("Please Select Action")
                              print("1) Restart Game")
                              print("2) Exit Game")
                              player_choice = input()
                              if player_choice == "1":
                                new_round = False
                              elif player_choice == "2":
                                print("---" * 7)
                                print("Thanks for playing!!!!")
                                exit()
                              else:
                                print("Invalid Input")
                        elif player_choice == "2":
                          player_moves + 1
                          print("Heal player")
                          player["health"] = player["health"] + player["heal"]
                          if player["health"] >= 100:
                            player["health"] = 100
                          else:
                            print("Invalid Input")

@ColePete

ColePete (24)

@Whippingdot WOW thanks for all the tips. I am still a noob at this coding thing. (I will deny ever saying this) So thanks for all the tips and help that you have provided me!

Whippingdot (158)

If you put this on the share section, @ mention my name cause I helped you soo much. Also mark me as the answer. The boss is not fully complete I think, but I also helped on it. finish the boss section and then share it. @ColePete

ColePete (24)

@Whippingdot will do! also, if you check the FAQ page in the read me, you will see that I already mentioned you there.

ColePete (24)

@Whippingdot, also, how do I make it show the counter at the end?

Whippingdot (158)

Just print the counter.

print(counter)

@ColePete

ColePete (24)

ok thanks

@Whippingdot

EDIT: whenever i put that code, i get the red line under it

Whippingdot (158)

I don't what the error is. Try to do it yourself. I have helped you so much. @ColePete

ColePete (24)

@Whippingdot I think i found out what was wrong, i am testing it right now. I am sorry that i made you go through all this trouble for a video game.

Whippingdot (158)

Naa, I like helping you. Just was stressed that I was not helping you quick enough. Thanks. @ mention me when you have another doubt. Have a good day/night. Bye! @ColePete

ColePete (24)

@Whippingdot bruh, you fixed the code faster than I ever could have. not fast enough? psh whatever. Thanks again!

RYANTADIPARTHI (3242)

To answer you're question, it's because if you were using functions, you would put the first function calling at the very end of every Single function. Since all the functions, would run. But for the second to third, you just call it on each other, like this:

def first_func():
  # code
  second_func() # calling second function here

def second_func():
  # code
  third_func() # calling third one here. and so on

def third_func():
  # code

first_func() # calling

That's the reason

ColePete (24)

@RYANTADIPARTHI so, could you change this to make it specifically to my code?

RYANTADIPARTHI (3242)

@ColePete can't, because you are using while loops, but you can do levels with functions.

ColePete (24)

@RYANTADIPARTHI So how do I fix while keeping a similar code.

RYANTADIPARTHI (3242)

@ColePete well, on top of your code, break into functions. Just add def func() and indent the code.

RYANTADIPARTHI (3242)

@ColePete ok, like this:

def first_func():
while game_running == True:
    new_round = True
    player = {"attack": 10, "heal": 16, "health": 100}
    monster = {"attack": 12, "health": 100}
    weapon = {"close range": "Sword", "long range": "Bow and Arrow"}
    
    clear(.1)
    random_name = random.randint( 0, 4)
    monster_name1 = monster_names[random_name]
    del monster_names2[random_name]
    random_name = random.randint( 0, 3)
    monster_name2 = monster_names2[random_name]
    del boss_names[random_name]
    random_name = random.randint( 0, 2)
    boss_name = boss_names[random_name]
    

    print("---" * 7)
    print("Enter PLAYER Name")
    player_name = input() 
    clear() 
    while select_weapon == True:
        clear(1)
        print("---" * 7)
        print("Please Select Weapon")
        print("1) Sword")
        print("2) Bow and Arrow")
        player_weapon = input()
        if player_weapon == "1":
            print("---" * 7)
            print("You have chosen a sword as your weapon")
            player = {"attack": 14, "heal": 12, "health": 100}
            monster = {"attack" : 16, "health" : 100, "name" : random_name}
            select_weapon = False
        elif player_weapon == "2":
            print("---" * 7)
            print("You have chosen a bow and arrow as your weapon")
            player = {"attack": 8, "heal": 20, "health": 100}
            monster = {"attack" : 16, "health" : 100, "name" : random_name}
            select_weapon = False
        else:
            print("***" * 7)
            print("ERR: Invalid Input")
            print("***" * 7)
    clear(1.5)

first_func() # calling
    

Like i did above, do the same for others.

ColePete (24)

@RYANTADIPARTHI is there anything that I delete?

ColePete (24)

@RYANTADIPARTHI so I just add that instead of my first while loop?

RYANTADIPARTHI (3242)

@ColePete if you want to you can keep your look

ColePete (24)

@RYANTADIPARTHI can you just fork it and then show me the forked code with your edits?

RYANTADIPARTHI (3242)

@ColePete you just have to put that function like i said, and call it at the end.

ColePete (24)

@RYANTADIPARTHI But where do I put it? inside the first while loop at the top, or delete the first while loop and put that there in its place????????

RYANTADIPARTHI (3242)

@ColePete try both, and see which one works

RYANTADIPARTHI (3242)

@ColePete ok, i would suggest not deleting anything, and putting it first.

ColePete (24)

@RYANTADIPARTHI whenever I put the code in I get on error under "while select weapon == True"