Esempio n. 1
0
        private async void StartingGame(Game g, User u)
        {


            // Ready and waiting for other user
            if (g.GameStatus == 3 && u.UserName == App.Current.AppUser.UserName)
            {

            }
            var messageDialog = new MessageDialog("Do you want to Join the Game now?");
            // Add commands and set their command ids
            messageDialog.Commands.Add(new UICommand("Not Now", (command) =>
            {
                App.Current.CurrentGame = null;
            },
            0));
            messageDialog.Commands.Add(new UICommand("Join Game", (command) =>
            {
                App.Current.SignalRHub.JoinGame(App.Current.AppUser, App.Current.CurrentGame);
                App.Current.SignalRHub.SignalRServerNotification -= new SignalRServerHandler(SignalRHub_SignalRServerNotification);

                Frame.Navigate(typeof(LobbyPage));
            },
            1));

            // Set the command that will be invoked by default
            messageDialog.DefaultCommandIndex = 1;

            // Show the message dialog and get the event that was invoked via the async operator
            var commandChosen = await messageDialog.ShowAsync();
            /*
            //chatDialog.Text += "\r\n" + "Starting Game...";
            //Was the App User the last one to Join? If yes trigger Start Event
            if (u.UserName == App.Current.AppUser.UserName)
            {
                App.Current.SignalRHub.JoinGame(App.Current.AppUser, App.Current.CurrentGame);
                App.Current.SignalRHub.SignalRServerNotification -= new SignalRServerHandler(SignalRHub_SignalRServerNotification);

                Frame.Navigate(typeof(LobbyPage));
                //App.Current.SignalRHub.StartGame(App.Current.CurrentGame, u); //Lobby Message to start game
            }
             //            Add commands and set their command ids

             //Set the command that will be invoked by default
            //messageDialog.DefaultCommandIndex = 1;

             //Show the message dialog and get the event that was invoked via the async operator
            //await messageDialog.ShowAsync();

            */

        }
Esempio n. 2
0
 public async virtual void StartGame(Game game)
 {
     // Post message to Server Chatroom.
     await SignalRGameHub.Invoke("StartGame", game);
 }
Esempio n. 3
0
 public async virtual void InGameMessageCall(Game game, InGameMessage im)
 {
     // Post message to Server Chatroom.
     await SignalRGameHub.Invoke("InGameMessageCall", game, im);
 }
Esempio n. 4
0
 public async virtual void CreateGame(User tabletChatClient, Game game)
 {
     // Leave the Server's Chatroom.
     await SignalRGameHub.Invoke("CreateGame", tabletChatClient, game);
 }
Esempio n. 5
0
 public async virtual void JoinGame(User x, Game g)
 {
     // Post message to Server Chatroom.
     await SignalRGameHub.Invoke("JoinGame", x, g);
 }
Esempio n. 6
0
        private async void OpenMessageDialog(Game g)
        {
            try
            {
                var messageDialog = new MessageDialog("Do you want to Join the Game now?");
                // Add commands and set their command ids
                messageDialog.Commands.Add(new UICommand("Not Now", (command) =>
                {
                    //App.Current.CurrentGame = null;
                    //ServerMessage sm = new ServerMessage(0, "update", "created a game");

                    //App.Current.SignalRHub.UserUpdate(App.Current.AppUser,sm );
                    j = false;
                },
                0));
                messageDialog.Commands.Add(new UICommand("Join Game", (command) =>
                {
                    App.Current.CurrentGame = g;
                    //App.Current.SignalRHub.JoinGame(App.Current.AppUser, App.Current.CurrentGame);
                    //ChangeListener();

                    //Frame.Navigate(typeof(LobbyPage));
                    j = true;
                },
                1));

                // Set the command that will be invoked by default
                messageDialog.DefaultCommandIndex = 1;

                // Show the message dialog and get the event that was invoked via the async operator
                var commandChosen = await messageDialog.ShowAsync();

                if (j == true)
                {
                    App.Current.SignalRHub.JoinGame(App.Current.AppUser, App.Current.CurrentGame);
                    ChangeListener();

                    Frame.Navigate(typeof(LobbyPage));
                }
                else
                {
                    App.Current.CurrentGame = null;
                    ServerMessage sm = new ServerMessage(0, "update", "created a game");

                    App.Current.SignalRHub.UserUpdate(App.Current.AppUser, sm);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Join Dialog Exception " + ex.Message);
            }
 
        }
Esempio n. 7
0
 private void spheroGridView_ItemClick(object sender, ItemClickEventArgs e)
 {
     //JoinGame
     selectedGame = (Game)e.ClickedItem;
     //Debug.WriteLine("IMPLEMENT");
 }
Esempio n. 8
0
        private async void EndGame(Game g)
        {
            string wm;
            if (g.Winner.UserId == App.Current.AppUser.UserId)
            {
                wm = "Game Over, you WON!";
            }
            else
            {
                wm = "Game Over, you lost.";
            }
            var messageDialog = new MessageDialog(wm);
            // Add commands and set their command ids
            messageDialog.Commands.Add(new UICommand("Ok", (command) =>
            {
                App.Current.CurrentGame = null;
                App.Current.SignalRHub.SignalRServerNotification -= new SignalRServerHandler(SignalRHub_SignalRServerNotification);
                ServerMessage sm = new ServerMessage(0, "update", "null");
                App.Current.SignalRHub.UserUpdate(App.Current.AppUser, sm);
                Frame.Navigate(typeof(HubPage));
            },
            0));


            // Set the command that will be invoked by default
            messageDialog.DefaultCommandIndex = 0;

            // Show the message dialog and get the event that was invoked via the async operator
            var commandChosen = await messageDialog.ShowAsync();
        }
Esempio n. 9
0
        private void CreateGame_Button_Click(object sender, RoutedEventArgs e)
        {
            string s;

            if (_maxTime < 0 || _maxHits < 0 || App.Current.OppUserTest == null)
            {
                if (_maxHits < 0)
                {
                    s = "Error: You need to choose how many lives Sphero Player will have.";
                    GameError(s);
                }
                else
                {
                    if (opponent.UserName == null || App.Current.OppUserTest == null)
                    {
                        s = "Error: You need to select an opponent";
                        GameError(s);
                    }
                    else
                    {
                        if (_maxTime <0)
                        {
                            s = "Error: You need to choose how long the game will last.";
                            GameError(s);
                        }
                    }
                }
            }
            else
            {
                Game ugame = new Game();
                ugame.SpheroPlayer = App.Current.AppUser;
                ugame.DronePlayer = App.Current.OppUserTest;
                ugame.OpponentName = App.Current.OppUserTest.UserName;
                ugame.CreatorName = App.Current.AppUser.UserName;
                ugame.MaxTime = _maxTime;
                ugame.MaxHits = _maxHits;
                ugame.GameStatus = 0;
                ugame.DronePlayerName = App.Current.OppUserTest.UserName;
                ugame.SpheroPlayerName = App.Current.AppUser.UserName;
                ugame.GameId = App.Current.AppUser.UserId + "game";
                ugame.DateCreated = DateTime.Now;
                App.Current.SignalRHub.CreateGame(App.Current.AppUser, ugame);
                App.Current.CurrentGame = ugame;
                Frame.Navigate(typeof(HubPage));
            }


            //Frame.Navigate(typeof(LobbyPage));
        }
Esempio n. 10
0
        public void InGameMessageCall(Game game, InGameMessage im)
        {
            //send start message
            //Check to see if timer is up
            //Check to see what states match //Correct State
            //check to see what is the command //Valid Command
            Game g = new Game();


            g = InPlayGames.Find(fg => fg.GameId.Equals(game.GameId) && fg.DateCreated.Equals(game.DateCreated));// && (fg.DronePlayer.UserId.Equals(user.UserId) || fg.SpheroPlayer.UserId.Equals(user.UserId)));
            int place = InPlayGames.FindIndex(fg => fg.GameId.Equals(game.GameId) && fg.DateCreated.Equals(game.DateCreated));
            if (game.GameState != g.GameState)
            {
                //User is in the wrong state send inGameMessage with the correct state and Game object
            }
            else
            {
                switch (game.GameState)
                {
                    case 0:
                        //Actions - update GameObject - start Time, targeted, end
                        if (im.Action == "target")
                        {
                            im.Action = "targeted";
                            //if I'm a sphero display Warning
                            game.GameState = 1;
                            InPlayGames.RemoveAt(place);
                            InPlayGames.Insert(place, game);
                            Clients.Group(game.GameId).inGameMessage(game, im);
                           
                        }
                        break;
                    case 1:
                        if (im.Action == "lost")
                        {
                            im.Action = "lost";
                            //if I'm a sphero display Warning
                            game.GameState = 0;
                            InPlayGames.RemoveAt(place);
                            InPlayGames.Insert(place, game);
                            Clients.Group(game.GameId).inGameMessage(game, im);

                        }
                        if (im.Action == "fire")
                        {
                            im.Hits++; 
                            if (im.Hits == game.MaxHits)
                            {
                                im.Action = "end";
                                //_serverTimer.Stop();
                                game.Winner = game.DronePlayer; 
                                game.GameState = 2;

                                InPlayGames.RemoveAt(place);
                                AllGamesList.Add(game);
                                //AvailableGames.Insert(place, game);
                                Clients.Group(game.GameId).inGameMessage(game, im);
                                //find game replace..
                                //send end message im.Action end, 
                                RemovePlayer(game.DronePlayer, game.GameId);
                                RemovePlayer(game.SpheroPlayer, game.GameId);
                                
                                
                            }
                            else
                            {
                                im.Action = "hit";                               
                                //if I'm a sphero display Warning
                                game.GameState = 0;
                                InPlayGames.RemoveAt(place);
                                InPlayGames.Insert(place, game);
                                Clients.Group(game.GameId).inGameMessage(game, im);
                            }

                        }

                        break; 
                    case 2:
                        break; 


                }
                //targeted - change state of Game Object (insert it into GameList)
                //
            }
            //Debug.WriteLine("Server is in Start Method");
            //Clients.Group(game.GameId).inGameMessage(game, im);
        }
Esempio n. 11
0
        public void JoinGame(User user, Game game)
        {
            ServerMessage jm = new ServerMessage();
            jm.Command = 3;
            int a = -1;
            a = AvailableGames.FindIndex(fg => fg.GameId.Equals(game.GameId) && fg.DateCreated.Equals(game.DateCreated) && (fg.DronePlayer.UserId.Equals(user.UserId) || fg.SpheroPlayer.UserId.Equals(user.UserId)));
            bool triggerStart = false;
            if (a > 0 )
            {
                game.GameStatus++;
                if (game.GameStatus <= 2)
                {
                    jm.Action = "join";
                    jm.Message = user.UserName + " has entered the Lobby";
                    AvailableGames.RemoveAt(a);
                    AvailableGames.Insert(a, game);
                    Groups.Add(Context.ConnectionId, game.GameId);
                    Clients.Group(game.GameId).lobbyMessage(user, game, jm);
                }
                else
                {
                    if (game.GameStatus==3)
                    {
                        jm.Action = "ready";
                        jm.Message = user.UserName + " is Ready to Start the game. ";
                        AvailableGames.RemoveAt(a);
                        AvailableGames.Insert(a, game);
                        //Groups.Add(Context.ConnectionId, game.GameId);
                        Clients.Group(game.GameId).lobbyMessage(user, game, jm);
                    }
                    if (game.GameStatus == 4)
                    {
                        InGameMessage igm = new InGameMessage();
                        igm.Action = "start";
                        
                        game.GameState = 0;

                        /*
                        if (InPlayGames.Count == 0) //No Games Are Running
                        {
                            //Start Timer ...for duration of the game
                            //on every tick check all the games end time === startime + timeInterval of maxtime*60*1000
                            //if curtime < endtime Do nothing... if curtime> endtime then send end event! for that game with igm and keep going...
                            startServerTimer(game);
                        }*/
                        AvailableGames.RemoveAt(a);

                        InPlayGames.Add(game);

                        //Groups.Add(Context.ConnectionId, game.GameId);
                        Clients.Group(game.GameId).inGameMessage(game, igm);
                    }

                }
               
            }
            else
            {
                if (AvailableGames.ElementAt(a).GameId != game.GameId)
                {
                    jm.Message = "ERROR - TRIED TO JOIN A GAME THAT DOESN'T EXIST";
                    //game not in list
                    Debug.WriteLine("ERROR - TRIED TO JOIN A GAME THAT DOESN'T EXIST");
                }
                else
                {
                    jm.Message = "ERROR - Tried to Join a game you weren't invited to";
                    //game not in list
                    Debug.WriteLine("ERROR - WRONG USER, trying to access game");
                }
            }

        }
Esempio n. 12
0
 /*
  * We want to create a game
  * Then send a game created event - this triggers Client side (Do you want to Join this game)
  * So the created events needs game message and message and sent to all Users!
  * 
  */
        public void CreateGame(User user, Game g)
        {
            // Call the addNewMessageToPage method to update clients.
            AllGamesList.Add(g);
            AvailableGames.Add(g);
            //int i = AllGamesList.FindIndex(x => x.Equals(g));
           // g.Id = i.ToString(); 
            //AvailableGames.Add(g);


            ServerMessage sm = new ServerMessage();
            sm.Command = 2;
            sm.Action = "created";
            sm.Message = "game created";
            //Clients.User(g.SpheroPlayer.UserName).gameCreated(g, sm); //The User() takes contextID - so make UID = contextID

            //string context;

            //Clients.User("user1").addNewMessageToPage(name, message);
            //if (user.UserId != null) {
            //    context = user.UserId;
            //    Clients.User(context).gameCreated(g, sm);

            //}
            //else
            //{
            //    Clients.All.gameCreated(g, sm);

            //}
            Clients.All.gameCreated(g, sm);
        }