JS+HTML5 게임 템플릿

3883 단어
game.html :
<html >
<head>
<title></title>
<script src="game.js"></script>
</head>

<canvas id="cvsPnl" width = 800 height = 500 style="border:2px #939393 solid"></canvas>

<div id="debug" style="width:200px;height:20px;"></div>
<body>
<script type="text/javascript">


var canvas = document.getElementById("cvsPnl");
var context = canvas.getContext("2d");

//// 
var gameMaster;
var debuger;
     window.onload=function(){
     gameMaster = new GameMaster(context);
     gameMaster.GameStart();
     }

//// handler
     document.onkeydown = function (){
      var key = document.all ? event.keyCode : arguments[0].keyCode;
      
      ////left
      if(key == 37){
     
      }
      ////up
      else if(key == 38){
    
      }
      ////right
      else if(key == 39){
     
      }
      
      //down
      else if(key == 40){
     
      }
     }
//// 
     document.onkeyup = function(){
     var key = document.all ? event.keyCode : arguments[0].keyCode;
     
      if(key == 37 || key == 38 || key == 39 ||key == 40){
     isKeyBoardMoving = false;
      }
     }
//// 
     document.onclick=function(e){
     //// 
     if (e.button == 0){

    // clickX = Math.round(e.clientX/10) * 10;
    // clickY = Math.round(e.clientY/10) * 10;

     }
     
     }

</script>
</body>
</html>

game.js:
document.write("<script language='javascript' src='config.js'></script>");
document.write("<script language='javascript' src='utility.js'></script>");
document.write("<script language='javascript' src='global.js'></script>");
document.write("<script language='javascript' src='debug.js'></script>");
////////////////////////
//// ////////////
////////////////////////
var debuger;
function GameMaster(context){
this.context = context;
debuger = new Debuger("debug");
}

GameMaster.prototype = {

GameStart : function(){
this.InitGame();
this.RunGame(this);
},

InitGame : function(){

},

RunGame : function(gameMaster){
if(timer){
clearInterval(timer);
}

timer = setInterval(function(){
if(gameMaster.IsGameOver()){
    alert("game over!");
clearInterval(timer);
return;
}

debuger.DebugTxt(GetCurrentDateTime());
gameMaster.Repaint();

},sleepTime);
},
    
IsGameOver : function(){
return false;
},

//// 
Repaint : function(){

}

}
config.js:

/*
 
*/

var timer;
var sleepTime = 1000;

utility.js:

/*
 
*/

//// 
function $(clientId){
return document.getElementById(clientId);
}

//// SELECT 
function GetSelectObj(clientId){
var obj = $(clientId);

var index = obj.selectedIndex; //  
return obj.options[index];
}

//// 
function GetRandom(n){return Math.floor(Math.random()*n+1)}

//// 
function addKV(k,v){
localStorage.setItem(k,v);

}

//// 
function getV(k){
return localStorage.getItem(k);
}

//// 
function getAllValueToStr(){
var content = "";
 for(var i=0;i<localStorage.length;i++){
  //key(i) , getItem() 
   content += localStorage.key(i)+ " : " + localStorage.getItem(localStorage.key(i)) + "<br />";
}
return content;
}

//// 
function GetCurrentDateTime(){
    var time ;
    with(new Date()){
        time =toLocaleString() + ' ' + ' '.charAt(getDay());
    }
    return time;
    }
global.js

debug.js:

function Debuger(clientId){
this.clientId = clientId;
}

Debuger.prototype = {

DebugTxt : function(value){

$(this.clientId).innerHTML = value;
}

}

좋은 웹페이지 즐겨찾기