Skip to content

Commit

Permalink
Merge branch 'main' into brick49584
Browse files Browse the repository at this point in the history
  • Loading branch information
pallasivasai authored Aug 10, 2024
2 parents 1f42bc3 + 507cc3a commit ec81a43
Show file tree
Hide file tree
Showing 31 changed files with 8,326 additions and 9 deletions.
30 changes: 30 additions & 0 deletions MultiPlayer - Games/Tug of war/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tug of War Game</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<div class="scoreboard">
<div id="player1-score" class="score">Player 1: 0</div>
<div id="player2-score" class="score">Player 2: 0</div>
</div>
<div class="game-area">
<div id="rope" class="rope"></div>
<div id="marker" class="marker"></div>
</div>
<div class="instructions">
<p>Player 1: Press "A"</p>
<p>Player 2: Press "L"</p>
</div>
<div id="result" class="result"></div>
<button id="start-btn" class="btn">Start Game</button>
<button id="reset-btn" class="btn">Reset Game</button>
<div id="countdown" class="countdown"></div>
</div>
<script src="script.js"></script>
</body>
</html>
80 changes: 80 additions & 0 deletions MultiPlayer - Games/Tug of war/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
let player1Score = 0;
let player2Score = 0;
const winningScore = 10;
const scoreIncrement = 1;
const marker = document.getElementById('marker');
const result = document.getElementById('result');
const startBtn = document.getElementById('start-btn');
const resetBtn = document.getElementById('reset-btn');
const countdownEl = document.getElementById('countdown');
let gameStarted = false;

document.addEventListener('keydown', function(event) {
if (gameStarted) {
if (event.key === 'a' || event.key === 'A') {
player1Score += scoreIncrement;
updateMarker();
} else if (event.key === 'l' || event.key === 'L') {
player2Score += scoreIncrement;
updateMarker();
}
}
});

startBtn.addEventListener('click', function() {
startGame();
});

resetBtn.addEventListener('click', function() {
resetGame();
});

function startGame() {
startBtn.disabled = true;
resetBtn.disabled = true;
let countdown = 5;
countdownEl.style.display = 'block';
countdownEl.textContent = countdown;

const countdownInterval = setInterval(() => {
countdown--;
countdownEl.textContent = countdown;
if (countdown <= 0) {
clearInterval(countdownInterval);
countdownEl.style.display = 'none';
gameStarted = true;
startBtn.disabled = true;
resetBtn.disabled = false;
}
}, 1000);
}

function updateMarker() {
const totalScore = player1Score + player2Score;
const player1Ratio = player1Score / totalScore;
const newLeftPosition = 50 - (player1Ratio * 50) + (player2Score / totalScore * 50);
marker.style.left = `${newLeftPosition}%`;

document.getElementById('player1-score').textContent = `Player 1: ${player1Score}`;
document.getElementById('player2-score').textContent = `Player 2: ${player2Score}`;

if (player1Score >= winningScore) {
endGame('Player 1');
} else if (player2Score >= winningScore) {
endGame('Player 2');
}
}

function endGame(winner) {
result.textContent = `Congratulations ${winner}, you win!`;
result.style.display = 'block';
gameStarted = false;
startBtn.disabled = false;
resetBtn.disabled = true;
}

function resetGame() {
window.location.reload();
}

updateMarker();
108 changes: 108 additions & 0 deletions MultiPlayer - Games/Tug of war/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: linear-gradient(120deg, #f6d365 0%, #fda085 100%);
margin: 0;
}

.container {
text-align: center;
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
max-width: 500px;
width: 100%;
}

.scoreboard {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
}

.score {
font-size: 1.2em;
font-weight: bold;
}

.game-area {
position: relative;
height: 100px;
background: #fff3e0;
border: 2px solid #e0e0e0;
border-radius: 10px;
margin-bottom: 20px;
}

.rope {
position: absolute;
top: 50%;
left: 50%;
width: 300px;
height: 5px;
background: #d32f2f;
transform: translate(-50%, -50%);
}

.marker {
position: absolute;
top: 50%;
left: 50%;
width: 10px;
height: 10px;
background: #1976d2;
border-radius: 50%;
transform: translate(-50%, -50%);
}

.instructions {
font-size: 1em;
margin-bottom: 20px;
}

.result {
font-size: 1.5em;
font-weight: bold;
color: #388e3c;
display: none;
}

.btn {
padding: 10px 20px;
margin: 10px;
border: none;
border-radius: 5px;
background-color: #1976d2;
color: white;
cursor: pointer;
font-size: 1em;
}

.btn:hover {
background-color: #0d47a1;
}

.countdown {
font-size: 2em;
color: #d32f2f;
margin-top: 20px;
display: none;
}

@media (max-width: 600px) {
.game-area {
height: 80px;
}

.rope {
width: 200px;
}

.instructions p {
font-size: 0.9em;
}
}
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,27 @@ ________________________________________________________________________________
| 202 | [Doodling_Game](.SinglePlayer%20-%20Games/Doodling_Game) |
| 203 | [Duck_Hunt_Game](.SinglePlayer%20-%20Games/Duck_Hunt_Game) |
| 204 | [Breakout_Game](.SinglePlayer%20-%20Games/BreakOut_Game) |
| 205 | [Breakout_Game](.SinglePlayer%20-%20Games/Maze_Game) |
| 206 | [Bomber_Game](.SinglePlayer%20-%20Games/Bomber_Game) |
| 207 | [Shape_Clicker_Game](.SinglePlayer%20-%20Games/Shape_Clicker_Game) |
| 208 | [Arkanoid_Game](.SinglePlayer%20-%20Games/Arkanoid_Game) |
| 209 | [Brick_Breaker_Game](.SinglePlayer%20-%20Games/Brick_Breaker_Game) |
| 205 | [Breakout_Game](.SinglePlayer%20-%20Games/Maze_Game) |
| 206 | [Pixel Painter](.SinglePlayer%20-%20Games/Pixel%20Painter) |
| 207 | [Breakout_Game](.SinglePlayer%20-%20Games/Bomber_Game) |
| 208 | [Maze_Game](.SinglePlayer%20-%20Games/Maze_Game) |
| 209 | [Bomber_Game](.SinglePlayer%20-%20Games/Bomber_Game) |
| 210 | [Shape_Clicker_Game](.SinglePlayer%20-%20Games/Shape_Clicker_Game) |
| 211 | [Arkanoid_Game](.SinglePlayer%20-%20Games/Arkanoid_Game) |
| 212 | [Tug of War ](.SinglePlayer%20-%20Games/Tug_of_war) |
| 213 | [Shape_Clicker_Game](.SinglePlayer%20-%20Games/Shape_Clicker_Game) |
| 214 | [Shape_Clicker_Game](.SinglePlayer%20-%20Games/Shape_Clicker_Game) |
| 215 | [Arkanoid_Game](.SinglePlayer%20-%20Games/Arkanoid_Game) |
| 216 | [Breakout_Game](.SinglePlayer%20-%20Games/Maze_Game) |
| 217 | [Plankman](.SinglePlayer%20-%20Games/Plankman) |
| 218 | [Breakout_Game](.SinglePlayer%20-%20Games/Bomber_Game)
| 219 | [Bomber_Game](.SinglePlayer%20-%20Games/Bomber_Game) |
| 220 | [Shape_Clicker_Game](.SinglePlayer%20-%20Games/Shape_Clicker_Game) |
| 221 | [Arkanoid_Game](.SinglePlayer%20-%20Games/Arkanoid_Game) |
| 222 | [Brick_Breaker_Game](.SinglePlayer%20-%20Games/Brick_Breaker_Game) |
| 223 | [Bash_Mole_Game](.SinglePlayer%20-%20Games/Bash_Mole_Game) |
| 224 | [Brick_Breaker_Game](.SinglePlayer%20-%20Games/Brick_Breaker_Game) |



</div>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions SinglePlayer - Games/Bash_Mole_Game/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Bash Mole Game

This is a simple **Bash Mole Game** built using HTML, CSS, and JavaScript. The objective of the game is to click (bash) on the moles that pop up from the holes to earn points.

## How to Play

- The game lasts for 10 seconds.
- Moles will randomly pop up from the holes.
- Click on the moles to increase your score.
- Your score is displayed at the top of the page.

## Files

- `index.html`: The main HTML file that sets up the game structure.
- `style.css`: The CSS file for styling the game interface.
- `script.js`: The JavaScript file containing the game logic.

## How to Run

1. Clone or download this repository.
2. Open `index.html` in your web browser.

## Future Enhancements

- Add different levels with increasing difficulty.
- Implement a high-score tracking system.
- Add sound effects and animations for better gameplay experience.

## License

This project is open-source and available under the MIT License.
25 changes: 25 additions & 0 deletions SinglePlayer - Games/Bash_Mole_Game/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bash Mole Game</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Bash Mole Game</h1>
<p id="score">Score: 0</p>
<div class="grid">
<div class="hole" id="hole1"></div>
<div class="hole" id="hole2"></div>
<div class="hole" id="hole3"></div>
<div class="hole" id="hole4"></div>
<div class="hole" id="hole5"></div>
<div class="hole" id="hole6"></div>
<div class="hole" id="hole7"></div>
<div class="hole" id="hole8"></div>
<div class="hole" id="hole9"></div>
</div>
<script src="script.js"></script>
</body>
</html>
49 changes: 49 additions & 0 deletions SinglePlayer - Games/Bash_Mole_Game/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const holes = document.querySelectorAll('.hole');
const scoreDisplay = document.getElementById('score');
let score = 0;
let lastHole;
let timeUp = false;

function randomTime(min, max) {
return Math.round(Math.random() * (max - min) + min);
}

function randomHole(holes) {
const index = Math.floor(Math.random() * holes.length);
const hole = holes[index];
if (hole === lastHole) {
return randomHole(holes);
}
lastHole = hole;
return hole;
}

function peep() {
const time = randomTime(200, 1000);
const hole = randomHole(holes);
hole.classList.add('mole');
setTimeout(() => {
hole.classList.remove('mole');
if (!timeUp) peep();
}, time);
}

function startGame() {
scoreDisplay.textContent = 'Score: 0';
score = 0;
timeUp = false;
peep();
setTimeout(() => timeUp = true, 10000); // 10 seconds game
}

function whack(e) {
if (!e.isTrusted) return; // Prevent cheating
if (e.target.classList.contains('mole')) {
score++;
e.target.classList.remove('mole');
scoreDisplay.textContent = 'Score: ' + score;
}
}

holes.forEach(hole => hole.addEventListener('click', whack));
startGame();
Loading

0 comments on commit ec81a43

Please sign in to comment.