Add fix snake

This commit is contained in:
s434585 2018-01-16 15:35:05 +01:00
parent 71c214561a
commit af18120527
4 changed files with 59 additions and 24 deletions

View File

@ -1,5 +1,7 @@
$(document).ready(function () {
var canvas = $("#myCanvas")[0];
var ctx = canvas.getContext("2d");
var w = $("#myCanvas").width();
@ -20,6 +22,13 @@ $(document).ready(function () {
function stop(gameloop){
clearInterval(gameloop);
}
function getQuestionCouter(){
var questionCouter = localStorage.getItem("question_couter");
return questionCouter;
}
function setQuestionCouter(questionCouter){
localStorage.setItem("question_couter", questionCouter);
}
function getSessionScore(){
var sessionScore = localStorage.getItem("session_score");
@ -55,6 +64,11 @@ $(document).ready(function () {
localStorage.setItem("new_question",form);
$(this).closest('form').find("input[type=text]").val("");
});
$('#option1').click(function(){
});
$('#add_question').click(function(){
var isHidden = localStorage.getItem('isHidden');
@ -90,25 +104,31 @@ $(document).ready(function () {
paint_cell(snake.x, snake.y, "green");
}
function showGameOver() {
function showQuestionTask() {
var current = $('#current').text();
$('#final').text(current);
$('#popup').fadeIn();
$('#yes').click(function () {
$('.yes').click(function () {
if ($('#yes').is(':checked')) {
$('#correct').fadeIn('slow');
$('#session').text(getSessionScore());
$('#no').attr('disabled','disabled').delay(1000);;
$('#yes').prop('checked', false);
$('#yes').prop('checked', true);
var sessionScore = getSessionScore();
var questionCouter = getQuestionCouter();
questionCouter++;
sessionScore++;
$('#question_couter').text(questionCouter);
$('#session').text(sessionScore);
setSessionScore(sessionScore);
setQuestionCouter(questionCouter);
}
});
$('#no').click(function(){
$('.no').click(function(){
if($('#no').is(':checked')){
$('#incorrect').fadeIn('slow');
$('#yes').attr('disabled','disabled').delay(1000);;
$('#no').prop('checked', false);
localStorage.removeItem('session_score');
$('#no').prop('checked', true);
}
})
}
@ -147,8 +167,7 @@ $(document).ready(function () {
function check_borders() {
if (snake.x < 0 || snake.x > (w - cw) / cw || snake.y < 0 || snake.y > (h - cw) / cw) {
stop(gameloop);
showGameOver();
console.log("sprawdzimy")
}
}
@ -161,18 +180,22 @@ $(document).ready(function () {
function check_food() {
if (food.x == snake.x && food.y == snake.y) {
var current = parseInt($('#current').text());
current += 1;
$('#current').text(current);
checkScore(current);
// var current = parseInt($('#current').text());
// current += 1;
// $('#current').text(current);
// checkScore(current);
stop(gameloop);
showQuestionTask();
placeFood();
}
}
gameloop = start();
gameloop = start();
placeFood();
paint_cell(food.x, food.y, "grey");
placeSnake();
@ -197,7 +220,7 @@ $(document).ready(function () {
} else if (key == "40") {
snake.y += 1;
d = "DOWN";
} else if(key == "33"){
} else if(key == "32"){
reset();
}

View File

@ -55,7 +55,7 @@ body {
background-color: grey;
}
#current, #highest, #session {
#current, #highest, #session, #question_couter {
font-size : 25px;
color: black;
text-align: center;
@ -68,4 +68,4 @@ a {
span {
color : #FFFFFF;
}
}

View File

@ -21,8 +21,8 @@
Odpowiedz na pytanie!
<br>
<p>Czy lubisz jablka?</p>
<input id="yes" type="radio" value="yes" name="yes_no">Tak<br>
<input id="no" type="radio" value="no" name="yes_no">No<br>
<input class="yes" type="radio" value="option1" name="yes_no">odpowiedz1<br>
<input class="no" type="radio" value="option2" name="yes_no">odpowiedz2<br>
<a type="submit" value="submit">
<span id="correct">To jest dobra odpowiedz,<br> mozesz grac dalej!</span><br>
<!-- <button id="continue_game">Ruszaj dalej!</button> -->
@ -37,9 +37,7 @@
Your browser does not support the canvas feature
</canvas>
<div id="score">
<div>Current Score:<span id="current">0</span>
</div>
<div>Session Score:<span id="session">0</span>
<div>Session Score:<span id="session">0</span>&#47<span id="question_couter">0</span>
</div>
</div>
</div>

View File

@ -1,5 +1,19 @@
- obsluga bledu, gdzie nie ma gry,
- zjadam muche mam pytanie, jak odpowiem to dostane punkt, jak wpadne w sciane strata punktu,(poprawic mechanike snejka,
- obsluga bledu, gdzie nie ma gry,
- wyglad(głowna i strona snejka),
- pacman(jak zjada to jest pytanie),
- baza danych juz nie,
index.html:
-popup z nickiem do gry,
-zmienić icony (zamiast policji jakiś wąż, zamiast kina pacman),
-wprawadzanie pytan z budynku(pop-up)
-tablica wynik(opcjonlanie, pomyslec pozniej)
-avatar(opcjonalnie),
snejk.html:
-przy wejsciu wyswietla sie pop-up z opisem gry(jak ona działa, klawiszami sterowania i przyciskiem start!),
-zjadam muche mam pytanie, jak odpowiem to dostane punkt, jak wpadne w sciane strata punktu,(poprawic mechanike snejka,