Sign In Register

How can we help you today?

Start a new topic
Answered

Can someone give me some help on defining a simple Turn Base game?

Hi all,


I've been trying to create a very simple demo with GameSparks using a simple turn-based game worflow but have not been able yet. Wondering if you guys can help me.


The game is this:

2 players

The server creates a random integer from 0 to 10

Both players try to guess and whoever comes closer to the number wins.


That's all.


I am developing using the Android Java SDK.


This is what I am thinking:

First, I created both users in Test Harness. Then, in android, I issue MatchmakingRequest for User1 (U1).

Then, User2 (U2) does a JoinChallengeRequest and joins the request from U1.


U2 then makes the guess and submits the turn (how do you submit the turn?). I would imagine that submitting the turn would mean sending the U2 guess number to U1 (or maybe a cloud code). Then U1 does his turn, sends his guess to the cloud code and then the cloud code compares both guesses and pushes the results to both players.


So I think what I am missing here is:

  • Where do I generate the random number? Cloud Code?
  • How do players take turns?
  • How do you send players turn data to the cloud or to the other player?
  • And, finally, is the JoinChallengeRequest the right call to be done to join U1 request?

Thanks everyone
Fe


Best Answer

Hey Felipe,


I would suggest you review our TicTacToe tutorial and Heartstone Tutorial for some examples of challenge management.

With regard to your questions I would recommend:


  • I would recommend generating this number in cloud code and storing it in the challenge instance data for security reasons.
  • Players generally take turns by sending messages to the server via Events.
  • For this I would have the turn data stored in the challenge instances scriptData() through the events you called.
  • JoinChallangeRequest is useful for having a player such as a friend join your challenge, if this is what your aiming to do then JoinChallangeRequest is ideal.


If you want to be able to challenge other players who may not be friends of the current client consider checking out our multiplayer API reference 
here


Hope this helps,

- Tony.

1 Comment

Answer

Hey Felipe,


I would suggest you review our TicTacToe tutorial and Heartstone Tutorial for some examples of challenge management.

With regard to your questions I would recommend:


  • I would recommend generating this number in cloud code and storing it in the challenge instance data for security reasons.
  • Players generally take turns by sending messages to the server via Events.
  • For this I would have the turn data stored in the challenge instances scriptData() through the events you called.
  • JoinChallangeRequest is useful for having a player such as a friend join your challenge, if this is what your aiming to do then JoinChallangeRequest is ideal.


If you want to be able to challenge other players who may not be friends of the current client consider checking out our multiplayer API reference 
here


Hope this helps,

- Tony.

Login to post a comment