Saturday, 23 April 2011

Class confusion

Yesterday I learned how to make a new class - right click on the namespace in the solution explorer, select 'new' and select 'class'. Ok, sounds simple. I'm just getting to grips with what they're for...

'Program' is the default class which is the first thing that's looked at when the game runs.

Classes have methods in them, which are 'mini-programs' - they either 'do something' or return a value of variable. I get the idea of methods - they can be called when you need them, and save you writing the same code mulitple times. Classes seem to be like methods... but what's the difference? And crucially, what's the point of having classes?

In the tutorials I'm following, class instances are defined like variables -

Hero myhero;
Battle battle;
(Hero and Battle are classes)

To create a new class instance, this code is used:
myhero = new Hero();
The only time I've seen 'new' before is with random numbers:
randomNumber = new Random();
To run a certain method within a class this code is used:
Hero.Initialise(myhero);
'Initialise' is a method withing the Hero class. Like methods can accept variable values, Initialise accepts instances of the Hero class. This is what the first line of Initialise looks like within the class Hero:
public static void Initialise(Hero hero)
In the tutorials, the current purpose of the Initialise method (the tutorial calls methods in classes other than Program 'arguments' for some reason) is to give values to loads of variables, like the hero's health, defense, etc.

This has all been a lot to try to take in and understand, hence my confusion and scepticism.

On a different topic, here's a cool 'bullet hell' game. Guaranteed to make you say fuck a lot.


DN8 at newgrounds.com
 And no, those aren't health orbs, they're BULLETS.

No comments:

Post a Comment