URLHunter를 만들어보자!!
정진경 ¶
http://joojis.net/urlhunter.php
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<script>
var maintimer=null;
var mop=new Array(40);
var hunter=20;
var time=0
var str;
function redraw(){
str="|||";
for(i=1; i<=40; i++){
if(mop[i]==1 || hunter==i){
if(mop[i]==1 && hunter==i){
str=str+'@';
}else if(mop[i]==1){
str=str+'a';
}else{ // hunter==i
str=str+'O';
}
}else{
str=str+'-';
}
}
location.href="./urlhunter.php#"+str+"||| time:"+(30-time);
}
function spawn(){
var temp=Math.floor(Math.random()*40)+1
if(mop[temp]!=0 && hunter!=temp){
mop[temp]=1;
}
}
function gametimer(){
var temp=Math.floor(Math.random()*10)+1;
if(temp<9){
spawn();
}
time++;
if(time<31){
redraw();
}else{
location.href="./urlhunter.php#Game Over";
pause();
}
}
function init(){
if(maintimer==null){
maintimer=setInterval("gametimer();", 1000);
}else{
alert("이미 실행중입니다.");
}
redraw();
}
function pause(){
clearInterval(maintimer);
maintimer=null;
}
function keyevent(){
switch(event.keyCode){
case 37: // Left
if(hunter>1){
hunter--;
}else if(hunter==1){
hunter=40;
}
break;
case 39: // Right
if(hunter<40){
hunter++;
}else if(hunter==40){
hunter=1;
}
break;
case 32: // Space Bar
if(mop[hunter]==1){
mop[hunter]=0;
}
break;
}
if(time<31){
redraw();
}
}
</script>
</head>
<body onload="init();" onkeydown="keyevent();">
<input type="button" value="pause" onclick="pause();"/>
<br/>
Hello, PHP On CentOS6! </body>
</html>
박정근 ¶
- The Hunter.html
<heml>
<head>
<title>The Hunter</title>
<script language ="Javascript" src ="Hunter.js"></script>
</head>
<body onload ="replash()">
You should kill all the monsters.
Your gun point is 'O' and 'a' is Monsters.
</body>
</html>
- Hunter.js
var replash = function(){
setInter = setInterval("URLChange();",100);
}
var CrtURL = (document.URL.indexOf('#') == -1)? document.URL+'#': document.URL.slice(0,document.URL.indexOf('#')+1);
var URLChange = function(){
if(map.peace){
clearInterval(setInter);
location.href = CrtURL + "You Killed monsters!!";
alert("The World has peace!");
}else{
map.makeS();
location.href = CrtURL + " |" + map.s.join('') + "|";
}
}
document.onkeydown = KeyInput;
function KeyInput(e){
var code = (window.event)? window.event.keyCode: e.which;
if(code == 39) map.H.right();
else if (code == 37) map.H.left();
else if (code == 32) map.kill();
}
function Monster(w){
this.where = w;
this.alive = true;
this.right = function(){this.where = (this.where+1)%50;}
this.left = function(){
this.where = (this.where-1<0)? 49: this.where-1;
}
this.randomMove = function(){
if (this.alive){
var t = (Math.floor(Math.random()*100)%3);
if(t==0)
this.right();
else if(t==1)
this.left();
}else{
this.where = -1;
}
}
}
function Hunter(w){
this.where = w;
this.right = function(){this.where = (this.where+1)%50;}
this.left = function(){
this.where = (this.where-1<0)? 49: this.where-1;
}
}
function Map(){
this.peace = false;
this.a1 = new Monster(Math.floor(Math.random()*50));
this.a2 = new Monster(Math.floor(Math.random()*50));
this.a3 = new Monster(Math.floor(Math.random()*50));
this.a4 = new Monster(Math.floor(Math.random()*50));
this.H = new Hunter(3);
this.s = new Array(50);
this.makeS = function(){
if((this.a1.where == -1)&&(this.a2.where == -1)&&(this.a3.where == -1)&&(this.a4.where == -1)) this.peace = true;
this.a1.randomMove();
this.a2.randomMove();
this.a3.randomMove();
this.a4.randomMove();
if (this.a1.alive) this.s[this.a1.where] = 'a';
if (this.a2.alive) this.s[this.a2.where] = 'a';
if (this.a3.alive) this.s[this.a3.where] = 'a';
if (this.a4.alive) this.s[this.a4.where] = 'a';
if((this.H.where==this.a1.where)||(this.H.where==this.a2.where)||(this.H.where==this.a3.where)||(this.H.where==this.a4.where))
this.s[this.H.where] = '@';
else
this.s[this.H.where] = 'O';
var i=0;
for(i = 0; i<50;i++){
if((i!=this.a1.where)&&(i!=this.a2.where)&&(i!=this.a3.where)&&(i!=this.a4.where)&&(i!=this.H.where))
this.s[i] = '-';
}
}
this.deada1 = function(){ this.a1.alive = false; }
this.deada2 = function(){ this.a2.alive = false; }
this.deada3 = function(){ this.a3.alive = false; }
this.deada4 = function(){ this.a4.alive = false; }
this.kill = function(){
if (this.H.where == this.a1.where) this.deada1();
else if(this.H.where == this.a2.where) this.deada2();
else if(this.H.where == this.a3.where) this.deada3();
else if(this.H.where == this.a4.where) this.deada4();
}
this.allkill = function(){
this.deada1();
this.deada2();
this.deada3();
this.deada4();
}
}
var map = new Map()
map.makeS();










