Spaces:
Running
Running
Upload 3 files
Browse files- ai_studio_code.css +104 -0
- ai_studio_code.html +90 -0
- ai_studio_code.js +199 -0
ai_studio_code.css
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono&display=swap');
|
| 2 |
+
|
| 3 |
+
:root {
|
| 4 |
+
--bg-color: #020513;
|
| 5 |
+
--window-bg: rgba(5, 10, 31, 0.85);
|
| 6 |
+
--neon-cyan: #00e5ff;
|
| 7 |
+
--neon-red: #ff003c;
|
| 8 |
+
--text-color: #a4b4cc;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
body {
|
| 12 |
+
margin: 0; overflow: hidden; font-family: 'Share Tech Mono', monospace;
|
| 13 |
+
color: var(--text-color);
|
| 14 |
+
background-color: #000; /* Fallback */
|
| 15 |
+
background-image: url('YOUR_UPLOADED_IMAGE_PATH_HERE.jpg'); /* PUT WALLPAPER HERE */
|
| 16 |
+
background-size: cover; background-position: center; background-repeat: no-repeat;
|
| 17 |
+
height: 100vh; user-select: none;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
/* =========================================
|
| 21 |
+
CRT Effect & Boot Screen
|
| 22 |
+
========================================= */
|
| 23 |
+
.crt {
|
| 24 |
+
position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
|
| 25 |
+
background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%),
|
| 26 |
+
linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
|
| 27 |
+
background-size: 100% 2px, 3px 100%;
|
| 28 |
+
z-index: 9999; /* Keeps scanlines over EVERYTHING */
|
| 29 |
+
pointer-events: none; /* Allows clicking through the scanlines */
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
#boot-screen {
|
| 33 |
+
position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
|
| 34 |
+
background-color: #020513; z-index: 9000;
|
| 35 |
+
padding: 20px; box-sizing: border-box;
|
| 36 |
+
display: flex; flex-direction: column; justify-content: flex-end;
|
| 37 |
+
transition: opacity 1s ease-out;
|
| 38 |
+
}
|
| 39 |
+
#boot-text {
|
| 40 |
+
color: var(--neon-cyan); text-shadow: 0 0 5px var(--neon-cyan);
|
| 41 |
+
font-size: 14px; white-space: pre-wrap; word-wrap: break-word;
|
| 42 |
+
overflow-y: hidden;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
/* =========================================
|
| 46 |
+
Desktop & Windows
|
| 47 |
+
========================================= */
|
| 48 |
+
.desktop { padding: 20px; display: flex; flex-direction: column; gap: 20px; position: relative; z-index: 1;}
|
| 49 |
+
.icon {
|
| 50 |
+
width: 80px; text-align: center; cursor: pointer; padding: 10px; border-radius: 5px;
|
| 51 |
+
transition: background 0.2s;
|
| 52 |
+
}
|
| 53 |
+
.icon:hover { background: rgba(0, 229, 255, 0.2); border: 1px solid var(--neon-cyan); }
|
| 54 |
+
.icon img { width: 40px; height: 40px; filter: drop-shadow(0 0 5px var(--neon-cyan)); }
|
| 55 |
+
.icon span { display: block; margin-top: 5px; font-size: 12px; color: white; text-shadow: 0 0 5px black; }
|
| 56 |
+
|
| 57 |
+
.window {
|
| 58 |
+
position: absolute; top: 100px; left: 150px; width: 600px; height: 450px;
|
| 59 |
+
background: var(--window-bg); border: 1px solid var(--neon-cyan);
|
| 60 |
+
box-shadow: 0 0 20px rgba(0, 229, 255, 0.2), inset 0 0 10px rgba(0, 229, 255, 0.1);
|
| 61 |
+
backdrop-filter: blur(5px); display: flex; flex-direction: column; z-index: 10;
|
| 62 |
+
}
|
| 63 |
+
.window-header {
|
| 64 |
+
background: linear-gradient(90deg, #0a1930 0%, #050a1f 100%);
|
| 65 |
+
border-bottom: 1px solid var(--neon-cyan); padding: 5px 10px;
|
| 66 |
+
display: flex; justify-content: space-between; align-items: center;
|
| 67 |
+
cursor: grab; color: var(--neon-cyan); font-weight: bold;
|
| 68 |
+
}
|
| 69 |
+
.window-header:active { cursor: grabbing; }
|
| 70 |
+
.window-controls button {
|
| 71 |
+
background: none; border: none; color: var(--text-color); cursor: pointer; font-family: inherit; font-size: 16px;
|
| 72 |
+
}
|
| 73 |
+
.window-controls button:hover { color: var(--neon-red); text-shadow: 0 0 5px var(--neon-red); }
|
| 74 |
+
.window-content { flex-grow: 1; overflow-y: auto; display: flex; flex-direction: column; }
|
| 75 |
+
|
| 76 |
+
/* =========================================
|
| 77 |
+
App Specific Styles
|
| 78 |
+
========================================= */
|
| 79 |
+
.system-msg { color: #555; font-style: italic; }
|
| 80 |
+
.bot-msg { color: var(--neon-cyan); }
|
| 81 |
+
.hacker-input {
|
| 82 |
+
background: transparent; border: none; border-bottom: 1px solid var(--neon-cyan);
|
| 83 |
+
color: white; width: 100%; font-family: inherit; outline: none; margin-top: auto; padding: 5px 0;
|
| 84 |
+
}
|
| 85 |
+
#notepad-input {
|
| 86 |
+
width: 100%; height: 100%; background: transparent; border: none; color: var(--neon-cyan);
|
| 87 |
+
font-family: 'Share Tech Mono', monospace; padding: 15px; box-sizing: border-box; resize: none; outline: none;
|
| 88 |
+
}
|
| 89 |
+
#snake-canvas { border: 1px solid var(--neon-cyan); box-shadow: 0 0 10px var(--neon-cyan); }
|
| 90 |
+
|
| 91 |
+
/* =========================================
|
| 92 |
+
Taskbar
|
| 93 |
+
========================================= */
|
| 94 |
+
.taskbar {
|
| 95 |
+
position: absolute; bottom: 0; width: 100%; height: 40px;
|
| 96 |
+
background: rgba(5, 10, 31, 0.9); border-top: 1px solid var(--neon-cyan);
|
| 97 |
+
display: flex; align-items: center; padding: 0 10px; box-sizing: border-box; z-index: 100;
|
| 98 |
+
}
|
| 99 |
+
.start-btn {
|
| 100 |
+
background: var(--neon-cyan); color: black; border: none; padding: 5px 15px;
|
| 101 |
+
font-weight: bold; font-family: inherit; cursor: pointer; text-transform: uppercase;
|
| 102 |
+
}
|
| 103 |
+
.start-btn:hover { box-shadow: 0 0 10px var(--neon-cyan); }
|
| 104 |
+
.clock { margin-left: auto; color: var(--neon-cyan); font-weight: bold; }
|
ai_studio_code.html
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>XORTRON OS</title>
|
| 7 |
+
<link rel="stylesheet" href="style.css">
|
| 8 |
+
</head>
|
| 9 |
+
<body>
|
| 10 |
+
<!-- CRT Scanline Effect Overlay -->
|
| 11 |
+
<div class="crt"></div>
|
| 12 |
+
|
| 13 |
+
<!-- Boot Sequence Screen -->
|
| 14 |
+
<div id="boot-screen">
|
| 15 |
+
<div id="boot-text"></div>
|
| 16 |
+
</div>
|
| 17 |
+
|
| 18 |
+
<!-- Desktop Icons -->
|
| 19 |
+
<div class="desktop">
|
| 20 |
+
<div class="icon" ondblclick="openWindow('chat-window')">
|
| 21 |
+
<img src="https://cdn-icons-png.flaticon.com/512/1183/1183672.png" alt="Terminal">
|
| 22 |
+
<span>XORTRON.exe</span>
|
| 23 |
+
</div>
|
| 24 |
+
<div class="icon" ondblclick="openWindow('snake-window'); initSnake();">
|
| 25 |
+
<img src="https://cdn-icons-png.flaticon.com/512/834/834148.png" alt="Snake Game">
|
| 26 |
+
<span>XOR-Snake</span>
|
| 27 |
+
</div>
|
| 28 |
+
<div class="icon" ondblclick="openWindow('notes-window')">
|
| 29 |
+
<img src="https://cdn-icons-png.flaticon.com/512/1055/1055285.png" alt="Notepad">
|
| 30 |
+
<span>Notes.txt</span>
|
| 31 |
+
</div>
|
| 32 |
+
</div>
|
| 33 |
+
|
| 34 |
+
<!-- 1. Draggable Chat Window -->
|
| 35 |
+
<div class="window" id="chat-window">
|
| 36 |
+
<div class="window-header" id="chat-window-header">
|
| 37 |
+
<span class="window-title">TERMINAL :: XORTRON CHATLINK</span>
|
| 38 |
+
<div class="window-controls">
|
| 39 |
+
<button onclick="closeWindow('chat-window')">X</button>
|
| 40 |
+
</div>
|
| 41 |
+
</div>
|
| 42 |
+
<div class="window-content" style="padding: 0;">
|
| 43 |
+
<!-- Your Chatbot iFrame goes here -->
|
| 44 |
+
<div class="fake-chat" style="padding: 15px;">
|
| 45 |
+
<p class="system-msg">Establishing secure connection to XORTRON servers...</p>
|
| 46 |
+
<p class="system-msg">Connection encrypted. Proceed.</p>
|
| 47 |
+
<p class="bot-msg">> Welcome back, Operative. Awaiting input.</p>
|
| 48 |
+
<input type="text" class="hacker-input" placeholder="Type command here...">
|
| 49 |
+
</div>
|
| 50 |
+
</div>
|
| 51 |
+
</div>
|
| 52 |
+
|
| 53 |
+
<!-- 2. Draggable Snake Game Window -->
|
| 54 |
+
<div class="window" id="snake-window" style="display: none; top: 150px; left: 200px; width: 420px; height: 480px;">
|
| 55 |
+
<div class="window-header" id="snake-window-header">
|
| 56 |
+
<span class="window-title">XOR-SNAKE.exe</span>
|
| 57 |
+
<div class="window-controls">
|
| 58 |
+
<button onclick="closeWindow('snake-window')">X</button>
|
| 59 |
+
</div>
|
| 60 |
+
</div>
|
| 61 |
+
<div class="window-content" style="display: flex; justify-content: center; align-items: center; background: #000;">
|
| 62 |
+
<canvas id="snake-canvas" width="400" height="400"></canvas>
|
| 63 |
+
</div>
|
| 64 |
+
</div>
|
| 65 |
+
|
| 66 |
+
<!-- 3. Draggable Notepad Window -->
|
| 67 |
+
<div class="window" id="notes-window" style="display: none; top: 200px; left: 250px; width: 500px; height: 400px;">
|
| 68 |
+
<div class="window-header" id="notes-window-header">
|
| 69 |
+
<span class="window-title">DECRYPTED_NOTES.txt</span>
|
| 70 |
+
<div class="window-controls">
|
| 71 |
+
<button onclick="closeWindow('notes-window')">X</button>
|
| 72 |
+
</div>
|
| 73 |
+
</div>
|
| 74 |
+
<div class="window-content" style="padding: 0;">
|
| 75 |
+
<textarea id="notepad-input" spellcheck="false" placeholder="Enter encrypted notes here..."></textarea>
|
| 76 |
+
</div>
|
| 77 |
+
</div>
|
| 78 |
+
|
| 79 |
+
<!-- Taskbar -->
|
| 80 |
+
<div class="taskbar">
|
| 81 |
+
<button class="start-btn">XORTRON</button>
|
| 82 |
+
<div class="open-apps" id="taskbar-apps">
|
| 83 |
+
<!-- Dynamic taskbar items go here -->
|
| 84 |
+
</div>
|
| 85 |
+
<div class="clock" id="clock">00:00</div>
|
| 86 |
+
</div>
|
| 87 |
+
|
| 88 |
+
<script src="script.js"></script>
|
| 89 |
+
</body>
|
| 90 |
+
</html>
|
ai_studio_code.js
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* =========================================
|
| 2 |
+
1. Boot Sequence Logic
|
| 3 |
+
========================================= */
|
| 4 |
+
const bootLines =[
|
| 5 |
+
"XORTRON CRIMINAL COMPUTING BIOS v2.4.1",
|
| 6 |
+
"Copyright (C) 2084 XORTRON Syndicate",
|
| 7 |
+
"Initializing hardware interface... OK",
|
| 8 |
+
"Checking memory... 64000K OK",
|
| 9 |
+
"Loading Neural Net Drivers... SUCCESS",
|
| 10 |
+
"Connecting to Dark Web Node 77-Alpha...",
|
| 11 |
+
"Bypassing security protocols...",
|
| 12 |
+
"Decryption key accepted.",
|
| 13 |
+
"Mounting virtual drives...",
|
| 14 |
+
"System Ready. Welcome, Operative."
|
| 15 |
+
];
|
| 16 |
+
|
| 17 |
+
let bootScreen = document.getElementById('boot-screen');
|
| 18 |
+
let bootText = document.getElementById('boot-text');
|
| 19 |
+
let lineIndex = 0;
|
| 20 |
+
|
| 21 |
+
function runBootSequence() {
|
| 22 |
+
if (lineIndex < bootLines.length) {
|
| 23 |
+
bootText.innerHTML += bootLines[lineIndex] + "<br>";
|
| 24 |
+
lineIndex++;
|
| 25 |
+
// Speed of boot lines appearing
|
| 26 |
+
setTimeout(runBootSequence, Math.random() * 300 + 100);
|
| 27 |
+
} else {
|
| 28 |
+
// Wait 1 second after boot text finishes, then fade out
|
| 29 |
+
setTimeout(() => {
|
| 30 |
+
bootScreen.style.opacity = '0';
|
| 31 |
+
setTimeout(() => { bootScreen.style.display = 'none'; }, 1000);
|
| 32 |
+
}, 1000);
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
window.onload = runBootSequence;
|
| 36 |
+
|
| 37 |
+
/* =========================================
|
| 38 |
+
2. System Clock & Window Management
|
| 39 |
+
========================================= */
|
| 40 |
+
function updateClock() {
|
| 41 |
+
const now = new Date();
|
| 42 |
+
document.getElementById('clock').innerText = now.toLocaleTimeString();
|
| 43 |
+
}
|
| 44 |
+
setInterval(updateClock, 1000);
|
| 45 |
+
updateClock();
|
| 46 |
+
|
| 47 |
+
let highestZIndex = 10;
|
| 48 |
+
|
| 49 |
+
function openWindow(id) {
|
| 50 |
+
let win = document.getElementById(id);
|
| 51 |
+
win.style.display = 'flex';
|
| 52 |
+
bringToFront(win);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
function closeWindow(id) {
|
| 56 |
+
document.getElementById(id).style.display = 'none';
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
function bringToFront(elmnt) {
|
| 60 |
+
highestZIndex++;
|
| 61 |
+
elmnt.style.zIndex = highestZIndex;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
// Apply drag functionality to all windows
|
| 65 |
+
document.querySelectorAll('.window').forEach(win => {
|
| 66 |
+
dragElement(win);
|
| 67 |
+
// Bring window to front when clicked anywhere on it
|
| 68 |
+
win.addEventListener('mousedown', () => bringToFront(win));
|
| 69 |
+
});
|
| 70 |
+
|
| 71 |
+
function dragElement(elmnt) {
|
| 72 |
+
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
|
| 73 |
+
var header = document.getElementById(elmnt.id + "-header");
|
| 74 |
+
|
| 75 |
+
if (header) { header.onmousedown = dragMouseDown; }
|
| 76 |
+
else { elmnt.onmousedown = dragMouseDown; }
|
| 77 |
+
|
| 78 |
+
function dragMouseDown(e) {
|
| 79 |
+
e = e || window.event;
|
| 80 |
+
e.preventDefault();
|
| 81 |
+
pos3 = e.clientX;
|
| 82 |
+
pos4 = e.clientY;
|
| 83 |
+
document.onmouseup = closeDragElement;
|
| 84 |
+
document.onmousemove = elementDrag;
|
| 85 |
+
bringToFront(elmnt);
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
function elementDrag(e) {
|
| 89 |
+
e = e || window.event;
|
| 90 |
+
e.preventDefault();
|
| 91 |
+
pos1 = pos3 - e.clientX;
|
| 92 |
+
pos2 = pos4 - e.clientY;
|
| 93 |
+
pos3 = e.clientX;
|
| 94 |
+
pos4 = e.clientY;
|
| 95 |
+
elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
|
| 96 |
+
elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
function closeDragElement() {
|
| 100 |
+
document.onmouseup = null;
|
| 101 |
+
document.onmousemove = null;
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
/* =========================================
|
| 106 |
+
3. XOR-Snake Game Logic
|
| 107 |
+
========================================= */
|
| 108 |
+
const canvas = document.getElementById('snake-canvas');
|
| 109 |
+
const ctx = canvas.getContext('2d');
|
| 110 |
+
const gridSize = 20;
|
| 111 |
+
let snake =[{x: 200, y: 200}];
|
| 112 |
+
let apple = {x: 100, y: 100};
|
| 113 |
+
let dx = 0;
|
| 114 |
+
let dy = 0;
|
| 115 |
+
let gameInterval;
|
| 116 |
+
let gameRunning = false;
|
| 117 |
+
|
| 118 |
+
function initSnake() {
|
| 119 |
+
if(gameRunning) return;
|
| 120 |
+
snake =[{x: 200, y: 200}];
|
| 121 |
+
dx = gridSize; dy = 0; // Start moving right
|
| 122 |
+
placeApple();
|
| 123 |
+
gameRunning = true;
|
| 124 |
+
gameInterval = setInterval(gameLoop, 100);
|
| 125 |
+
|
| 126 |
+
// Auto-focus window to accept keystrokes immediately
|
| 127 |
+
bringToFront(document.getElementById('snake-window'));
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
function placeApple() {
|
| 131 |
+
apple.x = Math.floor(Math.random() * (canvas.width / gridSize)) * gridSize;
|
| 132 |
+
apple.y = Math.floor(Math.random() * (canvas.height / gridSize)) * gridSize;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
function gameLoop() {
|
| 136 |
+
// Move Snake
|
| 137 |
+
const head = {x: snake[0].x + dx, y: snake[0].y + dy};
|
| 138 |
+
snake.unshift(head);
|
| 139 |
+
|
| 140 |
+
// Check collision with apple
|
| 141 |
+
if (head.x === apple.x && head.y === apple.y) {
|
| 142 |
+
placeApple();
|
| 143 |
+
} else {
|
| 144 |
+
snake.pop(); // Remove tail if no apple eaten
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
// Check collision with walls or self
|
| 148 |
+
if (head.x < 0 || head.x >= canvas.width || head.y < 0 || head.y >= canvas.height || collision(head)) {
|
| 149 |
+
clearInterval(gameInterval);
|
| 150 |
+
gameRunning = false;
|
| 151 |
+
ctx.fillStyle = '#ff003c';
|
| 152 |
+
ctx.font = '30px "Share Tech Mono"';
|
| 153 |
+
ctx.fillText('SYSTEM FAILURE', 80, 200);
|
| 154 |
+
return;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
// Draw Background
|
| 158 |
+
ctx.fillStyle = 'black';
|
| 159 |
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
| 160 |
+
|
| 161 |
+
// Draw Grid Lines (Hacker aesthetic)
|
| 162 |
+
ctx.strokeStyle = '#003333';
|
| 163 |
+
for(let i=0; i<canvas.width; i+=gridSize) {
|
| 164 |
+
ctx.beginPath(); ctx.moveTo(i, 0); ctx.lineTo(i, canvas.height); ctx.stroke();
|
| 165 |
+
ctx.beginPath(); ctx.moveTo(0, i); ctx.lineTo(canvas.width, i); ctx.stroke();
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
// Draw Apple
|
| 169 |
+
ctx.fillStyle = '#ff003c';
|
| 170 |
+
ctx.fillRect(apple.x, apple.y, gridSize - 2, gridSize - 2);
|
| 171 |
+
|
| 172 |
+
// Draw Snake
|
| 173 |
+
ctx.fillStyle = '#00e5ff';
|
| 174 |
+
snake.forEach(part => {
|
| 175 |
+
ctx.fillRect(part.x, part.y, gridSize - 2, gridSize - 2);
|
| 176 |
+
});
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
function collision(head) {
|
| 180 |
+
for (let i = 1; i < snake.length; i++) {
|
| 181 |
+
if (head.x === snake[i].x && head.y === snake[i].y) return true;
|
| 182 |
+
}
|
| 183 |
+
return false;
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
// Arrow Key Controls for Snake (Only active if window is displayed)
|
| 187 |
+
document.addEventListener('keydown', (e) => {
|
| 188 |
+
if(document.getElementById('snake-window').style.display !== 'flex') return;
|
| 189 |
+
|
| 190 |
+
// Prevent default scrolling when using arrows
|
| 191 |
+
if(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].indexOf(e.code) > -1) {
|
| 192 |
+
e.preventDefault();
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
if (e.code === 'ArrowUp' && dy === 0) { dx = 0; dy = -gridSize; }
|
| 196 |
+
else if (e.code === 'ArrowDown' && dy === 0) { dx = 0; dy = gridSize; }
|
| 197 |
+
else if (e.code === 'ArrowLeft' && dx === 0) { dx = -gridSize; dy = 0; }
|
| 198 |
+
else if (e.code === 'ArrowRight' && dx === 0) { dx = gridSize; dy = 0; }
|
| 199 |
+
});
|