ActionScript 3.0 Design Patterns

(Chris Devlin) #1

470 | Chapter 13: Symmetric Proxy Pattern


that describe the game. This process gets more challenging when the players are


making simultaneous (parallel) moves, and both players won’t know the outcome of


a turn until both have completed their moves.


One such game isRock, Paper, Scissors(RPS). In this game, two players simulta-


neously throw hand signals for a rock (fist), paper (a flat hand) or scissors (a horizon-


tal V-sign with the inde xand middle fingers). Rock defeats scissors, scissors defeat


paper, and paper defeats rock. (Seehttp://www.worldrps.comfor details). With such


clear, simple, and universal rules, the game is an ideal way to discover design pat-


terns that accommodate the role of parallel Internet interaction.


As a point of reference, the concept of the Symmetric Proxy design pattern grew out


of a paper, a Pattern for Distributing Turn-Based Games, by James Heliotis and Axel


Schreiner, both of Rochester Institute of Technology, and a presentation based on


that paper at the 2006 OOPSLA conference in Portland, Oregon by Axel Schreiner.


Just about any background work in design patterns will sooner or later
lead you to OOPSLA. The acronym stands for Object-Oriented Pro-
gramming, Systems, Languages & Applications. It’s an annual confer-
ence that focuses on different OOP topics, mixing in both academic
and practical materials. In 1991, the first part of the Design Pattern
catalog was presented at an OOPSLA conference, and ever since,
design patterns have played a role at OOPSLA conferences. The Euro-
pean sister conference is ECOOP (European Conference on Object-
Oriented Programming).

What we developed for this book is based on both the paper and conference presen-


tation, but the example for this book took on a life of its own, and we in no way hold


Drs. Heliotis or Schreiner responsible for what has been developed here. In part, this


is because we’re using ActionScript 3.0 and Flash Media Server 2, and in part


because we deviated from the specifics. Nevertheless, we’ve strived to keep the origi-


nal concepts and reasoning intact. They deserve credit for what we did right, but we


take responsibility for anything gone wrong.


The Player


At the very base of the idea of a symmetric proxy is the concept of a player interface


containing methods for playing a game,anygame, not just RPS, that can be con-


ducted over the Internet. Our list is slightly different from that presented by Heliotis


and Schreiner, but the core concepts are borrowed from their work.



  • Make a move (makeMove). Each player needs a method for translating user
    input through a user interface (UI).

  • Indicate that a local player has made a move (localMove). Once a move has
    been made, a game requires that the state (local player has moved) be
    recorded. It also prevents the same user from making another move until the
    next turn.

Free download pdf