[common] refactor ControlFactory
This commit is contained in:
@@ -4,8 +4,12 @@ import ru.m.geom.Point;
|
||||
import ru.m.geom.Position;
|
||||
import ru.m.tankz.bundle.IConfigBundle;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.control.Controller;
|
||||
import ru.m.tankz.control.IControlFactory;
|
||||
import ru.m.tankz.control.NoneControlFactory;
|
||||
import ru.m.tankz.core.Entity;
|
||||
import ru.m.tankz.core.EntityType;
|
||||
import ru.m.tankz.engine.IEngine;
|
||||
import ru.m.tankz.game.GameEvent;
|
||||
import ru.m.tankz.game.GameState;
|
||||
import ru.m.tankz.game.IGame;
|
||||
@@ -21,6 +25,8 @@ import ru.m.tankz.Type;
|
||||
public var winner(default, null):Null<TeamId>;
|
||||
public var state(default, null):GameState;
|
||||
public var frame(default, null):Int;
|
||||
public var engine(default, null):IEngine;
|
||||
public var controlFactory(default, null):IControlFactory;
|
||||
|
||||
@:provide var configBundle:IConfigBundle;
|
||||
|
||||
@@ -30,6 +36,7 @@ import ru.m.tankz.Type;
|
||||
this.teams = new Map();
|
||||
this.config = configBundle.get(type);
|
||||
this.frame = 0;
|
||||
this.controlFactory = new NoneControlFactory();
|
||||
connect(this);
|
||||
}
|
||||
|
||||
@@ -74,6 +81,15 @@ import ru.m.tankz.Type;
|
||||
var team:Team = new Team(teamConfig, teamPoints, state.teams[teamConfig.id]);
|
||||
teams[team.id] = team;
|
||||
}
|
||||
for (team in teams.iterator()) {
|
||||
for (player in team.players.iterator()) {
|
||||
var control = controlFactory.build(player.id, AController.fromString(player.config.control));
|
||||
if (control != null) {
|
||||
player.control = control;
|
||||
player.control.bind(this, engine);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function dispose():Void {
|
||||
|
||||
@@ -3,8 +3,6 @@ package ru.m.tankz.game;
|
||||
import ru.m.geom.Line;
|
||||
import ru.m.geom.Point;
|
||||
import ru.m.tankz.control.Control;
|
||||
import ru.m.tankz.control.Controller;
|
||||
import ru.m.tankz.control.IControlFactory;
|
||||
import ru.m.tankz.core.Bonus;
|
||||
import ru.m.tankz.core.Bullet;
|
||||
import ru.m.tankz.core.Eagle;
|
||||
@@ -18,10 +16,6 @@ import ru.m.tankz.Type;
|
||||
import ru.m.Timer;
|
||||
|
||||
class GameRunner extends Game implements EngineListener {
|
||||
@:provide var controlFactory:IControlFactory;
|
||||
|
||||
public var engine(default, null):IEngine;
|
||||
|
||||
private var timer:Timer;
|
||||
private var builder:EntityBuilder;
|
||||
|
||||
@@ -50,13 +44,6 @@ class GameRunner extends Game implements EngineListener {
|
||||
super.start();
|
||||
engine.map.setData(state.level.data);
|
||||
for (team in teams.iterator()) {
|
||||
for (player in team.players.iterator()) {
|
||||
var control = controlFactory.build(player.id, AController.fromString(player.config.control));
|
||||
if (control != null) {
|
||||
player.control = control;
|
||||
player.control.bind(this, engine);
|
||||
}
|
||||
}
|
||||
team.spawner.runner = spawn;
|
||||
for (player in team.players.iterator()) {
|
||||
if (team.tryRespawn(player.id)) {
|
||||
@@ -120,8 +107,10 @@ class GameRunner extends Game implements EngineListener {
|
||||
private function complete(winner:TeamId):Void {
|
||||
for (team in teams.iterator()) {
|
||||
for (player in team.players) {
|
||||
player.control.action(TankAction.STOP);
|
||||
player.control.dispose();
|
||||
if (player.control != null) {
|
||||
player.control.action(TankAction.STOP);
|
||||
player.control.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
Timer.delay(function() {
|
||||
|
||||
@@ -2,6 +2,7 @@ package ru.m.tankz.game;
|
||||
|
||||
import haxework.signal.Signal;
|
||||
import ru.m.tankz.config.Config;
|
||||
import ru.m.tankz.control.IControlFactory;
|
||||
import ru.m.tankz.Type;
|
||||
|
||||
interface IGame extends GameListener {
|
||||
@@ -11,6 +12,7 @@ interface IGame extends GameListener {
|
||||
public var winner(default, null):Null<TeamId>;
|
||||
public var state(default, null):GameState;
|
||||
public var frame(default, null):Int;
|
||||
public var controlFactory(default, null):IControlFactory;
|
||||
|
||||
public var gameEventSignal(default, null):Signal<GameEvent>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user