import random
import time
import sys
TOTAL_NIGHTS = 3
NIGHT_LENGTH = 30
STARTING_POWER = 100.0
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():
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):
cost = 1.5
power -= cost
cam = random.choice(CAMERAS)
print(f\"You flip to the {cam} camera (cost {cost} power). Observing...\")
sighting = []
for name, info in ANIMATRONICS.items():
prob = info.get('speed', 0.03) + 0.02
if name == 'Foxy' and not info.get('awake', False):
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():
for name, info in ANIMATRONICS.items():
if name == 'Foxy' and info.get('awake', False):
move_chance = info['speed'] + 0.12
else:
move_chance = info['speed'] + random.uniform(0, 0.02)
if random.random() < move_chance:
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
tick = 0
while tick < NIGHT_LENGTH:
tick += 1
show_status(night_num, tick, power, left_closed, right_closed)
# small natural power drain each tick
drain = 0.5 + (0.4 if left_closed else 0) + (0.4 if right_closed else 0)
power -= drain
# animatronics may move each tick
animatronic_move()
# player action
action = input(\"Action [c/l/r/w] > \").strip().lower()
if action == 'c':
power = check_camera(power)
elif action == 'l':
left_closed = not left_closed
print(\"Left door toggled to {}.\".format('CLOSED' if left_closed else 'OPEN'))
elif action == 'r':
right_closed = not right_closed
print(\"Right door toggled to {}.\".format('CLOSED' if right_closed else 'OPEN'))
elif action == 'w' or action == '':
print(\"You wait and listen...\")
else:
print(\"Unknown action. You fumble and waste time.\")
# power check
if power <= 0:
print(\"\\n--- POWER OUT ---\\nYour lights and doors fail. You are vulnerable...\")
# with no power, animatronics have higher chance to reach office immediately
for name, info in ANIMATRONICS.items():
if info['position'] != 'office' and random.random() < 0.35:
info['position'] = 'office'
attacked, who = check_attack(False, False)
if attacked:
print(f\"{who} attacks you in the dark. You didn't survive Night {night_num}.\")
return False
else:
print(\"They wander but don't get you before morning...you survive the blackout this time.\")
# check whether an animatronic attacks this tick
attacked, who = check_attack(left_closed, right_closed)
if attacked:
print(f\"\\n{who} has reached you and attacks! You lose Night {night_num}...\")
return False
# short pause for pacing (turn off or reduce in fast compiles)
time.sleep(0.15)
print(f\"\\n*** Morning! You survived Night {night_num}! ***\\n\")
# small reset for positions (advance difficulty)
for name, info in ANIMATRONICS.items():
# make them a little faster for next night
info['speed'] *= 1.15
# reset positions
info['position'] = 'stage' if name != 'Foxy' else 'pirate_cove'
if name == 'Foxy':
info['awake'] = False
return True
def main():
intro()
for night in range(1, TOTAL_NIGHTS + 1):
print(f\"Starting Night {night}... Stay sharp.\")
survived = night_loop(night)
if not survived:
print(\"Game Over. Try again or lower the difficulty in the source code.\")
break
else:
print(\"You get a small break. Prepare for the next night...\\n\")
time.sleep(1.0)
else:
print(\"\\n*** Congratulations! You survived all nights. You did it! ***\")
if __name__ == '__main__':
main()