added Server and Client Game

This commit is contained in:
Jeena Paradies 2012-07-13 19:33:52 +02:00
parent e959c8e7a2
commit bffb16e77c
5 changed files with 57 additions and 10 deletions

21
lib/Chuck/ClientGame.js Normal file
View file

@ -0,0 +1,21 @@
define(["Chuck/Processors/ClientProcessor"], function(ClientProcessor) {
function ClientGame(networker){
this.networker = networker;
this.processor = new ClientProcessor();
}
ClientGame.prototype.loadLevel = function(path) {
this.processor.loadLevel(path);
}
ClientGame.prototype.processGameCommand = function(command, options){
console.log('(not implemented) processGameCommand:', command, options);
}
ClientGame.prototype.destruct = function(){
this.processor.destruct();
}
return ClientGame;
});

View file

@ -9,7 +9,8 @@ var requires = [
"RequestAnimationFrame"
];
define(requires, function(ViewController, PhysicsEngine, Player, InputControlUnit, Settings, Box2D, Level, requestAnimFrame){
define(requires,
function(ViewController, PhysicsEngine, Player, InputControlUnit, Settings, Box2D, Level, requestAnimFrame) {
function ClientGame () {
this.init();

21
lib/Chuck/ServerGame.js Normal file
View file

@ -0,0 +1,21 @@
define(["Chuck/Processors/ServerProcessor"], function(ServerProcessor) {
function ServerGame(chanel) {
this.chanel = chanel;
this.processor = new ServerProcessor();
}
ServerGame.prototype.loadLevel = function(path) {
this.processor.loadLevel(path);
}
ServerGame.prototype.processGameCommand = function(command, options) {
console.log('(not implemented) processGameCommand:', command, options);
}
ServerGame.prototype.destruct = function() {
this.processor.destruct();
}
return ServerGame;
});

View file

@ -1,8 +1,8 @@
define(["Protocol/Helper", "Chuck/Game"], function(ProtocolHelper, Game) {
define(["Protocol/Helper", "Chuck/ClientGame"], function(ProtocolHelper, ClientGame) {
function Networker(socketLink) {
this.socketLink = socketLink;
this.game = null;
this.clientGame = null;
this.init();
}
@ -36,8 +36,8 @@ define(["Protocol/Helper", "Chuck/Game"], function(ProtocolHelper, Game) {
}
Networker.prototype.onDisconnect = function() {
this.game.destruct();
this.game = null;
this.clientGame.destruct();
this.clientGame = null;
}
Networker.prototype.join = function(channelName){
@ -50,7 +50,8 @@ define(["Protocol/Helper", "Chuck/Game"], function(ProtocolHelper, Game) {
}
Networker.prototype.onJoinSuccess = function(channelName) {
this.game = new Game(this);
this.clientGame = new ClientGame(this);
this.clientGame.loadLevel("default.json")
}
Networker.prototype.processControlCommand = function(command, options){
@ -60,7 +61,7 @@ define(["Protocol/Helper", "Chuck/Game"], function(ProtocolHelper, Game) {
break;
case 'gameCommand':
this.game.processGameCommand(options);
this.clientGame.processGameCommand(options);
break;
default:

View file

@ -1,10 +1,9 @@
define(["Chuck/Game"], function(Game) {
define(["Chuck/ServerGame"], function(ServerGame) {
function Channel(name) {
this.name = name;
this.users = {};
this.game = new Game();
// create game here
this.serverGame = new ServerGame(this);
}
Channel.validateName = function(name){
@ -19,6 +18,10 @@ define(["Chuck/Game"], function(Game) {
delete this.users[user.id];
}
Channel.prototype.sendToAllUsers = function(package) {
console.log("not implemented sendToAllUsers: " + JSON.stringify(package))
}
return Channel;
});