Skip to content

Instantly share code, notes, and snippets.

@vinothbabu
Created September 3, 2012 16:06
Show Gist options
  • Save vinothbabu/3610325 to your computer and use it in GitHub Desktop.
Save vinothbabu/3610325 to your computer and use it in GitHub Desktop.
Puzzle Game - Titanium and JavaScript
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>15 Puzzle</title>
<style type="text/css">
body{color:black;background:white;font-family:Arial,Helvetica,sans-serif;font-size:20px;margin:0;}
table tr td{text-align:center;}
td.puzzle{background-color:#777;}
table table{border:1px solid #777;}
td.puzzle td{border:1px solid #777;width:3em;height:3em;font-size:small;background-color:#eee;}
td.puzzle td.blank{background-color:white;}
</style>
</head>
<body>
<script type="text/javascript">
Array.prototype.toTable=function(){
var t=document.createElement('table');
var rows=[t.insertRow(0),t.insertRow(1),t.insertRow(2),t.insertRow(3)];
for(var i=0;i<4;i++)
for(var j=0;j<4;j++)
{
t.rows[i].insertCell(j);
if(this[i*4+j]!=null)t.rows[i].cells[j].appendChild(document.createTextNode(this[i*4+j]));
else t.rows[i].cells[j].appendChild(document.createTextNode("\xa0")).parentNode.className='blank';
};
return t;
}
</script>
<div>
<h1 style="text-align:center;">15 Puzzle</h1>
</div>
<center>
<table>
<tr><th>Puzzle</th></tr>
<tr><td class="puzzle">
<div id="puzzle"></div>
</td></tr>
<tr><td colspan="2" style="background-color:white;padding-right:0;margin-right:0;">
</table>
</center>
<script type="text/javascript">
var table=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,null].toTable();
document.getElementById("puzzle").appendChild(table);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment