URLHunter를 만들어보자!!
박정근 ¶
- 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();










