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').


        // 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'.


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