Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Show Posts

| * |

  Show Posts
Pages: [1]
1  Announcements and General Discussion / General Discussion / Game Logic Placement (Command or Proxy) on: November 27, 2007, 03:10:37
Hi,

Before I begin I'd just like to say that PureMVC is simply amazing. For my first framework I have to say that it was very easy to pick up and dive into in a matter of days. Simple yet powerful. It has definitely made Flash development fun for me again and not some messy nightmare. And thanks to this framework, my first venture into the Flash development industry as an independent contractor has been a wonderful experience and it's only been my first month. Thank you very much Cliff for this beauty. I hope in to coming weeks, months, and years to give back to the community and contribute some of the stuff I'm able to build using this framework with all you developers out there.

Now onto my question.

I've just about completed my first Flash game using PureMVC and am now working on an online multiplayer Flash game using sockets. Throughout the development process something has been bugging me. I found myself placing most of my game logic inside a Proxy and I'm not so sure that that code is supposed to go in the Proxy. So for example, say a player's ship is hit by enemy fire. I'm going to want to decline the ships health amount by 1. The ships health is stored in a proxy called GameStateProxy which stores various info about the state of the player's ship (lives, health, ammo, etc). So the ships health starts at say, 10, and when it reaches 0 it's game over.

Now here's what takes place in the code. The Mediator sends the Notification(SHIP_HIT) to inform ShipHitCommand that the ship sprite has been hit. It is at that point, in ShipHitCommand's execute method, that I become unsure. Should I make a call to some method on GameStateProxy such as shipIsHit() which decrements the health value by one and checks if it has reached 0:
:
class GameStateProxy extends Proxy implements IProxy {
  private var state:Object;
  public function GameStateProxy() {
    state.health = 10;
  }
  //shipIsHit() called by ShitHitCommand
  public function shipIsHit() {
    health--;
    if (health <= 0) sendNotification(GFacade.GAME_OVER);
  }
  public function get health():Number {
    return state.health;
  }
  public function set health(val:Number):void {
    state.health = val;
  }
}


Or should ShipHitCommand handle that logic:

:
class ShipHitCommand extends SimpleCommand implements ICommand {
  override public function execute(note:INotification) {
     var gameStateProxy = facade.retrieve(GameStateProxy.NAME) as GameStateProxy;
     gameStateProxy.health--;
     if (gameStateProxy.health < 0) sendNotification(GAME_OVER);
  }
}

I reread the "Best Practices" doc and I get the feeling that no logic should go in the Proxy. The Proxy is there only to hold data and should not be reponsible for say, determining if it is game over, that should be the Command's responsibility.

-Andres
Pages: [1]