Browse Source

clearer game over screen

A
Josh 2 years ago
parent
commit
c68f687017
  1. 23
      namedropper/Assets/GameOverScreen.cs
  2. 5
      namedropper/Assets/ScoreStack.cs
  3. 38
      namedropper/Assets/Scripts/Category.cs
  4. 14
      namedropper/Assets/Scripts/Game.cs
  5. 10
      namedropper/Assets/Scripts/Player.cs

23
namedropper/Assets/GameOverScreen.cs

@ -16,11 +16,30 @@ public class GameOverScreen : MonoBehaviour
{ {
GameManager.Instance.HighScore = score; GameManager.Instance.HighScore = score;
} }
_gameOverMessage.text = "GAME OVER\n\nYour score: " + score + "\nToday's hi-score: " + GameManager.Instance.HighScore.ToString() + "\n\nPress 'R' to Replay"; _gameOverMessage.text = "GAME OVER\n\nYour score: " + score + "\nToday's hi-score: " + GameManager.Instance.HighScore.ToString() + "\n\nPress 'R' to replay";
} }
else else
{ {
_gameOverMessage.text = "GAME OVER\n\nScores: " + GameManager.Instance.Score1 + "\n" + GameManager.Instance.Score2 + "\n" + GameManager.Instance.Score3 + "\n" + GameManager.Instance.Score4; ScoreStack blueScoreStack = GameObject.Find("/ScoreStackBlue").GetComponent<ScoreStack>();
ScoreStack redScoreStack = GameObject.Find("/ScoreStackRed").GetComponent<ScoreStack>();
if (blueScoreStack.Score > redScoreStack.Score)
{
_gameOverMessage.color = Color.blue;
_gameOverMessage.text = "BLUE TEAM WINS!\n" + blueScoreStack.Score + " to " + redScoreStack.Score;
}
else if (redScoreStack.Score > blueScoreStack.Score)
{
_gameOverMessage.color = Color.red;
_gameOverMessage.text = "RED TEAM WINS!\n" + redScoreStack.Score + " to " + blueScoreStack.Score;
}
else
{
_gameOverMessage.color = Color.white;
_gameOverMessage.text = "TIE!\n" + redScoreStack.Score + " to " + blueScoreStack.Score;
}
_gameOverMessage.text += "\n\nPress 'R' to replay";
} }
} }

5
namedropper/Assets/ScoreStack.cs

@ -8,6 +8,11 @@ public class ScoreStack : MonoBehaviour
[SerializeField] Sprite _darkSprite; [SerializeField] Sprite _darkSprite;
int _numCheckers = 0; int _numCheckers = 0;
// Start is called before the first frame update // Start is called before the first frame update
public int Score
{
get { return _numCheckers; }
}
void Start() void Start()
{ {
// //

38
namedropper/Assets/Scripts/Category.cs

@ -23,22 +23,40 @@ public class Category : MonoBehaviour
HideAllFeedback(); HideAllFeedback();
} }
public void ShowFeedbackGood(int streak) public int ShowFeedbackGood(int streak)
{ {
ShowFeedback(_feedbackGood); int streakPayout = GetStreakPayout(streak);
if (streakPayout > 0)
ShowFeedback(_feedbackGood, duration:2f);
else
ShowFeedback(_feedbackGood);
_streak.SetActive(true); if (streakPayout > 0)
_streak.GetComponent<TMPro.TMP_Text>().text = "10";
_streak.GetComponent<TMPro.TMP_Text>().color = Color.green;
if (streak > 1)
{ {
_streak.GetComponent<TMPro.TMP_Text>().text += " x " + streak; _streak.SetActive(true);
_streak.GetComponent<TMPro.TMP_Text>().text = "";
_streak.GetComponent<TMPro.TMP_Text>().color = Color.blue;
_streak.GetComponent<TMPro.TMP_Text>().text = streak + " in a row\n+" + streakPayout + " bonus";
} }
return streakPayout;
}
int GetStreakPayout(int streak)
{
if (streak == 3)
return 1;
else if (streak == 5)
return 1;
else if (streak > 5 && streak % 5 == 0) //every other 5
return 3;
else
return 0;
} }
public void ShowFeedbackBad(string wrongAnswer) public void ShowFeedbackBad(string wrongAnswer)
{ {
ShowFeedback(_feedbackBad); ShowFeedback(_feedbackBad, duration: 2f);
if (SHOW_RIGHT_ANSWERS) if (SHOW_RIGHT_ANSWERS)
{ {
@ -48,11 +66,11 @@ public class Category : MonoBehaviour
} }
} }
void ShowFeedback(SpriteRenderer feedback, bool show = true) void ShowFeedback(SpriteRenderer feedback, bool show = true, float duration = 1f)
{ {
feedback.enabled = show; feedback.enabled = show;
CancelInvoke(); CancelInvoke();
Invoke("HideAllFeedback", 1f); Invoke("HideAllFeedback", duration);
} }
void HideAllFeedback() void HideAllFeedback()

14
namedropper/Assets/Scripts/Game.cs

@ -6,6 +6,7 @@ using UnityEngine.SceneManagement;
public class Game : MonoBehaviour public class Game : MonoBehaviour
{ {
const bool HIDE_SCORES = true;
int _seconds = 70; int _seconds = 70;
[SerializeField] Text Score1; [SerializeField] Text Score1;
@ -216,12 +217,23 @@ public class Game : MonoBehaviour
public System.Tuple<string,string> PickRandomWord() public System.Tuple<string,string> PickRandomWord()
{ {
int index = Random.Range(0, _categories.Length); int index = Random.Range(0, _categories.Length);
return new System.Tuple<string, string>(_categories[index].Name, _categories[index].PickRandomWord()); return new System.Tuple<string, string>(_categories[index].Name, _categories[index].PickRandomWord());
} }
public void UpdateScores() public void UpdateScores()
{ {
if (HIDE_SCORES)
{
Score1.text = "";
Score2.text = "";
Score3.text = "";
Score4.text = "";
return;
}
if (GameManager.Instance.Competitive == false) { if (GameManager.Instance.Competitive == false) {
int score = GameManager.Instance.Score1 + GameManager.Instance.Score2 + GameManager.Instance.Score3 + GameManager.Instance.Score4; int score = GameManager.Instance.Score1 + GameManager.Instance.Score2 + GameManager.Instance.Score3 + GameManager.Instance.Score4;
Score1.text = score.ToString(); Score1.text = score.ToString();

10
namedropper/Assets/Scripts/Player.cs

@ -187,10 +187,10 @@ public class Player : MonoBehaviour
if (category.Elements.Contains(_text.text)) if (category.Elements.Contains(_text.text))
{ {
_streak++; _streak++;
int score = 10 * _streak; int streakBonus = category.ShowFeedbackGood(_streak);
int score = 10 + 10 * streakBonus;
_game.AddScore(score, _playerNumber); _game.AddScore(score, _playerNumber);
category.ShowFeedbackGood(_streak);
Respawn(); Respawn();
} }
else else
@ -198,8 +198,8 @@ public class Player : MonoBehaviour
_streak = 0; _streak = 0;
category.ShowFeedbackBad(_categoryName); category.ShowFeedbackBad(_categoryName);
this.gameObject.SetActive(false); this.gameObject.SetActive(false);
Respawn(); //Respawn();
//Invoke("Respawn", 2f); Invoke("Respawn", 2f);
} }
} }

Loading…
Cancel
Save