|
| 1 | +# Rock Paper Scissors Game |
| 2 | + |
| 3 | +A classic Rock Paper Scissors game built with HTML, CSS, and JavaScript that demonstrates randomization, event handling, DOM manipulation, and game logic concepts. |
| 4 | + |
| 5 | +## 🎮 Features |
| 6 | + |
| 7 | +**Core Gameplay:** |
| 8 | +- ✅ Choose between Rock, Paper, or Scissors |
| 9 | +- ✅ Computer randomly selects its move |
| 10 | +- ✅ Real-time winner determination for each round |
| 11 | +- ✅ Live score tracking (You vs Computer) |
| 12 | +- ✅ Visual feedback with choice animations |
| 13 | + |
| 14 | +**Bonus Features:** |
| 15 | +- ✅ **Smooth animations** - Button selections and choice displays |
| 16 | +- ✅ **Reset functionality** - Restart the game at any time |
| 17 | +- ✅ **Round history** - View past 10 rounds with results |
| 18 | +- ✅ **Responsive design** - Works perfectly on all devices |
| 19 | +- ✅ **Keyboard support** - Press R, P, or S keys to play |
| 20 | +- ✅ **Modern UI** - Beautiful gradient design with glass morphism |
| 21 | + |
| 22 | +## 🛠 Technologies Demonstrated |
| 23 | + |
| 24 | +**JavaScript Concepts:** |
| 25 | +- **Randomization** - `Math.random()` for computer choice generation |
| 26 | +- **Conditional Logic** - Winner determination using if/else statements |
| 27 | +- **Event Listeners** - Click handlers for game buttons |
| 28 | +- **DOM Manipulation** - Dynamic updates to scores, choices, and history |
| 29 | +- **Array Methods** - Managing game history and choices |
| 30 | +- **ES6 Classes** - Object-oriented game structure |
| 31 | + |
| 32 | +**CSS Concepts:** |
| 33 | +- **Responsive Design** - Mobile-first approach with media queries |
| 34 | +- **CSS Grid & Flexbox** - Layout management |
| 35 | +- **Animations** - `@keyframes` for smooth transitions |
| 36 | +- **Modern Styling** - Gradients, backdrop-filter, and shadows |
| 37 | + |
| 38 | +## 📁 Project Structure |
| 39 | + |
| 40 | +``` |
| 41 | +Rock-Paper-Scissors/ |
| 42 | +├── index.html # Game interface and structure |
| 43 | +├── styles.css # Styling and animations |
| 44 | +└── script.js # Game logic and functionality |
| 45 | +``` |
| 46 | + |
| 47 | +## 🎯 How to Play |
| 48 | + |
| 49 | +1. **Make your move** by clicking one of the three buttons: |
| 50 | + - 🪨 **Rock** - Press R key |
| 51 | + - 📄 **Paper** - Press P key |
| 52 | + - ✂️ **Scissors** - Press S key |
| 53 | + |
| 54 | +2. **Computer makes its move** automatically using random selection |
| 55 | + |
| 56 | +3. **Winner is determined** based on classic rules: |
| 57 | + - Rock beats Scissors |
| 58 | + - Paper beats Rock |
| 59 | + - Scissors beats Paper |
| 60 | + - Same choices = Tie |
| 61 | + |
| 62 | +4. **Score updates** and round is added to history |
| 63 | + |
| 64 | +5. **Play again** or click "Reset Game" to start over |
| 65 | + |
| 66 | +## 🔧 Game Rules Implementation |
| 67 | + |
| 68 | +```javascript |
| 69 | +determineWinner(player, computer) { |
| 70 | + if (player === computer) { |
| 71 | + return 'tie'; |
| 72 | + } |
| 73 | + |
| 74 | + const winConditions = { |
| 75 | + rock: 'scissors', |
| 76 | + paper: 'rock', |
| 77 | + scissors: 'paper' |
| 78 | + }; |
| 79 | + |
| 80 | + return winConditions[player] === computer ? 'win' : 'lose'; |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +## 🎨 Key Features Explained |
| 85 | + |
| 86 | +### Random Computer Choice |
| 87 | +```javascript |
| 88 | +getComputerChoice() { |
| 89 | + const randomIndex = Math.floor(Math.random() * this.choices.length); |
| 90 | + return this.choices[randomIndex]; |
| 91 | +} |
| 92 | +``` |
| 93 | + |
| 94 | +### Score Tracking |
| 95 | +- Player and computer scores update in real-time |
| 96 | +- Visual feedback with scaling animations |
| 97 | +- Persistent throughout the game session |
| 98 | + |
| 99 | +### Round History |
| 100 | +- Stores last 10 rounds with full details |
| 101 | +- Color-coded results (green=win, red=lose, gray=tie) |
| 102 | +- Scrollable interface for reviewing past games |
| 103 | + |
| 104 | +### Animations |
| 105 | +- Button selection animations with `pulse` effect |
| 106 | +- Shake animation for choice reveals |
| 107 | +- Smooth score updates with scale transforms |
| 108 | + |
| 109 | +## 🎯 Learning Outcomes |
| 110 | + |
| 111 | +After studying this example, you'll understand: |
| 112 | + |
| 113 | +**JavaScript Fundamentals:** |
| 114 | +- Random number generation and array manipulation |
| 115 | +- Event-driven programming with click handlers |
| 116 | +- Conditional logic for game state management |
| 117 | +- DOM manipulation for dynamic content updates |
| 118 | +- ES6 class structure and methods |
| 119 | + |
| 120 | +**CSS Techniques:** |
| 121 | +- Responsive design with media queries |
| 122 | +- CSS animations and transitions |
| 123 | +- Modern styling with gradients and effects |
| 124 | +- Layout management with Grid and Flexbox |
| 125 | + |
| 126 | +**Game Development Concepts:** |
| 127 | +- Game state management |
| 128 | +- User interaction handling |
| 129 | +- Score tracking and persistence |
| 130 | +- Game loop implementation |
| 131 | + |
| 132 | +## 🚀 Game Strategy Tips |
| 133 | + |
| 134 | +💡 **Pattern Recognition**: The computer chooses randomly each time, so there's no pattern to exploit! |
| 135 | + |
| 136 | +💡 **Quick Play**: Use keyboard shortcuts (R, P, S) for faster gameplay |
| 137 | + |
| 138 | +💡 **Track History**: Use the round history to analyze your win/loss patterns |
| 139 | + |
| 140 | +💡 **Reset Often**: Start fresh games to practice different strategies |
| 141 | + |
| 142 | +## 📱 Responsive Design |
| 143 | + |
| 144 | +- **Desktop**: Full-width layout with side-by-side score display |
| 145 | +- **Tablet**: Optimized spacing and touch-friendly buttons |
| 146 | +- **Mobile**: Stacked layout with larger touch targets |
| 147 | + |
| 148 | +## 🔊 Sound Effects (Optional) |
| 149 | + |
| 150 | +To add sound effects: |
| 151 | +1. Add audio files (`win.mp3`, `lose.mp3`, `tie.mp3`) to the game directory |
| 152 | +2. Uncomment the `playSound()` function in `script.js` |
| 153 | +3. Customize sound playback as needed |
| 154 | + |
| 155 | +## 🎮 Browser Compatibility |
| 156 | + |
| 157 | +- ✅ Chrome (recommended) |
| 158 | +- ✅ Firefox |
| 159 | +- ✅ Safari |
| 160 | +- ✅ Edge |
| 161 | +- ✅ Mobile browsers |
| 162 | + |
| 163 | +## 🏆 Challenge Yourself |
| 164 | + |
| 165 | +Try these extensions: |
| 166 | +- Add sound effects for each action |
| 167 | +- Implement different difficulty levels |
| 168 | +- Add a tournament mode |
| 169 | +- Create player name input |
| 170 | +- Add game statistics (win percentage, streaks) |
| 171 | + |
| 172 | +--- |
| 173 | + |
| 174 | +**Happy gaming!** 🎉 |
0 commit comments