Advertisement
jeffdeon

example action/GC

Oct 8th, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {GameController} from "./GameController"
  2.  
  3.  
  4. export interface IRoadActions {
  5.     updateAfterRoadPlaced()
  6. }
  7.  
  8. export class FogIslandController implements IRoadActions {  // used in Seafarers GC
  9.  
  10.     updateAfterRoadPlaced() {
  11.         // logic here
  12.     }
  13.  
  14. }
  15.  
  16. export class KnightController implements IRoadActions { // used in Seafarers GC
  17.  
  18.     updateAfterRoadPlaced() {
  19.         // logic here
  20.     }
  21.  
  22. }
  23.  
  24. export class RoadActions {
  25.  
  26.     parentGame: GameController
  27.     attributesToUpdate: IRoadActions[]
  28.  
  29.     constructor(game: GameController) {
  30.         this.parentGame = game
  31.  
  32.         const gameControllerAttributes = Object.keys(this.parentGame)
  33.  
  34.         for(const gameControllerAttribute of gameControllerAttributes) {
  35.             const gameControllerComponent = gameControllerAttributes[gameControllerAttribute]
  36.             if(typeof gameControllerComponent['updateAfterRoadPlaced'] === 'function') this.attributesToUpdate.push(gameControllerComponent)
  37.         }
  38.     }
  39.  
  40.     validateAction() {
  41.         // make sure its an allowed move
  42.  
  43.         this.completeAction()
  44.     }
  45.  
  46.     completeAction() {
  47.         // before logic common to all
  48.         // ------------
  49.         // this.parentGame.broadcastRoadPlaced
  50.         // this.parentGame.currentMap.placeRoad()
  51.         // ------------
  52.  
  53.         for(const component of this.attributesToUpdate) {
  54.             component.updateAfterRoadPlaced()
  55.         }
  56.  
  57.         // after logic common to all
  58.         // -------------
  59.         // this.parentGame.checkVictoryStatus()
  60.     }
  61. }
  62.  
  63.  
  64.  
  65. export interface ISeafarers {
  66.     fogIslandController: FogIslandController
  67. }
  68.  
  69.  
  70. export class GCSeafarers implements ISeafarers {
  71.     fogIslandController: FogIslandController
  72.  
  73.     constructor() {
  74.         this.fogIslandController = new FogIslandController()
  75.     }
  76. }
  77.  
  78. export interface ICititesAndKnights {
  79.     knightController: KnightController
  80. }
  81.  
  82. export class GCCitiesAndKnights implements ICititesAndKnights {
  83.     knightController: KnightController
  84.  
  85.     constructor() {
  86.         this.knightController = new KnightController()
  87.     }
  88. }
  89.  
  90. export class GCSeafarersAndCititesAndKnights implements ISeafarers, ICititesAndKnights {
  91.     fogIslandController: FogIslandController
  92.     knightController: KnightController
  93.  
  94.     constructor() {
  95.         this.knightController = new KnightController()
  96.         this.fogIslandController = new FogIslandController()
  97.     }
  98. }
  99.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement