Skip to content

Commit

Permalink
Merge pull request #1047 from pallasivasai/city890
Browse files Browse the repository at this point in the history
City_Builder_Game is added
  • Loading branch information
Durgesh4993 authored Jul 2, 2024
2 parents 6b4aa69 + 0fb0105 commit 75b8113
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 8 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,17 @@ ________________________________________________________________________________
| 188 | [Cubula_Game](.SinglePlayer%20-%20Games/Cubula_Game) |
| 189 | [Ball_Shooting_Game](.SinglePlayer%20-%20Games/Ball_Shooting_Game) |
| 190 | [Baseball_Game](.SinglePlayer%20-%20Games/Baseball_Game) |
| 191 | [Hand_Cricket_Champ](./SinglePlayer%20-%20Games/Hand_Cricket_Champ) |
| 192 | [Pop My Balloon](<MultiPlayer - Games/Pop_My_Balloon>) |
| 193 | [Doraemon Run](.SinglePlayer%20-%20Games/DoraemonRun) |
| 194 | [Earth_Guardian](./SinglePlayer%20-%20Games/Earth_Guardian) |
| 195 | [Hand_Cricket_Champ](./SinglePlayer%20-%20Games/Hand_Cricket_Champ) |
| 196 | [SnakeBites Game](./SinglePlayer%20-%20Games/SnakeBites) |
| 197 | [Flames_Game](../MultiPlayer%20-%20Games/Flames_Game) |
| 198 | [Ball_Fall_Game](.SinglePlayer%20-%20Games/Ball_Fall_Game) |
| 191 | [Doraemon Run](.SinglePlayer%20-%20Games/DoraemonRun) |
| 192 | [Hand_Cricket_Champ](./SinglePlayer%20-%20Games/Hand_Cricket_Champ) |
| 193 | [SnakeBites Game](./SinglePlayer%20-%20Games/SnakeBites) |
| 194 | [Pop My Balloon](<MultiPlayer - Games/Pop_My_Balloon>) |
| 196 | [Doraemon Run](.SinglePlayer%20-%20Games/DoraemonRun) |
| 197 | [Earth_Guardian](./SinglePlayer%20-%20Games/Earth_Guardian) |
| 198 | [Flames_Game](../MultiPlayer%20-%20Games/Flames_Game) |
| 199 | [Ball_Fall_Game](.SinglePlayer%20-%20Games/Ball_Fall_Game) |
| 200 | [City_Builder_Game](.SinglePlayer%20-%20Games/City_Builder_Game) |





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

This is a simple City Builder game where players can place different types of buildings on a grid to manage their money and the city's happiness. The game is built using HTML, CSS, and JavaScript.

## How to Play

1. **Choose a Building**: Select a building type by clicking one of the buttons (Place House, Place Factory, Place Park).
2. **Place a Building**: Click on a cell in the grid to place the selected building.
3. **Manage Resources**: Placing buildings will affect your money and the city's happiness. Ensure you have enough money to place a building and maintain a positive happiness score.

## Project Structure

The project consists of the following files:

- `index.html`: The main HTML file that contains the structure of the game.
- `styles.css`: The CSS file that styles the game.
- `script.js`: The JavaScript file that contains the game logic.

## Setup and Installation

1. Clone the repository or download the project files.
2. Open `index.html` in your web browser to start the game.

## Gameplay
Place House: Costs 100 money, increases happiness by 10, and is displayed in green.
Place Factory: Costs 200 money, decreases happiness by 20, and is displayed in gray.
Place Park: Costs 150 money, increases happiness by 20, and is displayed in light green.
24 changes: 24 additions & 0 deletions SinglePlayer - Games/City_Builder_Game/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>City Builder Game</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div id="gameContainer">
<div id="gameBoard"></div>
<div id="controls">
<button id="placeHouse">Place House</button>
<button id="placeFactory">Place Factory</button>
<button id="placePark">Place Park</button>
<div id="info">
<p>Money: <span id="money">1000</span></p>
<p>Happiness: <span id="happiness">100</span></p>
</div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
55 changes: 55 additions & 0 deletions SinglePlayer - Games/City_Builder_Game/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// script.js
const gameBoard = document.getElementById('gameBoard');
const moneyElement = document.getElementById('money');
const happinessElement = document.getElementById('happiness');

const buildings = {
house: { cost: 100, happiness: 10, color: 'green' },
factory: { cost: 200, happiness: -20, color: 'gray' },
park: { cost: 150, happiness: 20, color: 'lightgreen' }
};

let currentBuilding = null;
let money = 1000;
let happiness = 100;

// Create the game board
for (let i = 0; i < 100; i++) {
const cell = document.createElement('div');
cell.addEventListener('click', () => placeBuilding(cell));
gameBoard.appendChild(cell);
}

// Update money and happiness display
function updateInfo() {
moneyElement.textContent = money;
happinessElement.textContent = happiness;
}

// Place a building on the selected cell
function placeBuilding(cell) {
if (currentBuilding && cell.style.backgroundColor === '') {
const building = buildings[currentBuilding];
if (money >= building.cost) {
cell.style.backgroundColor = building.color;
money -= building.cost;
happiness += building.happiness;
updateInfo();
} else {
alert('Not enough money to place this building!');
}
}
}

// Button event listeners
document.getElementById('placeHouse').addEventListener('click', () => {
currentBuilding = 'house';
});
document.getElementById('placeFactory').addEventListener('click', () => {
currentBuilding = 'factory';
});
document.getElementById('placePark').addEventListener('click', () => {
currentBuilding = 'park';
});

updateInfo();
56 changes: 56 additions & 0 deletions SinglePlayer - Games/City_Builder_Game/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* styles.css */
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background: #f0f0f0;
margin: 0;
font-family: Arial, sans-serif;
}

#gameContainer {
display: flex;
flex-direction: column;
align-items: center;
}

#gameBoard {
display: grid;
grid-template-columns: repeat(10, 40px);
grid-template-rows: repeat(10, 40px);
gap: 2px;
margin-bottom: 20px;
}

#gameBoard div {
width: 40px;
height: 40px;
background: #e0e0e0;
border: 1px solid #ccc;
display: flex;
justify-content: center;
align-items: center;
}

#controls {
display: flex;
justify-content: space-around;
width: 100%;
}

button {
padding: 10px;
margin: 0 10px;
cursor: pointer;
}

#info {
display: flex;
flex-direction: column;
align-items: center;
}

#info p {
margin: 5px 0;
}
57 changes: 57 additions & 0 deletions additionalpage/game.html
Original file line number Diff line number Diff line change
Expand Up @@ -7502,6 +7502,63 @@ <h4 class = "text-white uppercase game-card-title">Ball_Fall_Game</h4>



<!--Card start-->
<div class = "game-card">
<div class = "game-card-top img-fit-cover">
<video src="https://drive.google.com/file/d/1BAR4uZ4855mGb1XnESEWKF33HYDY9_2S/view?usp=drive_link" link " type="video/mp4" muted loop class="clip" ></video>
<img src = "../SinglePlayer - Games/Banner - images/City_Builder_Game.png" alt = "">
<div class = "ratings-count">
45
<img src = "../SinglePlayer - Games/Banner - images/City_Builder_Game.png" alt = "" class = "ms-2">
</div>
</div>
<div class = "game-card-bottom">
<div class="share-icon text-2xl" onclick="copyLink(this)">
<i class="fas fa-share-alt"></i>
<input type="hidden"
value="https://gamesphere-multiplayer.github.io/GameSphere/SinglePlayer%20-%20Games/City_Builder_Game/index.html" />
<!--If there are spaces in your naming of folder, put %20 in between, ex:
link%20to%20the%html%file%20for%your&game-->

<!--The share link will be active only when it is deployed over website-->
</div>

<div class = "flex flex-col sm:flex-row justify-between items-start flex-wrap">
<div class = "py-1">
<h4 class = "text-white uppercase game-card-title">City_Builder_Game</h4>
<p class = "para-text">City_Builder_Game</p>
</div>
<div class = "star-rating mt-2 sm:mt-0 py-1">
<img src = "../assets/icons/star-green.svg">
<img src = "../assets/icons/star-green.svg">
<img src = "../assets/icons/star-green.svg">
<img src = "../assets/icons/star-green.svg">
<img src = "../assets/icons/star-green-half.svg">
</div>
</div>
<div class = "block-wrap flex justify-between items-end">
<div class = "details-group">
<div class = "flex items-center">
<p class = "font-semibold">Release Date: &nbsp;</p>
<p>20.06.2023</p>
</div>
<div class = "flex items-center">
<p class = "font-semibold">Updated: &nbsp;</p>
<p>Action | Desktop</p>
</div>
</div>
<div class = "flex flex-col items-end justify-between">
<a target="_blank" href = "../SinglePlayer - Games/City_Builder_Game/index.html" class = "btn-primary uppercase">Play Now</a>
</div>
</div>
</div>
</div>
<!--Card end-->





<!--Card start-->
<div class="game-card">
<div class="game-card-top img-fit-cover">
Expand Down

0 comments on commit 75b8113

Please sign in to comment.