Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 10th, 2012  |  syntax: JavaScript  |  size: 1.20 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. function play_record_click(x,y){
  3.         log('Click on '+x+' '+y);
  4.         log(clickMatrix);
  5.         // check if grid[x][y] is free
  6.        
  7.         for (c=0;c<10;++c){
  8.                 if (clickMatrix[x][y]==""){
  9.                         clickMatrix[x][y]=isTurn;
  10.                        
  11.                         isTurn=(isTurn=="X")?"0":"X";
  12.                         show_grid();
  13.                         if (c>=5){
  14.                                 check_game_result();
  15.                         }
  16.                 }
  17.                 //else{alert('This cell is allready ocupied.')}
  18.         }
  19. }
  20.  
  21.  
  22.  
  23. function game_is_finished(){
  24. //0. citeste toata matricea
  25. //      1. verifica daca sunt valori egale pe linii, coloane sau diagonale
  26. //      2. return true daca #1 este indeplinit
  27.         for (i=0; i<3; i++){
  28.                 for (j=0; j<3; j++){
  29.                         if (clickMatrix[i,j]==clickMatrix[i,j+1]==clickMatrix[i,j+2] || clickMatrix[i,j]==clickMatrix[i+1,j]==clickMatrix[i+2,j] || clickMatrix[0,0]==clickMatrix[1,1]==clickMatrix[2,2] || clickMatrix[0,2]==clickMatrix[1,1]==clickMatrix[2,0]){
  30.                                 return true;   
  31.                        
  32.                         }else{
  33.                                 return false;
  34.                         }
  35.                 }
  36.         }      
  37. }
  38.  
  39.  
  40. function check_game_result(){
  41.         log('result is '+html);
  42.         // if game_is_finished
  43.         if (game_is_finished()==true){
  44.                 var html='we have a winner';
  45.         }else{
  46.                 var html='we don\'t have a winner';
  47.         }
  48.        
  49.         document.getElementById('init_game').innerHTML = html;
  50.         return html;
  51.  
  52.        
  53.                 // show game finish form,
  54.         // else
  55. }