<!doctype html>
<html>
<head>
<title>Star Proteins Versus Superbugs Game - RJM Programming - September, 2016 - Inspired by http://www.smh.com.au/technology/sci-tech/beyond-antibiotics-starshaped-protein-kills-feared-superbugs-20160912-grehpx.html</title>
<link href='//www.rjmprogramming.com.au/PHP/emboss_h1.css' rel='stylesheet' type='text/css'>
<script type='text/javascript'>
'use strict';
var numBricks=location.search.split('numbricks=')[1] ? eval(location.search.split('numbricks=')[1].split('&')[0]) : 40;
var numStars=7;
var numSuperbugs=7;
var thisone=-1;
var nextBrickToGo=1;
var seconds=0;
var pubu='';
var starone=null, brickone=null, superbugone=null, hone=null;
// Arrays of objects (either DOM or DOM accompanied by Class) below
var staro=[], bricko=[], superbugo=[];
var starfireo=[];
// Class code below does not work everywhere
var Star=null, Brick=null, Superbug=null;
var Starfire=null;
try {
eval(" "
+ "Star = class Star {"
+ " constructor(id, domo) {"
+ " this.id = id;"
+ " this.domo = domo;"
+ " }"
+ ""
+ " style_border(onsb) {"
+ " this.domo.style.border=onsb;"
+ " }"
+ "}; "
);
} catch(estar) {
}
try {
eval(" "
+ "Brick = class Brick {"
+ " constructor(id, domo) {"
+ " this.id = id;"
+ " this.domo = domo;"
+ " this.opacity = 1.0;"
+ " }"
+ ""
+ " getid() {"
+ " return this.id;"
+ " }"
+ ""
+ " getopacity() {"
+ " return this.opacity;"
+ " }"
+ ""
+ " setopacity(thisop) {"
+ " this.opacity=thisop;"
+ " this.domo.style.opacity=thisop;"
+ " this.domo.style.border=eval(10 - eval(thisop * 10)) + 'px solid red';"
+ " }"
+ ""
+ " style_width(sw) {"
+ " if (sw == '1px') { if (brickone) { bricko[eval(-1 + eval(brickone.getid().replace('b','')))].style_width('01px'); } brickone=this; setTimeout(fadeout,1000); } else { this.domo.style.border=''; this.domo.style.width=sw; }"
+ " }"
+ "}; "
);
} catch(ebrick) {
}
try {
eval(" "
+ "Superbug = class Superbug {"
+ " constructor(id, domo) {"
+ " this.id = id;"
+ " this.domo = domo;"
+ " this.opacity = 1.0;"
+ " }"
+ ""
+ " getid() {"
+ " return this.id;"
+ " }"
+ ""
+ " getopacity() {"
+ " return this.opacity;"
+ " }"
+ ""
+ " setopacity(thisop) {"
+ " this.opacity=thisop;"
+ " this.domo.style.opacity=thisop;"
+ " this.domo.style.border=eval(10 - eval(thisop * 10)) + 'px solid red;';"
+ " }"
+ ""
+ " style_width(sw) {"
+ " if (sw == '1px') { if (superbugone) { superbugo[eval(-1 + eval(superbugone.getid().replace('sb','')))].style_width('01px'); } superbugone=this; setTimeout(fadeout,1000); } else { this.domo.style.border=''; this.domo.style.width=sw; }"
+ " }"
+ "}; "
);
} catch(esuperbug) {
}
try {
eval(" "
+ "Starfire = class Starfire {"
+ " constructor(id, domo) {"
+ " this.id = id;"
+ " this.domo = domo;"
+ " }"
+ ""
+ " style_display(sd) {"
+ " this.domo.style.display=sd;"
+ " }"
+ "}; "
);
} catch(estarfire) {
}
function createStars(numtodo) {
var isiPad = navigator.userAgent.match(/iPad/i) != null;
var isiPhone = navigator.userAgent.match(/iPhone/i) != null;
//if ((isiPad || isiPhone) && document.URL.indexOf('.html') == -1 && document.URL.indexOf('.htm') != -1) location.href=document.URL.replace('.htm','.html');
var i, sih='';
var starlist=["onestar.jpg","twostar.jpg","threestar.jpg","fourstar.jpg","fivestar.jpg","sixstar.jpg","sevenstar.jpg"];
if (numtodo == 0) {
numStars=numtodo;
document.getElementById('stars').innerHTML='';
} else if (numtodo > 0) {
numStars=numtodo;
document.getElementById('stars').innerHTML='';
}
if (Brick) document.getElementById('myh4').innerHTML+=' ... Please note that Sound Effects could occur with this game.';
for (i=1; i<=numStars; i++) {
if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
sih+="<img style='margin-top:-70px; display:inline; -ms-transform: scale(0.5, 0.5); -webkit-transform: scale(0.5, 0.5); transform: scale(0.5, 0.5); ' id='s" + i + "' src='" + starlist[eval(-1 + i)] + "' ontouchstart='doesBrickGo(" + eval(-1 + i) + ");' onclick='doesBrickGo(" + eval(-1 + i) + ");' title='Another Protein Star " + i + " against the wall'></img><hr id='h" + i + "' style='color:red;background-color:red;height:20px;margin-top:-40px;display:none;'>";
} else {
sih+="<img id='s" + i + "' src='" + starlist[eval(-1 + i)] + "' ontouchstart='doesBrickGo(" + eval(-1 + i) + ");' onclick='doesBrickGo(" + eval(-1 + i) + ");' title='Another Protein Star " + i + " against the wall'></img><hr id='h" + i + "' style='color:red;background-color:red;height:20px;margin-top:-40px;display:none;'>";
if (Math.floor(Math.random() * 2) == 0) sih+='<br><br>';
}
}
document.getElementById('stars').innerHTML=sih;
for (i=1; i<=numStars; i++) {
if (!Star) {
staro.push(document.getElementById('s' + i));
} else {
staro.push(new Star('s' + i, document.getElementById('s' + i)));
starfireo.push(new Starfire('h' + i, document.getElementById('h' + i)));
}
}
}
function createBricks(numtodo) {
var i, bih='';
if (numtodo == 0) {
numBricks=numtodo;
document.getElementById('bricks').innerHTML='';
} else if (numtodo > 0) {
numBricks=numtodo;
document.getElementById('bricks').innerHTML='';
}
for (i=1; i<=numBricks; i++) {
bih+="<img id='b" + i + "' src='brick.jpg' title='Another brick " + i + " in the wall'></img>";
if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
if (eval(i % 3) == 0) bih+=" ";
} else {
if (eval(i % 2) == 0) bih+=" ";
}
}
document.getElementById('bricks').innerHTML=bih;
for (i=1; i<=numBricks; i++) {
if (Brick) {
bricko.push(new Brick('b' + i, document.getElementById('b' + i)));
}
}
}
function createSuperbugs(numtodo) {
var i, sih='', suffix='';
if (numtodo == 0) {
numSuperbugs=numtodo;
document.getElementById('superbugs').innerHTML='';
} else if (numtodo > 0) {
numSuperbugs=numtodo;
document.getElementById('superbugs').innerHTML='';
}
for (i=1; i<=numSuperbugs; i++) {
sih+="<img style='display:inline;' id='sb" + i + "' src='superbug.jpg' title='Another Superbug " + i + " protected by the wall'></img>" + suffix;
if (suffix == '') {
suffix='<br>';
} else {
suffix='';
}
}
if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
document.getElementById('superbugs').style.width='35%';
document.getElementById('bricks').style.width='45%'; //'50%';
document.getElementById('superbugs').innerHTML=sih;
} else if (0 == 0) {
document.getElementById('superbugs').style.width='35%';
document.getElementById('bricks').style.width='35%';
document.getElementById('superbugs').innerHTML=sih;
} else {
document.getElementById('superbugs').innerHTML='<table><tr>' + sih.replace(/<br>/g,'').replace(/\/img>/g, '/img></td>').replace(/<img/g, '<td><img') + '</tr></table>';
}
for (i=1; i<=numSuperbugs; i++) {
if (Superbug) {
superbugo.push(new Superbug('sb' + i, document.getElementById('sb' + i)));
}
}
}
function fadeout() { // can only happen if Class functionality works on this web browser
var opis=1.0, newopis;
if (brickone) {
opis=bricko[eval(-1 + eval(brickone.getid().replace('b','')))].getopacity();
newopis=eval(-0.1 + opis);
bricko[eval(-1 + eval(brickone.getid().replace('b','')))].setopacity(newopis);
if (eval(newopis) <= 0.0) {
bricko[eval(-1 + eval(brickone.getid().replace('b','')))].style_width('01px');
brickone=null;
} else {
var snd=new Audio('http://www.rjmprogramming.com.au/Games/Battleshipsandcruisers/sounds/Wind-SoundBible.com-950807958.wav');
snd.play();
}
}
if (superbugone) {
opis=superbugo[eval(-1 + eval(superbugone.getid().replace('sb','')))].getopacity();
newopis=eval(-0.1 + opis);
superbugo[eval(-1 + eval(superbugone.getid().replace('sb','')))].setopacity(newopis);
if (eval(newopis) <= 0.0) {
superbugo[eval(-1 + eval(superbugone.getid().replace('sb','')))].style_width('01px');
superbugone=null;
} else {
var snd=new Audio('http://www.rjmprogramming.com.au/Games/Battleshipsandcruisers/sounds/Thunder-Mike_Koenig-315681025.wav');
snd.play();
}
}
if (brickone || superbugone) setTimeout(fadeout, 1000);
}
function andu() {
location.href=pubu;
}
function ask(nb) {
var xnb=prompt(nb,numBricks);
if (xnb) {
if (xnb != '') {
pubu='./star_proteins_vs_superbugs.htm?numbricks=' + xnb;
} else {
pubu='./star_proteins_vs_superbugs.htm';
}
setTimeout(andu, 2000);
}
}
function doesBrickGo(tone) {
if (eval(tone) == eval(thisone)) {
if (nextBrickToGo <= numBricks) {
if (Brick) {
bricko[eval(-1 + nextBrickToGo)].style_width('1px');
} else {
document.getElementById('b' + nextBrickToGo).style.width='1px';
}
} else {
if (Superbug) {
superbugo[eval(-1 + nextBrickToGo - numBricks)].style_width('1px');
} else {
document.getElementById('sb' + eval(nextBrickToGo - numBricks)).style.width='1px';
}
}
if (Starfire) {
//alert(tone);
hone=starfireo[eval(tone)];
hone.style_display('block');
} else {
hone=document.getElementById('h' + eval(1 + tone));
hone.style.display='block';
}
nextBrickToGo++;
if (nextBrickToGo > eval(numBricks + numSuperbugs)) {
document.getElementById('superbugs').innerHTML='';
ask('Congratulations! That took you ' + seconds + ' seconds (ie. ' + eval((0.0 + seconds) / eval(eval(numBricks) + eval(numSuperbugs))) + ' seconds per brick and superbug). Another game with number of bricks in wall, below?');
}
}
}
function andthen() {
if (hone != null) {
if (Starfire) {
hone.style_display('none');
} else {
hone.style.display='none';
}
hone=null;
}
}
function startBorderizing() {
var i;
for (i=0; i<staro.length; i++) {
if (!Star) {
staro[i].style.border='';
} else {
staro[i].style_border('');
}
}
if (hone != null) {
setTimeout(andthen, 500); //1500
}
thisone=Math.floor(Math.random() * eval(0 + staro.length)) + 0;
if (!Star) {
staro[thisone].style.border='15px solid yellow';
} else {
staro[thisone].style_border('15px solid yellow');
}
if (navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i)) {
setTimeout(startBorderizing, 800);
} else {
setTimeout(startBorderizing, 1200);
}
}
function counter() {
seconds++;
setTimeout(counter,1000);
}
</script>
</head>
<body onload='createStars(-1); startBorderizing(); createBricks(-1); createSuperbugs(-1); setTimeout(counter,1000); '>
<h1 style='width:100%;text-align:center;'>Star Proteins Versus Superbugs Game</h1>
<h2 style='width:100%;text-align:center;'>RJM Programming <a target=_blank style='text-decoration:underline;' title='Another game' onclick=" ask('Another game with number of bricks in wall, below?'); ">-</a> September, 2016</h2>
<h2 style='width:100%;text-align:center;'>Inspired by <a target=_blank title='Brilliance of Shu Lam' href='http://www.smh.com.au/technology/sci-tech/beyond-antibiotics-starshaped-protein-kills-feared-superbugs-20160912-grehpx.html'>This Breakthrough</a> and thanks to this <a target=_blank title='Clipart Website ... thanks' href='http://www.clipartkid.com'>Clipart Website</a></h2>
<h4 style='width:100%;text-align:center;' id='myh4'>As Star Proteins Go Yellow Click to Break Down Wall and Superbug Protection</h4>
<table style='background-color: #f0f0f0;'>
<tr><td id='stars'><div style='-webkit-overflow-scrolling:touch;overflow:scroll;'></div></td>
<td id='bricks' style='width:20%;valign:top;border-left:1px gray dotted;'></td><td id='superbugs' style='width:50%;'></td></table>
</body>
</html>