-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 26ee59e
Showing
35 changed files
with
1,567 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
[ | ||
{ | ||
"name": "Bowling Game", | ||
"description": "Enjoy a classic game of bowling with friends and family!", | ||
"type": "Physical", | ||
"minimumAge": 10, | ||
"pricing": { | ||
"hourly": "$25.00", | ||
"perGame": "$5.00" | ||
}, | ||
"image": { | ||
"description": "Bowling alley with pins and colorful lights.", | ||
"path":"images/bowling-image.jpg" | ||
} | ||
}, | ||
{ | ||
"name": "Arcade Basketball", | ||
"description": "Test your basketball skills and aim for the high score!", | ||
"type": "Physical", | ||
"minimumAge": 10, | ||
"pricing": { | ||
"hourly": "$25.00", | ||
"perGame": "$5.00" | ||
}, | ||
"image": { | ||
"description": "Arcade basketball hoop with colorful balls.", | ||
"path": "images/arcade-basketball.jpg" | ||
} | ||
}, | ||
{ | ||
"name": "Air Hockey", | ||
"description": "Fast-paced fun with air hockey. Defeat your opponents!", | ||
"type": "Table Game", | ||
"minimumAge": 10, | ||
"pricing": { | ||
"hourly": "$25.00", | ||
"perGame": "$5.00" | ||
}, | ||
"image": { | ||
"description": "Air hockey table with paddles and puck.", | ||
"path": "images/air-hockey.jpg" | ||
} | ||
}, | ||
{ | ||
"name": "Virtual Reality Racing", | ||
"description": "Experience the thrill of high-speed racing in virtual reality!", | ||
"type": "Virtual Reality", | ||
"minimumAge": 10, | ||
"pricing": { | ||
"hourly": "$25.00", | ||
"perGame": "$5.00" | ||
}, | ||
"image": { | ||
"description": "Virtual reality racing simulator with immersive graphics.", | ||
"path": "images/VR-racing.jpg" | ||
} | ||
}, | ||
{ | ||
"name": "Classic Pinball", | ||
"description": "Play vintage pinball machines and relive the nostalgia!", | ||
"type": "Physical", | ||
"minimumAge": 12, | ||
"pricing": { | ||
"hourly": "$20.00", | ||
"perGame": "$4.00" | ||
}, | ||
"image": { | ||
"description": "Classic pinball machine with vibrant artwork.", | ||
"path": "images/Pinball.jpg" } | ||
}, | ||
{ | ||
"name": "Laser Tag", | ||
"description": "Experience the thrill of high-tech laser tag battles with your friends!", | ||
"type": "Interactive", | ||
"minimumAge": 8, | ||
"pricing": { | ||
"hourly": "$25.00", | ||
"perGame": "$6.50" | ||
}, | ||
"image": { | ||
"description": "Laser tag arena with neon lights and futuristic obstacles.", | ||
"path": "images/laser-tag.jpg" | ||
} | ||
}, | ||
{ | ||
"name": "Virtual Reality Roller Coaster", | ||
"description": "Ride the wildest virtual reality roller coaster and experience adrenaline like never before!", | ||
"type": "Virtual Reality", | ||
"minimumAge": 12, | ||
"pricing": { | ||
"hourly": "$28.00", | ||
"perGame": "$5.75" | ||
}, | ||
"image": { | ||
"description": "Virtual reality roller coaster simulation with twists and turns.", | ||
"path": "images/vr-roller-coaster.jpg" | ||
} | ||
}, | ||
{ | ||
"name": "Skee-Ball", | ||
"description": "Roll the balls and aim for the target holes in this classic Skee-Ball game!", | ||
"type": "Physical", | ||
"minimumAge": 6, | ||
"pricing": { | ||
"hourly": "$16.00", | ||
"perGame": "$2.25" | ||
}, | ||
"image": { | ||
"description": "Skee-Ball lanes with rolling balls and scoring holes.", | ||
"path": "images/skee-ball.jpg" | ||
} | ||
} | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
const express = require('express'); | ||
const { MongoClient, ObjectId } = require('mongodb'); | ||
const app = express(); | ||
const port = 3000; | ||
const methodOverride = require('method-override'); | ||
const bodyParser = require('body-parser'); | ||
|
||
// MongoDB setup | ||
const url = 'mongodb://localhost:27017'; | ||
const client = new MongoClient(url); | ||
let db; | ||
|
||
async function connectDB() { | ||
try { | ||
await client.connect(); | ||
console.log("Connected to MongoDB"); | ||
db = client.db('Arcade'); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
connectDB(); | ||
|
||
app.set('view engine', 'ejs'); | ||
app.use(express.static('public')); | ||
app.use(methodOverride('_method')); | ||
app.use(bodyParser.urlencoded({ extended: true })); | ||
|
||
// Redirect | ||
app.get('/', (req, res) => { | ||
res.redirect('/games'); | ||
}); | ||
|
||
// Route for listing games | ||
app.get('/games', async (req, res) => { | ||
let query = {}; | ||
if (req.query.title) { | ||
query.name = { $regex: new RegExp(req.query.title, 'i') }; // Case-insensitive partial search | ||
} | ||
if (req.query.type && req.query.type !== 'No filter') { | ||
query.type = req.query.type; | ||
} | ||
|
||
try { | ||
const games = await db.collection('ArcadeGames').find(query).toArray(); | ||
const types = await db.collection('ArcadeGames').distinct('type'); // Get all distinct types for the dropdown | ||
res.render('games', { games, types }); | ||
} catch (e) { | ||
res.status(500).send("Error fetching games: " + e.message); | ||
} | ||
}); | ||
|
||
// Add new games | ||
app.get('/games/new', (req, res) => { | ||
res.render('newGame'); // This should point to a 'newGame.ejs' form without needing an ID | ||
}); | ||
|
||
// Route for add new games | ||
app.post('/games', async (req, res) => { | ||
try { | ||
await db.collection('ArcadeGames').insertOne({ | ||
name: req.body.title, | ||
description: req.body.description, | ||
type: req.body.type, | ||
minimumAge: req.body.minimumAge, | ||
pricing: { | ||
hourly: req.body.pricingHourly, | ||
perGame: req.body.pricingPerGame | ||
}, | ||
image: { | ||
path: req.body.imagePath, | ||
description: req.body.imageAlt | ||
} | ||
}); | ||
res.redirect('/games'); | ||
} catch (e) { | ||
res.status(500).send("Error creating new game: " + e.message); | ||
} | ||
}); | ||
|
||
// Route for game detail | ||
app.get('/games/:id', async (req, res) => { | ||
try { | ||
const gameId = new ObjectId(req.params.id); | ||
const game = await db.collection('ArcadeGames').findOne({ _id: gameId }); | ||
|
||
if (!game) { | ||
return res.status(404).send("Game not found"); | ||
} | ||
|
||
res.render('gameDetails', { game }); | ||
} catch (e) { | ||
res.status(500).send("Error fetching game details: " + e.message); | ||
} | ||
}); | ||
|
||
// Route to show the edit form | ||
app.get('/games/:id/edit', async (req, res) => { | ||
try { | ||
const game = await db.collection('ArcadeGames').findOne({ _id: new ObjectId(req.params.id) }); | ||
if (!game) { | ||
return res.status(404).send("Game not found"); | ||
} | ||
res.render('editGame', { game }); | ||
} catch (e) { | ||
res.status(500).send("Error showing edit form: " + e.message); | ||
} | ||
}); | ||
|
||
// Route to update the game details | ||
app.put('/games/:id', async (req, res) => { | ||
try { | ||
const gameId = new ObjectId(req.params.id); | ||
await db.collection('ArcadeGames').updateOne( | ||
{ _id: gameId }, | ||
{ $set: { | ||
name: req.body.title, | ||
description: req.body.description, | ||
type: req.body.type, | ||
minimumAge: req.body.minimumAge, | ||
pricing: { | ||
hourly: req.body.pricingHourly, | ||
perGame: req.body.pricingPerGame | ||
}, | ||
image: { | ||
path: req.body.imagePath, | ||
description: req.body.imageAlt | ||
} | ||
}} | ||
); | ||
res.redirect('/games/' + req.params.id); // Redirect to the updated game details page | ||
} catch (e) { | ||
res.status(500).send("Error updating game: " + e.message); | ||
} | ||
}); | ||
|
||
// Route to handle the DELETE request | ||
app.delete('/games/:id', async (req, res) => { | ||
try { | ||
await db.collection('ArcadeGames').deleteOne({ _id: new ObjectId(req.params.id) }); | ||
res.redirect('/games'); | ||
} catch (e) { | ||
res.status(500).send("Error deleting game: " + e.message); | ||
} | ||
}); | ||
|
||
|
||
app.listen(port, () => { | ||
console.log(`Server running on http://localhost:${port}`); | ||
}); |
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.
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.
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.
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.
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.
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.
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.
Oops, something went wrong.