diff --git a/SimonGame/SimonsGame/DPanvish/README.md b/SimonGame/SimonsGame/DPanvish/README.md new file mode 100644 index 000000000..9eee7fc26 --- /dev/null +++ b/SimonGame/SimonsGame/DPanvish/README.md @@ -0,0 +1,134 @@ +# Simon's Game 🎮 + +A simple and easy-to-understand implementation of the classic Simon's memory game built with HTML, CSS, and JavaScript. + +## Sample Working Output 📸 + +![Simon's Game Interface](SG.png) + +*The game features a modern glass morphism design with four colored buttons arranged in a circle, score display, and intuitive controls.* + +## Features ✨ + +- **Simple Code**: Easy to read and understand for beginners +- **Classic Mode**: Traditional Simon's game with increasing difficulty +- **Endless Mode**: Keep playing as long as you can +- **Audio Support**: Custom sounds for each color and game over +- **Speed Control**: Adjust how fast the pattern plays +- **Volume Control**: Adjust audio volume +- **Responsive Design**: Works on desktop and mobile + +## How to Play 🎯 + +1. **Start the Game**: Click "Start Game" or "Endless Mode" +2. **Watch the Pattern**: The game shows you a sequence of colors +3. **Repeat the Pattern**: Click the colors in the same order +4. **Progress**: Each level adds one more color +5. **Score Points**: Earn points based on your level + +## Audio Files Required 🔊 + +Add these audio files to the same folder: + +- `sound1.mp3` - Red button sound +- `sound2.mp3` - Blue button sound +- `sound3.mp3` - Green button sound +- `sound4.mp3` - Yellow button sound +- `GameOver.mp3` - Game over sound + +## Controls 🎮 + +- **Mouse**: Click colored buttons to play +- **Sliders**: Adjust speed and volume +- **Buttons**: Start, Endless Mode, Reset + +## Game Modes 🎲 + +### Classic Mode +- Game ends when you make a mistake +- Try to get the highest score + +### Endless Mode +- No game over - keep playing forever! +- Perfect for practice + +## Code Structure 📁 + +``` +Panvish/ +├── index.html # Simple HTML structure +├── style.css # Clean CSS styles +├── main.js # Easy-to-read JavaScript +├── README.md # This file +├── sound1.mp3 # Red button audio +├── sound2.mp3 # Blue button audio +├── sound3.mp3 # Green button audio +├── sound4.mp3 # Yellow button audio +└── GameOver.mp3 # Game over audio +``` + +## Getting Started 🚀 + +1. **Download** the project files +2. **Add Audio Files** - Place your audio files in the same folder +3. **Open index.html** in your web browser +4. **Start Playing** - Click "Start Game" to begin! + +## Code Explanation 📝 + +### HTML (index.html) +- Simple structure with clear sections +- Easy to understand element names +- Comments explain each part + +### CSS (style.css) +- Clean, organized styles +- Simple color scheme +- Mobile-friendly design +- Easy to modify + +### JavaScript (main.js) +- Single game object with clear methods +- Simple variable names +- Step-by-step comments +- Easy to follow logic + +## Tips for Learning 🎓 + +- **Read the Comments**: Each section is explained +- **Start Simple**: Focus on basic functionality first +- **Modify Colors**: Try changing the button colors +- **Add Features**: Experiment with new ideas +- **Practice**: Play the game to understand how it works + +## Troubleshooting 🔧 + +### No Sound? +- Check that audio files are in the correct folder +- Make sure browser allows audio +- Try adjusting volume slider + +### Game Not Working? +- Check browser console for errors +- Make sure JavaScript is enabled +- Try refreshing the page + +## Learning Opportunities 📚 + +This simplified version is perfect for: +- **HTML Beginners**: Learn basic structure +- **CSS Learners**: Understand styling and layout +- **JavaScript Newbies**: See how games work +- **Web Developers**: Study clean, readable code + +## Customization Ideas 💡 + +- Change button colors +- Add new game modes +- Modify scoring system +- Add sound effects +- Create different themes + +--- + +**Enjoy learning and playing Simon's Game!** 🎉 diff --git a/SimonGame/SimonsGame/DPanvish/SG.png b/SimonGame/SimonsGame/DPanvish/SG.png new file mode 100644 index 000000000..b9bf5c43b Binary files /dev/null and b/SimonGame/SimonsGame/DPanvish/SG.png differ diff --git a/SimonGame/SimonsGame/DPanvish/index.html b/SimonGame/SimonsGame/DPanvish/index.html new file mode 100644 index 000000000..85690f54d --- /dev/null +++ b/SimonGame/SimonsGame/DPanvish/index.html @@ -0,0 +1,86 @@ + + + + + + Simon's Game + + + +
+ +
+

Simon's Game

+
+ + +
+
Score: 0
+
Level: 1
+
Mode: Classic
+
+ + +
+
+
+ +
+
+
+
+ + +
+
+
Press Start
+ + + +
+
+
+
+
+ + + + +
+

How to Play:

+ +
+
+ + + + + + + + + + + + diff --git a/SimonGame/SimonsGame/DPanvish/main.js b/SimonGame/SimonsGame/DPanvish/main.js new file mode 100644 index 000000000..bb9ffa1b0 --- /dev/null +++ b/SimonGame/SimonsGame/DPanvish/main.js @@ -0,0 +1,341 @@ +// Simple Simon's Game - Super Easy Version + +// Game variables +let sequence = []; +let playerSequence = []; +let score = 0; +let level = 1; +let isPlaying = false; +let speed = 1000; +let audioContext = null; + +// Colors +let colors = ['red', 'blue', 'green', 'yellow']; + +// Initialize game when page loads +document.addEventListener('DOMContentLoaded', function() { + setupGame(); +}); + +// Setup the game +function setupGame() { + // Setup buttons + document.getElementById('startBtn').onclick = startGame; + document.getElementById('endlessBtn').onclick = startEndlessMode; + document.getElementById('resetBtn').onclick = resetGame; + + // Setup color buttons + colors.forEach(function(color) { + document.getElementById(color).onclick = function() { + handleClick(color); + }; + }); + + // Initialize audio context on first user interaction + document.addEventListener('click', initAudio, { once: true }); + + // Setup audio volume + setVolume(0.5); // Set default volume to 50% + + updateDisplay(); +} + +// Initialize audio context +function initAudio() { + try { + audioContext = new (window.AudioContext || window.webkitAudioContext)(); + console.log('Audio initialized successfully'); + + // Set up periodic audio health check + setInterval(checkAudioHealth, 5000); // Check every 5 seconds + + } catch (error) { + console.log('Audio not supported'); + audioContext = null; + } +} + +// Check and fix audio context health +function checkAudioHealth() { + if (audioContext && audioContext.state === 'suspended') { + console.log('Audio context suspended, attempting to resume...'); + audioContext.resume().catch(function(error) { + console.log('Failed to resume audio context, recreating...'); + audioContext = null; + }); + } +} + + + +// Start classic game +function startGame() { + resetGame(); + isPlaying = true; + document.getElementById('mode').textContent = 'Classic'; + hideStartButtons(); + showPattern(); +} + +// Start endless mode +function startEndlessMode() { + resetGame(); + isPlaying = true; + document.getElementById('mode').textContent = 'Endless'; + hideStartButtons(); + showPattern(); +} + +// Reset game +function resetGame() { + sequence = []; + playerSequence = []; + score = 0; + level = 1; + isPlaying = false; + + document.getElementById('gameStatus').textContent = 'Press Start'; + showStartButtons(); + updateDisplay(); +} + +// Add new color to sequence +function addToSequence() { + let randomColor = colors[Math.floor(Math.random() * colors.length)]; + sequence.push(randomColor); +} + +// Show pattern to player +function showPattern() { + document.getElementById('gameStatus').textContent = 'Watch the pattern...'; + + // Quick audio test before showing pattern + if (audioContext && audioContext.state === 'suspended') { + audioContext.resume().then(function() { + console.log('Audio resumed before pattern'); + startPattern(); + }).catch(function() { + console.log('Audio resume failed, recreating context'); + audioContext = null; + startPattern(); + }); + } else { + startPattern(); + } + + function startPattern() { + // Add new color + addToSequence(); + + // Show each color + let i = 0; + function showNext() { + if (i < sequence.length) { + flashColor(sequence[i]); + i++; + setTimeout(showNext, speed); + } else { + // Pattern complete, player's turn + document.getElementById('gameStatus').textContent = 'Your turn!'; + playerSequence = []; + } + } + showNext(); + } +} + +// Flash a color button +function flashColor(color) { + let button = document.getElementById(color); + let soundIndex = colors.indexOf(color) + 1; + let sound = document.getElementById('sound' + soundIndex); + + // Activate button + button.classList.add('active'); + playSound(sound, color); + + // Deactivate after delay + setTimeout(function() { + button.classList.remove('active'); + }, speed / 2); +} + +// Handle player click +function handleClick(color) { + if (!isPlaying) return; + + playerSequence.push(color); + flashColor(color); + + // Check if correct + let currentIndex = playerSequence.length - 1; + if (playerSequence[currentIndex] !== sequence[currentIndex]) { + gameOver(); + return; + } + + // Check if level complete + if (playerSequence.length === sequence.length) { + levelComplete(); + } +} + +// Level complete +function levelComplete() { + score += level * 10; + level++; + + document.getElementById('gameStatus').textContent = 'Level Complete!'; + updateDisplay(); + + // Continue to next level + setTimeout(function() { + if (isPlaying) { + showPattern(); + } + }, 1000); +} + +// Game over +function gameOver() { + isPlaying = false; + + // Play game over sound + let gameOverSound = document.getElementById('gameOverSound'); + playSound(gameOverSound, 'gameOver'); + + // Show final score + document.getElementById('gameStatus').textContent = 'Game Over! Score: ' + score; + showStartButtons(); + + // Show alert + setTimeout(function() { + alert('Game Over!\n\nFinal Score: ' + score + '\nLevel Reached: ' + (level - 1) + '\n\nGreat job! Try again!'); + }, 500); +} + +// Play sound with fallback +function playSound(audio, color) { + // Always try to play tone first (more reliable) + playColorTone(color); + + // Also try to play audio file if available + if (audio && audio.src) { + audio.currentTime = 0; + audio.volume = 0.3; // Lower volume so it doesn't conflict with tone + audio.play().catch(function(e) { + // Ignore errors - tone is already playing + }); + } +} + +// Play different tones for each color +function playColorTone(color) { + // Make sure audio context is initialized and working + if (!audioContext || audioContext.state === 'closed') { + try { + audioContext = new (window.AudioContext || window.webkitAudioContext)(); + console.log('Audio context recreated'); + } catch (error) { + console.log('Audio not supported'); + return; + } + } + + try { + // Resume audio context if it's suspended + if (audioContext.state === 'suspended') { + audioContext.resume().then(function() { + console.log('Audio context resumed'); + playTone(color); + }).catch(function(error) { + console.log('Failed to resume audio context:', error); + // Try to recreate audio context + audioContext = null; + playColorTone(color); + }); + return; + } + + playTone(color); + + } catch (error) { + console.log('Error in playColorTone:', error); + // Try to recreate audio context + audioContext = null; + playColorTone(color); + } +} + +// Helper function to actually play the tone +function playTone(color) { + try { + let oscillator = audioContext.createOscillator(); + let gainNode = audioContext.createGain(); + + // Connect nodes + oscillator.connect(gainNode); + gainNode.connect(audioContext.destination); + + // Set different frequency for each color + let frequency = 440; // Default + switch(color) { + case 'red': frequency = 523; break; // C note + case 'blue': frequency = 587; break; // D note + case 'green': frequency = 659; break; // E note + case 'yellow': frequency = 698; break; // F note + default: frequency = 220; break; // Low A (for game over) + } + + oscillator.frequency.setValueAtTime(frequency, audioContext.currentTime); + oscillator.type = 'sine'; + + // Set volume and fade out + gainNode.gain.setValueAtTime(0.5, audioContext.currentTime); + gainNode.gain.exponentialRampToValueAtTime(0.01, audioContext.currentTime + 0.3); + + // Play sound + oscillator.start(audioContext.currentTime); + oscillator.stop(audioContext.currentTime + 0.3); + + console.log('Playing ' + color + ' tone at ' + frequency + 'Hz'); + + } catch (error) { + console.log('Error playing tone:', error); + } +} + +// Set volume +function setVolume(volume) { + colors.forEach(function(color, index) { + let audio = document.getElementById('sound' + (index + 1)); + if (audio) { + audio.volume = volume; + } + }); + + let gameOverSound = document.getElementById('gameOverSound'); + if (gameOverSound) { + gameOverSound.volume = volume; + } +} + +// Update display +function updateDisplay() { + document.getElementById('score').textContent = score; + document.getElementById('level').textContent = level; +} + +// Hide start buttons +function hideStartButtons() { + document.getElementById('startBtn').style.display = 'none'; + document.getElementById('endlessBtn').style.display = 'none'; + document.getElementById('resetBtn').style.display = 'inline-block'; +} + +// Show start buttons +function showStartButtons() { + document.getElementById('startBtn').style.display = 'inline-block'; + document.getElementById('endlessBtn').style.display = 'inline-block'; + document.getElementById('resetBtn').style.display = 'none'; +} diff --git a/SimonGame/SimonsGame/DPanvish/style.css b/SimonGame/SimonsGame/DPanvish/style.css new file mode 100644 index 000000000..c12926722 --- /dev/null +++ b/SimonGame/SimonsGame/DPanvish/style.css @@ -0,0 +1,321 @@ +/* Modern Simon's Game Styles */ + +/* Reset default styles */ +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +/* Main page layout */ +body { + font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; + background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); + min-height: 100vh; + display: flex; + justify-content: center; + align-items: center; + color: #333; + padding: 20px; +} + +.container { + max-width: 900px; + width: 100%; + background: rgba(255, 255, 255, 0.1); + backdrop-filter: blur(10px); + border-radius: 25px; + padding: 30px; + box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1); + border: 1px solid rgba(255, 255, 255, 0.2); +} + +/* Header */ +header { + text-align: center; + margin-bottom: 30px; +} + +header h1 { + font-size: 3.5rem; + color: white; + text-shadow: 2px 2px 4px rgba(0,0,0,0.3); + margin-bottom: 20px; + font-weight: 700; + letter-spacing: 2px; +} + +/* Game info display */ +.game-info { + display: flex; + justify-content: space-around; + background: rgba(255,255,255,0.95); + padding: 20px; + border-radius: 20px; + box-shadow: 0 8px 25px rgba(0,0,0,0.1); + margin-bottom: 30px; + font-size: 1.3rem; + font-weight: 600; + border: 2px solid rgba(255,255,255,0.3); +} + +.game-info > div { + text-align: center; + padding: 10px 20px; + border-radius: 15px; + background: linear-gradient(135deg, #667eea, #764ba2); + color: white; + min-width: 120px; + box-shadow: 0 4px 15px rgba(0,0,0,0.1); +} + +.game-info span { + display: block; + font-size: 1.8rem; + font-weight: 700; + margin-top: 5px; +} + +/* Game board */ +.game-board { + display: flex; + justify-content: center; + margin-bottom: 30px; +} + +.simon-container { + width: 450px; + height: 450px; + position: relative; +} + +.simon-circle { + width: 100%; + height: 100%; + border-radius: 50%; + background: #2c3e50; + box-shadow: 0 15px 35px rgba(0,0,0,0.3); + overflow: hidden; + position: relative; + border: 8px solid #34495e; +} + +/* Color buttons */ +.color-button { + position: absolute; + width: 50%; + height: 50%; + cursor: pointer; + transition: all 0.2s ease; + border: 4px solid #2c3e50; + opacity: 0.8; +} + +.color-button:hover { + transform: scale(1.02); + opacity: 1; + box-shadow: 0 0 20px rgba(255,255,255,0.3); +} + +.color-button.active { + opacity: 1; + transform: scale(1.05); + box-shadow: 0 0 30px rgba(255,255,255,0.8); + filter: brightness(1.3); +} + +/* Button positions and colors */ +.color-button.red { + top: 0; + left: 0; + background: linear-gradient(45deg, #e74c3c, #c0392b); + border-radius: 100% 0 0 0; +} + +.color-button.blue { + top: 0; + right: 0; + background: linear-gradient(45deg, #3498db, #2980b9); + border-radius: 0 100% 0 0; +} + +.color-button.green { + bottom: 0; + left: 0; + background: linear-gradient(45deg, #2ecc71, #27ae60); + border-radius: 0 0 0 100%; +} + +.color-button.yellow { + bottom: 0; + right: 0; + background: linear-gradient(45deg, #f1c40f, #f39c12); + border-radius: 0 0 100% 0; +} + +/* Center control panel */ +.center-circle { + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + width: 140px; + height: 140px; + background: linear-gradient(135deg, #ecf0f1, #bdc3c7); + border-radius: 50%; + display: flex; + justify-content: center; + align-items: center; + box-shadow: inset 0 8px 20px rgba(0,0,0,0.1); + border: 6px solid #34495e; +} + +.center-content { + text-align: center; + width: 100%; + padding: 10px; +} + +.game-status { + font-size: 1rem; + font-weight: 600; + color: #2c3e50; + margin-bottom: 15px; + min-height: 25px; + text-shadow: 1px 1px 2px rgba(0,0,0,0.1); +} + +/* Buttons */ +.start-btn, .endless-btn, .reset-btn { + background: linear-gradient(45deg, #667eea, #764ba2); + color: white; + border: none; + padding: 10px 18px; + border-radius: 25px; + cursor: pointer; + font-size: 0.9rem; + font-weight: 600; + margin: 3px; + transition: all 0.3s ease; + box-shadow: 0 4px 15px rgba(0,0,0,0.2); + text-transform: uppercase; + letter-spacing: 1px; +} + +.start-btn:hover, .endless-btn:hover, .reset-btn:hover { + transform: translateY(-3px); + box-shadow: 0 8px 25px rgba(0,0,0,0.3); +} + +.endless-btn { + background: linear-gradient(45deg, #f39c12, #e67e22); +} + +.reset-btn { + background: linear-gradient(45deg, #e74c3c, #c0392b); +} + + + +/* Instructions */ +.instructions { + background: rgba(255,255,255,0.95); + padding: 25px; + border-radius: 20px; + box-shadow: 0 8px 25px rgba(0,0,0,0.1); + border: 2px solid rgba(255,255,255,0.3); +} + +.instructions h3 { + color: #2c3e50; + margin-bottom: 20px; + font-size: 1.5rem; + font-weight: 600; + text-align: center; +} + +.instructions ul { + list-style-type: none; + padding-left: 0; +} + +.instructions li { + margin-bottom: 12px; + padding-left: 25px; + position: relative; + line-height: 1.6; + font-size: 1.1rem; + color: #34495e; +} + +.instructions li:before { + content: "▶"; + color: #667eea; + font-weight: bold; + position: absolute; + left: 0; + font-size: 0.9rem; +} + +.instructions li:last-child { + margin-bottom: 0; +} + +/* Mobile responsive */ +@media (max-width: 768px) { + body { + padding: 10px; + } + + .container { + padding: 20px; + } + + header h1 { + font-size: 2.5rem; + } + + .simon-container { + width: 320px; + height: 320px; + } + + .center-circle { + width: 110px; + height: 110px; + } + + .game-info { + flex-direction: column; + gap: 10px; + } + + .game-info > div { + min-width: auto; + } +} + +@media (max-width: 480px) { + .simon-container { + width: 280px; + height: 280px; + } + + .center-circle { + width: 90px; + height: 90px; + } + + .game-status { + font-size: 0.9rem; + } + + .start-btn, .endless-btn, .reset-btn { + font-size: 0.8rem; + padding: 8px 14px; + } + + header h1 { + font-size: 2rem; + } +}