Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dai sù zio. Pulla sta roba. #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ float: right;
position: absolute;
top: 20px;
left: 0px;
height: 700px;
height: auto;
width: 200px;
overflow: hidden;
}

.content {
position: relative;
overflow: hidden;
height: 700px;
height: auto;
}

.column {
Expand Down Expand Up @@ -81,3 +81,11 @@ button {
.ascii-art {
white-space: pre;
}

footer {
position: fixed;
right: 10px;
bottom: 10px;
color: #666;
z-index: 10;
}
30 changes: 20 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<body>
<pre id="header" class="ascii-art">

$$$$$$$$\ $$\ $$\ $$$$$$$$\ $$$$$$\ $$$$$$\ $$\ $$\ $$\
\__$$ __|$$ | \__| \__$$ __| $$ __$$\ $$ __$$\ $$$\ $$$ |\__|
$$ | $$$$$$$\ $$\ $$$$$$$\ $$ | $$$$$$\ $$\ $$\ $$ / $$ |$$ / \__| $$$$\ $$$$ |$$\ $$$$$$$\ $$$$$$\
Expand All @@ -17,8 +18,8 @@
$$ | $$ | $$ |$$ | \____$$\ $$ |$$ __$$ | $$ $$< $$ | $$ |$$ | $$ |\$ /$$ |$$ |$$ | $$ |$$ ____|
$$ | $$ | $$ |$$ |$$$$$$$ | $$ |\$$$$$$$ |$$ /\$$\ $$$$$$ |$$ | $$ | \_/ $$ |$$ |$$ | $$ |\$$$$$$$\
\__| \__| \__|\__|\_______/ \__| \_______|\__/ \__| \______/ \__| \__| \__|\__|\__| \__| \_______|
</pre>


</pre>
<div class="wrapper">
<hr>
<div id="text" class="notifications">
Expand All @@ -28,22 +29,31 @@
<div class="column left">
<p> STATUS</p>
<p id="money"></p>
<input type="button" onclick="onWork()" value="Work" />
<input id="bnRestart" type="button" onclick="onRestart()" value="Restart" style="display: none" />
<input id="bnWork" type="button" onclick="World.onWork()" value="Work" style="display: none" />
<input id="bnRestart" type="button" onclick="World.onRestart()" value="Restart" style="display: none" />
</div>
<div class="column right">
<p> SCORE</p>
<p id="scoretime"></p>
<p> DAYS TO PAY</p>
<p id="time"></p>
</div>

</div>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous">
</script>
<script src="./js/world.js"></script>
<script src="./js/notifications.js"></script>
<script src="./js/renderer.js"></script>
<footer>
<div>
<p id="errorUsername" class="bold cost" style="display: none"> </p>
<input id="inputStart" type="input" placeholder="Cocco Bill" />
<input id="bnStart" type="button" onclick="World.onStart()" value="Start" />
<p id="username" class="bold" style="display: none"> </p>
</div>
</header>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous">
</script>
<script src="./js/world.js"></script>
<script src="./js/notifications.js"></script>
</body>

</html>
29 changes: 0 additions & 29 deletions js/renderer.js

This file was deleted.

94 changes: 80 additions & 14 deletions js/world.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
'use strict';

var World = {
DAYS_TO_PAY: 10,
money: 0,
DAYS_TO_PAY: 30,
gametime: 0,
score: 0,
gRefreshInterval: null,
gIsGameOver: false,
moneyDiv: document.getElementById('money'),
timeDiv: document.getElementById('time'),
scoreDiv: document.getElementById('scoretime'),
player: {
productivity: 1,
baseIncome: 50,
money: 0,
},
tax: {
incomeTax: () => {
return Math.floor(World.player.money * 0.7);
},
totalTax: () => {
return World.tax.incomeTax();
}
},
init: function () {
$('#bnRestart').hide();

this.gametime = this.DAYS_TO_PAY;
this.score = 0;
Notifications.init();

this.setMoney(5000);
this.setMoney(1000);
this.syncUI();

this.gIsGameOver = false;

},
start: function () {
this.gRefreshInterval = setInterval(function () {
World.gameloop();
}, 1000);
},
addMoney: function (amount) {
this.money += amount;
this.player.money += amount;
},
setMoney: function (amount) {
this.money = amount;
this.player.money = amount;
},
syncUI: function () {
this.moneyDiv.innerText = 'Money: ' + this.money;
this.moneyDiv.innerText = 'Money: ' + this.player.money;
this.timeDiv.innerText = this.gametime;
if(this.timeDiv.innerText >= 0 && this.timeDiv.innerText <= 5){
this.scoreDiv.innerText = this.score;
if (this.timeDiv.innerText >= 0 && this.timeDiv.innerText <= 5) {
this.timeDiv.className = 'countdown';
} else {
this.timeDiv.className = '';
Expand All @@ -42,21 +56,73 @@ var World = {
this.gametime -= 1;

if (this.gametime < 0) {
onPayTaxes();
this.onPayTaxes();
this.gametime = this.DAYS_TO_PAY;
}
this.score++;
this.syncUI();
this.checkGameOver();
if (this.gIsGameOver) {
return;
}
},
checkGameOver: function () {
if (World.money <= 0) {
if (this.player.money <= 0) {
this.gIsGameOver = true;
clearInterval(this.gRefreshInterval);
Notifications.create('GAME OVER :(');
$('#bnRestart').show();
$("#bnRestart").show();
}
},
onPayTaxes: function () {
if (World.gIsGameOver) {
return;
}
let t = -Math.floor(World.tax.totalTax());
Notifications.create("You have paid " + Math.abs(t) + " in taxes", t);
World.addMoney(t);
},
onWork: () => {
if (World.gIsGameOver) {
return;
}
let wage = Math.floor(World.player.baseIncome * World.player.productivity * Math.random());
Notifications.create("You have gained " + wage, wage);
World.addMoney(wage);
World.syncUI();
},
onRestart: () => {
World.saveScore();
World.init();
World.start();
},
onStart: () => {
if (World.onLogin()) {
World.init();
World.start();
}
},
onLogin: () => {
var username = $("#inputStart").val();
if (!(username === "")) {
$("#inputStart").hide();
$("#bnStart").hide();
$("#username").text("Logged as: " + username);
$("#username").show();
$("#errorUsername").hide();
$("#bnWork").show();
localStorage.username = username;
return true;
} else {
$("#errorUsername").text("Inserire un username corretto!");
$("#errorUsername").show();
return false;
}
},
onSaveScore: () => {
$.post("https://backend-ttom.herokuapp.com/users", { username: localStorage.username, score: World.score },
function (returnedData) {
console.log(returnedData);
});
}
}
25 changes: 25 additions & 0 deletions leaderboard/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>This Tax of Mine - Leaderboard</title>
<link rel="stylesheet" href="../css/main.css">
</head>

<body>
<table id="scoreboard">
<tr>
<th>Position</th>
<th>Username</th>
<th>Score</th>
</tr>
</table>

<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous">
</script>
<script src="./main.js"></script>
</body>

</html>
19 changes: 19 additions & 0 deletions leaderboard/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
$(document).ready(function () {
var userList = null;
$.get('https://backend-ttom.herokuapp.com/users', function (responseText) {
userList = responseText;
}).done(function() {
table(userList);
});
});

function table(list) {
var count = 1;
list.forEach(element => {
var newRowContent = '"<tr><td>'+count+'</td><td>'+element.username+'</td><td>'+element.score+'</td></tr>';
$("tbody").append(newRowContent);
console.log(element.username);
console.log(element.score);
count++;
});
}