0
\$\begingroup\$

I am new to c# game development and just start. I decided to start with the basics, Console Applications.

I am try trying to recreate a game created by Lincoln Li and it's called Mr Sprinkle's Great Escape.

There are 2 classes Stats (An attribute system) and Death where they kind of linked together. Here is the snippet of the code:

Stats

private static int thirst;

    static public void ThirstLevel()
    {
        Console.WriteLine("Your thirst level is: {0}", thirst);
    }

    static public void DecreaseThirstLevel()
    {
        thirst--;
        Console.WriteLine("Your thirst level is: {0}", thirst);
        if (thirst == 20)
        {
            Console.WriteLine("Your thirst level is 2/3 gone!");
            Console.WriteLine();
            Console.WriteLine("You're getting thirsty!");
            Console.WriteLine();
        }
        else if (thirst == 10)
        {
            Console.WriteLine("Danger! Danger! Your thirst level is 1/3 gone!");
            Console.WriteLine();
            Console.WriteLine("Better go get some water!");
            Console.WriteLine();
        }
        else if (thirst <= 0)
        {
            Console.Clear();
            Death.DeathByThirst();
        }
    }

Now my question, is how will I implement Death.DeathByThirst in the Death class. How will I proceed to call the logic of the Stats class to Death Class?

So far I'm stumped here :/

 static public void DeathByThirst()
    {
            ???
    }

Your help will be appreciated! :)

\$\endgroup\$
  • \$\begingroup\$ Can you edit your question to describe what the DeathByThirst() method is intended to do? It's not clear to me from the description so far. \$\endgroup\$ – DMGregory Sep 12 '16 at 1:31
  • \$\begingroup\$ Welcome to gamedev stack exchange. This is a bit off topic here and more a generic question about C# programming. I would recommended looking up some tutorials, there are plenty out there, lots of free good stuff on youtube etc. good luck with your development journey. \$\endgroup\$ – lozzajp Sep 12 '16 at 9:38
1
\$\begingroup\$

You will have to declare an instance of the Stats class within the Death Class to use the methods and properties of the Stats class, make sure the classes are public you are trying to access.

Declare the Stats Class in the Death Class and perform a myStatsClass[Dot] whatever your methods are named in the method that you want to use the Stats class IE in the Death Class Declare :

Stats myStatsClass; 

In the Death Class Method :

public void DeathByThirst()
 {
    myStatsClass.CallStatsClassMethod();
 }
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.