first commit

This commit is contained in:
2020-03-04 10:01:48 +01:00
commit a190ac0ea5
7 changed files with 376 additions and 0 deletions

4
scripts/blockamount.js Normal file
View File

@@ -0,0 +1,4 @@
$("<h1>Include this using jquery</h1>").appendTo("body");
console.log($("body").html());

131
scripts/gameboard.js Normal file
View File

@@ -0,0 +1,131 @@
// Game settings
var viewspeed = 500; // time the player can see the answers MS
var timeout = 1000; // Time after all cards showed
var health = 5;
var level = 9;
var difficulty = 3;
var showcontent = false; // show numbers inside the cards
// Game settings end
var play_array = [];
var anim = 0;
var y = 1;
var correct_answers = 0;
function initiate(){ // Call all the functions
calc_difficulty();
console.log(level);
make_playground();
randomized();
animation();
console.log(difficulty);
}
// function animation(){
// for(anim = 0; play_array.length > anim; anim++){
// // document.getElementById(play_array[anim]).style.border = "3px solid green";
// console.log(anim);
// // $("#"+play_array[anim]).addClass('animations');
// // setTimeout(function () {
// // $("#"+play_array[anim]).removeClass('animations');
// // }, 2000);
// }
// }
function animation () {
setTimeout(function () {
$("#"+play_array[anim]).addClass('animations')
anim++;
if (play_array.length > anim) {
animation();
}else{
basic_timeout();
}
}, viewspeed)
}
function basic_timeout () {
setTimeout(function () {
$(".card").removeClass('animations');
}, timeout)
}
function clear_values(){
play_array = [];
randoms = null;
}
function calc_difficulty(){
if (level < 9){ // The level value cannot be lower than 9.
level = 9;
} else{
level = level + 1;
}
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(){
//Loop out cards on the playground
var i;
for (i = 1; i < level; i++) { //Creates a new div for each loop wth the attributes and content set below.
var div = document.createElement('div');
if(showcontent == true){
div.textContent = i;
}
div.setAttribute('class', 'card');
div.setAttribute('id', i);
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("wrapper").appendChild(div);
}
}
function clear_playground(){ //When called, makes the playground empty
document.getElementById("wrapper").innerHTML = "";
clear_values();
} //hello
function randomized(){ // Fills the array with random numbers. Max number determines by level
while(play_array.length < difficulty){
var randoms = Math.floor(Math.random() * level) + 1;
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.
clicked_id = Number(clicked_id);
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.
document.getElementById(clicked_id).style.border = "3px solid green"; // Makes the div/cards border green
document.getElementById(clicked_id).style.backgroundColor = "green";
correct_answers++;
if(play_array.length == correct_answers)
{
alert("You survived this round!");
}
}else{
document.getElementById(clicked_id).style.border = "3px solid red"; // Makes the div/cards border red
document.getElementById(clicked_id).style.backgroundColor = "red";
health--;
console.log("Liv: " + health);
if(health == 0)
{
alert("Game over!");
}
}
document.getElementById("alerted").innerHTML = clicked_id; // Just prints it out on the screen for testing
}
/*
pseudocode:'
/
if (exists) clicked_id= randomized[x] = true
if (value already added skip(Done with array, if exists/contains)) = false
variable add 1
if variable(int) == all answers(int) = true
next round
add score
else
health - 1
if health < 5
gameover
*/

55
scripts/main.js Normal file
View File

@@ -0,0 +1,55 @@
// Modules to control application life and create native browser window
const {app, BrowserWindow} = require('electron')
const path = require('path')
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 800,
height: 600,
frame: false,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: true
}
})
// and load the index.html of the app.
mainWindow.loadFile('index.html')
// Open the DevTools.
// mainWindow.webContents.openDevTools()
// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null
})
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)
// Quit when all windows are closed.
app.on('window-all-closed', function () {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') app.quit()
})
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) createWindow()
})
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.