Can someone fix my python 3 code? It supposed to be a simple fnaf one remake #978
Closed
ryangraf52-ops
started this conversation in
General
Replies: 1 comment
-
|
Or use this link "https://www.programiz.com/online-compiler/8BWZRr0jiFgZ9" |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
import random
import time
import sys
Configuration
TOTAL_NIGHTS = 3
NIGHT_LENGTH = 30 # number of "ticks" per night (seconds-ish): shorten for testing
STARTING_POWER = 100.0
Animatronics and their initial aggressiveness
ANIMATRONICS = {
"Bonnie": {"position": "stage", "speed": 0.05},
"Chica": {"position": "stage", "speed": 0.04},
"Foxy": {"position": "pirate_cove", "speed": 0.02, "awake": False},
"Freddy": {"position": "stage", "speed": 0.025, "visible_prob": 0.02}
}
CAMERAS = [
"Show Stage",
"Dining Area",
"Kitchen",
"Pirate Cove",
"Backstage"
]
def clear_line():
# helper to keep output tidy
print("\r", end="")
def intro():
print("\nWELCOME: Night Security (text edition)")
print("Survive the nights by managing power, checking cameras, and closing doors.")
print("Controls each tick: [c]heck camera, [l]eft door, [r]ight door, [w]ait (do nothing)")
print("Cameras cost power while used. Doors cost power while closed.")
print("Good luck!\n")
input("Press Enter to begin...")
def show_status(night, tick, power, left_closed, right_closed):
print(f"Night {night} - Time: {tick}/{NIGHT_LENGTH} | Power: {power:.1f}% | LeftDoor:{'C' if left_closed else 'O'} RightDoor:{'C' if right_closed else 'O'}")
def check_camera(power):
# costs power
cost = 1.5
power -= cost
cam = random.choice(CAMERAS)
print(f"You flip to the {cam} camera (cost {cost} power). Observing...")
# small chance to see Freddy close by, or Bonnie/Chica closer
sighting = []
for name, info in ANIMATRONICS.items():
# basic chance to be "near" increases with position and speed
prob = info.get('speed', 0.03) + 0.02
if name == 'Foxy' and not info.get('awake', False):
# Foxy wakes up when you check Pirate Cove often
if cam == 'Pirate Cove' and random.random() < 0.22:
info['awake'] = True
print("Foxy peeks out and gets excited! You woke Foxy a little.")
if random.random() < prob:
sighting.append(name)
if sighting:
print("You see: " + ", ".join(sighting))
else:
print("Nothing interesting on camera.")
return power
def animatronic_move():
# each tick, animatronics have a chance to advance toward your office
for name, info in ANIMATRONICS.items():
# increase 'aggression' randomly by speed
if name == 'Foxy' and info.get('awake', False):
# Foxy moves faster when awake
move_chance = info['speed'] + 0.12
else:
move_chance = info['speed'] + random.uniform(0, 0.02)
if random.random() < move_chance:
# progress their position: for simplicity, we'll move through a list of stages
# positions: stage -> backstage -> dining area -> hall -> office
order = ['stage', 'backstage', 'dining', 'hall', 'office']
try:
idx = order.index(info['position'])
except ValueError:
idx = 0
if idx < len(order) - 1:
info['position'] = order[idx + 1]
# small chance Freddy "teleports" when visible_prob triggers
if name == 'Freddy' and random.random() < info.get('visible_prob', 0.02):
info['position'] = 'hall' # Freddy gets closer sometimes
def check_attack(left_closed, right_closed):
# returns (attacked: bool, who: str or None)
for name, info in ANIMATRONICS.items():
if info['position'] == 'office':
# determine if doors block them
# For simplification, Bonnie and Chica come from left side, Freddy from right, Foxy from right
if name in ('Bonnie', 'Chica'):
if left_closed:
# left door blocked
if random.random() < 0.7:
# blocked successfully
continue
else:
return True, name
else:
return True, name
else:
# Freddy or Foxy on the right side
if right_closed:
if random.random() < 0.6:
continue
else:
return True, name
else:
return True, name
return False, None
def night_loop(night_num):
power = STARTING_POWER
left_closed = False
right_closed = False
def main():
intro()
for night in range(1, TOTAL_NIGHTS + 1):
print(f"Starting Night {night}... Stay sharp.")
if name == 'main':
main()
Beta Was this translation helpful? Give feedback.
All reactions