This commit is contained in:
Paweł Kawczyński 2018-01-24 11:28:31 +01:00
parent f57dcad25f
commit 6836da99a6
3 changed files with 38 additions and 39 deletions

View File

@ -2,14 +2,14 @@
$(document).ready(function () { $(document).ready(function () {
var canvas = $("#myCanvas")[0]; var canvas = $("#myCanvas")[0];
var ctx = canvas.getContext("2d"); var ctx = canvas.getContext("2d");
var w = $("#myCanvas").width(); var w = $("#myCanvas").width();
@ -32,7 +32,7 @@ $(document).ready(function () {
setLifeCouter(3); setLifeCouter(3);
} }
} }
function tryAgain(){ function tryAgain(){
window.location.reload(); window.location.reload();
if(localStorage.getItem("life_couter") === null ){ if(localStorage.getItem("life_couter") === null ){
@ -94,18 +94,18 @@ $(document).ready(function () {
if(localStorage.getItem("new_question") === null){ if(localStorage.getItem("new_question") === null){
localStorage.setItem('id_question', 0); localStorage.setItem('id_question', 0);
localStorage.setItem("new_question",form); localStorage.setItem("new_question",form);
alert('Dodano pytanie. Wciśnij Ok. Dodaj następne pytanie lub wciśnij F5 i graj'); alert('Dodano pytanie. Wcisnij Ok. Dodaj nastepne pytanie lub wcisnij F5 i graj');
} }
else{ else{
id_question = localStorage.getItem('id_question'); id_question = localStorage.getItem('id_question');
id_question++ ; id_question++ ;
localStorage.setItem(`new_question-${id_question}`,form); localStorage.setItem(`new_question-${id_question}`,form);
localStorage.setItem('id_question', id_question); localStorage.setItem('id_question', id_question);
alert('Dodano pytanie. Wciśnij Ok. Dodaj następne pytanie lub wciśnij F5 i graj'); alert('Dodano pytanie. Wcisnij Ok. Dodaj nastepne pytanie lub wcisnij F5 i graj');
} }
$(this).closest('form').find("input[type=text]").val(""); $(this).closest('form').find("input[type=text]").val("");
}); });
// $('#accept').click(function(){ // $('#accept').click(function(){
// var goodAnswer = $("input[class='yes']"); // var goodAnswer = $("input[class='yes']");
// console.log(goodAnswer); // console.log(goodAnswer);
@ -115,7 +115,7 @@ $(document).ready(function () {
// else{ // else{
// console.log('zla odpowiedz'); // console.log('zla odpowiedz');
// } // }
// }); // });
$('#clear_local_storage').click(function(){ $('#clear_local_storage').click(function(){
localStorage.removeItem(`new_question`); localStorage.removeItem(`new_question`);
@ -128,7 +128,7 @@ $(document).ready(function () {
$('#restart_game').click(function(){ $('#restart_game').click(function(){
setLifeCouter(3); setLifeCouter(3);
setSessionScore(0); setSessionScore(0);
alert('Zresetowałeś swoje życia, wciśnij Ok, a następnie F5 żeby zacząć od nowa'); alert('Zresetowales swoje zycia, wcisnij Ok, a nastepnie F5 zeby zaczac od nowa');
}) })
$('#add_question').click(function(){ $('#add_question').click(function(){
var isHidden = localStorage.getItem('isHidden'); var isHidden = localStorage.getItem('isHidden');
@ -149,11 +149,11 @@ $(document).ready(function () {
$('#try_again').click(function(){ $('#try_again').click(function(){
tryAgain(); tryAgain();
}) })
$('#session').text(getSessionScore()); $('#session').text(getSessionScore());
$('#lifes').text(localStorage.getItem('life_couter')); $('#lifes').text(localStorage.getItem('life_couter'));
if(localStorage.getItem('life_couter') == 0){ if(localStorage.getItem('life_couter') == 0){
alert(`Koniec gry! Twoj wynik to: ${localStorage.getItem('session_score')}. Jeżeli chcesz zagrać jeszcze raz wciśnij Ok, następnie Resetuj grę, poźniej F5`); alert(`Koniec gry! Twoj wynik to: ${localStorage.getItem('session_score')}. Jezeli chcesz zagrac jeszcze raz wcisnij Ok, nastepnie Resetuj gre, pozniej F5`);
} }
function update() { function update() {
if (d == "RIGHT") if (d == "RIGHT")
@ -173,7 +173,7 @@ $(document).ready(function () {
} }
function randomYes() { function randomYes() {
var newClass = "yes"; var newClass = "yes";
var randomKey = parseInt(Math.floor(Math.random() * 4)); var randomKey = parseInt(Math.floor(Math.random() * 4));
$("div").each(function () { $("div").each(function () {
@ -202,7 +202,7 @@ $(document).ready(function () {
} }
function showQuestionTask() { function showQuestionTask() {
function pickRandomQuestion(){ function pickRandomQuestion(){
var questionKey = 'new_question'; var questionKey = 'new_question';
var id = localStorage.getItem('id_question'); var id = localStorage.getItem('id_question');
@ -224,17 +224,17 @@ $(document).ready(function () {
var current = $('#current').text(); var current = $('#current').text();
$('#final').text(current); $('#final').text(current);
if(randomQuestion === null){ if(randomQuestion === null){
alert('Pytania nie zostaly dodane. Wciśnij Ok, następnie F5 i dodaj pytania'); alert('Pytania nie zostaly dodane. Wcisnij Ok, nastepnie F5 i dodaj pytania');
} }
randomYes(); randomYes();
addTextToAnserws(randomQuestion); addTextToAnserws(randomQuestion);
$('#popup').fadeIn(); $('#popup').fadeIn();
// $(".popup-item").each(function(index){ // $(".popup-item").each(function(index){
// var newId = "yes"; // var newId = "yes";
// }); // });
$('.yes').click(function () { $('.yes').click(function () {
if ($('.yes').is(':checked')) { if ($('.yes').is(':checked')) {
@ -252,15 +252,15 @@ $(document).ready(function () {
setSessionScore(sessionScore); setSessionScore(sessionScore);
setQuestionCouter(questionCouter); setQuestionCouter(questionCouter);
$('#restart').fadeIn('slow'); $('#restart').fadeIn('slow');
} }
}); });
$('.no').click(function(){ $('.no').click(function(){
if($('.no').is(':checked')){ if($('.no').is(':checked')){
$('#incorrect').fadeIn('slow'); $('#incorrect').fadeIn('slow');
$('.yes').attr('disabled','disabled').delay(1000);; $('.yes').attr('disabled','disabled').delay(1000);;
$('.no').prop('checked', true); $('.no').attr('disabled', 'disabled');
$('#try_again').fadeIn('slow'); $('#try_again').fadeIn('slow');
} }
}) })
} }
@ -273,7 +273,7 @@ $(document).ready(function () {
} }
} }
function placeFood() { function placeFood() {
food = { food = {
x: Math.round(Math.random() * (w - cw) / cw), x: Math.round(Math.random() * (w - cw) / cw),
@ -327,7 +327,7 @@ $(document).ready(function () {
gameloop = start(); gameloop = start();
placeFood(); placeFood();
paint_cell(food.x, food.y, "grey"); paint_cell(food.x, food.y, "grey");
placeSnake(); placeSnake();

View File

@ -20,7 +20,7 @@ body {
#add_question { #add_question {
position : absolute; position : absolute;
top: 100px; top: 100px;
left: 1750px; left: 1500px;
} }
#popup { #popup {
background-color: rgba(0,0,0,.25); background-color: rgba(0,0,0,.25);
@ -32,7 +32,7 @@ body {
position: fixed; position: fixed;
top: 0; top: 0;
width: 100%; width: 100%;
} }
input[type="text"] { input[type="text"] {
@ -62,13 +62,13 @@ input[type="text"] {
#form-popup { #form-popup {
position: absolute; position: absolute;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
display: flex; display: flex;
top: 20%; top: 20%;
left: 40%; left: 32.5%;
background-color: rgb(255,255,255); background-color: rgb(255,255,255);
border-radius: 10px; border-radius: 10px;
padding: 0; padding: 0;
@ -80,7 +80,7 @@ input[type="text"] {
#popup_question { #popup_question {
position : absolute; position : absolute;
top: 150px; top: 150px;
left: 1750px; left: 1500px;
font-size: 20px; font-size: 20px;
text-align: center; text-align: center;
color: rgb(100, 219, 223); color: rgb(100, 219, 223);
@ -232,4 +232,3 @@ a {
position:relative; position:relative;
top:1px; top:1px;
} }

View File

@ -11,7 +11,7 @@
<button id="add_question">Dodaj pytanie!</button> <button id="add_question">Dodaj pytanie!</button>
<form id='popup_question'> <form id='popup_question'>
<input type="text" name="question" placeholder="Podaj pytanie"><br> <input type="text" name="question" placeholder="Podaj pytanie"><br>
<input type="text" name="answer" placeholder="Podaj odpowiedz 1 (poprawną)"><br> <input type="text" name="answer" placeholder="Podaj odpowiedz 1 (poprawna)"><br>
<input type="text" name="answer" placeholder="Podaj odpowiedz 2"><br> <input type="text" name="answer" placeholder="Podaj odpowiedz 2"><br>
<input type="text" name="answer" placeholder="Podaj odpowiedz 3"><br> <input type="text" name="answer" placeholder="Podaj odpowiedz 3"><br>
<input type="text" name="answer" placeholder="Podaj odpowiedz 4"><br> <input type="text" name="answer" placeholder="Podaj odpowiedz 4"><br>
@ -19,7 +19,7 @@
<br> <br>
<a id="clear_local_storage">Wyczyść bazę pytań</a> <a id="clear_local_storage">Wyczyść bazę pytań</a>
</form> </form>
<div id="popup"> <div id="popup">
<div id="form-popup"> <div id="form-popup">
<h2>Odpowiedz na pytanie!</h2> <h2>Odpowiedz na pytanie!</h2>
@ -36,18 +36,18 @@
Twoj wynik to: <span id="final"></span><br> Twoj wynik to: <span id="final"></span><br>
</span> </span>
<br> <br>
<button id="restart" href="#">Wyśnij, aby kontynuować</button> <button id="restart" href="#">Wysnij, aby kontynuowac</button>
<button id="try_again" href="#">Spróbuj jeszcze raz</button> <button id="try_again" href="#">Sprobuj jeszcze raz</button>
</div> </div>
</div> </div>
<canvas id="myCanvas" width="600" height="450"> <canvas id="myCanvas" width="600" height="450">
Your browser does not support the canvas feature Your browser does not support the canvas feature
</canvas> </canvas>
<div id="score"> <div id="score">
<div>Punkty:&nbsp;<span id="session">0</span></div> <div>Punkty:&nbsp;<span id="session">0</span></div>
<div>Życia:&nbsp;<span id="lifes">4</span></div> <div>Zycia:&nbsp;<span id="lifes">4</span></div>
</div> </div>
<button id="restart_game">Resetuj grę</button> <button id="restart_game">Resetuj gre</button>
</div> </div>
<!-- Json <!-- Json
<script src="js/pytania.json" type="text/javascript"></script> --> <script src="js/pytania.json" type="text/javascript"></script> -->