Using Deck in view and game

Game development with Board Game Arena Studio
Post Reply
Cowseye
Posts: 26
Joined: 11 August 2013, 17:33

Using Deck in view and game

Post by Cowseye »

Hi guys,

I am using Deck.php as a randomizer for beginning setup for the board game, which I did it in mygame.view.php naturally.
However, the remainder of this deck is need to be used subsequently in the game proper. How do I pass the remainder of the deck to mygame.game.php for further usage? In this case I have 3 such decks to be passed. Any advice?
User avatar
Andy_K
Posts: 51
Joined: 13 February 2014, 15:59

Re: Using Deck in view and game

Post by Andy_K »

If the deck contains game info, you probably want to move it to game.php. Declare it in the constructor and initialise in the setupNewGame method. You can then refer to it anywhere in game.php and return whatever info you need for display setup purposes in getAllDatas.

I'm not sure if you can directly access a deck created in game.php from view.php as I've not tried this, but if it works perhaps you can skip using getAllDatas
Cowseye
Posts: 26
Joined: 11 August 2013, 17:33

Re: Using Deck in view and game

Post by Cowseye »

Nope. I just tried declaring it in main but I can't access deck in view without declaring in it directly.

Can anyone share any ideas how should I go about resolving this issue
User avatar
fafa-fr
Posts: 383
Joined: 22 December 2013, 21:58

Re: Using Deck in view and game

Post by fafa-fr »

Cowseye wrote:Nope. I just tried declaring it in main but I can't access deck in view without declaring in it directly.
Have you tried using the way explained in .view.php doc?
How to access game information from .view.php?
From your .view.php, you can access the following:
...
Access game object
In your view file, "$this->game" contains an instance of your main game class.
Example:
// Access to some game elements description described in your "material.inc.php":
$my_cards_types = $this->game->card_types;

// Access to any (public) method defined in my .game.php file:
$result = $this->game->myMethod();
In your case, using $this->game->yourDeckName in your view.php file if you declared $this->yourDeckName in game.php.
But there may be a problem, depending on which informations of your deck you use to setup your game in view.php. Do you use informations that will change during the game? In case you do, isn't it a problem when a player loads a page of a game in progress (in turn-based games or when reloading the page), since view.php will not use the same informations for the base setup of your board?
In this case, maybe you should do as Andy_K suggested: handling the display of all game elements depending on your deck in game.php and yourgamename.js, and not in view.php.
Cowseye
Posts: 26
Joined: 11 August 2013, 17:33

Re: Using Deck in view and game

Post by Cowseye »

Thank you for your reply. I think I am missing out on the jstpl section in the tpl. Yes, those game states do get change over the course of time in the game. But I didn't have any idea how to handle view elements in Jas until I read about jstpl.

I will go into more details about the jstpl and try to work within game.php for my game setup and tasking the JavaScript to load the elements properly using getAllData.
Post Reply

Return to “Developers”