locked
C# help needed! RRS feed

  • Question

  • Hi,

    I've recently been trying to learn C# by programming a space invaders type game in XNA studio.
    Things are going fairly well so far, however I've come across an issue that's stumped me:

    Code:
    public Rectangle LeftMostInvader()
            {
               for (int column = 1; column <= NUM_INVADERS; column++)
                {
                    for (int row = NUM_INVADER_ROWS; row <= 1; *row--*)
                    {
                        if (!deadList[row, column])
                        {
                            return (invaders[row, column]);
                        }
                        else
                        {
                            return (invaders[0, 0]); //test case should never be returned
                        }
                    }
                }
            }
            public Rectangle RightMostInvader()
            {
                for (int column = NUM_INVADERS; column >= 1; column --)
                {
                    for (int row = NUM_INVADER_ROWS; row <= 1; *row --*)
                    {
                        if (!deadList[row, column])
                        {
                            return invaders[row, column];
                        }
                        else
                        {
                            return invaders[0, 0];
                        }
                    }
                }
            }
            public Rectangle BottomMostInvader()
            {
                for (int row = NUM_INVADER_ROWS; row <= 1; row --)
                {
                    for (int column = 1; NUM_INVADER_ROWS <= 1; )
                    {
                        *if (!deadList[row, column])*
                        {
                            return invaders[row, column];
                        }
                        else
                        {
                            return invaders[0, 0];
                        }
                    }
                }
            }


    Visual studio says that the code marked with * (for reference the statements are: row--, row-- , if) is unreachable. And that none of these functions return a value pon all code paths. Please advise!
    Friday, March 20, 2015 8:17 PM