private void UpdateScores(bool showScoreAnimation = true) { CurrentPlayer = game.CurrentPlayer; Score[game.CurrentPlayer] = game.Scores[game.CurrentPlayer]; currentScoreText = TextFormatting.AddSpacingBetweenCharacters(string.Format(scoreFormat, Score[0], 1)); if (PlayersPlaying > 1) { currentScoreText2 = TextFormatting.AddSpacingBetweenCharacters(string.Format(scoreFormat, Score[1], 2)); } if (showScoreAnimation) { var scorePopup = GameObject.Find("Score"); if (scorePopup != null) { scorePopup.SendMessage("ShowScore"); } } }
private void ShowScore(GameObject obj, Transform offsetX, GUIStyle style, string score) { Vector3 rawPosition = obj.transform.position; rawPosition.x = offsetX.position.x; Vector3 start = Camera.main.WorldToScreenPoint(rawPosition); start.y = Screen.height - start.y; float minWidth, maxWidth; string text = TextFormatting.AddSpacingBetweenCharacters(score); GUIContent content = new GUIContent(text); style.CalcMinMaxWidth(content, out minWidth, out maxWidth); float height = style.CalcHeight(content, maxWidth); height /= 2.0f; float halfWidth = maxWidth / 2.0f; GUI.Label(new Rect(start.x - halfWidth - 3, start.y + 2 - height, maxWidth, 120), FontColorUtils.Shadow(text), style); GUI.Label(new Rect(start.x - halfWidth, start.y - height, maxWidth, 120), FontColorUtils.MainGameScore(text), style); }
/// <summary> /// Use this for initialization. /// </summary> private void Start() { currentScoreText = TextFormatting.AddSpacingBetweenCharacters(string.Format(scoreFormat, 0, 1)); currentScoreText2 = TextFormatting.AddSpacingBetweenCharacters(string.Format(scoreFormat, 0, 2)); game = MemoryGame.Current; game.GameMode = GameMode; game.StartNewGame(); PlayersPlaying = DataMessenger.NumberOfPlayers; game.Players = PlayersPlaying; Score = game.Scores; CurrentPlayer = game.CurrentPlayer; CardsLeft = 0; int numberOfCards = game.DifficultyToNumberOfCards(DataMessenger.Difficulty) / 2; var fieldSize = DeckLayoutProvider.GetGridSize(numberOfCards * 2); if (IsDebuggingQuestionsEnabled) { DebugQuestionPopup(); } List <CardData> cards; if (DataMessenger.SelectedDeck != null) { cards = DataMessenger.SelectedDeck.Cards.OrderBy(a => Guid.NewGuid()).Take(numberOfCards).ToList(); gameTitle = DataMessenger.SelectedDeck.ResourceName; } else { cards = CardFactory.GetRandomDeck(numberOfCards); gameTitle = "Fossils"; } gameTitle = TextFormatting.AddSpacingBetweenCharactersWithSmallSpace(gameTitle, (int)(Initialize.Scale * 14)); while (cards.Count < numberOfCards) { cards.AddRange(cards); } if (cards.Count > numberOfCards) { cards = cards.Take(numberOfCards).ToList(); } cards.AddRange(cards); cards = cards.OrderBy(c => Guid.NewGuid()).ToList(); var field = WorldToRect.GetRect(SpawnLocation, SpawnEndLocation); field.x = 20; field.width = Screen.width - field.x - field.x; var list = CalculateLayout.Calculate( (int)fieldSize.y, (int)fieldSize.x, field.width, field.height, field.x, field.y, 10 * Initialize.Scale); float scale = 1f; float offsetY = 0f; switch (DataMessenger.Difficulty) { case 0: scale = 1f; break; case 1: scale = 0.8f; offsetY = 8f; break; case 2: scale = 0.6f; offsetY = 12f; break; case 3: scale = 0.5f; offsetY = 14f; break; case 4: scale = 0.4f; offsetY = 20f; break; } if (CardObject != null && SpawnLocation != null) { int i = 0; for (int y = 0; y < fieldSize.y; ++y) { for (int x = 0; x < fieldSize.x; ++x) { ++CardsLeft; var card = (GameObject)Instantiate(CardObject); card.SendMessage("SetCard", cards[i]); Vector3 newPosition = Camera.main.ScreenToWorldPoint( new Vector3(list[i].x + (list[i].width / 2.0f), list[i].y + (list[i].height / 3.0f) - offsetY)); newPosition.z = -2; GameObject obj = new GameObject(); obj.transform.position = newPosition; obj.transform.parent = SpawnLocation.transform; obj.transform.localScale = new Vector3(scale, scale, 1); card.transform.parent = obj.transform; card.transform.localPosition = new Vector3(); ++i; } } } }