<HTML>
<HEAD>
<basefont size=3>
<style>
.ishoppertext
{
font-size: 9px;
}
</style>
<TITLE>Make A Box Game</TITLE>
<META HTTP-EQUIV="The JavaScript Source" CONTENT = "no-cache">
<META NAME="description" CONTENT="Make a Box is a cute single player game made completely in JavaScript.">
<META NAME="date" CONTENT="2004-04-15">
<META NAME="channel" CONTENT="Web Developer">
<META NAME="author" CONTENT="Herb Hasler">
<META NAME="section" CONTENT="Games">
<STYLE>
.inputTableText {color=blue; font-family:Comic Sans MS, Bazooka; font-size: 10pt}
.resultTableText {color=white; background=gray; font-family:Comic Sans MS, Bazooka; font-size: 10pt}
</STYLE>
<SCRIPT Language="Javascript">
//
boxes = new Array(10);
vLines = new Array(10);
hLines = new Array(10);
for (i=0; i<10; i++) {
boxes[i] = new Array(10);
vLines[i] = new Array(10);
hLines[i] = new Array(10);
}
var gridSize = 9;
var canMove = false;
var compBox = false;
var compMoveAgain;
var doneMoves;
var gameStarted = false;
var htype = 'h';
var vtype = 'v';
var utype = 'u';
var ctype = 'c';
var m1;
var m2;
var m3;
var m1cnt;
var m2cnt;
var m3cnt;
var userImage = 0;
var userScore;
var compScore;
m1x = new Array(10);
m1y = new Array(10);
m2x = new Array(10);
m2y = new Array(10);
m3x = new Array(100);
m3y = new Array(100);
boxBlank = new Image(30,30);
boxBlank.src = 'blank.gif';
boxComputer = new Image(30,30);
boxComputer.src = 'computer.gif';
var boxUser = new Array(5);
for (i=0; i<5; i++) {
boxUser[i] = new Image(30,30);
boxUser[i].src = 'user' + i + '.gif';
}
var digits = new Array(10);
for (i=0; i<10; i++) {
digits[i] = new Image(64,64);
digits[i].src = 'frutti-' + i + '.gif';
}
boxVLine = new Image(5,30);
boxVLine.src = 'vline0.gif';
boxVLineH = new Image(5,30);
boxVLineH.src = 'vline1.gif';
boxHLine = new Image(35,5);
boxHLine.src = 'hline0.gif';
boxHLineH = new Image(35,5);
boxHLineH.src = 'hline1.gif';
buttonBeg = new Image(100,28);
buttonBeg.src = 'beginButton.gif';
buttonEnd = new Image(100,28);
buttonEnd.src = 'endButton.gif';
function newGame() {
gameStarted = true;
for (i=0; i<10; i++) {
for (j=0; j<10; j++) {
boxes[i][j] = 0;
vLines[i][j] = 0;
hLines[i][j] = 0;
}
}
for (j=0; j< gridSize; j++) {
for (i=0; i< gridSize; i++) {
document.images['hline'+j+i].src = boxHLine.src;
}
for (i=0; i<gridSize; i++) {
document.images['vline'+j+i].src = boxVLine.src;
document.images['box'+j+i].src = boxBlank.src;
}
document.images['vline'+j+gridSize].src = boxVLine.src;
}
for (i=0; i<gridSize; i++) {
document.images['hline'+gridSize+i].src = boxHLine.src;
}
canMove = true;
compScore = 0;
userScore = 0;
document.images['cdig1'].src = digits[0].src;
document.images['cdig2'].src = digits[0].src;
document.images['udig1'].src = digits[0].src;
document.images['udig2'].src = digits[0].src;
}
function clickButton() {
if (gameStarted == true) {
endGame();
} else {
document.images['buttonImg'].src = buttonEnd.src;
newGame();
}
}
function endGame() {
canMove = false;
var totScore = gridSize * gridSize;
gameStarted = false;
if ((compScore *1 + userScore*1) < totScore) {
compScore = totScore - userScore;
displayScore(compScore, 'cdig');
}
document.images['box31'].src = 'frutti-y.gif';
document.images['box32'].src = 'frutti-o.gif';
document.images['box33'].src = 'frutti-u.gif';
if (userScore > compScore) {
document.images['box35'].src = 'frutti-w.gif';
document.images['box36'].src = 'frutti-o.gif';
document.images['box37'].src = 'frutti-n.gif';
} else {
document.images['box35'].src = 'frutti-l.gif';
document.images['box36'].src = 'frutti-o.gif';
document.images['box37'].src = 'frutti-s.gif';
document.images['box38'].src = 'frutti-t.gif';
}
document.images['buttonImg'].src = buttonBeg.src;
}
function highLight(ltype, y, x) {
if (ltype == "h") {
var imgName = 'hline'+y+x;
document.images[imgName].src = boxHLineH.src;
} else {
var imgName = 'vline'+y+x;
document.images[imgName].src = boxVLineH.src;
}
}
function unHighLight(ltype, y, x) {
if (ltype == "h") {
if (hLines[y][x] != 1) {
var imgName = 'hline'+y+x;
document.images[imgName].src = boxHLine.src;
}
} else {
if (vLines[y][x] != 1) {
var imgName = 'vline'+y+x;
document.images[imgName].src = boxVLine.src;
}
}
}
function unHighLight(ltype, y, x)
{
if (mtype == utype && canMove == false) {
return;
}
compMoveAgain = false;
compBox = false;
if (ltype == 'h') {
if (hLines[y][x] == 0) {
hLines[y][x] = 1;
var imgName = 'hline'+y+x;
document.images[imgName].src = boxHLineH.src;
addBox(mtype, y, x);
if (y > 0) {
addBox(mtype, y*1-1, x);
}
} else {
if (mtype == utype) {
return;
}
}
} else {
if (vLines[y][x] == 0) {
vLines[y][x] = 1;
var imgName = 'vline'+y+x;
document.images[imgName].src = boxVLineH.src;
addBox(mtype, y, x);
if (x > 0) {
addBox(mtype, y, x*1-1);
}
} else {
if (mtype == utype) {
return;
}
}
}
if ((compBox == false) && (mtype == utype) && (gameStarted == true)) {
setTimeout(compMove,200);
} else {
if (mtype == ctype && compBox == true) {
compMoveAgain = true;
}
}
}
function addBox(mtype, y, x) {
var gotBox;
boxes[y][x] = (boxes[y][x])*1 +1;
gotBox = false
if (boxes[y][x] > 3) {
var imgName = 'box'+y+x;
if (mtype == utype) {
document.images[imgName].src = boxUser[userImage].src;
} else {
document.images[imgName].src = boxComputer.src;
}
updateScore(mtype);
compBox = true;
}
}
function updateScore(mtype) {
var dig1;
var dig2;
if (mtype == utype) {
userScore = userScore * 1 + 1;
displayScore(userScore, 'udig');
} else {
compScore = compScore * 1 + 1;
displayScore(compScore, 'cdig');}
if ((compScore*1 + userScore*1) >= (gridSize * gridSize)) {
endGame(); }
}
function updateScore(mtype) {
var dig1 = Math.floor(score / 10);
var dig2 = score % 10;
document.images[imgName + '1'].src = digits[dig1].src;
document.images[imgName + '2'].src = digits[dig2].src;
}
function compMove() {
if (gameStarted == false) {
return;
}
canMove = false;
compMoveAgain = false;
compDoMove();
if (compMoveAgain == false) {
canMove = true;
} else {
setTimeout(compMove,400);
}
}
function compDoMove() {
var boxY;
var boxX;
var cBoxY;
var cBoxX;
var foundMove;
var lpos;
m1cnt = 0;
m2cnt = 0;
m3cnt = 0;
doneMoves = true;
for (i=0; i<gridSize; i++) {
for (j=0; j<gridSize; j++) {
if (boxes[i][j] == 3) {
if (m1cnt < 10) {
m1x[m1cnt] = j;
m1y[m1cnt] = i;
m1cnt = m1cnt * 1 + 1;
}
} else if (boxes[i][j] == 2) {
if (m2cnt < 10) {
m2x[m2cnt] = j;
m2y[m2cnt] = i;
m2cnt = m2cnt * 1 + 1;
}
} else if (boxes[i][j] < 2) {
if (m3cnt < 100) {
m3x[m3cnt] = j;
m3y[m3cnt] = i;
m3cnt = m3cnt * 1 + 1;
}
}
}
}
if (m1cnt > 0) {
lpos = Math.floor(Math.random() * m1cnt);
boxX = m1x[lpos];
boxY = m1y[lpos];
} else if (m3cnt > 0) {
lpos = Math.floor(Math.random() * m3cnt);
boxX = m3x[lpos];
boxY = m3y[lpos];
} else if (m2cnt > 0) {
lpos = Math.floor(Math.random() * m2cnt);
boxX = m2x[lpos];
boxY = m2y[lpos];
}
cBoxY = boxY;
cBoxX = boxX;
foundMove = false;
compMoveAgain = false;
if (Math.floor(Math.random() * 2) == 1) {
for (j=0; j<2 && foundMove == false; j++) {
cBoxY = (boxY*1 + j*1);
if (cBoxY >= 0 && cBoxY <= gridSize) {
if (hLines[cBoxY][cBoxX] == 0) {
addLine(ctype, htype, cBoxY, cBoxX);
foundMove = true;
}
}
}
cBoxY = boxY;
cBoxX = boxX;
}
for (i=0; i< 2 && foundMove == false; i++) {
cBoxX = (boxX*1 + i*1);
if (cBoxX >= 0 && cBoxX <= gridSize) {
if (vLines[cBoxY][cBoxX] == 0) {
addLine(ctype, vtype, cBoxY, cBoxX);
foundMove = true;
}
}
}
cBoxX = boxX;
for (j=0; j<2 && foundMove == false; j++) {
cBoxY = (boxY*1 + j*1);
if (cBoxY >= 0 && cBoxY <= gridSize) {
if (hLines[cBoxY][cBoxX] == 0) {
addLine(ctype, htype, cBoxY, cBoxX);
foundMove = true;
}
}
}
}
function rotateImage() {
var prevImage = userImage;
userImage = userImage*1 + 1;
if (userImage > 4) {
userImage = 0;
}
document.images['userImage'].src = boxUser[userImage].src;
for (i=0; i<gridSize; i++) {
for (j=0; j<gridSize; j++) {
if (document.images['box'+i+j].src == boxUser[prevImage].src) {
document.images['box'+i+j].src = boxUser[userImage].src;
}
}
}
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR=#ffffff vlink=#0000FF background="Clear_Day_Bkgrd.jpg">
<center>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%"
id="table4" height="21">
<tr>
<td width="100%" bgcolor="#058F40" bordercolor="#FFFFFF" height="21">
<p align="center"><b><font face="Verdana" size="2" color="#FFFFFF">::
Welcome ::</font></b></td>
</tr>
</table>
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%"
id="table5" height="260">
<tr>
<td width="100%" bgcolor="#C0C0C0" height="19" bordercolor="#808080">
<p align="center" style="margin-top: 0; margin-bottom: 0"><b>
<font face="Arial" size="2">Make A Box Game</font></b></td>
</tr>
<tr>
<td width="100%" height="242" bgcolor="#F4FDEC">
<script language="JavaScript" type="text/javascript"><!--
function openDescription(ID) {
var url = "http://www.ppcforhosts.com/public/util/description.cfm?id=" + ID;
link =
window.open(url,"newWin","directories=0,height=250,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0,wid
th=450");
}
//--></script>
<BR>
<BR>
<table width="100%" cellpadding=0 cellspacing=0 border=0 id="table6">
<tr><td width="99%" align=center>
<basefont size=3>
<BR>
<center>
<b><font size="7"><img border="0" src="frutti-m.gif" width="56" height="60"><img border="0" src="frutti-a.gif"
width="57" height="61"><img border="0" src="frutti-k.gif" width="57" height="61"><img border="0" src="frutti-e.gif"
width="57" height="61">
<img border="0" src="frutti-a.gif" width="57" height="61">
<img border="0" src="frutti-b.gif" width="57" height="61"><img border="0" src="frutti-o.gif" width="57" height="61"><img
border="0" src="frutti-x.gif" width="57" height="61"></font></b></center>
<p>
<TABLE BORDER="0" WIDTH="845" CELLPADDING="0" CELLSPACING="0" id="table7">
<TR>
<TD WIDTH="75" ROWSPAN="6"> </TD>
</TR>
</TR>
<TD WIDTH="375" ROWSPAN="6">
<SCRIPT>
for (j=0; j<gridSize; j++) {
for (i=0; i<gridSize; i++) {
document.write('<a href="javascript:addLine(utype,htype,'+j+','+i+')" onMouseover="highLight(htype,'+j+','+i+')"
onMouseout="unHighLight(htype,'+j+','+i+')"><IMG SRC="hline0.gif" BORDER=0 NAME="hline' + j + + i +'"
WIDTH="35" HEIGHT="5"></A>');
}
document.write('<IMG SRC="hline0.gif" BORDER=0 NAME="hlineEnd" WIDTH="35" HEIGHT="5">');
document.write('<br>');
for (i=0; i<gridSize; i++) {
document.write('<a href="javascript:addLine(utype,vtype,'+j+','+i+')" onMouseover="highLight(vtype,'+j+','+i+')"
onMouseout="unHighLight(vtype,'+j+','+i+')"><IMG SRC="vline0.gif" BORDER=0 NAME="vline' + j+ i+ '"
WIDTH="5" HEIGHT="30"></a>');
document.write('<IMG SRC="blank.gif" BORDER=0 NAME="box' + j + i + '" WIDTH="30" HEIGHT="30">');
}
document.write('<a href="javascript:addLine(utype,vtype,'+j+','+gridSize+')"
onMouseover="highLight(vtype,'+j+','+gridSize+')" onMouseout="unHighLight(vtype,'+j+','+gridSize+')"><IMG
SRC="vline0.gif" BORDER=0 NAME="vline' + j+ gridSize + '" WIDTH="5" HEIGHT="30">');
document.write('<br>');
}
for (i=0; i<gridSize; i++) {
document.write('<a href="javascript:addLine(utype,htype,'+gridSize+','+i+')"
onMouseover="highLight(htype,'+gridSize+','+i+')" onMouseout="unHighLight(htype,'+gridSize+','+i+')"><IMG
SRC="hline0.gif" BORDER=0 NAME="hline' + gridSize + i +'" WIDTH="35" HEIGHT="5">');
}
document.write('<IMG SRC="hline0.gif" BORDER=0 NAME="hlineEnd" WIDTH="35" HEIGHT="5">');
document.write('<br>');
document.images['box22'].src = 'frutti-c.gif';
document.images['box23'].src = 'frutti-l.gif';
document.images['box24'].src = 'frutti-i.gif';
document.images['box25'].src = 'frutti-c.gif';
document.images['box26'].src = 'frutti-k.gif';
document.images['box32'].src = 'frutti-b.gif';
document.images['box33'].src = 'frutti-e.gif';
document.images['box34'].src = 'frutti-g.gif';
document.images['box35'].src = 'frutti-i.gif';
document.images['box36'].src = 'frutti-n.gif';
document.images['box43'].src = 'frutti-t.gif';
document.images['box44'].src = 'frutti-o.gif';
document.images['box52'].src = 'frutti-s.gif';
document.images['box53'].src = 'frutti-t.gif';
document.images['box54'].src = 'frutti-a.gif';
document.images['box55'].src = 'frutti-r.gif';
document.images['box56'].src = 'frutti-t.gif';
</SCRIPT>
</TD>
</TR>
<TR>
<TD align="center" width="395">
<br><A HREF="javascript:rotateImage()"><IMG SRC="user0.gif" BORDER=0 NAME="userImage" HEIGHT="48"
WIDTH="48"></A><br>
<b>Click To Change Your Icon</b></TD>
</TR>
<TR>
<TD align="center" width="395">
<BUTTON NAME="beginButton" onClick="clickButton()">
<IMG NAME="buttonImg" SRC="beginButton.gif" WIDTH="170" HEIGHT="170"></BUTTON>
</TD>
</TR>
<TR>
<TD align="center" width="395">
<b><font size="7">
<img border="0" src="frutti-y.gif" width="57" height="61"><img border="0" src="frutti-o.gif" width="57" height="61"><img
border="0" src="frutti-u.gif" width="56" height="60"><img border="0" src="frutti-dash.gif" width="37"
height="60"></font></b><IMG SRC="frutti-0.gif" BORDER=0 WIDTH="55" HEIGHT="60" NAME="udig1"><IMG
SRC="frutti-0.gif" BORDER=0 WIDTH="60" HEIGHT="60" NAME="udig2">
</TD>
</TR>
<TR>
<TD align="center" width="395">
<font size="7"><b> <img border="0" src="frutti-c.gif" width="57" height="61"><img border="0" src="frutti-o.gif"
width="57" height="61"><img border="0" src="frutti-m.gif" width="56" height="60"><img border="0" src="frutti-p.gif"
width="56" height="61"></b></font><b><font size="7"><img border="0" src="frutti-dash.gif" width="37"
height="60"></font></b><IMG SRC="frutti-0.gif" BORDER=0 WIDTH="60" HEIGHT="60" NAME="cdig1"><IMG
SRC="frutti-0.gif" BORDER=0 WIDTH="60" HEIGHT="60" NAME="cdig2">
</TD>
</TR>
</TABLE>
</FORM>
<P>
<P>
<a name="source">
</form>
<!--content_stop-->
<p>
</tr>
</table>
</td>
</tr>
</table>
<!-- text below generated by server. PLEASE REMOVE --><!-- Counter/Statistics data collection code --><script
language="JavaScript" src="http://hostingprod.com/js_source/geov2.js"></script><script
language="javascript">geovisit();</script>
<noscript><img src="http://visit.webhosting.yahoo.com/visit.gif?us1125289487" alt="setstats" border="0" width="1"
height="1">
</noscript>
<img SRC="http://geo.yahoo.com/serv?s=76001405&t=1125289487" ALT="1" WIDTH="1" HEIGHT="1"><SCRIPT
LANGUAGE="JavaScript">
<!-- Begin
function getCookieVal (offset) {
var endstr = document.cookie.indexOf(";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0)
break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = "/"; //(argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" +
expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
var emailcookie = GetCookie('email_address');
if (emailcookie == null) {
emailcookie = 'your email here';
}
function chk(email, formname)
{
invalid = "";
if (!email)
invalid = "No email address found! Try reloading the page then use the 'email a script' feature again.";
else {
if ( (email.indexOf("@") == -1) || (email.indexOf(".") == -1) )
invalid += "\n\nInvalid email address. Your email address is missing an '@' sign and a '.' in the domain name (like '.com').
Please check your address then submit again.";
if (email.indexOf("youremailhere") > -1)
invalid += "\n\nInvalid email address. Make sure your email address included your username, the '@' sign, and the domain
name (like '.com').";
if (email.indexOf("\\") > -1)
invalid += "\n\nEmail address contains an invalid back-slash (\\) character. Remove the character and submit again.";
if (email.indexOf("/") > -1)
invalid += "\n\nEmail address contains an invalid forward-slash (/) character. Remove the character and submit again.";
if (email.indexOf("'") > -1)
invalid += "\n\nEmail address contains an invalid apostrophe (') character. Remove the character and submit again.";
if (email.indexOf("zaz.com.br") > -1)
invalid += "\n\nPlease do not use an email address that has an autoresponder set up for it. Thanks.";
if (email.indexOf("!") > -1)
invalid += "\n\nEmail address contains an invalid exclamation point (!) character. Remove the character or correct the email
address then submit again.";
if ( (email.indexOf(",") > -1) || (email.indexOf(";") > -1) )
invalid += "\n\nPlease only enter one email address in the box at a time. Remove the extra addresses and submit again.";
if (email.indexOf("?subject") > -1)
invalid += "\n\nPlease do not add '?subject=...' to your email address. Scriptbot will send you the script with a pre-defined
subject already. Please remove the '?subject=...' from your email address and submit again.";
}
if (invalid == "")
{
var largeExpDate = new Date();
largeExpDate.setTime(largeExpDate.getTime() + (31 * 24 * 3600 * 1000));
SetCookie('email_address', email, largeExpDate);
if (formname == "scriptbot")
{
page = "http://javascript.internet.com/sent.html?" + email;
window.open(page, "AdWindow", "width=650,height=200");
}
return true;
}
else
{
alert("Oops, something is wrong...." + invalid);
return false;
}
}
function updateNewsletters() {
with (document.forms["newslettersignup"]) {
emailStr = email.value;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"; // remove ( ) < > @ , ; : \ " . [ ] */
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
alert("Email address seems incorrect (check @ and .'s)");
return false;;
}
var user=matchArray[1];
var domain=matchArray[2];
if (user.match(userPat)==null) {
alert("The username doesn't seem to be valid.");
return false;
}
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Destination IP address is invalid!");
return false;
}
}
}
var domainArray=domain.match(domainPat);
if (domainArray==null) {
alert("The domain name doesn't seem to be valid.");
return false;
}
var atomPat=new RegExp(atom,"g");
var domArr=domain.match(atomPat);
var len=domArr.length;
if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) {
alert("The address must end in a three-letter domain, or two letter country.");
return false;
}
if (len<2) {
var errStr="This address is missing a hostname!";
alert(errStr);
return false;
}
List_Name.value = newsletter.options[newsletter.selectedIndex].value
+ nltype.options[nltype.selectedIndex].value;
var largeExpDate = new Date();
largeExpDate.setTime(largeExpDate.getTime() + (31 * 24 * 3600 * 1000));
SetCookie('email_address', emailStr, largeExpDate);
return true;
}
}
// End -->
</script><p>
</body></html>
|