Page 1 of 1

Flip hidden card (and know which card is it from the client side)

Posted: 18 April 2020, 10:25
by Galeelox
Hi !
I'm a begginer on BGA development and I come with a very simple (but tricky for me) question.
Currently, I'm working on a kind of "memory" game. It start with some cards put face down on the table. The player only see the back of each card.
At its turn he must peek at two cards to see their face up.
And that's my issue. In the database I have all my cards recorded (with their color, value and position). How can I request this information from the client side?
Thanks for your help.
David

Re: Flip hidden card (and know which card is it from the client side)

Posted: 18 April 2020, 10:40
by RicardoRix
While the card is facedown, this data should not be in the client side, otherwise there is the possibility for a hacker to cheat.

The client will need to send a request action.
The server - You're going to randomly select a card from the available ones, and send back the data in a notification. The randomness could be done in game setup or if you prefer on the fly as needed.

There is the possibility that you expect the player to remember facedown cards, and if so you'll need to include the index / position in the request and store this in the DB, so each subsequent time they select the 2nd from left card they receive back the same result.

Re: Flip hidden card (and know which card is it from the client side)

Posted: 18 April 2020, 11:06
by Galeelox
Thank you for your answer.
But my question is How do you make this request?
I understand that you make an "action" to send data do the "game" file. But how could you answer from the "game" file to the "js" file?
I just can't understand how could I bring back information to the js from the sever side.
David

Re: Flip hidden card (and know which card is it from the client side)

Posted: 18 April 2020, 11:17
by apollo1001
Ricardo's answer is correct, but here are the detailed steps in case you need more guidance of the process

1. Set up the database on the server with the game layout.
2. Set out the grid on the client side with the data (passed by gamedatas/getAllDatas(), or a notification if not at the start of the game)
3. When you flip the cards, you must create new temporary ones showing the backs which don't referencethe id's of the originals, but probably just the location (temp_1_1, temp_1_2 etc..)
4. When creating the temp cards connect them to an onClick method which will call an action with an ajaxrequest (e.g. showCard) with the coordinates as parameters
5. Add the 'showCard' action to action.php.
6. Add the 'showCard' action to game.php and that can grab the real id of the card from the DB.
7. Send a notification with the real ID back from game.php to the client for displaying the selected card.
8. Call the notification method to display the correct card with the passed id parameter.

Re: Flip hidden card (and know which card is it from the client side)

Posted: 18 April 2020, 11:25
by Galeelox
Thank to both of you.
I totally missed the notification system. I passed by how it's powerful.