Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {GameController} from "./GameController"
- export interface IRoadActions {
- updateAfterRoadPlaced()
- }
- export class FogIslandController implements IRoadActions { // used in Seafarers GC
- updateAfterRoadPlaced() {
- // logic here
- }
- }
- export class KnightController implements IRoadActions { // used in Seafarers GC
- updateAfterRoadPlaced() {
- // logic here
- }
- }
- export class RoadActions {
- parentGame: GameController
- attributesToUpdate: IRoadActions[]
- constructor(game: GameController) {
- this.parentGame = game
- const gameControllerAttributes = Object.keys(this.parentGame)
- for(const gameControllerAttribute of gameControllerAttributes) {
- const gameControllerComponent = gameControllerAttributes[gameControllerAttribute]
- if(typeof gameControllerComponent['updateAfterRoadPlaced'] === 'function') this.attributesToUpdate.push(gameControllerComponent)
- }
- }
- validateAction() {
- // make sure its an allowed move
- this.completeAction()
- }
- completeAction() {
- // before logic common to all
- // ------------
- // this.parentGame.broadcastRoadPlaced
- // this.parentGame.currentMap.placeRoad()
- // ------------
- for(const component of this.attributesToUpdate) {
- component.updateAfterRoadPlaced()
- }
- // after logic common to all
- // -------------
- // this.parentGame.checkVictoryStatus()
- }
- }
- export interface ISeafarers {
- fogIslandController: FogIslandController
- }
- export class GCSeafarers implements ISeafarers {
- fogIslandController: FogIslandController
- constructor() {
- this.fogIslandController = new FogIslandController()
- }
- }
- export interface ICititesAndKnights {
- knightController: KnightController
- }
- export class GCCitiesAndKnights implements ICititesAndKnights {
- knightController: KnightController
- constructor() {
- this.knightController = new KnightController()
- }
- }
- export class GCSeafarersAndCititesAndKnights implements ISeafarers, ICititesAndKnights {
- fogIslandController: FogIslandController
- knightController: KnightController
- constructor() {
- this.knightController = new KnightController()
- this.fogIslandController = new FogIslandController()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement