-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Uproszczona gra NIM - zadanie na Narzędzia Informatyki
- Loading branch information
1 parent
8193557
commit c97a765
Showing
3 changed files
with
305 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
document.getElementById("okno_info").style.display = "none"; | ||
document.getElementById("okno_podsumowania").style.display = "none"; | ||
document.getElementById("ostatni_ruch").style.visibility = "hidden"; | ||
var poleIleZetonow=document.getElementById("ileZetonow"); | ||
poleIleZetonow.value=""; | ||
var buttonOK=document.getElementById("ok"); | ||
var buttonOK1=document.getElementById("ok1"); | ||
var buttonWez1=document.getElementById("1_zeton"); | ||
var buttonWez2=document.getElementById("2_zeton"); | ||
var liczba_zetonow=0; | ||
var ktoGra="Komputer"; | ||
var wygral="Komputer"; | ||
var ktoWygral=document.getElementById("kto_wygral"); | ||
var kto="Użytkownik"; | ||
var ile=0; | ||
|
||
function refresh() | ||
{ | ||
document.getElementById("ile_zetonow").innerHTML=liczba_zetonow; | ||
} | ||
|
||
function ileWziacZetonowKomputer() | ||
{ | ||
if (liczba_zetonow==0) | ||
{ | ||
koniecGry(); | ||
} | ||
else | ||
{ | ||
if ((liczba_zetonow/3)==Math.ceil(liczba_zetonow/3)) | ||
{ | ||
liczba_zetonow=liczba_zetonow-2; | ||
ile=2; | ||
} | ||
else | ||
{ | ||
liczba_zetonow=liczba_zetonow-1; | ||
ile=1; | ||
} | ||
zmianaUzytkownika(); | ||
refreshOstatniRuch(); | ||
} | ||
|
||
} | ||
|
||
function wezJedenZeton() | ||
{ | ||
liczba_zetonow=liczba_zetonow-1; | ||
ile=1; | ||
zmianaUzytkownika(); | ||
refreshOstatniRuch(); | ||
} | ||
|
||
function wezDwaZetony() | ||
{ | ||
if(liczba_zetonow==1) | ||
{ | ||
alert("Nie możesz wziąć dwóch żetonów!"); | ||
} | ||
else | ||
{ | ||
liczba_zetonow=liczba_zetonow-2; | ||
ile=2; | ||
zmianaUzytkownika(); | ||
refreshOstatniRuch(); | ||
} | ||
} | ||
|
||
function ruch() | ||
{ | ||
if (liczba_zetonow==0) | ||
{ | ||
koniecGry(); | ||
} | ||
else | ||
{ | ||
buttonWez1.disabled=false; | ||
buttonWez2.disabled=false; | ||
} | ||
} | ||
|
||
function refreshOstatniRuch() | ||
{ | ||
if (kto=="Użytkownik") | ||
{ | ||
kto=kto+"a"; | ||
} | ||
document.getElementById("kto").innerHTML=kto; | ||
document.getElementById("ile").innerHTML=ile; | ||
document.getElementById("ostatni_ruch").style.visibility = "visible"; | ||
} | ||
|
||
function zmianaUzytkownika() | ||
{ | ||
refresh(); | ||
kto=ktoGra; | ||
if (liczba_zetonow!=0) | ||
{ | ||
if (ktoGra=="Komputer") | ||
{ | ||
ktoGra="Użytkownik"; | ||
document.getElementById("ktoGra").innerHTML=ktoGra; | ||
ruch(); | ||
refresh(); | ||
} | ||
else | ||
{ buttonWez1.disabled=true; | ||
buttonWez2.disabled=true; | ||
ktoGra="Komputer"; | ||
document.getElementById("ktoGra").innerHTML=ktoGra; | ||
window.setTimeout(ileWziacZetonowKomputer, 3000); | ||
} | ||
} | ||
else | ||
{ | ||
koniecGry(); | ||
} | ||
} | ||
|
||
function uruchom() | ||
{ | ||
document.getElementById("ostatni_ruch").style.visibility = "hidden"; | ||
liczba_zetonow=poleIleZetonow.value; | ||
if((isNaN(liczba_zetonow)) || (liczba_zetonow.length==0) || (liczba_zetonow<0) || (liczba_zetonow!=Math.ceil(liczba_zetonow))) | ||
{ | ||
alert('Podaj dodatnią liczbę naturalną!'); | ||
} | ||
else if ((liczba_zetonow<=2)) | ||
{ | ||
alert('Gramy na co najmniej 3 żetonach!'); | ||
} | ||
else | ||
{ | ||
document.getElementById("okno_podsumowania").style.display = "none"; | ||
liczba_zetonow.value | ||
poleIleZetonow.value=""; | ||
document.getElementById("okno_info").style.display = "block"; | ||
document.getElementById("okno_powitalne").style.display = "none"; | ||
refresh(); | ||
zmianaUzytkownika(); | ||
} | ||
} | ||
|
||
function keyDown(event) | ||
{ | ||
event.which = event.which || event.keyCode; | ||
if (event.which==13) | ||
{ | ||
uruchom(); | ||
} | ||
} | ||
|
||
function ktoWygralGre() | ||
{ | ||
if(ktoGra=="Komputer") | ||
{ | ||
return "Użytkownik"; | ||
} | ||
else | ||
{ | ||
return "Komputer"; | ||
} | ||
} | ||
|
||
function koniecGry() | ||
{ | ||
refreshOstatniRuch(); | ||
buttonWez1.disabled=true; | ||
buttonWez2.disabled=true; | ||
document.getElementById("okno_podsumowania").style.display = "block"; | ||
wygral=ktoWygralGre(); | ||
ktoWygral.innerHTML=wygral; | ||
poleIleZetonow=document.getElementById("ileZetonow1"); | ||
poleIleZetonow.value=""; | ||
} | ||
|
||
buttonOK.onclick = uruchom; | ||
buttonOK1.onclick = uruchom; | ||
document.onkeydown=keyDown; | ||
buttonWez1.onclick=wezJedenZeton; | ||
buttonWez2.onclick=wezDwaZetony; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>Gra NIM</title> | ||
<meta charset="utf-8"> | ||
<link rel="stylesheet" type="text/css" href="style.css"/> | ||
<link href='https://fonts.googleapis.com/css?family=Lato:400,900|Josefin+Sans:400,700&subset=latin,latin-ext' rel='stylesheet' type='text/css'> | ||
</head> | ||
<body> | ||
<div id="container"> | ||
<div id="title" class="bold"><h1>Uproszczona gra NIM</h1></div> | ||
<div id="okno_powitalne"> | ||
<span id="witaj">Na ilu żetonach chcesz grać?</span> | ||
<input id="ileZetonow" type="text" placeholder="Wpisz liczbę żetonów" /> | ||
<button id="ok" type="submit">Graj!</button> | ||
</div> | ||
<div id="okno_info"> | ||
W trakcie jednej rundy gracz może wziąć 1 lub 2 żetony. | ||
<br> | ||
Przegrywa gracz który weźmie ostatni żeton. | ||
<br> | ||
Liczba żetonów na stole: <span id="ile_zetonow" class="bold"></span>. | ||
<br> | ||
Teraz gra: <span id="ktoGra" class="bold"></span> | ||
<br> | ||
<span id="ostatni_ruch"> | ||
Liczba ostatnio zabranych żetonów ze stołu przez | ||
<span id="kto" class="bold"></span>: <span id="ile" class="bold"></span>. | ||
</span> | ||
<br> | ||
<button type="submit" id="1_zeton">Weź 1 żeton</button> | ||
<button type="submit" id="2_zeton">Weź 2 żetony</button> | ||
</div> | ||
<div id="okno_podsumowania"> | ||
Wygrał: <span id="kto_wygral" class="bold"></span> . | ||
<br> | ||
<span id="witaj1">Jeśli chcesz grać ponownie wpisz, na ilu żetonach chcesz grać!</span> | ||
<br> | ||
<input id="ileZetonow1" type="text" placeholder="Wpisz liczbę żetonów" /> | ||
<button id="ok1" type="submit">Graj!</button> | ||
</div> | ||
</div> | ||
<script src="app.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
* { | ||
box-sizing: border-box; | ||
} | ||
|
||
body { | ||
margin: 1rem; | ||
font-family: 'Lato', sans-serif; | ||
background-color: #2fa5ef; | ||
color: #FFF; | ||
font-size: 1rem; | ||
} | ||
|
||
.bold { | ||
font-weight: bold; | ||
} | ||
|
||
div { | ||
line-height: 2rem; | ||
background-color: #0e83cd; | ||
} | ||
|
||
#container { | ||
width: 48rem; | ||
background-color: #0d72bc; | ||
margin: 0 auto; | ||
border-radius: 1rem; | ||
padding: 0rem 2rem; | ||
border: 0.25rem solid #fff; | ||
} | ||
|
||
#title { | ||
height: 5rem; | ||
vertical-align: middle; | ||
padding: 1rem; | ||
background-color: #0d72bc; | ||
} | ||
|
||
h1 { | ||
text-align: center; | ||
font-family: 'Josefin Sans', sans-serif; | ||
font-size: 2rem; | ||
} | ||
|
||
#okno_info, #okno_powitalne, #okno_podsumowania { | ||
border: 0.25rem solid #fff; | ||
margin: 1rem; | ||
text-align: center; | ||
padding: 1rem; | ||
border-radius: 1rem; | ||
} | ||
|
||
#ileZetonow, #ileZetonow1 { | ||
width: 9rem; | ||
height: 2rem; | ||
} | ||
|
||
input[placeholder], input[text] { | ||
color: #0d72bc; | ||
} | ||
|
||
button { | ||
height: 2rem; | ||
background-color: #0e83cd; | ||
transition: 800ms; | ||
border: 0.2rem solid #FFF; | ||
color: #FFF; | ||
font-weight: bold; | ||
border-radius: 1rem; | ||
} | ||
|
||
button:hover, button:active { | ||
background-color: #FFF; | ||
color: #0e83cd; | ||
} | ||
|
||
button:disabled { | ||
color: #949491; | ||
background-color: #C2C2BE; | ||
} |