[common] add BaseControlFactory
This commit is contained in:
@@ -1,22 +1,10 @@
|
||||
package ru.m.tankz.control;
|
||||
|
||||
import ru.m.tankz.bot.StupidBotControl;
|
||||
import ru.m.tankz.bot.HardBotControl;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
class ClientControlFactory implements IControlFactory {
|
||||
class ClientControlFactory extends BaseControlFactory {
|
||||
|
||||
public function new() {}
|
||||
|
||||
public function build(id:PlayerId, controller:Controller):Control {
|
||||
return switch controller {
|
||||
case HUMAN(index): new HumanControl(id, index);
|
||||
case BOT(type): switch type {
|
||||
case StupidBotControl.BOT_TYPE: new StupidBotControl(id);
|
||||
case HardBotControl.BOT_TYPE: new HardBotControl(id);
|
||||
case _: null;
|
||||
}
|
||||
case NONE: null;
|
||||
}
|
||||
override private function buildHuman(id:PlayerId, index:Int):Control {
|
||||
return new HumanControl(id, index);
|
||||
}
|
||||
}
|
||||
|
||||
30
src/common/haxe/ru/m/tankz/control/BaseControlFactory.hx
Normal file
30
src/common/haxe/ru/m/tankz/control/BaseControlFactory.hx
Normal file
@@ -0,0 +1,30 @@
|
||||
package ru.m.tankz.control;
|
||||
|
||||
import ru.m.tankz.bot.HardBotControl;
|
||||
import ru.m.tankz.bot.StupidBotControl;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
class BaseControlFactory implements IControlFactory {
|
||||
|
||||
public function new() {}
|
||||
|
||||
public function build(id:PlayerId, controller:Controller):Control {
|
||||
return switch controller {
|
||||
case Controller.HUMAN(index): buildHuman(id, index);
|
||||
case Controller.BOT(type): buildBot(id, type);
|
||||
case Controller.NONE: null;
|
||||
}
|
||||
}
|
||||
|
||||
private function buildHuman(id:PlayerId, index:Int):Control {
|
||||
return null;
|
||||
}
|
||||
|
||||
private function buildBot(id:PlayerId, type:String):Control {
|
||||
return switch type {
|
||||
case StupidBotControl.BOT_TYPE: new StupidBotControl(id);
|
||||
case HardBotControl.BOT_TYPE: new HardBotControl(id);
|
||||
case _: null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ class EntityBuilder {
|
||||
|
||||
public function new(config:Config) {
|
||||
this.config = config;
|
||||
this.entityId = 0;
|
||||
this.entityId = 1;
|
||||
}
|
||||
|
||||
public function buildRect(point:EntityPoint, width:Float, height:Float):Rectangle {
|
||||
|
||||
@@ -306,7 +306,7 @@ class GameRunner extends Game implements EngineListener {
|
||||
super.onGameEvent(event);
|
||||
switch event {
|
||||
case GameEvent.START(_):
|
||||
timer = new Timer(10);
|
||||
timer = new Timer(30);
|
||||
timer.run = update;
|
||||
case GameEvent.COMPLETE(_, _):
|
||||
if (timer != null) {
|
||||
|
||||
@@ -1,25 +1,13 @@
|
||||
package ru.m.tankz.server.control;
|
||||
|
||||
import ru.m.tankz.bot.HardBotControl;
|
||||
import ru.m.tankz.bot.StupidBotControl;
|
||||
import ru.m.tankz.control.BaseControlFactory;
|
||||
import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.control.Controller;
|
||||
import ru.m.tankz.control.IControlFactory;
|
||||
import ru.m.tankz.Type.PlayerId;
|
||||
|
||||
class ServerControlFactory implements IControlFactory {
|
||||
class ServerControlFactory extends BaseControlFactory {
|
||||
|
||||
public function new() {}
|
||||
|
||||
public function build(id:PlayerId, controller:Controller):Control {
|
||||
return switch controller {
|
||||
case HUMAN(index): new HardBotControl(id); // ToDo:
|
||||
case BOT(type): switch type {
|
||||
case StupidBotControl.BOT_TYPE: new StupidBotControl(id);
|
||||
case HardBotControl.BOT_TYPE: new HardBotControl(id);
|
||||
case _: null;
|
||||
}
|
||||
case NONE: null;
|
||||
}
|
||||
override private function buildHuman(id:PlayerId, index:Int):Control {
|
||||
return new HardBotControl(id); // ToDo:
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ class _GameListener implements GameListener {
|
||||
dispatcher.dispatchEvent(game, event);
|
||||
switch event {
|
||||
case COMPLETE(_, _):
|
||||
dispose();
|
||||
dispatcher.delete(game.proto.id);
|
||||
dispose();
|
||||
case _:
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user