problem with 'extends'. Need a new way of doing it.

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 488 Views - Last Post: 08 June 2014 - 10:44 AM Rate Topic: -----

#16 josephjnatale  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 07-June 14

Re: problem with 'extends'. Need a new way of doing it.

Posted 08 June 2014 - 10:12 AM

Here is the entire game if that would help, https://www.dropbox....k%20Fighter.zip , i've tried everything i could think of.
Was This Post Helpful? 0
  • +
  • -

#17 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1362
  • Posts: 3,002
  • Joined: 30-January 11

Re: problem with 'extends'. Need a new way of doing it.

Posted 08 June 2014 - 10:24 AM

Quote

i have piece extends Grid, because each piece needs to know how many other pieces are in the current row, so the method checkValidY() could run correctly.


No it doesn't. You need to take a step back and stop trying to fudge something together that is clearly not a good idea. You need to get your design straightened out (get rid of the bad inheritance) and then try to build on it. If it means scrapping what you have already then so be it - it happens.

I get where you're coming from with pieces trying to know about other pieces, but the truth of the matter is that its bad design. If you're going to do it then you may as well do it properly and learn something about proper design in the process - even if it takes you longer. You could make everything public and make it work happily, but that breaks every rule in the book and you won't get anywhere doing that.

You have your Piece class which should remain independent of every other Piece object that gets created. They should all work as individual units. I could create 10 or 1000 and they should all still work happily - not relying on any of the others. You then have your Grid class which contains a collection of Piece objects. This class is the only class that has access to these pieces and it and it alone contains the logic to modify the rows/columns depending on some rules. Ideally your main method shouldn't have any large logic in it at all. Its purpose is to just start up, initialise the bare minimum and get things going - its the role of other classes to actually house the game logic.

This post has been edited by Ryano121: 08 June 2014 - 10:28 AM

Was This Post Helpful? 1
  • +
  • -

#18 josephjnatale  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 07-June 14

Re: problem with 'extends'. Need a new way of doing it.

Posted 08 June 2014 - 10:44 AM

I get where you coming from, usually i try to be neater however, i need to get this working by Tuesday so ive just been trying to get it to a point where it works.

but do you see where it messes up? i cant figure out why it happens.

also 'a' and 'd' are to move the diamond left and right, 's' is to select
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2