Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- setInterval(function(){time()},1000);
- var sec = -1;
- var w,k;
- function time()
- {
- if(sec>-1){
- $('#time').html(sec++);
- }
- }
- function getId(strId) {
- arr = new Array(2);
- arr[0]=strId.substring(3, strId.indexOf('_'));
- arr[1]=strId.substring(strId.indexOf('_')+1, strId.length);
- return arr
- }
- function Picture(accept) {
- this.val;
- do{
- rand = Math.floor(Math.random() * accept.length);
- }while(accept[rand]==2);
- accept[rand]++;
- this.val = rand;
- }
- function GameBoard(n,m) {
- this.n = n;
- this.m = m;
- score = 0;
- picBoard = new Array(n);
- last = -1;
- accepTab = new Array(n*m/2);
- for (var i=0; i<accepTab.length; i++){
- accepTab[i] = 0;
- }
- for (var i=0; i<picBoard.length; i++){
- picBoard[i] = new Array(m);
- for (var j=0; j<picBoard[i].length; j++){
- picBoard[i][j] = new Picture(accepTab);
- }
- }
- function getPicture(id) {
- return picBoard[id[0]][id[1]].val
- }
- function show(obj){
- val = getPicture(getId(obj.id));
- $(obj).html(val);
- if(last==-1){
- last = val;
- lastId = getId(obj.id);
- } else {
- if(last==val){
- $('#score').html(++score);
- } else {
- setTimeout(function(){
- $(obj).html("X");
- $("#col"+lastId[0]+"_"+lastId[1]).html("X");
- }, 1000);
- }
- last=-1;
- }
- }
- for(var i=0; i<n; i++){
- $("#board").append("<div class=row id=row"+i+"> ");
- for(var j=0; j<m; j++){
- $("#board #row"+i).append("<span class=col id=col"+i+"_"+j+">X");
- $("#col"+i+"_"+j).bind("click", function() {
- show(this);
- });
- }
- }
- }
- var board;
- function start(){
- board = new GameBoard(w,k);
- sec=0;
- $("#start").unbind("click");
- }
- $().ready(function () {
- $("#start").bind("click", function() {
- wielkosc();
- });
- });
- function wielkosc() {
- w = parseInt(document.getElementById("w").value)
- k = parseInt(document.getElementById("k").value)
- if(w*k%2==0)
- start()
- else{
- alert("Bledny rozmiar tablicy");}
- }
- //////////////////////////////////////////////////////
- <!DOCTYPE html>
- <head>
- <meta charset="utf-8" />
- <link rel="stylesheet" href="style.css" />
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
- <script src="skrypt.js"></script>
- <title>Tytuł strony / podstrony</title>
- </head>
- <body>
- <header>
- <h1>Pamięć</h1>
- </header>
- <section>
- <p>
- <div class="button" id="start">Start</div>
- <div>
- Czas: <span id="time">0</span>
- </div>
- <div>
- Wynik: <span id="score">0</span>
- </div>
- </p>
- <div id="board"></div>
- </section>
- <section>
- wiersze: <input type="text" id="w" name="wier"><br>
- kolumny: <input type="text" id="k" name="kol"><br>
- </section>
- <footer>
- <p>
- <p>Copyright © 2014 jkozak.pl</p>
- </p>
- </footer>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement