/// <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> /// <param name="returnedTile"></param> public async Task <List <Tile> > PerformDumpAction(string actionSender, Tile returnedTile) { var tiles = _tileManager.PerformDumpAction(returnedTile); // // If the dump failed, return an empty tile list // if (tiles == null) { return(new List <Tile>()); } var viewModel = GameBoardViewModel.GetInstance(); _gameDataLogger.LogMove(actionSender, viewModel.GameTime, MoveType.Dump); viewModel.TilePileCount -= 2; var serverProxy = ServerProxy.GetInstance(); if (serverProxy.messageSender != null) { // ToDo: Send the actionsender name here instead of the client name in case it's a bot that's dumping. await serverProxy.messageSender.SendMessage(PacketType.c_Dump); } return(tiles); }
private void InitializeGameClock() { _gameClock = new DispatcherTimer(); _gameClock.Tick += GameClockOnTick; _gameClock.Interval = new TimeSpan(0, 0, 1); var viewModel = GameBoardViewModel.GetInstance(); viewModel.GameTime = 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")); }); }
/// <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(); }); }
/// <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(); }
/// <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); } }
private void GameClockOnTick(object sender, object o) { var viewModel = GameBoardViewModel.GetInstance(); viewModel.GameTime++; }