-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #219 from gavr-games/realtime_ui_disabling_refacto…
…ring Add controllers to game object and other refactoring
- Loading branch information
Showing
11 changed files
with
353 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"use strict" | ||
|
||
export class CardsController { | ||
constructor() { | ||
this.cards = [] | ||
this.cardActionDoneInThisTurn = false | ||
} | ||
|
||
setCardActionDoneInThisTurn(cardActionDoneInThisTurn) { | ||
this.cardActionDoneInThisTurn = cardActionDoneInThisTurn | ||
} | ||
|
||
canMakeAction() { | ||
let game = window.Game | ||
return (game.TurnController.myTurn && !game.CardsController.cardActionDoneInThisTurn) | ||
} | ||
|
||
canBuy() { | ||
return window.Game.PlayersController.getMyPlayer()['gold'].toInt() >= mode_config["card cost"] | ||
&& (realtime_cards || this.canMakeAction()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"use strict" | ||
|
||
export class Game { | ||
constructor(gameData, myPlayerNum) { | ||
this.creation_date = gameData['creation_date'] | ||
this.game_id = gameData['game_id'] | ||
this.mode_id = gameData['mode_id'] | ||
this.owner_id = gameData['owner_id'] | ||
this.status_id = gameData['status_id'] | ||
this.time_restriction = gameData['time_restriction'] | ||
this.title = gameData['title'] | ||
this.type_id = gameData['type_id'] | ||
|
||
this.PlayersController = new window.GameMode.PlayersController(myPlayerNum) | ||
this.CardsController = new window.GameMode.CardsController() | ||
this.TurnController = new window.GameMode.TurnController() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,27 @@ | ||
"use strict" | ||
|
||
import {Unit} from "./unit.js"; | ||
import {Building} from "./building.js"; | ||
import {BoardObject} from "./board_object.js"; | ||
import {Cell} from "./cell.js"; | ||
import {Game} from "./game.js" | ||
import {Player} from "./player.js" | ||
import {PlayersController} from "./players_controller.js" | ||
import {CardsController} from "./cards_controller.js" | ||
import {TurnController} from "./turn_controller.js" | ||
import {Unit} from "./unit.js" | ||
import {Building} from "./building.js" | ||
import {BoardObject} from "./board_object.js" | ||
import {Cell} from "./cell.js" | ||
|
||
class GameMode { | ||
constructor() { | ||
this.Unit = Unit | ||
this.Building = Building | ||
this.BoardObject = BoardObject | ||
this.Cell = Cell | ||
this.Game = Game | ||
this.Player = Player | ||
this.PlayersController = PlayersController | ||
this.CardsController = CardsController | ||
this.TurnController = TurnController | ||
} | ||
} | ||
|
||
window.GameMode = new GameMode(); | ||
window.GameMode = new GameMode() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"use strict" | ||
|
||
export class Player { | ||
constructor(data) { | ||
this.player_num = data['player_num'].toInt() | ||
this.name = data['name'] | ||
this.gold = data['gold'].toInt() | ||
this.owner = data['owner'].toInt() | ||
this.team = data['team'].toInt() | ||
} | ||
|
||
setGold(gold) { | ||
this.gold = gold.toInt() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"use strict" | ||
|
||
export class PlayersController { | ||
constructor(myPlayerNum) { | ||
this.players = [] | ||
this.myPlayerNum = myPlayerNum.toInt() | ||
} | ||
|
||
addPlayer(playerData) { | ||
player = new window.GameMode.Player(playerData) | ||
this.players.push(player) | ||
} | ||
|
||
removePlayer(playerNum) { | ||
this.players = this.players.filter((player, _index, _arr) => { | ||
return player.num != playerNum | ||
}) | ||
} | ||
|
||
getMyPlayer() { | ||
return this.getPlayerByNum(this.myPlayerNum) | ||
} | ||
|
||
isMyPlayer(playerNum) { | ||
return playerNum.toInt() == this.myPlayerNum | ||
} | ||
|
||
getPlayerByNum(playerNum) { | ||
return this.players.find((player) => { | ||
return player.player_num == playerNum | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"use strict" | ||
|
||
export class TurnController { | ||
constructor() { | ||
this.myTurn = false | ||
} | ||
|
||
setMyTurn(myTurn) { | ||
this.myTurn = myTurn | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.