private void UpdateScore() { int curScore = 0; for (int y = 0; y < HEIGHT; y++) { for (int x = 0; x < WIDTH; x++) { int value = board[y, x]; if (value < 3) { continue; } int rank = NextValueManager.GetRank(value); if (rank >= 1) { curScore += (int)Mathf.Pow(3f, (float)rank); } } } score = curScore; scoreObj.text = AddThousandsSeparator(score.ToString()); }
private int NormalizeValue(int value) { switch (value) { case 0: case 1: case 2: return(value); default: return(NextValueManager.GetRank(value) + 2); } }
private int GetHighestRank() { int highestRank = NextValueManager.GetRank(board[0, 0]); for (int y = 0; y < HEIGHT; y++) { for (int x = 0; x < WIDTH; x++) { int curRank = NextValueManager.GetRank(board[y, x]); if (curRank > highestRank) { highestRank = curRank; } } } return(highestRank); }
private void Init() { highScoreObj = highScoreContainer.GetComponent <Text>(); if (score > highScore) { nTimesHighScoreAchieved = 1; highScore = score; highScoreObj.text = AddThousandsSeparator(highScore.ToString()) + " (" + numMoves + ", 1)"; DumpResults(); } else if (score == highScore) { nTimesHighScoreAchieved++; highScoreObj.text = AddThousandsSeparator(highScore.ToString()) + " (" + numMoves + ", " + nTimesHighScoreAchieved + ")"; DumpResults(); } highestNMovesObj = highestNMovesContainer.GetComponent <Text>(); if (numMoves > highestNMoves) { highestNMoves = numMoves; highestNMovesObj.text = highestNMoves.ToString(); DumpResults(); DumpBestPlay(); } int curHighestRank = GetHighestRank(); highestRankObj = highestRankContainer.GetComponent <Text>(); if (curHighestRank > highestRank) { nTimeHighestRankAchieved = 1; highestRank = curHighestRank; highestRankObj.text = highestRank.ToString() + " (" + nTimeHighestRankAchieved + ")"; DumpResults(); } else if (curHighestRank == highestRank) { nTimeHighestRankAchieved++; highestRankObj.text = highestRank.ToString() + " (" + nTimeHighestRankAchieved + ")"; DumpResults(); } gameOverObj.SetActive(false); gameOver = false; restartButton.GetComponent <Button>().onClick.AddListener(Restart); scoreObj = scoreContainer.GetComponent <Text>(); score = 0; numMoves = 0; nextValueManager = new NextValueManager(); for (int y = 0; y < HEIGHT; y++) { for (int x = 0; x < WIDTH; x++) { board[y, x] = 0; } } FillInitialBoard(); UpdateBoard(); UpdateScore(); nextValues = GenerateNextValue(); bestPlayMoves.Clear(); }