public void SaveScore() { if (uiProcs.IsEndlessGame()) { if (openedCells > scoreData.Endless) { scoreData.Endless = openedCells; ShowHighscoreBlock(scoreData.Endless.ToString()); } } else { int currTime = Mathf.FloorToInt(time); switch (fieldProcs.currLevel) { case 1: { if (currTime < scoreData.Easy) { scoreData.Easy = currTime; ShowHighscoreBlock(TimeToText(scoreData.Easy)); } } break; case 2: { if (currTime < scoreData.Normal) { scoreData.Normal = currTime; ShowHighscoreBlock(TimeToText(scoreData.Normal)); } } break; case 3: { if (currTime < scoreData.Hard) { scoreData.Hard = currTime; ShowHighscoreBlock(TimeToText(scoreData.Hard)); } } break; } } FillScoreText(); FileManager fileManager = GetComponent <FileManager> (); fileManager.SaveScores(scoreData); }
void Open() { if (fieldMover == null) { Start(); } bool isGameOver = fieldMover.GetGameOver(); bool isWin = fieldMover.GetWin(); if (isGameOver || isWin || isFlag) { return; } if (!fieldMover.IsFirstOpen()) { fieldProcs.SetMinesOnFieldBlock(parentBlock, transform.parent.gameObject, uiProcs.IsEndlessGame()); fieldProcs.CalcValuesInFieldBlock(parentBlock); fieldMover.FirstOpen(); } if (cellParams.haveBlockAdj()) { Vector2 pos = parentBlock.pos; if (cellParams.Top) { Vector2 adjPos = new Vector2(pos.x, pos.y + 1); CheckAdjFieldBlock(adjPos); } if (cellParams.Bottom) { Vector2 adjPos = new Vector2(pos.x, pos.y - 1); CheckAdjFieldBlock(adjPos); } if (cellParams.LeftTop) { Vector2 adjPos = new Vector2(pos.x - 1, pos.y + 1); CheckAdjFieldBlock(adjPos); } if (cellParams.LeftBottom) { Vector2 adjPos = new Vector2(pos.x - 1, pos.y); CheckAdjFieldBlock(adjPos); } if (cellParams.RightTop) { Vector2 adjPos = new Vector2(pos.x + 1, pos.y); CheckAdjFieldBlock(adjPos); } if (cellParams.RightBottom) { Vector2 adjPos = new Vector2(pos.x + 1, pos.y - 1); CheckAdjFieldBlock(adjPos); } fieldProcs.CalcValuesInFieldBlock(parentBlock); } isOpen = true; if ((cellValue == 0) && (!isMine)) { for (int i = 0; i < fieldProcs.adjOffsets.Length; i++) { OpenCell adjOpenCell = fieldProcs.GetAdjOpenCell(this, i); if ((adjOpenCell == null) || (adjOpenCell.isOpen)) { continue; } if (adjOpenCell.isFlag) { adjOpenCell.isFlag = false; uiProcs.ChangeFlagsCount(1); } adjOpenCell.Open(); } } if (isMine) { if (uiProcs.IsEndlessGame()) { fieldMover.SaveScore(); } fieldMover.SetGameOver(true); fieldProcs.ViewMines(); } else { uiProcs.IncOpenedCells(); } if ((!uiProcs.IsEndlessGame()) && (fieldMover.openedCells >= needcells)) { fieldMover.SaveScore(); fieldMover.SetWin(true); } gameObject.SetActive(false); }