Compare commits

...

8 commits

10 changed files with 498 additions and 7 deletions

View file

View file

View file

BIN
secret/images/default.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 573 KiB

View file

@ -31,7 +31,7 @@
</div>
</a>
<a href="#" target="_blank" class="item">
<img src="images/blackjack.jpg" alt="Image can't be displayed" />
<img src="images/default.jpeg" alt="Image can't be displayed" />
<h2>Secret Blackjack</h2>
<div class="description">
<p>
@ -41,7 +41,7 @@
</div>
</a>
<a href="#" target="_blank" class="item">
<img src="images/snake.png" alt="Image can't be displayed" />
<img src="images/default.jpeg" alt="Image can't be displayed" />
<h2>Snake</h2>
<div class="description">
<p>
@ -51,7 +51,7 @@
</div>
</a>
<a href="#" target="_blank" class="item">
<img src="images/solitaire.png" alt="Image can't be displayed" />
<img src="images/default.jpeg" alt="Image can't be displayed" />
<h2>Solitaire</h2>
<div class="description">
<p>
@ -81,7 +81,7 @@
</div>
</a>
<a href="#" target="_blank" class="item">
<img src="images/endless_runner.png" alt="Image can't be displayed" />
<img src="images/default.jpeg" alt="Image can't be displayed" />
<h2>Endless Runner</h2>
<div class="description">
<p>

144
secret/snake/game.js Normal file
View file

@ -0,0 +1,144 @@
'use strict';
const upButton = document.getElementById('up');
const downButton = document.getElementById('down');
const leftButton = document.getElementById('left');
const rightButton = document.getElementById('right');
const startButton = document.getElementById('start');
const grid = document.createElement('div');
grid.id = 'grid';
document.querySelector('.game').appendChild(grid);
let snake = [{ x: 5, y: 5 }];
let apple = { x: 8, y: 5 };
let direction = { x: 0, y: 0 };
let gameInterval = null;
let isGameRunning = false;
const gridSize = 10;
function initGame() {
grid.style.display = 'grid';
grid.style.gridTemplateColumns = `repeat(${gridSize}, 1fr)`;
grid.style.gridTemplateRows = `repeat(${gridSize}, 1fr)`;
grid.style.width = '350px';
grid.style.height = '350px';
document.getElementById('title').style.display = 'none';
document.getElementById('description').style.display = 'none';
isGameRunning = true;
snake = [{ x: 5, y: 5 }];
apple = spawnApple();
direction = { x: 0, y: 0 };
clearInterval(gameInterval);
gameInterval = setInterval(gameLoop, 200);
render();
}
function spawnApple() {
let newApple;
do {
newApple = {
x: Math.floor(Math.random() * gridSize),
y: Math.floor(Math.random() * gridSize)
};
} while (snake.some(segment => segment.x === newApple.x && segment.y === newApple.y));
return newApple;
}
function updateSnake() {
const newHead = {
x: snake[0].x + direction.x,
y: snake[0].y + direction.y
};
if (newHead.x < 0) newHead.x = gridSize - 1;
if (newHead.y < 0) newHead.y = gridSize - 1;
if (newHead.x >= gridSize) newHead.x = 0;
if (newHead.y >= gridSize) newHead.y = 0;
if (snake.some(segment => segment.x === newHead.x && segment.y === newHead.y)) {
gameOver();
return;
}
snake.unshift(newHead);
if (newHead.x === apple.x && newHead.y === apple.y) {
apple = spawnApple();
} else {
snake.pop();
}
}
function render() {
grid.innerHTML = "";
for (let y = 0; y < gridSize; y++) {
for (let x = 0; x < gridSize; x++) {
const cell = document.createElement("div");
cell.classList.add("cell");
if ((x + y) % 2 === 0) {
cell.classList.add("light-green");
} else {
cell.classList.add("dark-green");
}
if (snake.some(segment => segment.x === x && segment.y === y)) {
cell.classList.add("snake");
}
if (apple.x === x && apple.y === y) {
cell.classList.add("apple");
}
grid.appendChild(cell);
}
}
}
function gameLoop() {
if (!isGameRunning) return;
updateSnake();
render();
}
function gameOver() {
alert('Game Over!');
clearInterval(gameInterval);
isGameRunning = false;
}
function handleDirectionInput(key) {
switch (key) {
case 'ArrowUp':
case 'w':
if (direction.y === 0) direction = { x: 0, y: -1 };
break;
case 'ArrowDown':
case 's':
if (direction.y === 0) direction = { x: 0, y: 1 };
break;
case 'ArrowLeft':
case 'a':
if (direction.x === 0) direction = { x: -1, y: 0 };
break;
case 'ArrowRight':
case 'd':
if (direction.x === 0) direction = { x: 1, y: 0 };
break;
}
}
upButton.addEventListener('click', () => handleDirectionInput('ArrowUp'));
downButton.addEventListener('click', () => handleDirectionInput('ArrowDown'));
leftButton.addEventListener('click', () => handleDirectionInput('ArrowLeft'));
rightButton.addEventListener('click', () => handleDirectionInput('ArrowRight'));
startButton.addEventListener('click', () => {
if (!isGameRunning) initGame();
});
document.addEventListener('keydown', (event) => {
handleDirectionInput(event.key);
});

49
secret/snake/index.html Normal file
View file

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Snake - Game</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div class="gameboy">
<!-- Game Boy Screen -->
<div class="screen">
<article class="game">
<h1 class="title" id="title">Snake - Game</h1>
<div class="description" id="description">
<h2>Description</h2>
<p>Eat as many apples and grow as much as possible</p>
<p>◀ or A or arrow left = move left</p>
<p>▶ or D or arrow right = move right</p>
<p>▲ or W or arrow up = move up</p>
<p>▼ or S or arrow down = move down</p>
</div>
<canvas id="game"></canvas>
</article>
</div>
<!-- Controls -->
<div class="controls">
<!-- D-Pad on the left -->
<div class="dpad">
<button class="dpad-btn up" id="up"></button>
<button class="dpad-btn left" id="left"></button>
<div class="dpad-center"></div>
<button class="dpad-btn right" id="right"></button>
<button class="dpad-btn down" id="down"></button>
</div>
<!-- A, B and start button on the right -->
<div class="action-buttons">
<button class="start-btn btn" id="start">Start</button>
<button class="btn" id="a">A</button>
<button class="btn" id="b">B</button>
</div>
</div>
</div>
<script src="game.js"></script>
<script src="styles.js"></script>
</body>
</html>

238
secret/snake/styles.css Normal file
View file

@ -0,0 +1,238 @@
/* Base Reset */
body,
html {
margin: 0;
padding: 0;
font-family: monospace;
background-color: #3a2d56;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
/* GameBoy Layout */
.gameboy {
background-color: #5f4c82; /* Game Boy Color purple shell */
width: 441px;
height: 735px;
border-radius: 20px;
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.6);
display: flex;
flex-direction: column;
align-items: center;
padding: 10px;
position: relative;
}
@media(max-width: 768px) {
.gameboy {
width: 100vw;
height: 100vh;
border-radius: 0;
}
}
/* Screen */
.screen {
background-color: black;
border: 4px solid #0f380f;
width: 90%;
height: 55%;
margin-top: 20px;
border-radius: 10px;
display: flex;
justify-content: center;
align-items: center;
box-shadow: inset 0 4px 8px rgba(0, 0, 0, 0.5);
overflow: hidden;
}
.game {
text-align: center;
width: 90%;
}
/* Titles */
h1 {
font-size: 2rem;
margin-bottom: 10px;
text-transform: uppercase;
color: #9bbc0f;
}
.description,
.description p {
font-size: 1.2rem;
margin: 0 auto;
padding: 0 auto;
color: white;
}
/* Grid container */
#grid {
display: grid;
grid-template-columns: repeat(10, 1fr); /* Adjust to match gridSize */
grid-template-rows: repeat(10, 1fr); /* Adjust to match gridSize */
width: 400px; /* Adjust as needed */
height: 400px; /* Adjust as needed */
border: 2px solid #0f380f;
margin: 20px auto;
/* initially hide */
display: none;
}
/* Individual cells */
.cell {
width: 100%;
height: 100%;
}
.cell.light-green {
background-color: #9bbc0f;
}
.cell.dark-green {
background-color: #0f380f;
}
/* Snake styling */
.snake {
background-color: #e600ff; /* Snake color */
z-index: 1000;
}
/* Apple styling */
.apple {
background-color: red; /* Apple color */
z-index: 999;
}
/* Controls Section */
.controls {
margin-top: 20px;
display: flex;
justify-content: space-between;
width: 80%;
align-items: center;
}
/* D-Pad */
.dpad {
position: relative;
width: 120px;
height: 120px;
}
/* Base Styling for D-Pad Buttons */
.dpad-btn {
background-color: #0f380f;
color: #9bbc0f;
border: none;
border-radius: 5px;
position: absolute;
width: 42px;
height: 42px;
font-size: 1.5rem;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
z-index: 1;
}
.dpad-btn.up {
top: 0;
left: 50%;
transform: translateX(-50%);
}
.dpad-btn.down {
bottom: 0;
left: 50%;
transform: translateX(-50%);
}
.dpad-btn.left {
top: 50%;
left: 0;
transform: translateY(-50%);
}
.dpad-btn.right {
top: 50%;
right: 0;
transform: translateY(-50%);
}
/* D-Pad Center to Connect Buttons */
.dpad-center {
background-color: #0f380f;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 40px;
height: 40px;
border: 2px solid transparent;
z-index: 0;
border-radius: 5px;
}
/* A and B Buttons */
.action-buttons {
display: flex;
flex-direction: column;
justify-content: space-between;
height: 200px;
}
.btn {
background-color: #0f380f;
color: #9bbc0f;
border: 2px solid #9bbc0f;
border-radius: 50%;
width: 60px;
height: 60px;
font-size: 1.8rem;
cursor: pointer;
transition: transform 0.1s, background-color 0.2s;
}
.btn:hover {
background-color: #9bbc0f;
color: #0f380f;
}
.btn:active {
transform: scale(0.9);
}
/* Start Button */
.start-btn {
background-color: #0f380f;
color: #9bbc0f;
border: 2px solid #9bbc0f;
border-radius: 5px;
width: 100px;
height: 40px;
font-size: 1.2rem;
cursor: pointer;
transition: transform 0.1s, background-color 0.2s;
margin-bottom: 20px;
}
.start-btn:hover {
background-color: #9bbc0f;
color: #0f380f;
}
.start-btn:active {
transform: scale(0.9);
}
/* Hidden Canvas for Debugging or Fallback */
canvas {
display: none;
z-index: 1000;
}

60
secret/snake/styles.js Normal file
View file

@ -0,0 +1,60 @@
'use strict';
const aBtn = document.querySelector('#a');
const bBtn = document.querySelector('#b');
const gameboy = document.querySelector('.gameboy');
const html = document.documentElement;
const body = document.body;
const dpadButtons = document.querySelectorAll('.dpad-btn');
const dpadCenter = document.querySelector('.dpad-center'); // Darker variant
const actionButtons = document.querySelectorAll('.btn');
const colors = [
{ gameboyColor: '#B39DDB', htmlColor: '#D1C4E9', buttonColor: '#673AB7', buttonTextColor: '#FFFFFF', dpadCenterColor: '#5E35B1' },
{ gameboyColor: '#FFC107', htmlColor: '#FFF9C4', buttonColor: '#FF9800', buttonTextColor: '#000000', dpadCenterColor: '#EF6C00' },
{ gameboyColor: '#8BC34A', htmlColor: '#C5E1A5', buttonColor: '#FF5722', buttonTextColor: '#FFFFFF', dpadCenterColor: '#E64A19' },
{ gameboyColor: '#F44336', htmlColor: '#FFCDD2', buttonColor: '#E91E63', buttonTextColor: '#FFFFFF', dpadCenterColor: '#C2185B' },
{ gameboyColor: '#03A9F4', htmlColor: '#BBDEFB', buttonColor: '#FFEB3B', buttonTextColor: '#000000', dpadCenterColor: '#0277BD' },
{ gameboyColor: '#FF7043', htmlColor: '#FFCCBC', buttonColor: '#FF5722', buttonTextColor: '#FFFFFF', dpadCenterColor: '#D84315' },
{ gameboyColor: '#9C27B0', htmlColor: '#E1BEE7', buttonColor: '#7B1FA2', buttonTextColor: '#FFFFFF', dpadCenterColor: '#6A1B9A' },
{ gameboyColor: '#FFD700', htmlColor: '#FFF9C4', buttonColor: '#FF9800', buttonTextColor: '#FFFFFF', dpadCenterColor: '#F57F17' },
{ gameboyColor: '#009688', htmlColor: '#B2DFDB', buttonColor: '#4CAF50', buttonTextColor: '#FFFFFF', dpadCenterColor: '#00796B' },
{ gameboyColor: '#795548', htmlColor: '#D7CCC8', buttonColor: '#9E9E9E', buttonTextColor: '#000000', dpadCenterColor: '#5D4037' },
{ gameboyColor: '#FF5733', htmlColor: '#FFCCCB', buttonColor: '#C70039', buttonTextColor: '#FFFFFF', dpadCenterColor: '#B71C1C' },
{ gameboyColor: '#00BCD4', htmlColor: '#B2EBF2', buttonColor: '#00ACC1', buttonTextColor: '#FFFFFF', dpadCenterColor: '#00838F' }
];
let currentColorIndex = localStorage.getItem('gameboyColorIndex') ? parseInt(localStorage.getItem('gameboyColorIndex')) : 0;
function updateGameBoyColor() {
gameboy.style.backgroundColor = colors[currentColorIndex].gameboyColor;
html.style.backgroundColor = colors[currentColorIndex].htmlColor;
body.style.backgroundColor = colors[currentColorIndex].htmlColor;
dpadButtons.forEach(button => {
button.style.backgroundColor = colors[currentColorIndex].buttonColor;
button.style.color = colors[currentColorIndex].buttonTextColor;
});
// Using darker dpad center color
dpadCenter.style.backgroundColor = colors[currentColorIndex].dpadCenterColor;
dpadCenter.style.color = colors[currentColorIndex].buttonTextColor;
actionButtons.forEach(button => {
button.style.backgroundColor = colors[currentColorIndex].buttonColor;
button.style.color = colors[currentColorIndex].buttonTextColor;
});
}
aBtn.addEventListener('click', () => {
currentColorIndex = (currentColorIndex - 1 + colors.length) % colors.length;
localStorage.setItem('gameboyColorIndex', currentColorIndex);
updateGameBoyColor();
});
bBtn.addEventListener('click', () => {
currentColorIndex = (currentColorIndex + 1) % colors.length;
localStorage.setItem('gameboyColorIndex', currentColorIndex);
updateGameBoyColor();
});
updateGameBoyColor();

View file

@ -15,7 +15,7 @@
<div class="grid-container">
<a href="" target="_blank" class="item">
<img
src="../secret/../secret/images/snake.png"
src="../secret/../secret/images/default.jpeg"
alt="Image can't be displayed"
/>
<h2>Snake</h2>
@ -28,7 +28,7 @@
</a>
<a href="" target="_blank" class="item">
<img
src="../secret/images/solitaire.png"
src="../secret/images/default.jpeg"
alt="Image can't be displayed"
/>
<h2>Solitaire</h2>
@ -71,7 +71,7 @@
</a>
<a href="" target="_blank" class="item">
<img
src="../secret/images/endless_runner.png"
src="../secret/images/default.jpeg"
alt="Image can't be displayed"
/>
<h2>Endless Runner</h2>