Ejemplo n.º 1
0
        private void SendResult()                  // send all relevant statistics to database
        {
            LocalDataStorage.RefreshSaveFileXML(); // insure we have last progress in local storage
            Guid gamerGuid = LocalDataStorage.GetGamerGuid();

            if (gamerGuid == Guid.Empty) // completely new gamer
            {
                gamerGuid = Guid.NewGuid();
                ResultDO.SendGamerToDatabase(gamerGuid, GamerNameTextBox.Text); // send new gamer to database
            }
            else if (!ResultDO.IsGuidInDatabase(gamerGuid))                     // wrong Guid of gamer, which isn't in database
            {
                gamerGuid = Guid.NewGuid();
                ResultDO.SendGamerToDatabase(gamerGuid, GamerNameTextBox.Text); // send new gamer to database
            }

            ResultDO.SendResultToDatabaseAsync(
                gamerGuid,
                LocalDataStorage.GetLastCurrentScore(),
                GameBoard.GetBiggestTile()
                );
            this.Visibility = Visibility.Collapsed;
            LocalDataStorage.SetGamerGuid(gamerGuid); // insure, that program will recognize gamer next time

            LocalDataStorage.ClearSaveFileBeforeNewGame();
        }
Ejemplo n.º 2
0
        private void GameBoardInit()
        {
            PrepareGameBoard(GAME_BOARD_SIZE);            // prepare empty gameboard
            GameBoard.gameBoardGrid = GetGameBoardGrid(); // make reference on gameboard grid in GameBoard class
            switch (LocalDataStorage.GetGameState())
            {
            // continue game
            case GameBoard.GameState.InProgress:
            case GameBoard.GameState.Paused:
                GameBoard.AddTiles(LocalDataStorage.GetTileMatrix());     // get tile's matrix from local storage
                break;

            // start new game
            default:
                LocalDataStorage.ClearSaveFileBeforeNewGame();
                GameBoard.AddTiles(STARTUP_TILE_COUNT);     // randomly add specified number of tiles on gameboard
                GameBoard.SetGameStateNewGame();
                break;
            }
            GameBoard.SetGameStateInProgress();                                                                   // change game state on "InProgress"

            GamePageViewModel.InitMoveCommandsInWindow();                                                         // add move commands

            GetGamePageResourceDictionary()["BestScore"]    = GameBoard.ScoreFormat(GameBoard.GetBestScore());    // fulfill best score
            GetGamePageResourceDictionary()["CurrentScore"] = GameBoard.ScoreFormat(GameBoard.GetCurrentScore()); // fulfill current score
            LocalDataStorage.RefreshSaveFileXML();
        }
Ejemplo n.º 3
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     if (MainWindowFrame.Source == new Uri("GamePage.xaml", UriKind.Relative)) // perform action only from game page
     {
         LocalDataStorage.RefreshSaveFileXML();                                // save progress before application is closed
     }
 }
Ejemplo n.º 4
0
        private void MainMenuButton_Click(object sender, RoutedEventArgs e) // navigate to main menu page
        {
            NavigationService nav = NavigationService.GetNavigationService(this);

            nav.Navigate(new Uri("MainMenuPage.xaml", UriKind.RelativeOrAbsolute));
            GameBoard.SetGameStatePaused();
            LocalDataStorage.RefreshSaveFileXML();
        }
Ejemplo n.º 5
0
        public static void TryAgain() // refresh game board
        {
            GameBoard.SetGameStateNewGame();
            NavigationService nav = NavigationService.GetNavigationService(GamePage.GetGamePageInstance());

            nav.Refresh();
            LocalDataStorage.RefreshSaveFileXML();
        }