ambiguity between variables in C#

You need to rename your private gameOver variable. Change this:

bool gameOver = false;
public bool GameOver {
        get { return gameOver; }
        set { gameOver = value; }
    }

to

bool _gameOver = false;
public bool GameOver {
        get { return _gameOver; }
        set { _gameOver = value; }
    }

You can't use the same variable name in a single class.

Alternatively, assuming you're using a recent version of .Net, you could remove your private variable and just have:

public bool GameOver { get; set; }

Good luck.


Name your private variable differently than your public one.

bool _gameOver = false;

public bool gameOver {
    get { return _gameOver; }
    set { _gameOver = value; }
}

Tags:

C#