Embezzle/index.js

81 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-02-15 23:22:09 +00:00
const lobby = require("./lobby.js")
2020-02-15 10:01:01 +00:00
const express = require('express')
2020-02-15 14:59:27 +00:00
const bodyParser = require('body-parser');
2020-02-15 10:01:01 +00:00
const app = express()
2020-02-15 23:22:09 +00:00
app.use(bodyParser.json(),function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE')
res.setHeader('Access-Control-Allow-Headers', 'Content-Type')
res.setHeader('Access-Control-Allow-Credentials', true)
next()
})
2020-02-15 10:01:01 +00:00
//top level
//get game list
2020-02-15 23:22:09 +00:00
app.get('/lobby/list' , async function (req, res) {
lobby.list().then(r => {
console.log(r)
2020-02-16 08:53:52 +00:00
res.send(JSON.stringify({gamesArr: r }))
2020-02-15 23:22:09 +00:00
})
2020-02-15 14:59:27 +00:00
})
2020-02-15 23:22:09 +00:00
2020-02-15 10:01:01 +00:00
//get game details
2020-02-16 08:53:52 +00:00
app.get('/lobby/details/:gameID', function (req, res) {
2020-02-15 23:22:09 +00:00
let obj=req.body
2020-02-16 08:53:52 +00:00
lobby.details(obj.gameID).then(r => {
res.send(JSON.stringify(r))
})
2020-02-15 14:59:27 +00:00
})
2020-02-15 23:22:09 +00:00
2020-02-15 10:01:01 +00:00
//post register player
2020-02-15 23:22:09 +00:00
app.post('/lobby/register', function (req, res) {
2020-02-15 14:59:27 +00:00
let obj=req.body
2020-02-15 23:22:09 +00:00
console.log(req.body)
response=JSON.stringify(lobby.register(obj.name))
res.send(response)
2020-02-15 14:59:27 +00:00
})
2020-02-15 23:22:09 +00:00
//post join an existing game
app.post('/lobby/join', function (req, res) {
let obj=req.body
response=JSON.stringify(lobby.join(obj.ownerID,obj.gameID))
res.send(response)
})
2020-02-15 10:01:01 +00:00
//get an empty game made
2020-02-15 23:22:09 +00:00
app.post('/lobby/make', function (req, res) {
let obj=req.body
response=JSON.stringify(lobby.make(obj.ownerID,obj.seats))
res.send(response)
2020-02-15 14:59:27 +00:00
})
2020-02-15 10:01:01 +00:00
2020-02-15 23:22:09 +00:00
//start a game
app.post('/lobby/start', function (req, res) {
let obj=req.body
response=JSON.stringify(lobby.start(obj.ownerID, obj.gameID))
res.send(response)
})
2020-02-15 14:59:27 +00:00
//gamelevel (??)
2020-02-15 10:01:01 +00:00
// get this game players
// get charity details
// get board funding details (how much money team has to work with)
// post distribution
// post accusation
// get winner
2020-02-15 14:59:27 +00:00
// get round status
2020-02-15 10:01:01 +00:00
2020-02-15 14:59:27 +00:00
console.log("Up")
2020-02-15 10:01:01 +00:00
app.listen(3000)