Exemplo n.º 1
0
        /// <summary>
        /// This method is invoked whenever someone from the server performs a
        /// dump action.
        /// </summary>
        /// <param name="actionSender">The person who performed the dump action</param>
        public async void DumpActionReceivedFromServer(string actionSender)
        {
            var viewModel = GameBoardViewModel.GetInstance();

            _gameDataLogger.LogMove(actionSender, viewModel.GameTime, Storage.MoveType.Dump);

            await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                viewModel.TilePileCount -= 2;

                // ToDo: Get these two Tiles from the server.
                _tileManager.DumpReceived(new Tile("a"), new Tile("b"));
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method is invoked whenever someone (either local or from the server) signals that
        /// they have won the game.
        /// </summary>
        /// <param name="winnerName"></param>
        public async void EndGame(string winnerName)
        {
            if (null == winnerName)
            {
                throw new ArgumentException();
            }

            GameStarted = false;

            _botManager.StopBots();


            //
            // Log the victory event. and then end the logging session.
            //

            var viewModel = GameBoardViewModel.GetInstance();

            _gameDataLogger.LogMove(winnerName, viewModel.GameTime, MoveType.Victory);


            _postGameData = await _gameDataLogger.EndLoggingSession();

            await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                _gameClock.Stop();

                string title = string.Format("{0} has won the game!", winnerName);

                //ToDo: Implement.
                var content = string.Format("Not Implemented");

                var dialog = new MessageDialog(content, title);

                dialog.Commands.Add(new UICommand("Play Again", OnPlayAgainClicked));
                dialog.Commands.Add(new UICommand("Main Menu", OnMainMenuClicked));

                // Set the cancel index (default button behavior) to return the user to the main page.
                dialog.CancelCommandIndex = 1;
                await dialog.ShowAsync();
            });
        }
Exemplo n.º 3
0
        /// <summary>
        /// Method starts the game.  Updates UI with game start animations and kicks off the bots.
        /// </summary>
        public async void StartGame()
        {
            if (GameStarted)
            {
                return;
            }
            GameStarted = true;

            if (_gameConnectionType == GameConnectionType.Local)
            {
                // ToDo: Make logging use email address instead of alias
                _gameDataLogger.BeginLoggingSession(_humanPlayer.Alias, _localPlayers);
            }

            else if (_gameConnectionType == GameConnectionType.Online)
            {
                var room = RoomManager.GetInstance();

                // ToDo: Make logging use email address instead of alias
                _gameDataLogger.BeginLoggingSession(room.Host.Alias, room.RoomMembers);
            }


            OnGameStarted();

            await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var viewModel = GameBoardViewModel.GetInstance();

                viewModel.GameTime      = 0;
                viewModel.TilePileCount = _tileManager.GetPileCount();
                _gameClock.Start();
            });

            // ToDo: Add a blocking method here that waits for the startgameanimation to complete.

            _botManager.StartBots();
        }
Exemplo n.º 4
0
 public static GameBoardViewModel GetInstance()
 {
     return _instance ?? (_instance = new GameBoardViewModel());
 }
Exemplo n.º 5
0
        /// <summary>
        /// Contains methods that are called when game action messages are received.
        /// </summary>
        /// <summary>
        /// This method is invoked whenever someone (either local or from the server) performs a
        /// peel action.
        /// </summary>
        /// <param name="actionSender">The person who performed the dump action</param>
        /// <param name="IsSenderLocal">If the person performing the peel action is local (not from server) or not</param>
        public async void PeelActionReceived(string actionSender, bool IsSenderLocal = true)
        {
            var serverProxy = ServerProxy.GetInstance();
            var roomManager = RoomManager.GetInstance();
            var viewModel   = GameBoardViewModel.GetInstance();


            //
            // If there are enough tiles left, then do a peel.  Otherwise, if there are not enough
            // tiles, then actionSender has won the game.
            //

            if (_tileManager.GetPileCount() >= (roomManager.RoomMembers.Count + _localPlayers.Count - 1))
            {
                var tiles = _tileManager.PerformPeelAction(roomManager.RoomMembers.Count + _localPlayers.Count - 1);

                if (null == tiles)
                {
                    return;
                }


                //
                // Update the hands of all of the players with one of the returned tiles from the peel.
                // If it's the human player's hand, update the UI too with the returned tile.
                //

                foreach (IPlayer player in _localPlayers)
                {
                    if (player.Alias == _humanPlayer.Alias)
                    {
                        OnPeelOccurred(tiles[0].TileContents, actionSender);
                    }

                    // ToDo: This line can possibly throw an out of bounds exception.
                    player.PeelActionReceived(tiles[0]);
                    tiles.RemoveAt(0);
                }


                //
                // Update UI.
                //

                await App.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    //
                    // Subtract total online players + bots.  Subtract one b/c the human player is
                    // double counted.
                    //

                    viewModel.TilePileCount -=
                        (roomManager.RoomMembers.Count + _localPlayers.Count - 1);
                });


                //
                // If the person performing the peel is local, then send a message to the server informing
                // of the peel.  Otherwise, if it came from the server, then don't send a message
                // to the server.
                //

                if ((serverProxy.messageSender != null) && IsSenderLocal)
                {
                    // ToDo: This will send the incorrect message to the server if a bot has peeled and not the client.
                    await serverProxy.messageSender.SendMessage(PacketType.c_Peel);
                }


                //
                // Log the Peel event
                //

                _gameDataLogger.LogMove(actionSender, viewModel.GameTime, Storage.MoveType.Peel);
            }
            else
            {
                if ((serverProxy.messageSender != null) && IsSenderLocal)
                {
                    await serverProxy.messageSender.SendMessage(PacketType.c_Victory);
                }

                EndGame(actionSender);
            }
        }
Exemplo n.º 6
0
        private void GameClockOnTick(object sender, object o)
        {
            var viewModel = GameBoardViewModel.GetInstance();

            viewModel.GameTime++;
        }
Exemplo n.º 7
0
 public static GameBoardViewModel GetInstance()
 {
     return(_instance ?? (_instance = new GameBoardViewModel()));
 }