Leave the game to which I was invited - google-play-games

I have problem with dealing with invitations.
Scenario:
1. Friend invites me to his game
2. I join to the game via push notification
3. onSignInSucceeded() in MenuActivity runs my main game activity
#Override
public void onSignInSucceeded() {
Games.Invitations.registerInvitationListener(getApiClient(), this);
if (getInvitationId() != null) {
Intent intent = new Intent(getApplicationContext(), FindRoomActivity.class);
intent.putExtra(BundleConstants.FRIEND_GAME_CLIENT, true);
intent.putExtra(BundleConstants.INVITATION_ID, getInvitationId());
startActivity(intent);
}
}
4. Friend leaves the game before it ends, on my screen popup shows up and after confirmation I'm back in my Menuactivity, and again runs code form onSignInSucceeded and once again getInvitationId() returns invitation to the same (canceled) game.
I was trying to run declineRoomInvitation or dismissRoomInvitation before I leave that canceled game, but nothing helps.

Ok I think I have an idea. I don't see why this wouldn't work.
When you call Games.RealTimeMultiplayer.leave(getApiClient(), this, mRoom.getRoomId());, you are inputting a RoomUpdateListener which has listeners: onJoinedRoom, onLeftRoom, onRoomCreated and onRoomConnected.
So this is what you do, when a player leaves a game, his/her onLeftRoom will be called, when it is called, send a message to the other player using Games.RealTimeMultiplayer.sendReliableMessage, then when the other player receives this message, he/she will know that the player left the game so you can make the invitation for that game null so when signInSucceeded gets called again, it won't try to accept an invitation to a canceled game.
I think this is the best way to implement it. Hope this has been of help :)

Related

How do I restart a series of dialogs in bot framework?

I've got a simple bot game I'm developing. It has a Root Dialog, which can take you to two others - A Start Dialog and a Join Dialog.
Join Dialog can lead to the Play Game Dialog, which when the game is over leads you to a Score Dialog.
Feels like a lot bot (sic) but it runs smoothly. When scoring is done, I'd like to get back to the Root Dialog for another round.
But I'm stuck.
Even though I issue both an EndDialog() activity and a CodeAction() activity that simply calls DialogContext.CancelAllDialogs(), I remain within what looks like the EndDialog and therefore I don't get back to Root.
Thus, I can't restart my game.
Is there something I'm missing? I'm using both Adaptive Dialogs as well as Adaptive Cards and Hero Cards. Although, I don't think the cards should matter.
So, this is what I ended up doing to get what I want. It might not be the best way, but it works:
I created a CodeAction dialog that runs when the message I want to trigger a round restart to come in - there's a specific intent that is tied to that.
The CodeAction calls this method:
private async Task<DialogTurnResult> CancelAndReturnToRoot(DialogContext dc, object options)
{
var lastDialog = dc;
var secondToLastDialog = lastDialog;
var journeysUp = 1;
while (lastDialog != null)
{
lastDialog = lastDialog.Parent;
if (lastDialog != null)
secondToLastDialog = lastDialog;
journeysUp++;
}
return await secondToLastDialog.CancelAllDialogsAsync();
}
This seems to release the dialogs that I created and let me get back to the beginning dialog.

deal with Unity 5 UI in augmented reality app

I'm trying to make an augmented reality application with vuforia and unity.
whenever it recognize the image target, it must tell a story by showing text , and it should enable the user to press next and back to go on reading the different parts of this story, I'm totally new to unity and don't know how to handle with UI throughout scripting, I need some help on how to accomplish the part of "going forward and backward on showing the story by hitting Next and Back buttons", and all these parts of story should be related to the same image target in the same scene.
I appreciate it if you help me with an example code.
You should create some script that attach on trackable object, maybe something like this.
public class DataBook {
string[] dataBook;
string idText;
bool isActive;
}
Then you must create another script to set that trackable object is active or not, this link can help you to get that.
https://developer.vuforia.com/forum/faq/unity-how-do-i-get-list-active-trackables
Then after you get the active trackable object, you can set the dialog from the book by create another controller script for button, example
public void Next() {
DataBook[] books = FindObjectsOfType<DataBook>(); // if the object more than one, it will be more easy if it only the one
foreach (var book in books)
{
if (book.isActive) {
book.idText += 1;
textUI.text = book.dataBook[idText]; //textUI assign to object text on canvas
}
}
}
you can learn about unity UI Button on this :
https://unity3d.com/learn/tutorials/modules/beginner/ui/ui-button
Good luck

JavaFX how to return to state where waiting for user event

I'm currently implementing a checkers game with Groovy and JavaFX. The window that contains the board is presented once primaryStage.show() is executed and waits for an event to fire.
I have set up a sequence of functions that execute once a user clicks to make a legal move:
blackSquare.onMouseClicked = { e ->
commenceTurns(pos, view)
}
Conveniently this has allowed me to implement the whole game from this initial click (the AI move just executes after the user move).
However, I've now hit a problem. I need to implement multi-takes for the user and this requires me to return to the state where the board is waiting for the click event to fire. I have no idea how to accomplish this.
The basic program flow is:
// WAITING FOR CLICK EVENT
// CLICK EVENT CALLS:
commenceTurns()
userTurn()
makeMove()
if (takeMade && canTakeFurther) {
// EITHER JUMP TO END OF STACK OR RETURN TO WAITING STATE
}
computerTurn()
makeMove()
redrawBoard()
// END OF STACK
Hopefully this makes it clear what I'm looking for. Appreciate any help!

Converting from 3.1 to 4.0... gamestates

I'm restarting development of a game I was working on, and have successfully converted it over to XNA 4.0 using the cheat sheet. Most of it works, some of it doesn't, and I'm in the process of fixing what doesn't work.
One thing that I had was a state system that was heavily based on the state system used as an example of XNA Unleashed, the ebook. I didn't have much in it.... basically just the ability to pause the game.
When I paused the game, the action of the game would stop, and the word "PAUSED" would appear in block letters across the screen, and you'd see the paused action. However, now it seems that the sprite batch automatically clears out everything between frames, so when I pause the game now, the screen clears, leaving PAUSED over a purple background. Back then, I believe that adding "SaveStateMode.SaveState" would prevent that from happening, but that functionality was removed. When I did some research, I found out that it was removed because it was essentially useless, that's all handled in the game state manager.
However, I can't find any documentation on this. Where should I start? Right now, my code looks like this:
In the Playing Game State update method:
if (input.WasPressed(0, Buttons.Start, Keys.Enter))
{
GameManager.PushState((GameState)ThisGame.PausedGameState.Value);
}
public void PushState(GameState newState)
{
AddState(newState);
//Let everyone know we just changed states
if (OnStateChange != null)
{
OnStateChange(this, null);
}
}
private void AddState(GameState state)
{
states.Push(state);
Game.Components.Add(state);
//Register the event for this state
OnStateChange += state.StateChanged;
}
//PausedGameState Draw method:
public override void Draw(GameTime gameTime)
{
ThisGame.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null);
DrawPaused(); //draws the Paused Text
ThisGame.SpriteBatch.End();
}
The goal is to make "PAUSED" appear over the screen, with a snapshot of where the gameplay left off... and not "PAUSED" over a cleared purple screen.
Do you suppose that GraphicsDevice.Clear() somehow got called after the state changed to paused? What does the DrawPaused() method do in your code?

Close browser/Exit from website Events

Nowadays I am creating browser game, using ASPX, CSS and AJAX.
I need to know when the user close the browser or exit from website,
because of these cases for example:
if a player opens a game room and than close the browser or exit from the website,
this room need to be deleted immediately.
2 players are playing in a room, and than one of them leave so the game is finished and the one that stay is the winner.
In this case I can use the countdown timer of the players' turns, and when the countdown timer reaches 0 - The other player wins,
but I prefer that the message will appear as soon as the player left the room,
its faster, and when the countdown reaches 0 there is 2 possibilities - the player left or the player didn't react in time.
Anyone can tell me how can I know when the user close the browser or exit from my website?
because as far as I know the Session object won't be effective since the Session_End method runs several minutes after the browser is close or the user is AFK,
and I can't let the Session_End close the room for players that are AFK since they are waiting for more players to join, and I need to fire my events immediately.
P.S: I found this method, I don't know if its works but I don't think it will fit my needs because I need the event to fire even when the user move from my site to another website.
Ext.EventManager.on(window, 'beforeunload', function() {
alert('cross-exit tab click AND cross-exit browser click');
});
The onbeforeunload event fires before the user leaves a page. This fires when the user closes the browser or tab, or goes to another page, even if that page is on your own website.
Inside the event handler, you'd make a call back to your server saying that the session was closed. Note that this will have to be an authenticated call with a crumb to avoid an XSRF (ie, player B tricks player A into ending his session).
The only caveat is that it does not work on Opera. For opera, you could use the onunload event, but since this fires when the browser is closed, it's very hard to send anything back to your server in this event handler.
Handling onbeforeunload will probably work.

Resources