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

Fixed getSmallest #8

Open
wants to merge 8 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
131 changes: 102 additions & 29 deletions app.js

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions client/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ var lmx = -1;
var lmy = -1;

var upgHP = 500;
const loseVal = 20;//set max value of points where you will lose the game if you die to 20

var uiVisible = false;
var shooter_blink_state = true;
var dead = false;
var lost = false;
var respawnCooldown = 0;
var colorBlink = 0;

Expand Down Expand Up @@ -232,6 +234,11 @@ socket.on("newPositions", function(data) {
}
if (data.players[i].spawnCooldown > -1) {
dead = true;
if(data.players[i].score<=loseVal){
lost=true;//if the player doesn't have more than the losing value of points, set lost to true
}else{
lost=false;//set to false otherwise because this is a loop that goes through all players
}
respawnCooldown = data.players[i].spawnCooldown;
} else {
dead = false;
Expand Down Expand Up @@ -329,10 +336,15 @@ socket.on("newPositions", function(data) {
}

if (dead) {
$("#death").show();
countdownDiv.innerHTML = "Respawn in " + respawnCooldown;
if(lost){
$("#loseGame").show();//if the players score is low enough that they lost, show the lost screen
}else{
$("#death").show();
countdownDiv.innerHTML = "Respawn in " + respawnCooldown;//otherwise, show normal death screen and respawn countdown
}
} else {
$("#death").hide();
$("#loseGame").hide();//if the player did not die, keep death screens hidden
}
});

Expand Down
5 changes: 5 additions & 0 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
<br>
<div id="countdown" class="noselect">0</div>
</div>
<div id="loseGame" class="noselect">
<div id="dead" class="noselect">
You lost the game :( Reload the page to play again <!--Div that appears when pleyer loses-->
</div>
</div>
<div id="powerupCountdown" class="noselect">
Powerup time left:
<div id="powerupCountdownTimer">
Expand Down
15 changes: 15 additions & 0 deletions client/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,21 @@ html {
display: none;
}

#loseGame {
background-color: rgba(0,0,0,0.0);
text-align: center;
z-index: 2;
position: absolute;
margin: auto;
top: 70%;
right: 0;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
display: none;
}

#dead {
text-align: center;
font-size: 500%;
Expand Down
Empty file modified install.sh
100644 → 100755
Empty file.
98 changes: 98 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Nodejs and html5 game",
"main": "app.js",
"scripts": {
"test": "node --debug --use_strict app.js",
"test": "jasmine --config=spec/support/jasmine.json",
"start": "node app.js"
},
"repository": {
Expand All @@ -24,5 +24,8 @@
"bugs": {
"url": "https://github.com/Zeeraa/jsShooter/issues"
},
"homepage": "https://github.com/Zeeraa/jsShooter#readme"
"homepage": "https://github.com/Zeeraa/jsShooter#readme",
"devDependencies": {
"jasmine": "^3.3.1"
}
}
Empty file modified run.sh
100644 → 100755
Empty file.
11 changes: 11 additions & 0 deletions spec/support/jasmine.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
],
"stopSpecOnExpectationFailure": false,
"random": false
}
32 changes: 32 additions & 0 deletions spec/test/appSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var app = require("../../app.js");
//getDistance
describe("getDistance", function(){

it("getDistance calculates correct values for positive number input", function() {
//arrange
expect(app.getDistance(2, 2, 2, 2)).toEqual(0);

});
});

//getSmallest
describe("getSmallest", function(){

it("getSmallest finds the smallest object from array given as input", function() {
//arrange
var array = [1, 2, 3, 4, 5];
expect(app.getSmallest(array)).toEqual(1);

});
});

//getSmallest
describe("countActivePlayers", function(){

it("countActivePlayers counts the number of players playing", function() {
//arrange

expect(app.getSmallest(array)).toEqual(1);

});
});