How to make a 3D bowling scoreboard for each 10 frames?
Hey, I am making a 3D bowling game but i don't know how to add each score for each frames. Foreg.. in 1st frame 9 or 7 pins fall i got 9 or 7 points for that then again if 1 or 3 pins fall then 10 will be total score for that frame. So on... up to 10 frames how can i add all 10 frames score. I want some logical help on this. Currently when my single pin falls i got 1 point.
@Shivang_Purwar - You'd better post an image of your intended behavior and design, no use for people start googling for some bowling related stuff - it will be guesswork.
Answer by kalen_08 · Aug 26, 2018 at 11:52 PM
Well you need to track each throw and also each frame.
I would use a List of type Vector3int as this accomplishes both.
Then keep track of how many throws they are on. (1, 2, 3), this will need to be reset after every frame.
Convert these then into vector3ints and add to the list.
At the end have a method that would total up everything. in fact I would create a custom struct just for all of this.
Here is a solution. Use it or not, this is as far as I go in this. Figure out whatever else you need, it should be easy to build on this given the properties I put in.
public class Score : MonoBehaviour
{
int frame = 0;
int attempt = 0;
int[] frameData = new int[3];
Frame currentFrame;
List<Frame> gameSummary = new List<Frame> ();
public void AddScore (int pins)
{
frameData[attempt] = pins;
NextAttempt();
}
void NextAttempt ()
{
currentFrame = new Frame (frameData[0], frameData[1], frameData[2]);
attempt++;
bool finished = attempt == 3 || currentFrame.IsStrike || currentFrame.IsSpare;
if (finished)
{
gameSummary.Add(currentFrame);
attempt = 0;
frame++;
}
}
int GetTotalScore ()
{
int score = 0;
foreach (var frame in gameSummary) {
score += frame.Total;
}
return score;
}
struct Frame
{
int a;
int b;
int c;
Frame (int a, int b, int c)
{
this.a = a;
this.b = b;
this.c = c;
}
public int Total { get { return a + b + c;}}
public bool IsStrike { get { return a == 10;}}
public bool IsSpare { get { return a + b == 10;}}
}
}
Your answer
Follow this Question
Related Questions
Detect all object are touching as one cluster 0 Answers
Using coroutine and texture array to randomly associate textures? 1 Answer
Hiding part of mesh 0 Answers
how to make a succession(n+1,5n,etc) that work in if statement? 0 Answers
Having An Issue Getting Level Lock System To Function Properly 0 Answers