[common] add BaseControlFactory

This commit is contained in:
2019-05-28 19:42:46 +03:00
parent 1d95de02e1
commit 31cb20bf85
6 changed files with 40 additions and 34 deletions

View File

@@ -1,22 +1,10 @@
package ru.m.tankz.control; package ru.m.tankz.control;
import ru.m.tankz.bot.StupidBotControl;
import ru.m.tankz.bot.HardBotControl;
import ru.m.tankz.Type; import ru.m.tankz.Type;
class ClientControlFactory implements IControlFactory { class ClientControlFactory extends BaseControlFactory {
public function new() {} override private function buildHuman(id:PlayerId, index:Int):Control {
return new HumanControl(id, index);
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;
}
} }
} }

View 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;
}
}
}

View File

@@ -23,7 +23,7 @@ class EntityBuilder {
public function new(config:Config) { public function new(config:Config) {
this.config = config; this.config = config;
this.entityId = 0; this.entityId = 1;
} }
public function buildRect(point:EntityPoint, width:Float, height:Float):Rectangle { public function buildRect(point:EntityPoint, width:Float, height:Float):Rectangle {

View File

@@ -306,7 +306,7 @@ class GameRunner extends Game implements EngineListener {
super.onGameEvent(event); super.onGameEvent(event);
switch event { switch event {
case GameEvent.START(_): case GameEvent.START(_):
timer = new Timer(10); timer = new Timer(30);
timer.run = update; timer.run = update;
case GameEvent.COMPLETE(_, _): case GameEvent.COMPLETE(_, _):
if (timer != null) { if (timer != null) {

View File

@@ -1,25 +1,13 @@
package ru.m.tankz.server.control; package ru.m.tankz.server.control;
import ru.m.tankz.bot.HardBotControl; 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.Control;
import ru.m.tankz.control.Controller;
import ru.m.tankz.control.IControlFactory;
import ru.m.tankz.Type.PlayerId; import ru.m.tankz.Type.PlayerId;
class ServerControlFactory implements IControlFactory { class ServerControlFactory extends BaseControlFactory {
public function new() {} override private function buildHuman(id:PlayerId, index:Int):Control {
return new HardBotControl(id); // ToDo:
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;
}
} }
} }

View File

@@ -21,8 +21,8 @@ class _GameListener implements GameListener {
dispatcher.dispatchEvent(game, event); dispatcher.dispatchEvent(game, event);
switch event { switch event {
case COMPLETE(_, _): case COMPLETE(_, _):
dispose();
dispatcher.delete(game.proto.id); dispatcher.delete(game.proto.id);
dispose();
case _: case _:
} }
} }