gutterball-3/Gutterball 3/Assets/Scripts/ScoreDisplay.cs
SkunkStudios 0b195a0fc1 Custom Balls and Cosmic Alleys
Strike it big with amazing bowling action! Everything that made Gutterball 3D a hit is here - incredible 3D graphics, cool ball-rolling controls, hilarious characters - and more! Eight all-new alleys are waxed and ready for you to toss your choice of 85 unique bowling balls. As you play, earn points and cash and unlock alleys and balls. Even customize a ball with your own settings and images! Addictive bowling fun that will bowl you over!
2025-01-16 16:07:45 +07:00

81 lines
No EOL
1.9 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
public class ScoreDisplay : MonoBehaviour
{
public enum Strikes { Strike, Double, Turkey }
public Strikes strikes;
public Text[] rollTexts, frameTexts;
public void FillRolls(List<int> rolls)
{
string scoresString = FormatRolls(rolls);
for (int i = 0; i < scoresString.Length; i++)
{
rollTexts[i].text = scoresString[i].ToString();
// turn ++;
}
}
public void FillFrames(List<int> frames)
{
for (int i = 0; i < frames.Count; i++)
{
frameTexts[i].text = frames[i].ToString();
}
}
public void ResetStrike()
{
strikes = Strikes.Strike;
}
public void AllStrike()
{
strikes++;
if (strikes > Strikes.Turkey)
{
strikes = Strikes.Strike;
}
}
public static string FormatRolls(List<int> rolls)
{
string output = "";
for (int i = 0; i < rolls.Count; i++)
{
int box = output.Length + 1; // Score box 1 to 21
if (rolls[i] == 0)
{ // Always enter 0 as -
output += "-";
}
else if (box % 2 == 0 && rolls[i - 1] + rolls[i] == 10)
{ // SPARE anywhere
output += "/";
}
else if (box >= 19 && rolls[i] == 10)
{ // STRIKE in frame 10
output += "X";
}
else if (rolls[i] == 10)
{ // STRIKE in frame 1-9
output += " X";
}
else
{
output += rolls[i].ToString();
// Normal 1-9 bowl
}
}
return output;
}
}