1
0
Fork 0

Added basic battle structure

This commit is contained in:
Michaël Lemaire 2014-12-29 01:00:00 +01:00 committed by Michaël Lemaire
parent c0233ebd93
commit b4b37a46d2
15 changed files with 165 additions and 53 deletions

View file

@ -21,7 +21,7 @@
<script>
window.onload = function() {
new SpaceTac.Game();
new SpaceTac.GameRouter();
};
</script>

View file

@ -1,15 +0,0 @@
/// <reference path="definitions/phaser.d.ts"/>
module SpaceTac {
export class Game extends Phaser.Game {
constructor() {
super(800, 600, Phaser.CANVAS, '-space-tac');
this.state.add('boot', State.Boot);
this.state.add('preload', State.Preload);
this.state.add('main', State.Main);
this.state.start('boot');
}
}
}

17
src/scripts/GameRouter.ts Normal file
View file

@ -0,0 +1,17 @@
/// <reference path="definitions/phaser.d.ts"/>
module SpaceTac {
// Router between game views
export class GameRouter extends Phaser.Game {
constructor() {
super(800, 600, Phaser.CANVAS, '-space-tac');
this.state.add('boot', View.Boot);
this.state.add('preload', View.Preload);
this.state.add('main', View.Main);
this.state.add('battle', View.BattleView);
this.state.start('boot');
}
}
}

View file

@ -0,0 +1,25 @@
module SpaceTac.Game {
// A turn-based battle between fleets
export class Battle {
// List of fleets engaged in battle
fleets: Fleet[];
// List of ships, sorted by their initiative throw
play_order: Ship[];
// Create a battle between two fleets
constructor(fleet1: Fleet, fleet2: Fleet) {
this.fleets = [fleet1, fleet2];
// TODO Initiative throws to set the play order
}
// Create a quick random battle, for testing purposes
static newQuickRandom(): Battle {
var player1 = Player.newQuickRandom();
var player2 = Player.newQuickRandom();
var result = new Battle(player1.fleet, player2.fleet);
return result;
}
}
}

15
src/scripts/game/Fleet.ts Normal file
View file

@ -0,0 +1,15 @@
module SpaceTac.Game {
// A fleet of ships
export class Fleet {
// Fleet owner
player: Player;
// List of ships
ships: Ship[];
// Create a fleet, bound to a player
constructor(player: Player) {
this.player = player;
}
}
}

View file

@ -0,0 +1,18 @@
module SpaceTac.Game {
// One player (human or IA)
export class Player {
// Current fleet
fleet: Fleet;
// Create a player, with an empty fleet
constructor() {
this.fleet = new Fleet(this);
}
// Create a quick random player, with a fleet, for testing purposes
static newQuickRandom(): Player {
var player = new Player();
return player;
}
}
}

19
src/scripts/game/Ship.ts Normal file
View file

@ -0,0 +1,19 @@
module SpaceTac.Game {
// A single ship in a Fleet
export class Ship {
// Fleet this ship is a member of
fleet: Fleet;
// Current level
level: number;
// Number of shield points
shield: number;
// Number of hull points
hull: number;
// Current initiative (high numbers will allow this ship to play sooner)
initiative: number;
}
}

View file

@ -0,0 +1,7 @@
module SpaceTac.Game {
// Main game universe
export class Universe {
// Current connected player
player: Player;
}
}

View file

@ -1,16 +0,0 @@
module SpaceTac.State {
export class Boot extends Phaser.State {
preload() {
this.load.image('preload-bar', 'assets/images/preloader.gif');
}
create() {
this.game.stage.backgroundColor = 0xFFFFFF;
this.input.maxPointers = 1;
this.stage.disableVisibilityChange = true;
this.game.state.start('preload');
}
}
}

View file

@ -1,8 +0,0 @@
module SpaceTac.State {
export class Main extends Phaser.State {
create() {
this.add.text(10, 10, "Let's code !", { font: "65px Arial" });
}
}
}

View file

@ -1,13 +0,0 @@
module SpaceTac.State {
export class Preload extends Phaser.State {
private preloadBar:Phaser.Sprite;
preload() {
this.preloadBar = this.add.sprite(290, 290, 'preload-bar');
}
create() {
this.game.state.start('main');
}
}
}

View file

@ -0,0 +1,23 @@
module SpaceTac.View {
// Interactive view of a Battle
export class BattleView extends Phaser.State {
// Displayed battle
battle: Game.Battle;
// Init the view, binding it to a specific battle
init(battle) {
this.battle = battle;
}
// Create view graphics
create() {
this.game.stage.backgroundColor = 0x000000;
}
// Leaving the view, we unbind the battle
shutdown() {
this.battle = null;
}
}
}

16
src/scripts/view/Boot.ts Normal file
View file

@ -0,0 +1,16 @@
module SpaceTac.View {
export class Boot extends Phaser.State {
preload() {
this.load.image('preload-bar', 'assets/images/preloader.gif');
}
create() {
this.game.stage.backgroundColor = 0xFFFFFF;
this.input.maxPointers = 1;
this.stage.disableVisibilityChange = true;
this.game.state.start('preload');
}
}
}

11
src/scripts/view/Main.ts Normal file
View file

@ -0,0 +1,11 @@
module SpaceTac.View {
export class Main extends Phaser.State {
create() {
this.add.text(10, 10, "Let's code !", {font: "65px Arial"});
// Switch to a test battle
this.game.state.start("battle", true, false, Game.Battle.newQuickRandom());
}
}
}

View file

@ -0,0 +1,13 @@
module SpaceTac.View {
export class Preload extends Phaser.State {
private preloadBar: Phaser.Sprite;
preload() {
this.preloadBar = this.add.sprite(290, 290, 'preload-bar');
}
create() {
this.game.state.start('main');
}
}
}