Mar-13-2025, 11:56 PM
(This post was last modified: Mar-13-2025, 11:56 PM by nezercat33.)
so i was trying to work on my game but when i change the "inbattle" variable to true it doesnt put them in battle, how do i fix this?
heres my code for reference:
heres my code for reference:
import random import time from threading import Timer damage = 1 timeout = 0.25 level = 0 inbattle = "N/A" gameplaying = True health = 10 xp = 0 player = '{-}' canheadattackchoice = 'undefined' enemy_canhead = '[=]' canheadattacks = ['headbash', 'defend', 'canslam'] canhead_health = 6 canhead_defense = 0 canhead_headbash_damage = 2 canhead_canslam_damage = 3 enemy_boulder = '+=\=+' boulder_attacks = ['rolling_strike', 'defend'] boulder_attack_choice = 'undefined' boulderhealth = 10 boulder_defense = 1 boulder_rs_damage = 4 enemychoice = [enemy_canhead, enemy_boulder] enemyinfight = random.choice(enemychoice) maplayer1 = [enemyinfight, '*', 'o'] maplayer2 = ['o', '*', 'o'] maplayer3 = ['o', player, 'o'] xpneededtolevel = level + 1 * 4 + 100 playerturn = False canhead_defense_active = "no" while True: if inbattle == True: # battle loop. if enemyinfight == "canhead": print(str(enemy_canhead) + "_______" + str(canhead_health) + " " + str(canhead_defense)) print() print() print(str(player), "________" + str(health)) playerturn = True action = input("what would you like to do?") if action == "attack": print(".....") print("-....") time.sleep(0.2) print("---..") time.sleep(0.2) print("attack now!") timeout = 0.7 t = Timer(timeout, print, ["action command failed"]) t.start() start_time = time.time() prompt = f"now!\n" answer = input(prompt) t.cancel() end_time = time.time() reaction_time = end_time - start_time if reaction_time > timeout: print("action command missed") damage = 1 else: damage += 1 canhead_health -= (damage - canhead_defense) playerdamage = 1 print("canhead is thinking") canheadattackchoice = random.choice(boulder_attacks) playerturn = False boulder_defense = 1 print("canhead used " + canheadattackchoice) if canheadattackchoice == "defend": canhead_defense += 1 canhead_defense_active = "yes" elif canheadattackchoice == "canslam": timeout = 0.8 t = Timer(timeout, print, ["action command failed"]) t.start() start_time = time.time() prompt = f"now!\n" answer = input(prompt) t.cancel() end_time = time.time() reaction_time = end_time - start_time if reaction_time > timeout: print("action command missed") health -= canhead_canslam_damage else: health = health elif canheadattackchoice == "headbash": timeout = 0.5 t = Timer(timeout, print, ["action command failed"]) t.start() start_time = time.time() prompt = f"now!\n" answer = input(prompt) t.cancel() end_time = time.time() reaction_time = end_time - start_time if reaction_time > timeout: print("action command missed") health -= canhead_headbash_damage else: health = health if canhead_health <= 0: print("battle won!") time.sleep(1) inbattle = False maplayer1[0] = 'o' else: print("your turn monkey") if enemyinfight == "enemy_boulder": print(str(enemy_boulder) + "_______" + str(boulderhealth) + " " + str(boulder_defense)) print() print() print(str(player), "________" + str(health)) playerturn = True action = input("what would you like to do?") if action == "attack": print(".....") print("-....") time.sleep(0.2) print("---..") time.sleep(0.2) print("attack now!") timeout = 0.7 t = Timer(timeout, print, ["action command failed"]) t.start() start_time = time.time() prompt = f"now!\n" answer = input(prompt) t.cancel() end_time = time.time() reaction_time = end_time - start_time if reaction_time > timeout: print("action command missed") damage = 1 else: damage += 1 boulderhealth -= (damage - boulder_defense) playerdamage = 1 print("boulder is thinking") boulder_attack_choice = random.choice(boulder_attacks) playerturn = False print("boulder used " + boulder_attack_choice) if boulder_attack_choice == "defend": boulder_defense += 1 elif boulder_attack_choice == "rolling_strike": timeout = 1.2 t = Timer(timeout, print, ["action command failed"]) t.start() start_time = time.time() prompt = f"now!\n" answer = input(prompt) t.cancel() end_time = time.time() reaction_time = end_time - start_time if reaction_time > timeout: print("action command missed") health -= boulder_rs_damage else: health = health if boulderhealth <= 0: print("battle won!") time.sleep(1) inbattle = False maplayer1[0] = 'o' else: print("your turn") else: pass xpneededtolevel = level + 1 * 4 + 100 mapcolumn1 = [maplayer1[0], maplayer2[0], maplayer3[0]] mapcolumn2 = [maplayer1[1], maplayer2[1], maplayer3[1]] mapcolumn3 = [maplayer1[2], maplayer2[2], maplayer3[2]] enemysquare = [maplayer1[0], mapcolumn1[0], enemyinfight] movement = input("where would you like to move") if movement == "right" and player in maplayer3 and player in mapcolumn2: maplayer3 = ['o', '*', player] elif movement == "right" and player in maplayer3 and player in mapcolumn3: # right movement print("you cannot move anymore to this direction!") elif movement == "right" and player in maplayer3 and mapcolumn1: # right movement maplayer3 = ['o', player, 'o'] elif movement == "left" and player in maplayer3 and player in mapcolumn2: # left movement maplayer3 = [player, '*', 'o'] elif movement == "left" and player in maplayer3 and player in mapcolumn1: # left movement print("you cannot move anymore to this direction!") elif movement == "left" and player in maplayer3 and mapcolumn3: # left movement maplayer3 = ['o', player, 'o'] elif movement == "down" and player in maplayer3 and player in mapcolumn2: # down movement print("you cannot move anymore in this direction!") elif movement == "down" and player in maplayer3 and player in mapcolumn3: # down movement print("you cannot move anymore to this direction!") elif movement == "down" and player in maplayer3 and mapcolumn1: # down movement print("you cannot move anymore in this direction!") elif movement == "up" and player in maplayer3 and player in mapcolumn2: # up movement maplayer3 = ['o', '*', 'o'] maplayer2 = ['o', player, 'o'] elif movement == "up" and player in maplayer3 and player in mapcolumn3: # up movement maplayer3 = ['o', '*', 'o'] maplayer2 = ['o', '*', player] elif movement == "up" and player in maplayer3 and mapcolumn1: maplayer3 = ['o', '*', 'o'] maplayer2 = [player, '*', 'o'] elif movement == "down" and player in maplayer2 and player in mapcolumn1: maplayer2 = ['o', '*', 'o'] maplayer3 = [player, '*', 'o'] elif movement == "down" and player in maplayer2 and player in mapcolumn2: maplayer2 = ['o', '*', 'o'] maplayer3 = ['o', player, 'o'] elif movement == "down" and player in maplayer2 and player in mapcolumn3: maplayer2 = ['o', '*', 'o'] maplayer3 = ['o', '*', player] elif movement == "right" and player in maplayer2 and player in mapcolumn3: maplayer2 = ['o', '*', player] print("you cannot move that way") elif movement == "right" and player in maplayer2 and player in mapcolumn2: maplayer2 = ['o', '*', player] elif movement == "right" and player in maplayer2 and player in mapcolumn1: maplayer2 = ['o', player, 'o'] elif movement == "left" and player in maplayer2 and player in mapcolumn1: print("you cannot move that way!") elif movement == "left" and player in maplayer2 and player in mapcolumn2: maplayer2 = [player, '*', 'o'] elif movement == "left" and player in maplayer2 and player in mapcolumn3: maplayer2 = ['o', player, 'o'] elif movement == "up" and player in maplayer2 and player in mapcolumn3: maplayer1[2] = player maplayer2[2] = 'o' elif movement == "up" and player in maplayer2 and player in mapcolumn2: maplayer1[1] = player maplayer2[1] = '*' elif movement == "up" and player in maplayer2 and player in mapcolumn2: inbattle = True elif movement == "right" and player in maplayer1 and player in mapcolumn3: print("nuh uh cant move anymore that way") elif movement == "right" and player in maplayer1 and player in mapcolumn2: maplayer1[2] = player maplayer1[1] = '*' elif movement == "left" and player in maplayer1 and player in mapcolumn3: maplayer1[1] = player maplayer1[2] = 'o' elif movement == "left" and player in maplayer1 and player in mapcolumn2 and enemychoice in maplayer1: inbattle = True enemy = maplayer1[0] print(maplayer1) print(maplayer2) print(maplayer3)