vendredi 20 avril 2018

c# How do you check for something that is not there

I have been trying to create an Othello game, but I can't seem to be able to check for a case that is not there (checking for a black token, and if it isn't there, dont do anything)

private void CaseClick(object sender, MouseEventArgs e)
    {
        Case allCases = (Case)sender;
        int a = 1;

        if (allCases.ColorToken == Case.Token.Nothing)
        {
            Case caseToModify;

            if (_turnIsBlack)
            {
                //Verify tokens from top to bottom
                if (Cases[allCases.Position.X, allCases.Position.Y + a].ColorToken == Case.Token.White)
                {
                    while (Cases[allCases.Position.X, allCases.Position.Y + a].ColorToken == Case.Token.White)
                    {
                        caseToModify = Cases[allCases.Position.X, allCases.Position.Y + a];
                        allCases.ColorToken = Case.Token.Black;
                        caseToModify.ColorToken = Case.Token.Black;
                        a++;
                        caseToModify.Refresh();
                        allCases.Refresh();
                        _turnIsBlack = false;
                    }
                }
            }
        }
    } 

I was just wondering if there was a way to check for the black token that isn't there. Doesn't need to be for this specific code, just an example of checking for something, and if it is not there, do nothing.

Aucun commentaire:

Enregistrer un commentaire