parent
2e5f7eafdc
commit
8708bac1a2
@ -0,0 +1,39 @@
|
||||
|
||||
var randomstring = require("randomstring");
|
||||
|
||||
function charityGen() {
|
||||
ffnames = ["Quren","Wendy","Erica","Rebecca","Tabitha","Yennifer","Ulanda","Irene","Omara","Penelope","Agne","Sarah","Diane","Febroch","Gillian","Hannah","Jessica","Karen","Laura","Zoe","Xephod","Caitlyn","Violet","Betty","Noreen","Martha"]
|
||||
mfnames = ["Qwin","William","Eric","Robert","Thomas","Yakov","Umber","Ian","Odin","Peter","Adam","Sam","Daniel","Fredrich","Geoff","Hubert","Jack","Kevin","Liam","Zack","Xaphod","Carl","Victor","Benjamin","Nathan","Mark"]
|
||||
lnames = ["Qwerner","Windburg","Eoinson","Rasputin","Thunburgler","Yankovic","Udenminster","Irason","Onglangling","Petrovic","Ainsly","Sumpworth","Donnington","Fontain","Goodly","Henderson","Jillersworth","Kurteen","Luth","Zundar","Xembi","Coats","Veloure","Bunglesworth","Nempham","Macklesmith"]
|
||||
establishments = ["Trust","Foundation","Service","Association","Fund","Philanthropic Enterprise","Centre","Endowment","Charity","Network","Service"]
|
||||
acronym = randomstring.generate({length:3,charset: 'alphabetic'}).toUpperCase()
|
||||
rand = Math.floor((Math.random() * 7) + 1)
|
||||
charityString=""
|
||||
|
||||
switch(rand) {
|
||||
|
||||
case 1 :
|
||||
charityString = "The "+ffnames[Math.floor(Math.random() * ffnames.length)]+" "+establishments[Math.floor(Math.random() * establishments.length)]
|
||||
break
|
||||
case 2:
|
||||
charityString = "The "+ffnames[Math.floor(Math.random() * ffnames.length)]+" "+ lnames[Math.floor(Math.random() * lnames.length)] +" "+establishments[Math.floor(Math.random() * establishments.length)]
|
||||
break
|
||||
case 3:
|
||||
charityString = "The "+mfnames[Math.floor(Math.random() * mfnames.length)]+" "+establishments[Math.floor(Math.random() * establishments.length)]
|
||||
break
|
||||
case 4:
|
||||
charityString = "The "+mfnames[Math.floor(Math.random() * mfnames.length)]+" "+ lnames[Math.floor(Math.random() * lnames.length)] +" "+establishments[Math.floor(Math.random() * establishments.length)]
|
||||
break
|
||||
case 5:
|
||||
charityString = "The "+lnames[Math.floor(Math.random() * lnames.length)] +" "+establishments[Math.floor(Math.random() * establishments.length)]
|
||||
break
|
||||
default:
|
||||
charityString = acronym+" "+establishments[Math.floor(Math.random() * establishments.length)]
|
||||
}
|
||||
|
||||
|
||||
return charityString
|
||||
}
|
||||
|
||||
|
||||
module.exports = charityGen
|
@ -0,0 +1,206 @@
|
||||
var mongo = require("./mongoHelp.js")
|
||||
const charityGen = require("./charitygen.js")
|
||||
const uuidv4 = require('uuid/v4')
|
||||
|
||||
function shuffle(arr) {
|
||||
var i,
|
||||
j,
|
||||
temp
|
||||
for (i = arr.length - 1; i > 0; i--) {
|
||||
j = Math.floor(Math.random() * (i + 1))
|
||||
temp = arr[i]
|
||||
arr[i] = arr[j]
|
||||
arr[j] = temp
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
|
||||
const game = {
|
||||
init: async (gameID) => {
|
||||
gameObj = await mongo.get("embezzle", "gamelist", {
|
||||
"gameID": gameID
|
||||
})
|
||||
gameObj = gameObj[0]
|
||||
//gen charities
|
||||
gameObj.charities = []
|
||||
gameObj.distributionLog = []
|
||||
gameObj.accuseLog = {}
|
||||
console.log(gameObj)
|
||||
for (let index = 0; index < gameObj.players.length; index++) {
|
||||
gameObj.charities.push({
|
||||
charityID: uuidv4(),
|
||||
name: charityGen(),
|
||||
capital: 0
|
||||
})
|
||||
}
|
||||
//assign charities to users
|
||||
gameObj.secretLink = []
|
||||
gameObj.players.forEach((element, index) => {
|
||||
charity = gameObj.charities[index]
|
||||
console.log(element)
|
||||
let link = {
|
||||
charity: charity.charityID,
|
||||
owner: element.name
|
||||
}
|
||||
gameObj.secretLink.push(link)
|
||||
})
|
||||
// Randomise the order of the arrays
|
||||
shuffle(gameObj.charities)
|
||||
//set board funds
|
||||
gameObj.players.forEach(element => {
|
||||
element.funds = 10000000
|
||||
element.status = "Employed"
|
||||
})
|
||||
//update game
|
||||
mongo.update("embezzle", "gamelist", {
|
||||
"gameID": gameID
|
||||
}, gameObj)
|
||||
|
||||
},
|
||||
myCharity: async (gameID, ownerID) => {
|
||||
name = await mongo.get("embezzle", "players", {
|
||||
"_id": ownerID
|
||||
})
|
||||
name = name[0].name
|
||||
secret = await mongo.get("embezzle", "gamelist", {
|
||||
"gameID": gameID
|
||||
})
|
||||
secret = secret[0].secretLink
|
||||
|
||||
let mine = ""
|
||||
secret.forEach(element => {
|
||||
console.log(element.owner,name)
|
||||
if (element.name == name) {
|
||||
mine = element.name
|
||||
}
|
||||
})
|
||||
|
||||
chairtyObj = {
|
||||
charity: mine
|
||||
}
|
||||
return chairtyObj
|
||||
},
|
||||
charityList: async (gameID) => {
|
||||
charArr = await mongo.get("embezzle", "gamelist", {
|
||||
"gameID": gameID
|
||||
})
|
||||
charArr = charArr[0].charities
|
||||
return ({
|
||||
charatiesArr: charArr
|
||||
})
|
||||
|
||||
},
|
||||
playerList: async (gameID) => {
|
||||
gameObj = await mongo.get("embezzle", "gamelist", {
|
||||
"gameID": gameID
|
||||
})
|
||||
players = gameObj[0].players
|
||||
return ({
|
||||
charatiesArr: players
|
||||
})
|
||||
|
||||
},
|
||||
boardFunding: async (gameID, ownerID) => {
|
||||
name = await mongo.get("embezzle", "players", {
|
||||
"_id": ownerID
|
||||
})
|
||||
name = name[0].name
|
||||
players = await mongo.get("embezzle", "gamelist", {
|
||||
"gameID": gameID
|
||||
})
|
||||
players = players[0].players
|
||||
result = ""
|
||||
players.forEach(element => {
|
||||
if (element.name == name) {
|
||||
result = name
|
||||
}
|
||||
})
|
||||
},
|
||||
distribution: async (gameID, ownerID, charityID, amount) => {
|
||||
//get the player info
|
||||
gameObj = await mongo.get("embezzle", "gamelist", {
|
||||
"gameID": gameID
|
||||
})
|
||||
gameObj = gameObj[0]
|
||||
|
||||
if (gameObj.status != "distribution") {
|
||||
return({error:"You have tried to distribute funds when it is not the distribution round"})
|
||||
}
|
||||
player = await mongo.get("embezzle", "players", {
|
||||
"_id": ownerID
|
||||
})
|
||||
player = player[0]
|
||||
//Wipe out the accuse log read for the next round
|
||||
gameObj.accuseLog={}
|
||||
// Check if we have two players left and if so, decide on a winner
|
||||
employedCount = 0
|
||||
gameObj.players.forEach(element => {
|
||||
if (element.status == "Employed") {
|
||||
employedCount++
|
||||
}
|
||||
})
|
||||
if (employedCount < 3) {
|
||||
return game.winner(gameID)
|
||||
}
|
||||
|
||||
// Now we know the game is still on-going:
|
||||
//add users funds to the charity & subtract donation from users funds
|
||||
|
||||
//check if user is trying to allocate too much money & set the amount so the users funds are wiped out
|
||||
if (amount > player.funds) {
|
||||
amount=player.funds
|
||||
}
|
||||
gameObj.charities.forEach( element => {
|
||||
if (element.charityID == charityID) {
|
||||
element.capital = element.capital+amount
|
||||
player.funds = player.funds - amount
|
||||
gameObj.distributionLog.push({
|
||||
donator:player.name,
|
||||
amount: amount,
|
||||
charity: element.name
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
reaminingFunding = 0
|
||||
gameObj.players.forEach(element => {
|
||||
reaminingFunding= reaminingFunding+element.funds
|
||||
if (reaminingFunding == 0) {
|
||||
roundStatus(gameID)
|
||||
}
|
||||
})
|
||||
|
||||
mongo.update("embezzle", "gamelist", {
|
||||
"gameID": gameID
|
||||
}, gameObj)
|
||||
return ({log: gameObj.distributionLog})
|
||||
},
|
||||
accuse: async (gameID, ownerID, player) => {
|
||||
//???
|
||||
},
|
||||
winner: async (gameID) => {
|
||||
winner = await mongo.get("embezzle", "gamelist", {
|
||||
"gameID": gameID
|
||||
})
|
||||
winer = winner[0].winner
|
||||
},
|
||||
roundStatus: async (gameID) => {
|
||||
gameObj = await mongo.get("embezzle", "gamelist", {
|
||||
"gameID": gameID
|
||||
})
|
||||
gameObj = gameObj[0]
|
||||
if (typeof gameObj == undefined || gameObj == "accuse") {
|
||||
gameObj.status = "distribution"
|
||||
} else {
|
||||
gameObj.status = "accuse"
|
||||
}
|
||||
|
||||
mongo.update("embezzle", "gamelist", {
|
||||
"gameID": gameID
|
||||
}, gameObj)
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
module.exports = game
|
@ -1,46 +1,110 @@
|
||||
var mongo = require("./mongoHelp.js")
|
||||
const uuidv4 = require('uuid/v4');
|
||||
const uuidv4 = require('uuid/v4')
|
||||
const game = require("./game.js")
|
||||
|
||||
var lobby={
|
||||
var lobby = {
|
||||
list: async () => {
|
||||
result = await mongo.get("embezzle","gamelist",{})
|
||||
return(result)
|
||||
result = await mongo.get("embezzle", "gamelist", {})
|
||||
pubArr = []
|
||||
result.forEach(element => {
|
||||
if (element.status == "lobby") {
|
||||
obj = {
|
||||
gameID: element.gameID,
|
||||
name: element.name,
|
||||
seats: element.seats,
|
||||
players: element.players,
|
||||
}
|
||||
pubArr.push(obj)
|
||||
}
|
||||
})
|
||||
return (pubArr)
|
||||
},
|
||||
details: async (gameID) => {
|
||||
result = await mongo.get("embezzle","gamelist",{"gameID":gameID})
|
||||
return (result)
|
||||
details: async (search) => {
|
||||
result = await mongo.get("embezzle", "gamelist", {
|
||||
gameID: search
|
||||
})
|
||||
pubArr = []
|
||||
result.forEach(element => {
|
||||
if (element.status == "lobby") {
|
||||
obj = {
|
||||
gameID: element.gameID,
|
||||
name: element.name,
|
||||
seats: element.seats,
|
||||
players: element.players,
|
||||
}
|
||||
pubArr.push(obj)
|
||||
}
|
||||
})
|
||||
return (pubArr)
|
||||
},
|
||||
register: (name) => {
|
||||
id=uuidv4()
|
||||
mongo.put("embezzle","players",{_id:id,name:name})
|
||||
console.log("yoohoo")
|
||||
return({ownerID:id})
|
||||
id = uuidv4()
|
||||
mongo.put("embezzle", "players", {
|
||||
_id: id,
|
||||
name: name
|
||||
})
|
||||
return ({
|
||||
ownerID: id
|
||||
})
|
||||
},
|
||||
make: (ownerID,seats) => {
|
||||
gameID=uuidv4()
|
||||
make: async (ownerID, seats) => {
|
||||
gameID = uuidv4()
|
||||
//todo write charity name generator
|
||||
name="Charity Name Example"
|
||||
mongo.put("embezzle","gamelist",{gameID:gameID,ownerID:ownerID,name:name,seats:seats, status:"lobby", players: []})
|
||||
// this.join(ownerID,gameID)
|
||||
|
||||
return({gameID:gameID})
|
||||
name = await mongo.get("embezzle", "players", {
|
||||
"_id": ownerID
|
||||
})
|
||||
name = name[0].name
|
||||
mongo.put("embezzle", "gamelist", {
|
||||
gameID: gameID,
|
||||
ownerID: ownerID,
|
||||
name: name,
|
||||
seats: seats,
|
||||
status: "lobby",
|
||||
players: []
|
||||
})
|
||||
lobby.join(ownerID, gameID)
|
||||
return ({
|
||||
gameID: gameID
|
||||
})
|
||||
// return({gameID:gameID})
|
||||
},
|
||||
join: (ownerID,gameID) => {
|
||||
mongo.get("embezzle","gamelist",{"gameID":gameID}).then(value => {
|
||||
console.log(value[0])
|
||||
value[0].players.push(ownerID)
|
||||
mongo.update("embezzle","gamelist",{"gameID":gameID},value[0])
|
||||
join: async (ownerID, gameID) => {
|
||||
value = await mongo.get("embezzle", "gamelist", {
|
||||
"gameID": gameID
|
||||
})
|
||||
gameObj = value[0]
|
||||
player = await mongo.get("embezzle", "players", {
|
||||
"_id": ownerID
|
||||
})
|
||||
player=player[0]
|
||||
playerObj = {
|
||||
name: player.name
|
||||
}
|
||||
|
||||
gameObj.players.push(playerObj)
|
||||
mongo.update("embezzle", "gamelist", {
|
||||
"gameID": gameID
|
||||
}, gameObj)
|
||||
return ({
|
||||
gameID: gameID
|
||||
})
|
||||
return({gameID:gameID})
|
||||
},
|
||||
start: (ownerID, gameID) => {
|
||||
mongo.get("embezzle","gamelist",{"gameID":gameID}).then(value => {
|
||||
console.log(value[0])
|
||||
value[0].status="playing"
|
||||
mongo.update("embezzle","gamelist",{"gameID":gameID,"ownerID":ownerID}, value[0])
|
||||
mongo.get("embezzle", "gamelist", {
|
||||
"ownerID": ownerID,
|
||||
"gameID": gameID
|
||||
}).then(value => {
|
||||
value[0].status = "playing"
|
||||
mongo.update("embezzle", "gamelist", {
|
||||
"gameID": gameID,
|
||||
"ownerID": ownerID
|
||||
}, value[0])
|
||||
game.init(gameID)
|
||||
})
|
||||
|
||||
return ({
|
||||
gameID: gameID
|
||||
})
|
||||
|
||||
return(gameID)
|
||||
},
|
||||
}
|
||||
|
||||
|
Loading…
Reference in new issue