Author Topic: I Feel Like Sharing some Code - My Unfinished AOE Class  (Read 16244 times)

corremn

  • Rogueliker
  • ***
  • Posts: 700
  • Karma: +0/-0
  • SewerJack Extraordinaire
    • View Profile
    • Demise RogueLike Games
Re: I Feel Like Sharing some Code - My Unfinished AOE Class
« Reply #15 on: August 02, 2011, 12:07:51 AM »
Yeah on second thought, because isInAreaOfEffect will have to be different for each type of AOE you might have to think harder about where to put it. 

corremn's Roguelikes. To admit defeat is to blaspheme against the Emperor.  Warhammer 40000 the Roguelike

TSMI

  • Rogueliker
  • ***
  • Posts: 65
  • Karma: +0/-0
    • View Profile
    • Email
Re: I Feel Like Sharing some Code - My Unfinished AOE Class
« Reply #16 on: August 02, 2011, 01:19:47 AM »
When working with objects I like to keep in mind the idea of "messaging" - forget about method calls and all that, view objects as independent entities that send messages to each other.

So I think it's perfectly reasonable to send a message to AreaOfEffect asking if a point is located inside of it.

taffer

  • Newcomer
  • Posts: 16
  • Karma: +0/-0
    • View Profile
    • Email
Re: I Feel Like Sharing some Code - My Unfinished AOE Class
« Reply #17 on: August 02, 2011, 04:14:26 AM »
Quote
I strongly disagree.

Well; _distance_ calculation should be the responsibility of a point class, right. But with some static methods like "isInAreaOfEffect(AreaOfEffect area, Point reference)" you are going the wrong way.

Instances of ConeAreaOfEffect, Square..., Circle... should calculate that - discard the enumerations, polymorphism is the way to go. By using enumerations you end with ugly switch case statements.

If you add another area of effect, do you really want to change multiple code locations?

Never thought of that I agree here Polymorphism would be the best way.   With my current code it was only working with circles I started to forget about Square, Cone and Beam.  I'm going to take the advice about killing the enumerations.  And Poly-morphing the different kind of AreaOfEffects. 

This has been a good thread for me I am learning quite a bit from all of you.  This is my first attempt at a real game.  I've made Pong, Tic Tac Toe, Tetris.  I've never had a program that was so complex as a roguelike.  Truthfully I am walking into this blindly, I thought it was an easy game to program, but this has been a very fun experience so far.

Taffer

corremn

  • Rogueliker
  • ***
  • Posts: 700
  • Karma: +0/-0
  • SewerJack Extraordinaire
    • View Profile
    • Demise RogueLike Games
Re: I Feel Like Sharing some Code - My Unfinished AOE Class
« Reply #18 on: August 03, 2011, 03:16:10 AM »
Truthfully I am walking into this blindly, I thought it was an easy game to program, but this has been a very fun experience so far.

"I suppose we all thought that, one way or another."
corremn's Roguelikes. To admit defeat is to blaspheme against the Emperor.  Warhammer 40000 the Roguelike