Adding up total scores for level

I am fairly new to c# and I have a few things that I want to create a formula to work out the final score

these are the stats that accumulate when playing to give scores and are in the PlayerStats Script:
PlayerStats.Rounds
PlayerStats.RoundScore
PlayerStats.Lives
PlayerStats.Money
PlayerStats.kills

I have the total for all these displaying on the end of level screen but want to display a final score

Eg:

Round Score + Money * Lives
or
Round Score + kills + lives
etc

I am not sure how to do maths in C# to work this out

Thanks.

Here is example of the scoring

8201463--1069983--score.png

Are you asking how to do plus signs and multiplication in c#? I’m actually so confused what you are asking.

Besides the basics of Googling for this, since it’s a common thing, you have the basics of your formula already written out.

Store the value in a variable and then just grab the variable value for your text like you’re already doing.

I’m actually not sure what you’re asking?

The scripting forums here are not really the place to learn the fundamentals/basics of C#. There are literally hundreds if not thousands of basic C# tutorials online that you could/should use. Trying to understand such basic things via a forum interaction is going to be painful and slow for you which is why I suggest following some tutorials.

Maybe you are not asking about how to use basic addition, subtraction in which case I’m sorry but it does sound like you should follow a tutorial.

Sorry I might not have been clear on what I am trying to do hahah

I’ve been looking for a tutorial or guides but cant seem to find what I am looking for. Ill keep looking :stuck_out_tongue:

This weekend I made this for my Impulse One Rogue Lander game:

Here is the main computation and message injection code, each thing computed, then reported, then the report screen above is started up:

                int baseScore = ScoreAdvanceTable.TL_ARCADE_LANDED;

                string lateralColor = null;
                int lateralScore = ScoreAdvanceTable.TaplanderArcadeLateralScore( xmove, out lateralColor);

                string verticalColor = null;
                int verticalScore = ScoreAdvanceTable.TaplanderArcadeVerticalScore( ymove, out verticalColor);

                int fuelRemaining = TLSTATE.Fuel;
                int fuelFrugalityScore = ScoreAdvanceTable.TaplanderArcadeFuelFrugalityAward(fuelRemaining);

                int totalScore = baseScore + lateralScore + verticalScore + fuelFrugalityScore;

                TLSTATE.AddScore( totalScore);

                int freshFuelAwarded = ScoreAdvanceTable.TaplanderArcadeFuelReplenishmentAward( xmove, ymove);

                // begin fabricating the list that goes off to taplander_landedresults
                List<string[]> Triplets = new List<string[]>();

                Triplets.Add( new string[] { ScoreAdvanceTable.DescribeLanding( xmove, ymove), "", ""});
                Triplets.Add( null);

                Triplets.Add( new string[] {"", "ARRIVED ON BASE", baseScore.ToString("+#;-#;0"), taplander_landedresults.GLYPH_GOOD});

                Triplets.Add( new string[] {"", "X-VELOCITY (" + xmove.ToString( "+#;-#;0") + "):", lateralScore.ToString("+#;-#;0"), lateralColor});

                Triplets.Add( new string[] {"", "Y-VELOCITY (" + ymove.ToString( "+#;-#;0") + "):", verticalScore.ToString("+#;-#;0"), verticalColor});

                Triplets.Add( new string[] {"", "FUEL REMAINING (" + fuelRemaining.ToString() + "):", fuelFrugalityScore.ToString("+#;-#;0")});

                Triplets.Add( new string[] {"", "TOTAL POINTS AWARDED:", totalScore.ToString("+#;-#;0")});

                Triplets.Add( null);

                Triplets.Add( new string[] {"", "CURRENT PLAYER SCORE:", TLSTATE.Score.ToString()});

                Triplets.Add( null);

                Triplets.Add( new string[] {"", "FRESH FUEL AWARDED:", freshFuelAwarded.ToString()});

                // throws up the scene, and has the previous continuations...
                taplander_landedresults.Load(
                    TripletYielder( Triplets),
                    () => {
                        if (DSM.taplander_config.IsArcade.bValue)
                        {
                            TLSTATE.AwardFuel( fuelAward);

                            TLSTATE.State = TLSTATE.TaplanderState.READY;
                            SceneHelper.LoadScene( taplander_scenes.s_TLPlaying);
                        }

                        if (DSM.taplander_config.IsCampaign.bValue)
                        {
                            SceneHelper.LoadScene( taplander_scenes.s_TLPlayLevels);
                        }
                    }
                );

Each endpoint such as ScoreAdvanceTable.TaplanderArcadeLateralScore serves to centralize the score computation mechanism, like this:

    public const int TL_ARCADE_LANDED = 10;

    // the last digit will be extended for all higher velocities
    static int[] TL_ARCADE_LATERAL = { 10, 2, 1, 0};
    static int[] TL_ARCADE_VERTICAL = { 100, 100, 50, 25, 20, 15, 10, 5, 2, 1, 0};

    public const int TL_MAX_MANHATTAN_SPEED = 16;

    public const int TL_MAX_HORIZONTAL_SPEED = 3;

    public static bool DeservesCongratulations(int xmove, int ymove)
    {
        xmove = Mathf.Abs( xmove);
        ymove = Mathf.Abs( ymove);

        if (ymove <= 3 && xmove == 0)
        {
            return true;
        }
        return false;
    }

    public static string DescribeLanding(int xmove, int ymove)
    {
        xmove = Mathf.Abs( xmove);
        ymove = Mathf.Abs( ymove);

        if (ymove <= 1 && xmove == 0)
        {
            return "PERFECT LANDING!!!!";
        }

        if (ymove <= 3 && xmove == 0)
        {
            return "SUPERB LANDING!";
        }

        if (ymove <= 6 && xmove <= 1)
        {
            return "GOOD LANDING!";
        }

        if (ymove <= 10 && xmove <= 1)
        {
            return "ROUGH LANDING!";
        }

        // you banged HARD...
        {
            // shuffle it on the first time of use
            if (RoverBarelyLanded < 0)
            {
                RoverBarelyLanded = 0;

                for (int i = 0; i < BarelyLandedStrings.Length; i++)
                {
                    int j = Random.Range( i, BarelyLandedStrings.Length);
                    if (i != j)
                    {
                        var tempSwap = BarelyLandedStrings[i];
                        BarelyLandedStrings[i] = BarelyLandedStrings[j];
                        BarelyLandedStrings[j] = tempSwap;
                    }
                }
            }

            int which = RoverBarelyLanded % BarelyLandedStrings.Length;
            RoverBarelyLanded++;
            return BarelyLandedStrings[ which];
        }
    }

    static int RoverBarelyLanded = -1;
    static string[] BarelyLandedStrings = new string[] {
        "WE'LL CALL IT A LANDING...",
        "DID WE GET SHOT DOWN!?",
        "THAT MIGHT BUFF OUT... NOT SURE...",
        "BANG IT DOWN LIKE YOU OWN IT!",
        "SLAM INTO THAT PLANET!",
        "SORT OF LANDED... SORT OF...",
        "DON'T WORRY, IT'S ONLY A RENTAL...",
        "THAT'LL BUFF OUT... MAYBE?",
        "WOW, I GUESS WE HAVE ARRIVED...",
        "WHEN THE MAGIC OF FLIGHT ENDS...",
        "I'LL NOTIFY MAINTENANCE...",
        "THE CHIEF PILOT WANTS A WORD WITH YOU!",
    };

    public static int TaplanderArcadeLateralScore( int xmove, out string color)
    {
        color = (xmove == 0) ? taplander_landedresults.GLYPH_GOOD : taplander_landedresults.GLYPH_MEH;

        xmove = Mathf.Abs( xmove);

        if (xmove >= TL_ARCADE_LATERAL.Length - 1)
        {
            color = taplander_landedresults.GLYPH_BAD;
            xmove = TL_ARCADE_LATERAL.Length - 1;
        }
        return TL_ARCADE_LATERAL[xmove];
    }

    public static int TaplanderArcadeVerticalScore( int ymove, out string color)
    {
        ymove = Mathf.Abs( ymove);

        color = (ymove <= 4) ? taplander_landedresults.GLYPH_GOOD : taplander_landedresults.GLYPH_MEH;

        if (ymove >= TL_ARCADE_VERTICAL.Length - 1)
        {
            color = taplander_landedresults.GLYPH_BAD;
            ymove = TL_ARCADE_VERTICAL.Length - 1;
        }
        return TL_ARCADE_VERTICAL[ymove];
    }

    // what score we award you for remaining fuel
    public static int TaplanderArcadeFuelFrugalityAward(int remainingFuel)
    {
        return remainingFuel / 5;
    }

    // what fuel we GIVE to you for a good landing
   public static int TaplanderArcadeFuelReplenishmentAward( int xmove, int ymove)
    {
        string dummy;
        int latFuel = TaplanderArcadeLateralScore( xmove, out dummy);
        int vertFuel = TaplanderArcadeVerticalScore( ymove, out dummy);

        int totalFuel = latFuel + vertFuel;
 
        totalFuel *= 2;

        totalFuel += 25;

        return totalFuel;
    }

Impulse One is available at the app stores:

Public TestFlight link:

1 Like