Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C#

Peter McClory
Peter McClory
2,365 Points

More detailed information for people struggling with Objects, Instances, Methods, Return values...

I had to watch the video a few times and write things down on paper to help me understand what is going on with all of this. It was a tricky concept to get my head around. In the end I fully understand it and thought it would be helpful to share my commented code here (from Game.cs).

        Map map = new Map(8, 5);
        // A new 'map' variable is defined as type 'Map'. It is then assigned an
        // instance of the 'Map' class with the values 8 and 5 of type 'int'.

        // the variable 'point' is being defined here as type 'Point' 
        Point point = new Point(7,4);

        // Write the boolean return value which results from
        // calling the 'OnMap' method via the 'map' variable which
        // has been assigned a 'Map' class instance (using 'new Map').

        Console.WriteLine($"{map.OnMap(point)}");

        // The co-ordinates which are being checked are held in the
        // 'point' variable which has been assigned a 'Point' instance 
        // with two values 7 and 4, held in public readonly variables
        // 'X' and 'Y' of type 'int'.

        // The local variable 'point' can be assigned a new value
        // which is a new 'Point' object instance with 10 and 4 assigned
        // to it's two method variables 'x', and 'y', both of type 'int'.

        point = new Point(10,4);

        // Now check if this new set of co-ordinates assigned to the
        // already defined 'point' variable (of type 'Point') is within the
        // boundaries of the 'Map' instance assigned to the variable 'map' of type 'Map'.

        Console.WriteLine($"{map.OnMap(point)}");

I hope this helps others, and if there is anything wrong here, please can any Pro's correct me? Thanks everyone.