466 lines
No EOL
14 KiB
HTML
466 lines
No EOL
14 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
<meta name="viewport" content="width=240">
|
|
<script src="/js/json2.js"></script>
|
|
<script src="/js/highscores.js"></script>
|
|
<title>Subdivide</title>
|
|
|
|
<style>
|
|
body
|
|
{
|
|
margin: 0px;
|
|
}
|
|
|
|
#nbessai, #remaining
|
|
{
|
|
border: 0px;
|
|
}
|
|
|
|
#ecranduhaut, #ecrandubas
|
|
{
|
|
overflow: hidden;
|
|
width: 240px;
|
|
height: 176px;
|
|
}
|
|
|
|
#resultat
|
|
{
|
|
padding-top: 2px;
|
|
font-family: Sans-Serif;
|
|
font-weight: bold;
|
|
font-size: 8pt;
|
|
line-height: 10pt;
|
|
height: 12pt;
|
|
background-color: #FFA000;
|
|
margin-top: 3px;
|
|
margin-bottom: 3px;
|
|
}
|
|
|
|
#attempt
|
|
{
|
|
margin-top: 10px;
|
|
}
|
|
|
|
#score
|
|
{
|
|
font-family: Sans-Serif;
|
|
font-weight: bold;
|
|
font-size: 8pt;
|
|
line-height: 12pt;
|
|
height: 12pt;
|
|
float: left;
|
|
margin-bottom: 3px;
|
|
margin-left: 2px;
|
|
text-align: left;
|
|
}
|
|
|
|
#level
|
|
{
|
|
font-family: Sans-Serif;
|
|
font-weight: bold;
|
|
font-size: 8pt;
|
|
line-height: 12pt;
|
|
height: 12pt;
|
|
float: right;
|
|
margin-bottom: 3px;
|
|
margin-right: 2px;
|
|
text-align: right;
|
|
}
|
|
|
|
#instruct
|
|
{
|
|
color: #000080;
|
|
}
|
|
|
|
#popup { position: absolute; left: 18px; top: 16px; width: 200px; height: 312px; border: 4px solid #777777; background-color: #DDDDDD; display: none; }
|
|
#infoarea { margin: 5px; width: 190px; height: 278px; overflow: hidden; font-size: 8px; font-family: sans-serif; color: black; }
|
|
#buttonarea { margin: 5px; width: 190px; height: 18px; line-height: 18px; background-color: #FFB000; color: #DDDDDD; }
|
|
#hiscores, #instructions { float: left; text-align: center; width: 95px; height: 18px; font: 12px sans-serif; }
|
|
.selected { background-color: #CC5500; color: white; }
|
|
</style>
|
|
|
|
<script>
|
|
function init()
|
|
{
|
|
document.body.scrollTop = 176;
|
|
}
|
|
</script>
|
|
|
|
|
|
<script language="JavaScript">
|
|
var hiscores = new HighScores("subdivide");
|
|
|
|
var COUNTS = [10, 50, 100, 250, 500, 1000, 1500, 2000, 2500, 5000, 7500, 9999];
|
|
var URlpage = location.href;
|
|
var cook;
|
|
var best;
|
|
var place;
|
|
var place2;
|
|
|
|
var level = 1;
|
|
var guesses = 5;
|
|
var score = 0;
|
|
|
|
var compteur = 0;
|
|
var plustard;
|
|
|
|
plustard = new Date(2020,11,11);
|
|
plustard = plustard.toGMTString();
|
|
|
|
function Secret()
|
|
{
|
|
var secret = Math.round(Math.random() * COUNTS[Math.min(level-1, COUNTS.length-1)]);
|
|
var xam = guesses << 2;
|
|
var sesseug = 0;
|
|
|
|
if(secret == 0) secret++;
|
|
|
|
this.isNumeric = function(str)
|
|
{
|
|
for(var i=0; i<str.length; i++)
|
|
{
|
|
if(str.charCodeAt(i) < "0".charCodeAt(0) || str.charCodeAt(i) > "9".charCodeAt(0)) return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
this.check = function(value)
|
|
{
|
|
sesseug++;
|
|
if(sesseug >= xam) window.elbasid = true;
|
|
|
|
if(value > secret) return 1;
|
|
if(value < secret) return -1;
|
|
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
function record()
|
|
{
|
|
document.jeu.rejou.value = "New game";
|
|
|
|
if(hiscores.isScoreHigher(score) && !window.elbasid) showScoreSubmit();
|
|
}
|
|
|
|
var secret = new Secret();
|
|
|
|
function verif()
|
|
{
|
|
if(!secret.isNumeric(document.jeu.essai.value)) return;
|
|
|
|
if (secret.check(document.jeu.essai.value) > 0)
|
|
{
|
|
guesses--;
|
|
{document.getElementById("resultat").innerHTML = document.jeu.essai.value + ' is too large';}
|
|
}
|
|
|
|
if (secret.check(document.jeu.essai.value) < 0)
|
|
{
|
|
guesses--;
|
|
{document.getElementById("resultat").innerHTML = document.jeu.essai.value + ' is too small';}
|
|
}
|
|
|
|
if (secret.check(document.jeu.essai.value) == 0)
|
|
{
|
|
document.jeu.nbessai.value = " ";
|
|
document.getElementById("resultat").innerHTML = 'Victory in ' + (compteur+1) + ' attempts!';
|
|
|
|
compteur = -1;
|
|
|
|
document.jeu.valid.disabled = true;
|
|
document.jeu.essai.disabled = true;
|
|
|
|
setTimeout(function() {
|
|
var points = (COUNTS[Math.min(level-1, COUNTS.length-1)] * guesses * level);
|
|
|
|
score += points;
|
|
|
|
document.getElementById("resultat").innerHTML = points + " points earned";
|
|
}, 4000);
|
|
|
|
setTimeout(function() {
|
|
level++;
|
|
guesses += 5;
|
|
secret = new Secret();
|
|
|
|
updateScore();
|
|
updateLevel();
|
|
updateInstruct();
|
|
|
|
document.getElementById("resultat").innerHTML = "You earned 5 more guesses";
|
|
}, 7000);
|
|
|
|
setTimeout(function() {
|
|
document.jeu.valid.disabled = false;
|
|
document.jeu.essai.disabled = false;
|
|
document.getElementById("resultat").innerHTML = "Begin Level "+level;
|
|
document.getElementById("remaining").value = guesses;
|
|
}, 10000);
|
|
}
|
|
|
|
document.getElementById("remaining").value = guesses;
|
|
document.jeu.nbessai.value = ++compteur;
|
|
document.jeu.essai.value="";
|
|
document.jeu.essai.focus();
|
|
|
|
updateScore();
|
|
updateLevel();
|
|
updateInstruct();
|
|
|
|
if(guesses < 1)
|
|
{
|
|
document.jeu.valid.disabled = true;
|
|
document.jeu.essai.disabled = true;
|
|
document.getElementById("resultat").innerHTML = "Game Over";
|
|
|
|
record();
|
|
}
|
|
}
|
|
|
|
function updateScore()
|
|
{
|
|
document.getElementById("score").innerHTML = "Score: "+score;
|
|
}
|
|
|
|
function updateLevel()
|
|
{
|
|
document.getElementById("level").innerHTML = "Level: "+level;
|
|
}
|
|
|
|
function updateInstruct()
|
|
{
|
|
document.getElementById("instruct").innerHTML = "Number between (1-"+(COUNTS[Math.min(level-1, COUNTS.length-1)])+")";
|
|
}
|
|
|
|
function showHighScores()
|
|
{
|
|
var scores = hiscores.getScores();
|
|
var info = document.getElementById("infoarea");
|
|
var table;
|
|
var row;
|
|
var cell;
|
|
|
|
clearElement(info);
|
|
|
|
document.getElementById("hiscores").className = "selected";
|
|
document.getElementById("instructions").className = "";
|
|
|
|
if(scores.length < 1)
|
|
{
|
|
info.appendChild(document.createTextNode("No scores are currently available."));
|
|
return;
|
|
}
|
|
|
|
table = document.createElement("table");
|
|
table.cellSpacing = "0";
|
|
table.cellPadding = "0";
|
|
table.border = "0";
|
|
table.style.width = "190px";
|
|
table.style.fontSize = "8pt";
|
|
table.style.color = "black";
|
|
|
|
|
|
for(var i=0; i<scores.length && i<20; i++)
|
|
{
|
|
row = table.insertRow(-1);
|
|
cell = row.insertCell(-1);
|
|
cell.appendChild(document.createTextNode((i+1)+". "));
|
|
cell = row.insertCell(-1);
|
|
cell.appendChild(document.createTextNode(scores[i].name));
|
|
cell = row.insertCell(-1);
|
|
cell.align = "right";
|
|
cell.appendChild(document.createTextNode(scores[i].score));
|
|
}
|
|
|
|
info.appendChild(table);
|
|
}
|
|
|
|
function clearElement(element)
|
|
{
|
|
while(element.hasChildNodes()) element.removeChild(element.childNodes[0]);
|
|
}
|
|
|
|
function showHidePopup(evt)
|
|
{
|
|
var popup = document.getElementById("popup");
|
|
|
|
if(evt && evt.keyCode != 13) return;
|
|
|
|
if(evt)
|
|
{
|
|
evt.preventDefault();
|
|
evt.stopPropagation();
|
|
}
|
|
|
|
if(popup.style.display == "block")
|
|
{
|
|
popup.style.display = "none";
|
|
clearElement(document.getElementById("infoarea"));
|
|
}
|
|
else
|
|
{
|
|
popup.style.display = "block";
|
|
|
|
if(document.getElementById("hiscores").className == "selected") showHighScores();
|
|
else showInstructions();
|
|
}
|
|
}
|
|
|
|
function showInstructions()
|
|
{
|
|
var info = document.getElementById("infoarea");
|
|
var button = document.getElementById("hiscores");
|
|
var instructions = [
|
|
"Subdivide is a game that challenges you to think logically and use your intuition to take risks.",
|
|
"Each level, the computer thinks of a random number and asks you to guess it. You have a limited number of guesses before you lose. Each time you make a successful guess, you get 5 more guesses for the next round.",
|
|
"The more guesses remaining at the end of each level, the more points you earn. The higher the level, the more each remaining guess is worth.",
|
|
"Do you have the mental skill to own the leaderboards?",
|
|
"(Use A to dismiss this window.)"
|
|
];
|
|
|
|
clearElement(info);
|
|
|
|
for(var i=0; i<instructions.length; i++)
|
|
{
|
|
var p = document.createElement("p");
|
|
|
|
p.style.textAlign = "justify";
|
|
p.style.paddingLeft = "5px";
|
|
p.style.paddingRight = "5px";
|
|
|
|
p.appendChild(document.createTextNode(instructions[i]));
|
|
info.appendChild(p);
|
|
}
|
|
|
|
document.getElementById("hiscores").className = "";
|
|
document.getElementById("instructions").className = "selected";
|
|
}
|
|
|
|
function showScoreSubmit()
|
|
{
|
|
var info = document.getElementById("infoarea");
|
|
var line;
|
|
var input;
|
|
|
|
clearElement(info);
|
|
|
|
line = document.createElement("div");
|
|
line.align = "center";
|
|
line.style.fontSize = "16px";
|
|
line.style.color = "black";
|
|
line.style.fontWeight = "bold";
|
|
line.appendChild(document.createTextNode("A new high score!"));
|
|
info.appendChild(line);
|
|
|
|
line = document.createElement("div");
|
|
line.align = "center";
|
|
line.style.fontSize = "20px";
|
|
line.style.color = "red";
|
|
line.style.fontWeight = "bold";
|
|
line.style.marginTop = "20px";
|
|
line.style.marginBottom = "20px";
|
|
line.appendChild(document.createTextNode(score));
|
|
info.appendChild(line);
|
|
|
|
line = document.createElement("div");
|
|
line.align = "center";
|
|
line.style.fontSize = "16px";
|
|
line.style.color = "black";
|
|
line.style.fontWeight = "bold";
|
|
line.style.marginBottom = "75px";
|
|
line.appendChild(document.createTextNode("Enter your name below to submit your score."));
|
|
info.appendChild(line);
|
|
|
|
line = document.createElement("div");
|
|
input = document.createElement("input");
|
|
line.align = "center";
|
|
line.style.fontSize = "16px";
|
|
line.style.color = "black";
|
|
line.style.fontWeight = "bold";
|
|
line.style.marginBottom = "10px";
|
|
input.style.width = "120px";
|
|
input.id = "user";
|
|
input.maxLength = "16";
|
|
|
|
if(hiscores.getCachedName()) input.value = hiscores.getCachedName().substring(0, 16);
|
|
|
|
line.appendChild(input);
|
|
info.appendChild(line);
|
|
|
|
line = document.createElement("div");
|
|
input = document.createElement("button");
|
|
line.align = "center";
|
|
line.style.fontSize = "16px";
|
|
line.style.color = "black";
|
|
line.style.fontWeight = "bold";
|
|
input.onclick = submitScore;
|
|
input.appendChild(document.createTextNode("Submit"));
|
|
line.appendChild(input);
|
|
info.appendChild(line);
|
|
|
|
document.getElementById("popup").style.display = "block";
|
|
}
|
|
|
|
function submitScore()
|
|
{
|
|
var user = document.getElementById("user").value;
|
|
var high = new HighScore(user, score);
|
|
|
|
if(user.length < 1) return;
|
|
|
|
high.level = level;
|
|
high.attempts = compteur;
|
|
|
|
hiscores.submitScore(high);
|
|
|
|
showHighScores();
|
|
}
|
|
|
|
document.addEventListener("keypress", showHidePopup, false);
|
|
</script>
|
|
|
|
</head>
|
|
<body onload="init()">
|
|
|
|
<div id="ecranduhaut">
|
|
<img src="logo.png" border="0">
|
|
</div>
|
|
|
|
<div id="ecrandubas">
|
|
|
|
<div align="center">
|
|
<div id="level">Level 1</div>
|
|
<div id="score">Score: 0</div>
|
|
<div> </div>
|
|
<font size="2" face="Verdana, Arial">
|
|
<form name="jeu">
|
|
<div id="instruct">Number between (1-10)</div>
|
|
<div id="attempt">
|
|
Your attempt : <input type="text" name="essai" size="3" maxlength="4">
|
|
<input type="button" name="valid" value="Guess" onClick="verif()">
|
|
</div>
|
|
|
|
<div id="resultat"></div>
|
|
|
|
Number of attempts : <input type="text" id="nbessai" name="nbessai" size=3 readonly value="0"><br />
|
|
Remaining Guesses : <input type="text" id="remaining" name="remaining" size=3 readonly value="5"><br /><br />
|
|
|
|
<input type="button" value="Scores/Instructions" onClick="showHidePopup();">
|
|
<input type="button" name="rejou" value="Replay" onClick="location.href = URlpage">
|
|
</form>
|
|
</font>
|
|
</div>
|
|
</div>
|
|
<div id="popup">
|
|
<div id="infoarea"></div>
|
|
<div id="buttonarea">
|
|
<div id="hiscores" class="selected" onclick="showHighScores(); return false;">High Scores</div>
|
|
<div id="instructions" onclick="showInstructions(); return false;">Instructions</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html> |