I am developing a console text game. Here is the problematic code for it.
Code Snippet
using System;
namespace CoolGameTextClean
{
class Engine
{
private static Player MainCharacter = new Player();
public Engine()
{
MainCharacter.StartingLevel();
}
public static void Main()
{
Console.WriteLine(MainCharacter.DisplayLevel.ToString()); // Displays 0. It should display 1
Console.ReadLine();
}
}
}
Code Snippet
namespace CoolGameTextClean
{
class Player
{
private int Level;
public int DisplayLevel
{
get
{
return Level;
}
set
{
Level = value;
}
}
public void StartingLevel()
{
Level = 1;
}
}
}
The problem is, in the Main method, I want to display the Level of the MainCharacter. In the constructer, I call the StartingLevel method, which sets the Level to 1, however, when I run the program, it displays the level as 0. What am I doing wrong Can someone tell me
Thanks.