Пример #1
0
        private void NewGameButton_Click(object sender, RoutedEventArgs e) // start new game
        {
            LocalDataStorage.ClearSaveFileBeforeNewGame();
            NavigationService nav = NavigationService.GetNavigationService(this);

            nav.Navigate(new Uri("GamePage.xaml", UriKind.RelativeOrAbsolute));
        }
Пример #2
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();
        }
Пример #3
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();
        }