Beta
This commit is contained in:
parent
2129889248
commit
457182504f
@ -2,8 +2,8 @@
|
||||
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"]
|
||||
ffnames = ["Quinn","Wendy","Erica","Rebecca","Tabitha","Yennifer","Ulanda","Irene","Omara","Penelope","Agne","Sarah","Diane","Febroch","Gillian","Hannah","Jessica","Karen","Laura","Zoe","Xephodette","Caitlyn","Violet","Betty","Noreen","Martha"]
|
||||
mfnames = ["Quintin","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()
|
||||
|
7
client/simpleclient/dockerfile
Normal file
7
client/simpleclient/dockerfile
Normal file
@ -0,0 +1,7 @@
|
||||
FROM nginx
|
||||
|
||||
ADD ./ /usr/share/nginx/html
|
||||
|
||||
LABEL traefik.port="80"
|
||||
EXPOSE 80
|
||||
CMD ["nginx", "-g", "'daemon off'"]
|
@ -1,12 +1,109 @@
|
||||
body{
|
||||
margin:40px auto;
|
||||
max-width:650px;
|
||||
max-width:90%;
|
||||
line-height:1.6;
|
||||
font-size:18px;
|
||||
color:#444;
|
||||
padding:0 10px;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
h1,h2,h3{
|
||||
line-height:1.2
|
||||
}
|
||||
|
||||
.donateInput{
|
||||
width: 35%;
|
||||
}
|
||||
|
||||
select{
|
||||
height: auto;
|
||||
width: 80%;
|
||||
font-size: large;
|
||||
}
|
||||
|
||||
input{
|
||||
height: auto;
|
||||
width: 80%;
|
||||
font-size: large;
|
||||
}
|
||||
|
||||
button{
|
||||
height: auto;
|
||||
width: 18%;
|
||||
font-size: large;
|
||||
}
|
||||
|
||||
#controls{
|
||||
width: 100%;
|
||||
}
|
||||
#Reigster-Container{
|
||||
visibility: visible;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#Make-Container{
|
||||
visibility: hidden;
|
||||
scale: 0;
|
||||
}
|
||||
|
||||
#Join-Container{
|
||||
visibility: hidden;
|
||||
scale: 0;
|
||||
}
|
||||
|
||||
#Start-Container{
|
||||
visibility: hidden;
|
||||
scale: 0;
|
||||
}
|
||||
|
||||
#Donate-Container{
|
||||
visibility: hidden;
|
||||
scale: 0;
|
||||
}
|
||||
|
||||
#Accuse-Container{
|
||||
visibility: hidden;
|
||||
scale: 0;
|
||||
}
|
||||
|
||||
|
||||
#messages{
|
||||
visibility: hidden;
|
||||
scale: 0;
|
||||
}
|
||||
|
||||
#games{
|
||||
visibility: hidden;
|
||||
scale: 0;
|
||||
}
|
||||
|
||||
#gameInfo{
|
||||
visibility: hidden;
|
||||
scale: 0;
|
||||
}
|
||||
|
||||
#myCharity{
|
||||
visibility: hidden;
|
||||
scale: 0;
|
||||
}
|
||||
|
||||
#charityStatus{
|
||||
visibility: hidden;
|
||||
scale: 0;
|
||||
}
|
||||
|
||||
#boardFunding{
|
||||
visibility: hidden;
|
||||
scale: 0;
|
||||
}
|
||||
|
||||
#transactionLog{
|
||||
visibility: hidden;
|
||||
scale: 0;
|
||||
}
|
||||
|
||||
#accusationLog{
|
||||
visibility: hidden;
|
||||
scale: 0;
|
||||
}
|
||||
|
@ -4,69 +4,117 @@
|
||||
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
|
||||
<meta content="utf-8" http-equiv="encoding"/>
|
||||
<script src="index.js"></script>
|
||||
<script src="jq.js"></script>
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
//sorry
|
||||
var _paq = window._paq || [];
|
||||
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
|
||||
_paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
|
||||
_paq.push(["setCookieDomain", "*.nannal.com"]);
|
||||
_paq.push(['trackPageView']);
|
||||
_paq.push(['enableLinkTracking']);
|
||||
(function() {
|
||||
var u="//matomo.nannal.com/";
|
||||
_paq.push(['setTrackerUrl', u+'matomo.php']);
|
||||
_paq.push(['setSiteId', '1']);
|
||||
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
|
||||
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
|
||||
})();
|
||||
|
||||
(function(f, a, t, h, o, m){
|
||||
a[h]=a[h]||function(){
|
||||
(a[h].q=a[h].q||[]).push(arguments)
|
||||
};
|
||||
o=f.createElement('script'),
|
||||
m=f.getElementsByTagName('script')[0];
|
||||
o.async=1; o.src=t; o.id='fathom-script';
|
||||
m.parentNode.insertBefore(o,m)
|
||||
})(document, window, '//fathom.nannal.com/tracker.js', 'fathom');
|
||||
fathom('set', 'siteId', 'QYBFW');
|
||||
fathom('trackPageview');
|
||||
</script>
|
||||
|
||||
<noscript><p><img src="//matomo.nannal.com/matomo.php?idsite=1&rec=1" style="border:0;" alt="" /></p></noscript>
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="controls">
|
||||
<div class="Reigster-Container">
|
||||
</br>Register
|
||||
<h1>Embezzle</h1>
|
||||
<div id="controls">
|
||||
|
||||
<div id="Reigster-Container">
|
||||
<div id="faq">
|
||||
<h2>How To Play</h2>
|
||||
By joining a game you become apointed to the board of a multinational company who in the name of extreme altruism (and for some significant tax breaks) must distribute some of their immesne profits to lowly charities. As the cunning fox you are, you've setup your own charity and must now redirect as much of this firehose of funds from silly rinky-dink operations like oxfam to your own back pocket.
|
||||
</br>
|
||||
However, you can't be <i>entierly</i> blatant about it as, after each quaters funds are distributed, a board member must be fired as they are undoubtedly performing the heinous crime of cold-heartedly stealing what few morsels of funding the benevolent company has seen fit to bestow on the worlds most needy and vulnerable. <b>The swines!</b>
|
||||
<ul>Join a board of directors</ul>
|
||||
<ul>Distribute funds to yourown and other's charities</ul>
|
||||
<ul>Vote out one of your fellow board members</ul>
|
||||
<ul>Have the most capital in your charity when only two members remain on the board to win</ul>
|
||||
</div>
|
||||
</br>Register a player</br>
|
||||
|
||||
<input id="register" type="text" placeholder="Name"/> <button onclick="register()">Register</button>
|
||||
</div>
|
||||
|
||||
<div class="Make-Container">
|
||||
</br>Make
|
||||
<div id="Make-Container">
|
||||
</br>Make A game (Select a number of player slots)</br>
|
||||
|
||||
<input id="makeSeats" type="number"/> <button onclick="make()">Make</button>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="Join-Container">
|
||||
</br>Join
|
||||
<div id="Join-Container">
|
||||
</br>Join a game (Using a GameID)</br>
|
||||
|
||||
<input id="join" type="text" placeholder="Name"/> <button onclick="join()">Join</button>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="Start-Container">
|
||||
</br>Start
|
||||
<div id="Start-Container">
|
||||
</br>Start the game!</br>
|
||||
|
||||
<button onclick="start()">Start</button>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="Donate-Container">
|
||||
</br>Donate
|
||||
<select id="donate" name="list">
|
||||
<option value="x">x</option>
|
||||
<div id="Donate-Container">
|
||||
</br>Donate</br>
|
||||
<select id="donate" name="list" class="donateInput">
|
||||
<option value="stringthatbrickstheserver">If you can see this, you're being naughty</option>
|
||||
</select>
|
||||
|
||||
<input id="amount" type="number">
|
||||
<input id="amount" type="number" class="donateInput">
|
||||
|
||||
<button onclick="donate()">Donate</button>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="Accuse-Container">
|
||||
</br>Accuse
|
||||
<div id="Accuse-Container">
|
||||
</br>Accuse a player of embezzlement</br>
|
||||
|
||||
<input id="accuse" type="text" placeholder="Name"/> <button onclick="accuse()">Accuse</button>
|
||||
<select id="accuse" name="list" class="accuseInput">
|
||||
<option value="stringthatbrickstheserver">If you can see this, you're being naughty</option>
|
||||
</select>
|
||||
<button onclick="accuse()">Accuse</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="info">
|
||||
<div id="gameID"></div>
|
||||
<div id="messages"></div>
|
||||
<div id="games"></div>
|
||||
<div id="gameInfo"></div>
|
||||
<div id="playerInfo"></div>
|
||||
<div id="myCharity"></div>
|
||||
<div id="charityStatus"></div>
|
||||
<div id="boardFunding"></div>
|
||||
<div id="transactionLog"></div>
|
||||
<div id="accusationLog"></div>
|
||||
|
||||
<div id="messages"></div>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
// Global Vars
|
||||
|
||||
serverAddr="http://localhost:3000"
|
||||
serverAddr="https://embezzle-server.nannal.com"
|
||||
ownerID=''
|
||||
// ownerID='6298bc89-41cb-4cc7-84cd-7fd8e419f263'
|
||||
gameID=''
|
||||
@ -24,6 +23,10 @@ function register(){
|
||||
//hide register
|
||||
//show make & join
|
||||
//show list of games
|
||||
cssHide("Reigster-Container")
|
||||
cssShow("Make-Container")
|
||||
cssShow("Join-Container")
|
||||
|
||||
listGames()
|
||||
})
|
||||
.catch((error) => {
|
||||
@ -37,7 +40,8 @@ function listGames(){
|
||||
return response.json();
|
||||
})
|
||||
.then((data) => {
|
||||
document.getElementById('messages').value='data.gamesArr'
|
||||
gamesFormat(data)
|
||||
cssShow("games")
|
||||
console.log(data);
|
||||
});
|
||||
}
|
||||
@ -60,6 +64,16 @@ function make(){
|
||||
// console.log(data)
|
||||
gameID=data.gameID
|
||||
gameData(gameID)
|
||||
document.getElementById("gameID").innerHTML="<h2>Your gameID is:"+gameID+"</h2><p> share the gameID with any users you want to join your game</p>"
|
||||
cssHide("games")
|
||||
cssHide("Make-Container")
|
||||
cssHide("Join-Container")
|
||||
|
||||
cssShow("messages")
|
||||
cssShow("gameInfo")
|
||||
cssShow("playerInfo")
|
||||
cssShow("Start-Container")
|
||||
|
||||
|
||||
})
|
||||
.catch((error) => {
|
||||
@ -70,6 +84,15 @@ function make(){
|
||||
function join(){
|
||||
console.log("join")
|
||||
gameID=document.getElementById('join').value
|
||||
gameData(gameID)
|
||||
|
||||
cssHide("games")
|
||||
cssHide("Make-Container")
|
||||
cssHide("Join-Container")
|
||||
|
||||
cssShow("messages")
|
||||
cssShow("gameInfo")
|
||||
cssShow("playerInfo")
|
||||
const data = {
|
||||
ownerID: ownerID,
|
||||
gameID: gameID };
|
||||
@ -83,11 +106,19 @@ function join(){
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
document.getElementById("gameID").innerHTML="<h2>Your gameID is:"+gameID+"</h2><p> share the gameID with any users you want to join your game</p>"
|
||||
// console.log(data)
|
||||
gameData(gameID)
|
||||
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error:', error);
|
||||
|
||||
cssShow("games")
|
||||
cssShow("Make-Container")
|
||||
cssShow("Join-Container")
|
||||
|
||||
cssHide("messages")
|
||||
cssHide("gameInfo")
|
||||
});
|
||||
}
|
||||
|
||||
@ -105,14 +136,18 @@ function gameData(gameID) {
|
||||
gameData(gameID)
|
||||
clearInterval(checkIfStarted)
|
||||
}, 1000)
|
||||
if (document.getElementById("messages").innerText != "Game Name: "+data.name+", GameID: "+data.gameID) {
|
||||
document.getElementById("messages").innerText="Game Name: "+data.name+", GameID: "+data.gameID
|
||||
html="Waiting For "+data.name+" to start the game, "+data.players.length+"/"+data.seats+" seats are full</br>"
|
||||
data.players.forEach(element => {
|
||||
html=html+"Player: "+element.name+"</br>"
|
||||
})
|
||||
if (document.getElementById("messages").innerHTML != html) {
|
||||
document.getElementById("messages").innerHTML=html
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function start(){
|
||||
console.log("start")
|
||||
const data = {
|
||||
ownerID: ownerID,
|
||||
gameID: gameID };
|
||||
@ -127,7 +162,7 @@ function start(){
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
console.log(data)
|
||||
|
||||
cssHide("Start-Container")
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error:', error);
|
||||
@ -156,6 +191,7 @@ function donate(){
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
donateFormat(data)
|
||||
// console.log(data)
|
||||
// gameData(gameID)
|
||||
})
|
||||
@ -182,7 +218,7 @@ function accuse(){
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
// console.log(data)
|
||||
document.getElementById("accuseLog").innerText=data
|
||||
accuseFormat(data)
|
||||
// gameData(gameID)
|
||||
})
|
||||
.catch((error) => {
|
||||
@ -219,7 +255,7 @@ function status() {
|
||||
|
||||
|
||||
//Quick Recurring updates
|
||||
setInterval(function(){
|
||||
statusint = setInterval(function(){
|
||||
fetch(serverAddr+'/game/'+gameID+'/boardFunding', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@ -249,9 +285,9 @@ function status() {
|
||||
});
|
||||
if (document.getElementById("donate").innerHTML != dropDownList){
|
||||
document.getElementById("donate").innerHTML=dropDownList
|
||||
statusObj.charitylist=data
|
||||
// statusObj.charitylist=data
|
||||
}
|
||||
document.getElementById("charityStatus").innerHTML=charityStatusFormat(data)
|
||||
charityStatusFormat(data)
|
||||
});
|
||||
|
||||
|
||||
@ -260,7 +296,37 @@ function status() {
|
||||
return response.json();
|
||||
})
|
||||
.then((data) => {
|
||||
statusObj.playerlist=data
|
||||
playerListFormat(data)
|
||||
// statusObj.playerlist=data
|
||||
// console.log(data);
|
||||
});
|
||||
|
||||
fetch(serverAddr+'/game/'+gameID+'/accuseinfo')
|
||||
.then((response) => {
|
||||
return response.json();
|
||||
})
|
||||
.then((data) => {
|
||||
accuseFormat(data)
|
||||
// statusObj.playerlist=data
|
||||
// console.log(data);
|
||||
});
|
||||
fetch(serverAddr+'/game/'+gameID+'/distributioninfo')
|
||||
.then((response) => {
|
||||
return response.json();
|
||||
})
|
||||
.then((data) => {
|
||||
donateFormat(data)
|
||||
// statusObj.playerlist=data
|
||||
// console.log(data);
|
||||
});
|
||||
|
||||
fetch(serverAddr+'/game/'+gameID+'/statusinfo')
|
||||
.then((response) => {
|
||||
return response.json();
|
||||
})
|
||||
.then((data) => {
|
||||
statusFormat(data)
|
||||
// statusObj.playerlist=data
|
||||
// console.log(data);
|
||||
});
|
||||
// fdocument.getElementById("info").innerText=prettyprint(statusObj)
|
||||
@ -276,12 +342,127 @@ function myCharityFormat(data) {
|
||||
|
||||
function charityStatusFormat(data) {
|
||||
html=""
|
||||
data.forEach(element => {
|
||||
html=html+"<b>"+element.name+":</b> "+element.capital
|
||||
data.charatiesArr.forEach(element => {
|
||||
html=html+"<b>"+element.name+":</b> "+element.capital+"</br>"
|
||||
})
|
||||
return html
|
||||
if (document.getElementById("charityStatus").innerHTML != html) {
|
||||
document.getElementById("charityStatus").innerHTML=html
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function boardFundingFormat(data) {
|
||||
if (document.getElementById("boardFunding").innerHTML != "<b>My Funds: </b>"+data.funds) {
|
||||
document.getElementById("boardFunding").innerHTML= "<b>My Funds: </b>"+data.funds
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function donateFormat(data) {
|
||||
html=""
|
||||
data.log.forEach(element => {
|
||||
html=html+element.donator+", donated "+element.amount+" to "+element.charity+"</br>"
|
||||
})
|
||||
if(document.getElementById("transactionLog").innerHTML != html){
|
||||
document.getElementById("transactionLog").innerHTML=html
|
||||
}
|
||||
}
|
||||
|
||||
function accuseFormat(data) {
|
||||
html=""
|
||||
if(typeof data.winner != "undefined"){
|
||||
document.getElementById("accusationLog").innerHTML="<h1>"+data.winner+" has won the game</h1>"
|
||||
clearInterval(statusint)
|
||||
}
|
||||
else{
|
||||
accusers=Object.keys(data.log)
|
||||
accusers.forEach(element => {
|
||||
html=html+element+" accuses "+data.log[element]+"</br>"
|
||||
})
|
||||
if(document.getElementById("accusationLog").innerHTML != html){
|
||||
document.getElementById("accusationLog").innerHTML=html
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function gamesFormat(data) {
|
||||
html="<h4>Games:</h4></br>"
|
||||
data.gamesArr.forEach(element => {
|
||||
html=html+element.gameID+", "+element.name+"</br>"
|
||||
})
|
||||
if (document.getElementById("games").innerHTML != html) {
|
||||
document.getElementById("games").innerHTML = html
|
||||
}
|
||||
}
|
||||
|
||||
function playerListFormat(data) {
|
||||
html=""
|
||||
accuseListFormat(data.playersArr)
|
||||
data.playersArr.forEach(element => {
|
||||
html=html+"<b>"+element.name+"</b>: Funds "+element.funds+", Status: "+element.status+"</br>"
|
||||
})
|
||||
if (document.getElementById("playerInfo").innerHTML != html){
|
||||
document.getElementById("playerInfo").innerHTML=html
|
||||
}
|
||||
}
|
||||
|
||||
function statusFormat(data) {
|
||||
if (document.getElementById("gameInfo").innerHTML != "<h1>Round Status: "+data.status+"</h1>") {
|
||||
document.getElementById("gameInfo").innerHTML="<h1>Round Status: "+data.status+"</h1>"
|
||||
}
|
||||
if (data.status == "Distribution") {
|
||||
cssHide("messages")
|
||||
cssShow("gameInfo")
|
||||
cssShow("myCharity")
|
||||
cssShow("charityStatus")
|
||||
cssShow("boardFunding")
|
||||
|
||||
cssShow("Donate-Container")
|
||||
cssShow("transactionLog")
|
||||
|
||||
cssHide("messages")
|
||||
cssHide("accusationLog")
|
||||
cssHide("Accuse-Container")
|
||||
}
|
||||
else {
|
||||
cssHide("Donate-Container")
|
||||
cssShow("accusationLog")
|
||||
cssShow("Accuse-Container")
|
||||
}
|
||||
}
|
||||
|
||||
function accuseListFormat(data){
|
||||
dropDownList=""
|
||||
data.forEach(element => {
|
||||
dropDownList=dropDownList+'<option value="'+element.name+'">'+element.name+'</option>'
|
||||
});
|
||||
if (document.getElementById("accuse").innerHTML != dropDownList){
|
||||
document.getElementById("accuse").innerHTML=dropDownList
|
||||
// statusObj.charitylist=data
|
||||
}
|
||||
}
|
||||
|
||||
function cssHide(id){
|
||||
if (document.getElementById(id).style.visibility != "Hidden") {
|
||||
document.getElementById(id).style.lineHeight=0
|
||||
document.getElementById(id).style.margin=0
|
||||
document.getElementById(id).style.fontSize=0
|
||||
document.getElementById(id).style.visibility="Hidden"
|
||||
document.getElementById(id).style.size="0px"
|
||||
document.getElementById(id).style.zIndex="100"
|
||||
document.getElementById(id).style.scale="0"
|
||||
}
|
||||
}
|
||||
|
||||
function cssShow(id){
|
||||
if (document.getElementById(id).style.visibility != "Visible") {
|
||||
document.getElementById(id).style.lineHeight=1.6
|
||||
document.getElementById(id).style.fontSize="Large"
|
||||
document.getElementById(id).style.visibility="Visible"
|
||||
document.getElementById(id).style.size="Auto"
|
||||
document.getElementById(id).style.zIndex="0"
|
||||
document.getElementById(id).style.scale="1"
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because one or more lines are too long
10
dockerfile
Normal file
10
dockerfile
Normal file
@ -0,0 +1,10 @@
|
||||
FROM node
|
||||
|
||||
ADD ./ /emb
|
||||
|
||||
WORKDIR /emb
|
||||
|
||||
LABEL traefik.port="3000"
|
||||
EXPOSE 3000
|
||||
|
||||
CMD ["node", "index.js"]
|
156
game.js
156
game.js
@ -15,6 +15,29 @@ function shuffle(arr) {
|
||||
return arr
|
||||
}
|
||||
|
||||
async function check (gameID,ownerID) {
|
||||
gameObj = await mongo.get("embezzle", "gamelist", {
|
||||
"gameID": gameID
|
||||
})
|
||||
gameObj = gameObj[0]
|
||||
name = await mongo.get("embezzle", "players", {
|
||||
"_id": ownerID
|
||||
})
|
||||
name = name[0].name
|
||||
found=0
|
||||
gameObj.players.forEach(element => {
|
||||
|
||||
if (element.name == name) {
|
||||
console.log(name)
|
||||
console.log(element.name)
|
||||
found=1
|
||||
}
|
||||
})
|
||||
console.log("Found: ",found)
|
||||
return found
|
||||
|
||||
}
|
||||
|
||||
|
||||
const game = {
|
||||
init: async (gameID) => {
|
||||
@ -26,7 +49,8 @@ const game = {
|
||||
gameObj.charities = []
|
||||
gameObj.distributionLog = []
|
||||
gameObj.accuseLog = {}
|
||||
gameObj.status = "distribution"
|
||||
gameObj.status = "Distribution"
|
||||
gameObj.round=1
|
||||
for (let index = 0; index < gameObj.players.length; index++) {
|
||||
gameObj.charities.push({
|
||||
charityID: uuidv4(),
|
||||
@ -48,9 +72,8 @@ const game = {
|
||||
shuffle(gameObj.charities)
|
||||
//set board funds
|
||||
gameObj.players.forEach(element => {
|
||||
element.funds = 10000000
|
||||
element.funds = 100000
|
||||
element.status = "Employed"
|
||||
console.log(element)
|
||||
})
|
||||
//update game
|
||||
mongo.update("embezzle", "gamelist", {
|
||||
@ -58,6 +81,25 @@ const game = {
|
||||
}, gameObj)
|
||||
|
||||
},
|
||||
reset: async (gameID) => {
|
||||
let gameObj = await mongo.get("embezzle", "gamelist", {
|
||||
"gameID": gameID
|
||||
})
|
||||
gameObj=gameObj[0]
|
||||
gameObj.players.forEach(element =>{
|
||||
fundvar=100000
|
||||
roundvar=fundvar+(fundvar/(gameObj.round))
|
||||
if (element.status != "Fired"){
|
||||
element.funds=roundvar
|
||||
} else {element.funds=roundvar/gameObj.players.length}
|
||||
|
||||
})
|
||||
gameObj.accuseLog={}
|
||||
|
||||
mongo.update("embezzle", "gamelist", {
|
||||
"gameID": gameID
|
||||
}, gameObj)
|
||||
},
|
||||
myCharity: async (gameID, ownerID) => {
|
||||
name = await mongo.get("embezzle", "players", {
|
||||
"_id": ownerID
|
||||
@ -67,25 +109,21 @@ const game = {
|
||||
"gameID": gameID
|
||||
})
|
||||
secret = gameObj[0].secretLink
|
||||
let mine = ""
|
||||
gameObj[0].charities.forEach(element => {
|
||||
secret.forEach(user => {
|
||||
console.log(name,user)
|
||||
if (name==user.name){
|
||||
console.log(element, user)
|
||||
console.log("User Found")
|
||||
if (element.charityID == user.charity) {
|
||||
console.log(element.charityID,user.charity)
|
||||
(console.log("Charity Found"))
|
||||
mine = element.name
|
||||
}
|
||||
mychar=""
|
||||
secret.forEach(char => {
|
||||
if (char.owner == name) {
|
||||
mychar=char.charity
|
||||
}
|
||||
})
|
||||
|
||||
charname=""
|
||||
gameObj[0].charities.forEach(element => {
|
||||
if (element.charityID == mychar) {
|
||||
charname=element.name
|
||||
}
|
||||
})
|
||||
|
||||
chairtyObj = {
|
||||
charity: mine
|
||||
charity: charname
|
||||
}
|
||||
return chairtyObj
|
||||
},
|
||||
@ -105,7 +143,7 @@ const game = {
|
||||
})
|
||||
players = gameObj[0].players
|
||||
return ({
|
||||
charatiesArr: players
|
||||
playersArr: players
|
||||
})
|
||||
|
||||
},
|
||||
@ -119,7 +157,6 @@ const game = {
|
||||
"gameID": gameID
|
||||
})
|
||||
players = players[0].players
|
||||
result = ""
|
||||
players.forEach(element => {
|
||||
if (element.name == name) {
|
||||
r = {funds: element.funds}
|
||||
@ -128,6 +165,10 @@ const game = {
|
||||
return r
|
||||
},
|
||||
distribution: async (gameID, ownerID, charityID, amount) => {
|
||||
|
||||
if (await check(gameID, ownerID) == 0) {
|
||||
return ({Error: "You're not a player"})
|
||||
}
|
||||
//turn the amount to an int
|
||||
amount=parseInt(amount)
|
||||
|
||||
@ -138,9 +179,9 @@ const game = {
|
||||
gameObj = gameObj[0]
|
||||
// console.log(gameObj)
|
||||
|
||||
if (gameObj.status != "distribution") {
|
||||
if (gameObj.status != "Distribution") {
|
||||
return({error:"You have tried to distribute funds when it is not the distribution round"})
|
||||
}
|
||||
} else {
|
||||
player = await mongo.get("embezzle", "players", {
|
||||
"_id": ownerID
|
||||
})
|
||||
@ -154,13 +195,6 @@ const game = {
|
||||
}
|
||||
})
|
||||
|
||||
//Wipe out the accuse log read for the next round
|
||||
gameObj.accuseLog={}
|
||||
|
||||
|
||||
// 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
|
||||
@ -169,26 +203,38 @@ const game = {
|
||||
if (element.charityID == charityID) {
|
||||
element.capital = element.capital+amount
|
||||
player.funds = player.funds - amount
|
||||
if (amount > 0 ){
|
||||
gameObj.distributionLog.push({
|
||||
donator: player.name,
|
||||
amount: amount,
|
||||
charity: element.name
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
reaminingFunding = 0
|
||||
gameObj.players.forEach(element => {
|
||||
reaminingFunding=reaminingFunding+element.funds
|
||||
})
|
||||
if (reaminingFunding == 0) {
|
||||
game.roundStatus(gameID)
|
||||
}
|
||||
|
||||
mongo.update("embezzle", "gamelist", {
|
||||
"gameID": gameID
|
||||
}, gameObj)
|
||||
|
||||
if (reaminingFunding == 0) {
|
||||
game.roundStatus(gameID)
|
||||
}
|
||||
|
||||
return ({log: gameObj.distributionLog})
|
||||
}
|
||||
|
||||
},
|
||||
accuse: async (gameID, ownerID, victim) => {
|
||||
if (await check(gameID, ownerID) == 0) {
|
||||
return {Error: "You're not a player"}
|
||||
}
|
||||
//Get votes on who should be fired
|
||||
player = await mongo.get("embezzle", "players", {
|
||||
"_id": ownerID
|
||||
@ -198,11 +244,10 @@ const game = {
|
||||
"gameID": gameID
|
||||
})
|
||||
gameObj = gameObj[0]
|
||||
if (gameObj.status != "accuse"){
|
||||
if (gameObj.status != "Accuse"){
|
||||
return {Error: "Game status is not accuse, you'll want to distribute funds before trying to fire someone"}
|
||||
}
|
||||
|
||||
|
||||
gameObj.players.forEach(element => {
|
||||
if (victim == element.name) {
|
||||
gameObj.accuseLog[player.name] = victim
|
||||
@ -221,7 +266,9 @@ const game = {
|
||||
})
|
||||
})
|
||||
sorted = Object.keys(vote).sort(function(a,b){return vote[a]-vote[b]})
|
||||
console.log("Sorted: ",sorted)
|
||||
fired = sorted[sorted.length-1]
|
||||
console.log("Fired: ",fired)
|
||||
gameObj.players.forEach(element => {
|
||||
if (element.name == fired ) {
|
||||
element.status="Fired"
|
||||
@ -237,7 +284,7 @@ const game = {
|
||||
employedCount++
|
||||
}
|
||||
})
|
||||
if (employedCount == 2) {
|
||||
if (employedCount < 3) {
|
||||
return game.winner(gameID)
|
||||
}
|
||||
|
||||
@ -245,7 +292,7 @@ const game = {
|
||||
mongo.update("embezzle", "gamelist", {
|
||||
"gameID": gameID
|
||||
}, gameObj)
|
||||
return ({log: gameObj.distributionLog})
|
||||
return ({log: gameObj.accuseLog})
|
||||
|
||||
},
|
||||
winner: async (gameID) => {
|
||||
@ -269,6 +316,7 @@ const game = {
|
||||
|
||||
//Declare the winner
|
||||
gameObj.status="Finished"
|
||||
gameObj.winner=winner
|
||||
mongo.update("embezzle", "gamelist", {
|
||||
"gameID": gameID
|
||||
}, gameObj)
|
||||
@ -279,18 +327,46 @@ const game = {
|
||||
"gameID": gameID
|
||||
})
|
||||
gameObj = gameObj[0]
|
||||
console.log(gameObj.status)
|
||||
if (typeof gameObj.status == "lobby" || gameObj.status == "accuse") {
|
||||
gameObj.status = "distribution"
|
||||
if (typeof gameObj.status == "Lobby" || gameObj.status == "Accuse") {
|
||||
gameObj.status = "Distribution"
|
||||
mongo.update("embezzle", "gamelist", {
|
||||
"gameID": gameID
|
||||
}, gameObj)
|
||||
game.reset(gameID)
|
||||
} else {
|
||||
gameObj.status = "accuse"
|
||||
gameObj.status = "Accuse"
|
||||
}
|
||||
console.log(gameObj.status)
|
||||
mongo.update("embezzle", "gamelist", {
|
||||
"gameID": gameID
|
||||
}, gameObj)
|
||||
|
||||
},
|
||||
roundStatusInfo: async (gameID) => {
|
||||
gameObj = await mongo.get("embezzle", "gamelist", {
|
||||
"gameID": gameID
|
||||
})
|
||||
gameObj = gameObj[0]
|
||||
return ({status: gameObj.status})
|
||||
|
||||
},
|
||||
accuseInfo: async (gameID) => {
|
||||
gameObj = await mongo.get("embezzle", "gamelist", {
|
||||
"gameID": gameID
|
||||
})
|
||||
gameObj = gameObj[0]
|
||||
if (typeof gameObj.winner != "undefined") {
|
||||
return ({winner: gameObj.winner})
|
||||
} else {
|
||||
return ({log: gameObj.accuseLog})
|
||||
}
|
||||
},
|
||||
distributionInfo: async (gameID) => {
|
||||
gameObj = await mongo.get("embezzle", "gamelist", {
|
||||
"gameID": gameID
|
||||
})
|
||||
gameObj = gameObj[0]
|
||||
return ({log: gameObj.distributionLog})
|
||||
},
|
||||
}
|
||||
|
||||
module.exports = game
|
26
index.js
26
index.js
@ -101,6 +101,32 @@ app.post('/game/:gameID/accuse', function (req, res) {
|
||||
res.send(JSON.stringify(r))
|
||||
})
|
||||
})
|
||||
|
||||
app.get('/game/:gameID/statusinfo', function (req, res) {
|
||||
game.roundStatusInfo(req.params.gameID).then(r => {
|
||||
res.send(JSON.stringify(r))
|
||||
})
|
||||
})
|
||||
|
||||
app.get('/game/:gameID/distributioninfo', function (req, res) {
|
||||
game.distributionInfo(req.params.gameID).then(r => {
|
||||
res.send(JSON.stringify(r))
|
||||
})
|
||||
})
|
||||
|
||||
app.get('/game/:gameID/accuseinfo', function (req, res) {
|
||||
game.accuseInfo(req.params.gameID).then(r => {
|
||||
res.send(JSON.stringify(r))
|
||||
})
|
||||
})
|
||||
|
||||
app.get('/game/:gameID/distributioninfo', function (req, res) {
|
||||
game.distributIoninfo(req.params.gameID).then(r => {
|
||||
res.send(JSON.stringify(r))
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
// roundStatus -- this should not be public wtf?
|
||||
// app.get('/game/:gameID/roundStatus', function (req, res) {
|
||||
// game.roundStatus(req.params.gameID).then(r => {
|
||||
|
12
lobby.js
12
lobby.js
@ -7,7 +7,7 @@ var lobby = {
|
||||
result = await mongo.get("embezzle", "gamelist", {})
|
||||
pubArr = []
|
||||
result.forEach(element => {
|
||||
if (element.status == "lobby") {
|
||||
if (element.status == "Lobby") {
|
||||
obj = {
|
||||
gameID: element.gameID,
|
||||
name: element.name,
|
||||
@ -25,7 +25,7 @@ var lobby = {
|
||||
})
|
||||
pubArr = []
|
||||
result.forEach(element => {
|
||||
if (element.status == "lobby") {
|
||||
if (element.status == "Lobby") {
|
||||
obj = {
|
||||
gameID: element.gameID,
|
||||
name: element.name,
|
||||
@ -39,7 +39,7 @@ var lobby = {
|
||||
},
|
||||
register: (name) => {
|
||||
id = uuidv4()
|
||||
name=name+'-'+id.split('-')[3]
|
||||
name=encodeURIComponent(name.substring(0,16))+'-'+id.split('-')[3]
|
||||
mongo.put("embezzle", "players", {
|
||||
_id: id,
|
||||
name: name
|
||||
@ -61,7 +61,7 @@ var lobby = {
|
||||
ownerID: ownerID,
|
||||
name: name,
|
||||
seats: seats,
|
||||
status: "lobby",
|
||||
status: "Lobby",
|
||||
players: []
|
||||
})
|
||||
lobby.join(ownerID, gameID)
|
||||
@ -83,7 +83,7 @@ var lobby = {
|
||||
playerObj = {
|
||||
name: player.name
|
||||
}
|
||||
if (gameObj.status != "lobby") {
|
||||
if (gameObj.status != "Lobby" || gameObj.players.length == gameObj.seats) {
|
||||
return {error:"Unable to join game"}
|
||||
} else {
|
||||
gameObj.players.push(playerObj)
|
||||
@ -101,7 +101,7 @@ var lobby = {
|
||||
"ownerID": ownerID,
|
||||
"gameID": gameID
|
||||
}).then(value => {
|
||||
value[0].status = "playing"
|
||||
value[0].status = "Playing"
|
||||
mongo.update("embezzle", "gamelist", {
|
||||
"gameID": gameID,
|
||||
"ownerID": ownerID
|
||||
|
@ -1,6 +1,6 @@
|
||||
var MongoClient = require('mongodb').MongoClient
|
||||
|
||||
var url = 'mongodb://localhost:27017'
|
||||
var url = process.env.mongo||'mongodb://embmongo'
|
||||
var options= {
|
||||
useNewUrlParser: true,
|
||||
useUnifiedTopology: true,
|
||||
|
Loading…
Reference in New Issue
Block a user