Added stats to the game, health left and score, and what level you are on
This commit is contained in:
37
cards.css
37
cards.css
@@ -1,14 +1,18 @@
|
||||
@import url('https://fonts.googleapis.com/css?family=Lalezar&display=swap');
|
||||
|
||||
@font-face {
|
||||
font-family: "8-bit-pusab";
|
||||
|
||||
src: url("./assets/fonts/8-bit-pusab.woff") format("woff"); /* Modern Browsers */
|
||||
src: url("./assets/fonts/8-bit-pusab.woff") format("woff");
|
||||
/* Modern Browsers */
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
*{
|
||||
}
|
||||
|
||||
* {
|
||||
transition: .3s;
|
||||
}
|
||||
|
||||
.card {
|
||||
cursor: pointer;
|
||||
padding-bottom: 85%;
|
||||
@@ -61,7 +65,8 @@
|
||||
body {
|
||||
background-color: #1d1e22;
|
||||
}
|
||||
#start-the-game{
|
||||
|
||||
#start-the-game {
|
||||
position: absolute;
|
||||
background-color: #44205c65;
|
||||
height: 100%;
|
||||
@@ -80,8 +85,28 @@ body {
|
||||
text-shadow: -5px 14px 20px rgb(0, 0, 0);
|
||||
cursor: pointer;
|
||||
}
|
||||
.printid:after{
|
||||
content:attr(id);
|
||||
|
||||
.printid:after {
|
||||
content: attr(id);
|
||||
position: absolute;
|
||||
|
||||
}
|
||||
|
||||
.stats {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-around;
|
||||
font-size: 18px;
|
||||
color: #fff;
|
||||
font-family: "8-bit-pusab";
|
||||
}
|
||||
|
||||
#container_r {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
#health {
|
||||
min-width: 170px;
|
||||
}
|
||||
27
index.php
27
index.php
@@ -1,14 +1,13 @@
|
||||
|
||||
<html>
|
||||
<head>
|
||||
|
||||
<title>My Electron Frameless Window</title>
|
||||
<head>
|
||||
<title>Blocks demo</title>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
||||
<!-- <link rel="stylesheet" href="style.css"> -->
|
||||
<link rel="stylesheet" href="cards.css">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
</head>
|
||||
<style>
|
||||
</head>
|
||||
<style>
|
||||
#particles-js {
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
@@ -19,9 +18,10 @@
|
||||
background-image: url(assets/textures/bg.png);
|
||||
background-size: cover;
|
||||
}
|
||||
</style>
|
||||
<div id="particles-js"></div>
|
||||
<body>
|
||||
</style>
|
||||
<div id="particles-js"></div>
|
||||
|
||||
<body>
|
||||
<div id="title-bar">
|
||||
<div id="title">
|
||||
Blocks
|
||||
@@ -35,6 +35,14 @@
|
||||
<!--- <div loaded="template/window_settings.html"></div> --->
|
||||
|
||||
<div class="flexwrap">
|
||||
<div class="stats">
|
||||
<div id="health"></div>
|
||||
<div id="container_r">Round: <div id="round"></div>
|
||||
</div>
|
||||
<div id="container_r"> Score: <div id="score">0</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div id="wrapper">
|
||||
<div id="test-group"></div>
|
||||
</div>
|
||||
@@ -50,5 +58,6 @@
|
||||
<!-- particles.js library -->
|
||||
<script src="http://cdn.jsdelivr.net/particles.js/2.0.0/particles.min.js"></script>
|
||||
<script src="scripts/particles.js"></script>
|
||||
</body>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -3,9 +3,9 @@ var viewspeed = 500; // time the player can see the answers MS
|
||||
var timeout = 1000; // Time after all cards showed
|
||||
var health = 5;
|
||||
var newPlayground = 3; // replaces the level variable
|
||||
var level = newPlayground*newPlayground;
|
||||
var level = newPlayground * newPlayground;
|
||||
var difficulty = -1;
|
||||
var showcontent = true; // show numbers inside the cards
|
||||
var showcontent = false; // show numbers inside the cards
|
||||
// Game settings end
|
||||
var allow_click = 0;
|
||||
var play_array = [];
|
||||
@@ -15,7 +15,12 @@ var correct_answers = 0;
|
||||
var avoid_repeat = []; // When a card is clicked, the player cant click on same card more than once
|
||||
var randoms = 0;
|
||||
var room_level;
|
||||
function initiate(){ // Call all the functions
|
||||
var no_fail_round = 0;
|
||||
var round_values = 0;
|
||||
|
||||
function initiate() { // Call all the functions
|
||||
round_value();
|
||||
lifes();
|
||||
prep();
|
||||
calc_difficulty();
|
||||
console.log(level);
|
||||
@@ -24,7 +29,9 @@ function initiate(){ // Call all the functions
|
||||
animation();
|
||||
console.log(difficulty);
|
||||
}
|
||||
function nextRound(){
|
||||
|
||||
function nextRound() {
|
||||
round_value();
|
||||
clear_playground();
|
||||
clear_values()
|
||||
calc_difficulty();
|
||||
@@ -34,28 +41,44 @@ function nextRound(){
|
||||
animation();
|
||||
console.log(difficulty);
|
||||
}
|
||||
function prep(){ // handles everythiing before the game starts
|
||||
|
||||
function prep() { // handles everythiing before the game starts
|
||||
document.getElementById("start-the-game").style.visibility = "hidden"; //hides the start button
|
||||
}
|
||||
function animation () { //Animations, shows what cards you click on
|
||||
|
||||
function round_value() {
|
||||
round_values++;
|
||||
document.getElementById("round").innerHTML = round_values;
|
||||
}
|
||||
|
||||
function animation() { //Animations, shows what cards you click on
|
||||
setTimeout(function () {
|
||||
$("#"+play_array[anim]).addClass('animations')
|
||||
$("#" + play_array[anim]).addClass('animations')
|
||||
anim++;
|
||||
if (play_array.length > anim) {
|
||||
animation();
|
||||
}else{
|
||||
} else {
|
||||
basic_timeout();
|
||||
allow_click = 1;
|
||||
}
|
||||
}, viewspeed)
|
||||
}
|
||||
function basic_timeout () { // small timeout before you can click and the shown cards disapear.
|
||||
}
|
||||
|
||||
function basic_timeout() { // small timeout before you can click and the shown cards disapear.
|
||||
setTimeout(function () {
|
||||
$(".card").removeClass('animations');
|
||||
}, timeout)
|
||||
}
|
||||
|
||||
function lifes() {
|
||||
for (let lives = 0; lives < health; lives++) {
|
||||
document.getElementById("health").innerHTML += '<img src="assets/textures/heart.png" alt="health">';
|
||||
}
|
||||
function clear_values(){ // Resets the values for next round.
|
||||
}
|
||||
|
||||
function clear_values() { // Resets the values for next round.
|
||||
newPlayground = newPlayground + 0.3;
|
||||
no_fail_round = 0;
|
||||
difficulty = -1;
|
||||
level = Math.ceil(newPlayground * newPlayground);
|
||||
play_array = [];
|
||||
@@ -68,26 +91,28 @@ function clear_values(){ // Resets the values for next round.
|
||||
allow_click = 0;
|
||||
avoid_repeat = [];
|
||||
correct_answers = 0;
|
||||
console.log("level="+level+"\n difficulty="+difficulty+"\n array="+play_array+"\n clicked_id="+clicked_id); // Console info
|
||||
console.log("level=" + level + "\n difficulty=" + difficulty + "\n array=" + play_array + "\n clicked_id=" + clicked_id); // Console info
|
||||
calc_difficulty();
|
||||
if (difficulty < level){
|
||||
// if (difficulty < level) {
|
||||
|
||||
}
|
||||
// }
|
||||
}
|
||||
function calc_difficulty(){
|
||||
if (level <= 9){ // The level value cannot be lower than 9.
|
||||
|
||||
function calc_difficulty() {
|
||||
if (level <= 9) { // The level value cannot be lower than 9.
|
||||
level = 9;
|
||||
} else{
|
||||
} else {
|
||||
level = level + 1;
|
||||
}
|
||||
difficulty = (35/100) * level + difficulty; //calc the difficulty to scale with the level
|
||||
difficulty = (35 / 100) * level + difficulty; //calc the difficulty to scale with the level
|
||||
difficulty = Math.round(difficulty) // Makes the difficulty value a integer
|
||||
}
|
||||
function make_playground(){
|
||||
|
||||
function make_playground() {
|
||||
//Loop out cards on the playground
|
||||
var i = 0;
|
||||
var card_ids = 0;
|
||||
for (var y = 0; y < newPlayground; y++){
|
||||
for (var y = 0; y < newPlayground; y++) {
|
||||
var row = document.createElement('div');
|
||||
row.setAttribute('id', 'card-row' + y);
|
||||
row.setAttribute('class', 'card-row');
|
||||
@@ -99,51 +124,58 @@ function make_playground(){
|
||||
div.setAttribute('id', card_ids);
|
||||
div.setAttribute('onClick', 'reply_click(this.id)'); // add an onClick event to the div that sends the id of it to the funcition reply_click()
|
||||
document.getElementById('card-row' + y).appendChild(div);
|
||||
if(showcontent == true){
|
||||
if (showcontent == true) {
|
||||
document.getElementById(card_ids).classList.add("printid");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function clear_playground(){ //When called, makes the playground empty
|
||||
|
||||
function clear_playground() { //When called, makes the playground empty
|
||||
document.getElementById("test-group").innerHTML = "";
|
||||
clear_values();
|
||||
} //hello
|
||||
|
||||
function randomized(){ // Fills the array with random numbers. Max number determines by level
|
||||
while(play_array.length < difficulty){
|
||||
function randomized() { // Fills the array with random numbers. Max number determines by level
|
||||
while (play_array.length < difficulty) {
|
||||
randoms = Math.floor(Math.random() * level);
|
||||
if(randoms != 0){
|
||||
if(play_array.indexOf(randoms) === -1){
|
||||
if (randoms != 0) {
|
||||
if (play_array.indexOf(randoms) === -1) {
|
||||
play_array.push(randoms);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function reply_click(clicked_id){ // Grabs the value from the id on the div/card when it's clicked on.
|
||||
function reply_click(clicked_id) { // Grabs the value from the id on the div/card when it's clicked on.
|
||||
clicked_id = Number(clicked_id);
|
||||
console.log("level="+level+"\n difficulty="+difficulty+"\n array="+play_array+"\n clicked_id="+clicked_id); // Console info
|
||||
console.log("level=" + level + "\n difficulty=" + difficulty + "\n array=" + play_array + "\n clicked_id=" + clicked_id); // Console info
|
||||
|
||||
if(play_array.includes(clicked_id)){ // Takes the id from the div and searches in the array for it. Returns either true or false.
|
||||
if (play_array.includes(clicked_id)) { // Takes the id from the div and searches in the array for it. Returns either true or false.
|
||||
// document.getElementById(clicked_id).style.border = "3px solid green"; // Makes the div/cards border green
|
||||
if(allow_click === 1){
|
||||
if (!avoid_repeat.includes(clicked_id)){
|
||||
if (allow_click === 1) {
|
||||
if (!avoid_repeat.includes(clicked_id)) {
|
||||
document.getElementById(clicked_id).style.backgroundColor = "green";
|
||||
document.getElementById(clicked_id).style.backgroundImage = "url(assets/textures/crate-green.png)";
|
||||
avoid_repeat.push(clicked_id);
|
||||
correct_answers++;
|
||||
if(play_array.length == correct_answers)
|
||||
{
|
||||
let x = document.getElementById("score").textContent;
|
||||
|
||||
if (play_array.length == correct_answers) {
|
||||
if (no_fail_round != 0) {
|
||||
document.getElementById("score").innerHTML = parseInt(x) * 1 + 13;
|
||||
} else {
|
||||
document.getElementById("score").innerHTML = parseInt(x) * 2 + 30;
|
||||
}
|
||||
alert("You survived this round!");
|
||||
nextRound();
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
//Avoid repeat fix
|
||||
if(allow_click === 1){
|
||||
if (!avoid_repeat.includes(clicked_id)){
|
||||
if (allow_click === 1) {
|
||||
if (!avoid_repeat.includes(clicked_id)) {
|
||||
// document.getElementById(clicked_id).style.border = "3px solid red"; // Makes the div/cards border red
|
||||
document.getElementById(clicked_id).style.backgroundColor = "red";
|
||||
document.getElementById(clicked_id).style.backgroundImage = "url(assets/textures/crate_bad.png)";
|
||||
@@ -151,9 +183,11 @@ function reply_click(clicked_id){ // Grabs the value from the id on the div/card
|
||||
avoid_repeat.push(clicked_id);
|
||||
|
||||
health--;
|
||||
let list = document.getElementById("health");
|
||||
list.removeChild(list.childNodes[0]);
|
||||
no_fail_round = 1;
|
||||
console.log("Liv: " + health);
|
||||
if(health == 0)
|
||||
{
|
||||
if (health == 0) {
|
||||
alert("Game over!");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user