import turtle
import random
import tkinter as tk
import time
from PIL import Image, ImageTk
# --- DATABASES ---
RIDDLES = [
("I have keys, but no locks.\nI have space, but no room.", "keyboard"),
("I am a set of instructions,\nwritten in lines of code.", "program"),
("I am a bug's worst enemy,\nthe process of fixing errors.", "debugging"),
("I travel the world in a web,\nconnecting everyone together.", "internet"),
("I am the brain of the machine,\nprocessing billions of bits.", "processor"),
("I can be cracked, made, told, and played.\nWhat am I?", "joke"),
("The more of me there is,\nthe less you see. What am I?", "darkness"),
("I follow you all day long,\nbut when the night comes, I am gone.", "shadow"),
("I am full of holes but still hold water.\nWhat am I?", "sponge"),
("I have cities, but no houses.\nI have mountains, but no trees.", "map"),
("I am always hungry, I must always be fed.\nThe finger I touch will soon turn red.", "fire"),
("The more you take, the more you leave behind.", "footsteps"),
("I have a neck but no head,\nand I wear a cap but have no hair.", "bottle"),
("What has to be broken\nbefore you can use it?", "egg"),
("I am an orange vegetable\nthat helps you see in the dark.", "carrot"),
("I have one eye but cannot see.\nI am very sharp and thin.", "needle"),
("I am the part of the computer\nthat allows you to see the output.", "monitor"),
("I am a small piece of data\nstored on your drive by a website.", "cookie"),
("I have hands but cannot clap,\nand I tell you the time.", "clock"),
("The more you dry, the wetter I get.", "towel"),
("I am a loop that never ends,\nrunning until a condition is met.", "while"),
("I protect your files with a secret string,\nkeep me safe and don't tell a soul.", "password"),
("I am a tiny electronic switch,\nbillions of me live in your CPU.", "transistor"),
("I am the language of the machine,\nconsisting only of zeros and ones.", "binary"),
("I am a collection of related data\nstored in a structured way.", "database")
]
# --- GLOBAL SETTINGS ---
TOTAL_LAYERS = 100
AI_MAX = 100
STARTING_LIVES = 3
game_mode = "NORMAL"
hardcore_mode = False
# --- HELPERS ---
def generate_key():
chars = "1234567890"
return "".join(random.choice(chars) for _ in range(5))
# --- LEADERBOARD LOGIC ---
def save_score(mode, score, is_hc):
tag = "[HC]" if is_hc else "[STD]"
try:
with open("system_logs.txt", "a") as f:
f.write(f"{mode}{tag}|{score:.2f}|{time.ctime()}\n")
except: pass
def get_best_score(mode, is_hc):
tag = "[HC]" if is_hc else "[STD]"
scores = []
try:
with open("system_logs.txt", "r") as f:
for line in f:
parts = line.strip().split("|")
if parts[0] == mode + tag: scores.append(float(parts[1]))
return max(scores) if scores else 0
except: return 0
# --- START SCREEN (Tkinter GUI) ---
class StartScreen:
def __init__(self, root):
self.root = root
self.root.title("SYSTEM COLLAPSE")
self.root.geometry("800x800")
self.root.configure(bg="black")
self.canvas = tk.Canvas(root, width=800, height=800, bg="black", highlightthickness=0)
self.canvas.pack()
try:
splash_img = Image.open("Gemini_Generated_Image_y9grs1y9grs1y9gr.png").resize((800, 800))
self.splash_photo = ImageTk.PhotoImage(splash_img)
selection_img = Image.open("Gemini_Generated_Image_oggvfboggvfboggv.png").resize((800, 800))
self.selection_photo = ImageTk.PhotoImage(selection_img)
self.bg_id = self.canvas.create_image(0, 0, anchor="nw", image=self.splash_photo)
except:
self.bg_id = None
self.canvas.create_text(400, 200, text="SYSTEM COLLAPSE", fill="red", font=("Courier", 40))
self.show_splash()
def show_splash(self):
self.start_btn = tk.Button(self.root, text=">> INITIALIZE SYSTEM <<", command=self.show_mode_selection,
fg="lime", bg="black", font=("Courier", 20, "bold"), borderwidth=5, relief="flat")
self.start_btn_window = self.canvas.create_window(400, 400, window=self.start_btn)
def show_mode_selection(self):
if self.bg_id: self.canvas.itemconfig(self.bg_id, image=self.selection_photo)
self.canvas.delete(self.start_btn_window)
self.hc_var = tk.BooleanVar()
hc_check = tk.Checkbutton(self.root, text="ENABLE HARDCORE PROTOCOL", variable=self.hc_var,
fg="red", bg="black", selectcolor="black", activebackground="black",
activeforeground="red", font=("Courier", 12, "bold"))
self.canvas.create_window(400, 100, window=hc_check)
self.canvas.create_text(400, 160, text="SELECT PROTOCOL", fill="white", font=("Courier", 24, "bold"))
self.create_mode_btn("NORMAL: RANDOM HYBRID", "NORMAL", 250)
self.create_mode_btn("STORY: RIDDLE RACE", "STORY", 350)
self.create_mode_btn("DEFENSE: HALT AI", "DEFENSE", 450)
self.create_mode_btn("BOSS: NEURAL LINK", "BOSS", 550)
def create_mode_btn(self, text, mode_val, y_pos):
btn = tk.Button(self.root, text=text, command=lambda: self.launch(mode_val),
fg="lime", bg="black", font=("Courier", 14), width=30)
self.canvas.create_window(400, y_pos, window=btn)
def launch(self, mode_val):
global game_mode, hardcore_mode
game_mode = mode_val
hardcore_mode = self.hc_var.get()
self.root.destroy()
launch_turtle_game()
# --- MAIN GAME (Turtle Graphics Engine) ---
def launch_turtle_game():
global player_layer, ai_layer, current_task, current_ans, user_input
global game_active, key_visible, sabotage_active, lives, current_phase, active_riddle_pool
global combo, shake_offset, hint_text, start_time, base_shake
player_layer = 50.0 if game_mode == "DEFENSE" else 0.0
ai_layer, lives = 0, STARTING_LIVES
user_input, game_active, key_visible, sabotage_active = "", True, False, False
current_phase = "INIT"
combo, shake_offset, hint_text, base_shake = 0, (0, 0), "", 10
start_time = time.time()
active_riddle_pool = list(RIDDLES)
random.shuffle(active_riddle_pool)
try:
screen = turtle.Screen()
screen.setup(800, 800)
screen.bgcolor("black")
screen.tracer(0)
pen = turtle.Turtle()
pen.hideturtle()
pen.penup()
except (turtle.Terminator, tk.TclError):
return
def trigger_shake():
global shake_offset
intensity = base_shake + (20 if hardcore_mode else 0)
for _ in range(6):
shake_offset = (random.randint(-intensity, intensity), random.randint(-intensity, intensity))
update_display()
shake_offset = (0, 0)
def set_next_task():
global current_task, current_ans, current_phase, active_riddle_pool, hint_text
if not game_active: return
hint_text = ""
if game_mode == "BOSS":
current_phase = "MEMORIZE"
else:
current_phase = "RIDDLE" if game_mode in ["STORY", "DEFENSE"] else random.choice(["RIDDLE", "MEMORIZE"])
if current_phase == "RIDDLE":
if not active_riddle_pool:
active_riddle_pool = list(RIDDLES); random.shuffle(active_riddle_pool)
current_task, current_ans = active_riddle_pool.pop()
else:
current_task, current_ans = "MEMORIZE", generate_key()
show_key()
def show_key():
global key_visible
if game_active and current_phase == "MEMORIZE":
key_visible = True
update_display()
timer = 1000 if hardcore_mode else 2000
try:
screen.ontimer(hide_key, timer)
except (turtle.Terminator, tk.TclError): pass
def hide_key():
global key_visible
key_visible = False
update_display()
def draw_static():
num_lines = 30 if hardcore_mode else 15
for _ in range(num_lines):
pen.color(random.choice(["red", "darkred", "#111111"]))
pen.pensize(random.randint(1, 5))
x, y = random.randint(-400, 400), random.randint(-400, 400)
pen.goto(x + shake_offset[0], y + shake_offset[1])
pen.pendown()
pen.goto(x + random.randint(-200, 200), y + random.randint(-10, 10))
pen.penup()
def draw_bar(y, progress, max_val, color, label):
if label == "AI_INTRUSION" and progress >= 80:
if int(time.time() * 6) % 2 == 0: color = "white"
pen.color("white")
pen.goto(-300 + shake_offset[0], y + shake_offset[1])
pen.pendown()
for _ in range(2): pen.forward(600); pen.left(90); pen.forward(20); pen.left(90)
pen.penup()
if progress > 0:
pen.goto(-300 + shake_offset[0], y + 2 + shake_offset[1])
pen.color(color)
pen.begin_fill()
fill_width = (min(progress, max_val) / max_val) * 600
for _ in range(2): pen.forward(fill_width); pen.left(90); pen.forward(16); pen.left(90)
pen.end_fill()
pen.goto(-300 + shake_offset[0], y + 25 + shake_offset[1])
pen.color(color if (label == "AI_INTRUSION" and progress >= 80) else "white")
pen.write(f"{label}: {int(progress)}%", font=("Courier", 10, "bold"))
def update_display():
try:
pen.clear()
if sabotage_active: draw_static()
if game_mode == "DEFENSE" and player_layer < 30:
screen.bgcolor("#2a0000" if random.random() > 0.7 else "black")
elif hardcore_mode:
screen.bgcolor("#0a0000")
else: screen.bgcolor("black")
pen.color("white")
pen.goto(-300 + shake_offset[0], 350 + shake_offset[1])
hc_tag = " [!] HARDCORE" if hardcore_mode else ""
pen.write(f"PROTOCOL: {game_mode}{hc_tag} | COMBO: x{combo}", font=("Courier", 11, "bold"))
if game_mode != "DEFENSE":
pen.color("red")
pen.goto(300 + shake_offset[0], 350 + shake_offset[1])
pen.write("❤️" * lives, align="right", font=("Courier", 18))
bar_label = "INTEGRITY" if game_mode == "DEFENSE" else "PROGRESS"
draw_bar(250, player_layer, TOTAL_LAYERS, "lime", bar_label)
if game_mode != "DEFENSE": draw_bar(-250, ai_layer, AI_MAX, "red", "AI_INTRUSION")
pen.goto(0 + shake_offset[0], 50 + shake_offset[1])
if game_active:
pen.color("red" if sabotage_active else "white")
txt = "--- SIGNAL LOST ---" if sabotage_active else (f"KEY RECALL:\n{current_ans}" if key_visible else current_task)
pen.write(txt, align="center", font=("Courier", 16 if not key_visible else 24, "bold"))
if hint_text and not hardcore_mode:
pen.goto(0, 15); pen.color("yellow"); pen.write(f"HINT: {hint_text}", align="center", font=("Courier", 11, "italic"))
else:
final_win = player_layer >= 100
pen.color("lime" if final_win else "red")
msg = "CORE SECURED" if final_win else "HARDWARE CRITICAL"
pen.write(msg, align="center", font=("Courier", 35, "bold"))
pen.goto(0, -100); pen.color("white")
best = get_best_score(game_mode, hardcore_mode)
current_score = (player_layer / (max(1, time.time() - start_time))) * 20 if game_mode != "BOSS" else (combo * 2)
if final_win: save_score(game_mode, current_score, hardcore_mode)
pen.write(f"FINAL SCORE: {current_score:.2f}\nBEST ({'HC' if hardcore_mode else 'STD'}): {best:.2f}", align="center", font=("Courier", 14))
#pen.goto(0, -180); pen.write("PRESS 'R' TO REINITIALIZE", align="center", font=("Courier", 12, "italic"))
if game_active:
pen.goto(0 + shake_offset[0], -50 + shake_offset[1])
pen.color("red" if (sabotage_active or key_visible) else "lime")
pen.write("[BUSY]" if (sabotage_active or key_visible) else f"> {user_input}_", align="center", font=("Courier", 20, "bold"))
screen.update()
except (turtle.Terminator, tk.TclError): pass
def main_loop():
global player_layer, ai_layer, game_active, sabotage_active, hint_text
if not game_active: return
try:
multiplier = 2.0 if hardcore_mode else 1.0
if game_mode == "DEFENSE":
player_layer -= (0.8 * multiplier) * (2.0 if player_layer < 30 else 1.0)
if random.random() < (0.05 * multiplier) and not sabotage_active:
sabotage_active = True; trigger_shake(); update_display()
screen.ontimer(lambda: globals().update(sabotage_active=False), 5000 if player_layer < 30 else 3000)
else:
if game_mode == "BOSS": pspd, aspd = 1.2, 1.1 * multiplier
else:
pspd = 0.4 if hardcore_mode else 0.7
aspd = 1.1 * multiplier if game_mode == "NORMAL" else 0.8 * multiplier
if game_mode == "NORMAL" and player_layer > 50: aspd = 1.5 * multiplier
elif game_mode != "STORY" and game_mode != "NORMAL" and player_layer > 70: aspd = 1.4 * multiplier
player_layer += pspd; ai_layer += aspd
if int(player_layer) in [25, 50, 75] and not sabotage_active:
sabotage_active = True; trigger_shake(); update_display()
screen.ontimer(lambda: globals().update(sabotage_active=False), 4000)
if not hardcore_mode and game_mode == "DEFENSE" and player_layer < 25 and current_phase == "RIDDLE":
hint_text = f"DECRYPTED: {current_ans[0]}...{current_ans[-1]}"
if player_layer >= 100: player_layer, game_active = 100.0, False
if player_layer <= 0: player_layer, game_active = 0.0, False
if game_mode != "DEFENSE" and ai_layer >= AI_MAX: ai_layer, game_active = AI_MAX, False
update_display()
if game_active: screen.ontimer(main_loop, 1000)
except (turtle.Terminator, tk.TclError): pass
def handle_keypress(key):
global user_input, ai_layer, player_layer, game_active, lives, combo, base_shake
#if not game_active:
# if key.lower() == 'r':
# try: screen.bye(); main_restart()
# except: main_restart()
#return
if sabotage_active or key_visible: return
if key == "BackSpace": user_input = user_input[:-1]
elif key == "Return":
if user_input.upper().strip() == current_ans.upper():
combo += 1
if hardcore_mode:
combo_bonus = 0.08 if combo > 5 else 0.04
mult = 1 + (combo * combo_bonus)
else: mult = 1 + (combo * 0.1)
if game_mode == "DEFENSE": player_layer = min(100, player_layer + (8 * mult))
else:
base_penalty = 4 if hardcore_mode else 8
ai_layer = max(0, ai_layer - (base_penalty * mult))
set_next_task()
else:
combo = 0; trigger_shake()
if hardcore_mode: base_shake += 5
if game_mode == "DEFENSE": player_layer = max(0, player_layer - 5)
else:
lives -= 1
if lives <= 0: game_active = False
if game_active and current_phase == "MEMORIZE": show_key()
user_input = ""
elif len(key) == 1: user_input += key.upper()
update_display()
try:
screen.listen()
for char in "abcdefghijklmnopqrstuvwxyz0123456789": screen.onkey(lambda c=char: handle_keypress(c), char)
screen.onkey(lambda: handle_keypress("BackSpace"), "BackSpace")
screen.onkey(lambda: handle_keypress("Return"), "Return")
screen.onkey(lambda: handle_keypress("r"), "r")
set_next_task(); main_loop(); screen.mainloop()
except (turtle.Terminator, tk.TclError): pass
def main_restart():
try:
new_root = tk.Tk()
StartScreen(new_root)
new_root.mainloop()
except: pass
if __name__ == "__main__":
main_restart()