You are viewing a single comment's thread from:

RE: [TUTORIAL] MINESWEEPER GAME - VISUAL STUDIO 2010 C#

in #games7 years ago

Had a quick scan through the code and like you have a nice consistent style :)

Small games like this teach you a lot.

Not sure why this stood out but thought I would point out. You had this piece of code

if (firstPlay)
{
    StartGame();
    firstPlay = false;

    widthBox.Enabled = false;
    heightBox.Enabled = false;
}
else
    if (!firstPlay)
    {
        ResetGame(width, height);
        StartGame();
    }

The second 'if' is not required the else means it will always be !firstPlay if the first 'if' fails

if (firstPlay)
{
    StartGame();
    firstPlay = false;

    widthBox.Enabled = false;
    heightBox.Enabled = false;
}
else
{
    ResetGame(width, height);
    StartGame();
}

:)

Sort:  

Thank you! I know it is not required, but anyway, it's checked very quickly because we talk about one byte. If it was a function .. that would have been the worst case .. because of a complexity probably larger than O (1) ;)

I guess for me it is more maintenance later on. I am in a code base at work that has been growing 10 years+ and not adding the extra if means there is less chance someone will come in for a bug fix and miss updating if the main if changes etc.

The less code the better in my books, I do all I can to minimise code size. :)

Coin Marketplace

STEEM 0.18
TRX 0.16
JST 0.030
BTC 66984.34
ETH 2607.28
USDT 1.00
SBD 2.66