[common] game state refactored

This commit is contained in:
2018-02-12 22:26:25 +03:00
parent d279d52b09
commit f68e5d160f
14 changed files with 266 additions and 257 deletions

View File

@@ -51,7 +51,7 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
render.draw(game.engine);
timer = new Timer(10);
timer.run = updateEngine;
state.text = stateString(s);
state.text = stateString(game);
}
private function stop():Void {
@@ -68,20 +68,18 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
render.reset();
}
private function stateString(state:GameState):String {
private function stateString(game:Game):String {
var result:Array<String> = [];
result.push('Level: ${state.level}');
for (teamId in state.teams.keys()) {
var ts:TeamState = state.teams[teamId];
if (ts.lose) {
result.push('${teamId}: LOSE');
} else if (ts.life > -1) {
result.push('${teamId}: ${ts.life}');
result.push('Level: ${game.state.level}');
for (team in game.teams) {
if (game.state.loser == team.id) {
result.push('${team.id}: LOSE');
} else if (team.life > -1) {
result.push('${team.id}: ${team.life}');
} else {
for (index in ts.players.keys()) {
var ps:PlayerState = ts.players[index];
if (ps.life > -1) {
result.push('${teamId}${index}: ${ps.life}');
for (player in team.players) {
if (player.life > -1) {
result.push('${player.id.team}${player.id.index}: ${player.life}');
}
}
}
@@ -90,14 +88,14 @@ class GameFrame extends VGroupView implements ViewBuilder implements IPacketHand
}
private function onGameStateChange(s:GameState):GameState {
state.text = stateString(s);
state.text = stateString(game);
return s;
}
private function onGameComplete(result:Option<GameState>):Void {
switch (result) {
case Option.Some(s):
state.text = stateString(s);
state.text = stateString(game);
case Option.None:
}
switch (game.next()) {

View File

@@ -47,14 +47,8 @@ class StartFrame extends VGroupView implements ViewBuilder implements StartFrame
}
}
private function startGame(type:GameType, mode:GameMode):Void {
switch (type) {
case ClassicGame.TYPE:
Provider.set(GameState, ClassicGame.buildState(0, mode));
Provider.get(IFrameSwitcher).change(LevelFrame.ID);
case DotaGame.TYPE:
Provider.set(GameState, DotaGame.buildState(0, mode));
Provider.get(IFrameSwitcher).change(LevelFrame.ID);
}
private function startGame(type:GameType, presetId:PresetId):Void {
Provider.set(GameState, new GameState(type, presetId));
Provider.get(IFrameSwitcher).change(LevelFrame.ID);
}
}

View File

@@ -17,18 +17,55 @@ bricks:
- {type: 4, layer: 2, armor: 2} # armor
- {type: 5, layer: 2, armor: 1} # brick
teams:
- id: human
player:
human: &human
control: human
life: 3
tanks:
- {type: human0, rate: 1}
- id: bot
spawnInterval: 3000
bot: &bot
control: bot
life: -1
tanks:
- {type: bot0, rate: 0.25, bonus: 0.25}
- {type: bot1, rate: 0.25, bonus: 0.25}
- {type: bot2, rate: 0.25, bonus: 0.25}
- {type: bot3, rate: 0.25, bonus: 0.25}
presets:
- id: player1
teams:
- id: human
life: -1
players:
- {<<: *human, index: 0, color: 0xFC9838, life: 3}
- id: bot
spawnInterval: 3000
life: 20
players:
- {<<: *bot, index: 0}
- {<<: *bot, index: 1}
- {<<: *bot, index: 2}
- {<<: *bot, index: 3}
- id: player2
teams:
- id: human
life: -1
players:
- {<<: *human, index: 0, color: 0xFC9838, life: 3}
- {<<: *human, index: 1, color: 0x159D49, life: 3}
- id: bot
spawnInterval: 3000
life: 20
players:
- {<<: *bot, index: 0}
- {<<: *bot, index: 1}
- {<<: *bot, index: 2}
- {<<: *bot, index: 3}
- {<<: *bot, index: 4}
- {<<: *bot, index: 5}
points:
- {team: human, type: eagle, index: -1, direction: right, x: 12, y: 24}
- {team: human, type: tank, index: 0, direction: top, x: 8, y: 24}

View File

@@ -17,18 +17,72 @@ bricks:
- {type: 4, layer: 2, armor: 2} # armor
- {type: 5, layer: 2, armor: 1} # brick
team_tanks: &team_tanks
team:
radiant: &radiant
id: radiant
color: 0xff5555
life: 20
dire: &dire
id: dire
color: 0x5555ff
life: 20
player: &player
life: -1
control: bot
tanks:
- {type: slow, rate: 0.5}
- {type: fast, rate: 0.5}
teams:
- <<: *team_tanks
id: radiant
color: 0xff5555
- <<: *team_tanks
id: dire
color: 0x5555ff
presets:
- id: player1
teams:
- <<: *radiant
players:
- {<<: *player, index: 0, control: human, color: 0xff7777}
- {<<: *player, index: 1}
- {<<: *player, index: 2}
- {<<: *player, index: 3}
- {<<: *player, index: 4}
- <<: *dire
players:
- {<<: *player, index: 0}
- {<<: *player, index: 1}
- {<<: *player, index: 2}
- {<<: *player, index: 3}
- {<<: *player, index: 4}
- id: player2_coop
teams:
- <<: *radiant
players:
- {<<: *player, index: 0, control: human, color: 0xff7777}
- {<<: *player, index: 1, control: human, color: 0xff7777}
- {<<: *player, index: 2}
- {<<: *player, index: 3}
- {<<: *player, index: 4}
- <<: *dire
players:
- {<<: *player, index: 0}
- {<<: *player, index: 1}
- {<<: *player, index: 2}
- {<<: *player, index: 3}
- {<<: *player, index: 4}
- id: player2_vs
teams:
- <<: *radiant
players:
- {<<: *player, index: 0, control: human, color: 0xff7777}
- {<<: *player, index: 1}
- {<<: *player, index: 2}
- {<<: *player, index: 3}
- {<<: *player, index: 4}
- <<: *dire
players:
- {<<: *player, index: 0, control: human, color: 0x7777ff}
- {<<: *player, index: 1}
- {<<: *player, index: 2}
- {<<: *player, index: 3}
- {<<: *player, index: 4}
points:
- {team: radiant, type: eagle, index: -1, direction: right, x: 0, y: 28}