[common] change game team players from array to map

This commit is contained in:
2018-02-04 22:33:50 +03:00
parent 1c9ccf0fb8
commit ad4744cfef
6 changed files with 32 additions and 46 deletions

View File

@@ -1,5 +1,6 @@
package ru.m.tankz.control;
import ru.m.tankz.game.Game;
import ru.m.tankz.control.Control;
import haxe.Timer;
import ru.m.geom.Direction;
@@ -18,9 +19,9 @@ class HumanControl extends Control {
private var moveQueue:Array<Int>;
private var shotTimer:Timer;
public function new(index:Int) {
super({type:Control.HUMAN, index:index});
this.keyBinding = resolve(index);
public function new(playerId:PlayerId, controlIndex:Int) {
super(playerId);
this.keyBinding = resolve(controlIndex);
moveQueue = new Array<Int>();
Lib.current.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
Lib.current.stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
@@ -82,8 +83,8 @@ class HumanControl extends Control {
action(TankAction.SHOT);
}
private static function resolve(index:Int):KeyBinding {
switch (index) {
private static function resolve(controlIndex:Int):KeyBinding {
switch (controlIndex) {
case 0:
return [
Keyboard.A => TankAction.MOVE(Direction.LEFT),
@@ -100,8 +101,8 @@ class HumanControl extends Control {
Keyboard.RIGHT => TankAction.MOVE(Direction.RIGHT),
Keyboard.NUMPAD_0 => TankAction.SHOT
];
case _:
throw 'Invalid control index ${index}';
case x:
throw 'Invalid control index ${x}';
}
}
}