Netscape 6, Part VI: Object-Oriented DOCJSLIB 1.2: connectthree.html - Doc JavaScript | WebReference

Netscape 6, Part VI: Object-Oriented DOCJSLIB 1.2: connectthree.html - Doc JavaScript


Netscape 6, Part VI: Object-Oriented DOCJSLIB 1.2

connectthree.html

<HTML>
<HEAD>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript" SRC="browserSniffer.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="createTheProperSubClass.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="docjslibSuperClass.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="docjslibIE4SubClass.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="docjslibIE5SubClass.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="docjslibNS4SubClass.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="docjslibNS6SubClass.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
var classSelectionObj = new createTheProperSubClass();
var myBrowserAPIObj = classSelectionObj.getTheProperSubClass();
function rowComplete() {
  var lastPlayedBy = grid[1][1];
  if ((lastPlayedBy != "") &&
      (grid[2][1] == lastPlayedBy) &&
      (grid[3][1] == lastPlayedBy)) return(true);
  lastPlayedBy = grid[1][2];
  if ((lastPlayedBy != "") && 
      (grid[2][2] == lastPlayedBy) &&
      (grid[3][2] == lastPlayedBy)) return(true);
  lastPlayedBy = grid[1][3];
  if ((lastPlayedBy != "") && 
      (grid[2][3] == lastPlayedBy) &&
      (grid[3][3] == lastPlayedBy)) return(true);
  lastPlayedBy = grid[1][1];
  if ((lastPlayedBy != "") && 
      (grid[1][2] == lastPlayedBy) &&
      (grid[1][3] == lastPlayedBy)) return(true);
  lastPlayedBy = grid[2][1];
  if ((lastPlayedBy != "") && 
      (grid[2][2] == lastPlayedBy) &&
      (grid[2][3] == lastPlayedBy)) return(true);
  lastPlayedBy = grid[3][1];
  if ((lastPlayedBy != "") && 
      (grid[3][2] == lastPlayedBy) &&
      (grid[3][3] == lastPlayedBy)) return(true);
  lastPlayedBy = grid[1][1];
  if ((lastPlayedBy != "") && 
      (grid[2][2] == lastPlayedBy) &&
      (grid[3][3] == lastPlayedBy)) return(true);
  lastPlayedBy = grid[1][3];
  if ((lastPlayedBy != "") && 
      (grid[2][2] == lastPlayedBy) &&
      (grid[3][1] == lastPlayedBy)) return(true);
}
function itsAtie() {
  for( var i = 1; i <= 3; i++)
    for( var j = 1; j <= 3; j++)
      if (grid[i][j] == "") return(false);
  return(true);
}
function handleImageClick(id, param1, param2) {
    if (myBrowserAPIObj.getSrc(id).indexOf('initialbutton.gif') < 0) return;  
    if (lastPlayedBy == "o") {
      myBrowserAPIObj.setSrc(id, "xbutton.gif");
      lastPlayedBy = "x";
    } 
    else {  // lastPlayedBy = "x"
      myBrowserAPIObj.setSrc(id, "obutton.gif");
      lastPlayedBy = "o";
    }
    grid[param1][param2] = lastPlayedBy;
    if (rowComplete()) {
      alert("The " + lastPlayedBy + " wins");
      window.location.reload();
    }
    else if (itsAtie()) {
           alert("It's a tie");
           window.location.reload();
         }
}
var lastPlayedBy = "o";
var grid = new Array();
grid[1] = new Array();
grid[2] = new Array();
grid[3] = new Array();
for (var i = 1; i <= 3; i++)
  for (var j = 1; j <= 3; j++)
    grid[i][j] = "";
 
var xBase = 8;
var yBase = 8;
for (var i = 1; i <= 3; i++) {
  for (var j = 1; j <= 3; j++) {
    myBrowserAPIObj.makeImage("box" + i + "" + j,          // id
              "initialbutton.gif",         // URL
              100,                         // height
              100,                         // width
              "game box",                  // alternative
               xBase + (i-1) * 108,        // position from left
               yBase + (j-1) * 108,        // position from top
               i,                          // parameter passed to onclick handler
               j);                         // parameter passed to onclick handler
  }
}
// -->
</SCRIPT>
</BODY>
</HTML>

Next: Browser sniffer

http://www.internet.com


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: February 12, 2001
Revised: February 12, 2001

URL: http://www.webreference.com/js/column77/10.html