Subscribe to Journey of a Nublet        RSS Feed
-----

It's working, now let's tear it apart and rebuild it!

Icon 2 Comments
Fun fact. Up until now, I've been writing "Pongu" into a single class.
And it's working. But I'm getting tired of scrolling up and down looking for a single thing
or to put a single line of code in five different places...

So it's time to rebuild! I'm making a new project, this time I'll grit my teeth
and make separate classes (they scare me, they really do!) for everything I need.
I know this'll be another painful learning experience but in the long run it'll help me a lot!

Once I get it back to this state with more organized code, I'll work on getting
a character selection screen going, some better ball physics, and a better AI.

Then I'll work on implementing some difficulty levels and maybe a scoring system!

After that... well, that's all supposed to be a surprise. :3
It'll be fun though... ...or will it...!?

2 Comments On This Entry

Page 1 of 1

AdamSpeight2008 Icon

20 September 2013 - 12:51 AM
Separate class should be scary, they are your friends. They let you organise the complexity into smaller and simpler blocks.

For example the following C# code. Points and scoring is handled by the Points class.
The Player base class handles basic player details, allowing us to inherit it to be utilised be HumanPlayer and RobotPlayer

class Points
  public class Points
  {
    int _Value = 0;
    public Points() { }
    public int Value { get { return _Value; } }
    public void Increment() { _Value++; }
    public void Decrement() { _Value--; }
    public override String ToString() { return String.Format("{0}pts", this.Value)}
  }
  class Player
  {
    public string Name { get; private set; }
    public Points Points { get; private set; }
    protected Player(string Name) { this.Name = Name; }
    public override string ToString() { return String.Format("{0} : {1}", this.Name, this.Points); }
  }
  class HumanPlayer : Player
  {
    public HumanPlayer(String name) : base(name) { }
  }
  class RobotPlayer : Player
  {
    public RobotPlayer(String name) : base(name) { }
  }
}



See how using separate classes allowed us to encapsulate specific functionality and attributes, which can be reused.
2

mimimintan Icon

20 September 2013 - 08:04 PM

AdamSpeight2008, on 20 September 2013 - 12:51 AM, said:

Separate class should be scary, they are your friends. They let you organise the complexity into smaller and simpler blocks.

For example the following C# code. Points and scoring is handled by the Points class.
The Player base class handles basic player details, allowing us to inherit it to be utilised be HumanPlayer and RobotPlayer

class Points
  public class Points
  {
    int _Value = 0;
    public Points() { }
    public int Value { get { return _Value; } }
    public void Increment() { _Value++; }
    public void Decrement() { _Value--; }
    public override String ToString() { return String.Format("{0}pts", this.Value)}
  }
  class Player
  {
    public string Name { get; private set; }
    public Points Points { get; private set; }
    protected Player(string Name) { this.Name = Name; }
    public override string ToString() { return String.Format("{0} : {1}", this.Name, this.Points); }
  }
  class HumanPlayer : Player
  {
    public HumanPlayer(String name) : base(name) { }
  }
  class RobotPlayer : Player
  {
    public RobotPlayer(String name) : base(name) { }
  }
}



See how using separate classes allowed us to encapsulate specific functionality and attributes, which can be reused.


Yeah, it's mostly just a matter of getting accustomed to them. I used them a few times while taking Java in school, but only when absolutely necessary because I was scared of over-complicating things....and I'll admit, for the longest time, I understood the concept but it took forever for me to figure out how to put them in code. Finally somebody let me see their code and explained what did what... it was a huge "...that's it!?" moment. I think it'll take some quality time with them for me to get rid of that idea that they're complicated, though.

Thank you very much for your input and example. :) I'm working on getting better q w q it'll just take a little pushing.
0
Page 1 of 1

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

April 2014

S M T W T F S
  12345
6789101112
13141516171819
202122 23 242526
27282930   

Recent Entries

Search My Blog

0 user(s) viewing

0 Guests
0 member(s)
0 anonymous member(s)

I'm trying things out hnn?

Well, this is rather intriguing.

:whistling:

AAAAAAAAAAAAH

I DON'T KNOW HOW THESE BLOCK THINGS WORK


AAAAAAAAAAHHH

AAAAAAAAAAAAAAAAAAAHHH
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHHHH???