[jboss-cvs] jboss-seam/examples/remoting/poker/src/org/jboss/seam/example/poker ...

Shane Bryzak Shane_Bryzak at symantec.com
Wed Oct 11 00:43:22 EDT 2006


  User: sbryzak2
  Date: 06/10/11 00:43:22

  Added:       examples/remoting/poker/src/org/jboss/seam/example/poker     
                        Card.java Deck.java Game.java PlayerAction.java
                        PlayerLocal.java
  Log:
  New remoting example, under construction.
  
  Revision  Changes    Path
  1.1      date: 2006/10/11 04:43:22;  author: sbryzak2;  state: Exp;jboss-seam/examples/remoting/poker/src/org/jboss/seam/example/poker/Card.java
  
  Index: Card.java
  ===================================================================
  package org.jboss.seam.example.poker;
  
  import org.jboss.seam.annotations.Name;
  
  /**
   * A single playing card.
   *
   * @author Shane Bryzak
   */
  @Name("card")
  public class Card
  {
    public enum Value {
      ace("A"),
      two("2"),
      three("3"),
      four("4"),
      five("5"),
      six("6"),
      seven("7"),
      eight("8"),
      nine("9"),
      ten("10"),
      jack("J"),
      queen("Q"),
      king("K"),
      joker("J");
  
      private String symbol;
  
      Value(String symbol)
      {
        this.symbol = symbol;
      }
  
      public String getSymbol()
      {
        return symbol;
      }
    }
  
    public enum Suit { heart, diamond, club, spade };
  
    private Value value;
    private Suit suit;
  
    public Card(Value value, Suit suit)
    {
      this.value = value;
      this.suit = suit;
    }
  
    public Value getValue()
    {
      return value;
    }
  
    public Suit getSuit()
    {
      return suit;
    }
  
    public String toString()
    {
      return value == Value.joker ? "Joker" : String.format("%s %s", value.getSymbol(), suit.toString());
    }
  }
  
  
  
  1.1      date: 2006/10/11 04:43:22;  author: sbryzak2;  state: Exp;jboss-seam/examples/remoting/poker/src/org/jboss/seam/example/poker/Deck.java
  
  Index: Deck.java
  ===================================================================
  package org.jboss.seam.example.poker;
  
  import org.jboss.seam.annotations.Name;
  import java.util.Queue;
  import java.util.LinkedList;
  import java.util.Set;
  import java.util.Random;
  import java.util.List;
  import java.util.ArrayList;
  import java.util.HashSet;
  
  /**
   * A deck of cards
   *
   * @author Shane Bryzak
   */
  @Name("deck")
  public class Deck
  {
    /**
     * The cards remaining in the deck
     */
    private Queue<Card> cards = new LinkedList<Card>();
  
    /**
     * The complete contents of the deck
     */
    private Set<Card> contents;
  
    /**
     * Constructor, initialises the deck.
     *
     * @param contents Set The set of cards that the deck will contain
     */
    public Deck(Set<Card> contents)
    {
      this.contents = contents;
      reset();
    }
  
    /**
     * Resets the deck to its original contents
     */
    public void reset()
    {
      cards.clear();
      cards.addAll(contents);
    }
  
    /**
     * Shuffles the cards in the deck
     */
    public void shuffle()
    {
      Random rnd = new Random(System.currentTimeMillis());
  
      List<Card> tmp = new ArrayList<Card>();
  
      while (!cards.isEmpty())
        tmp.add(cards.poll());
  
      while (!tmp.isEmpty())
        cards.offer(tmp.remove(rnd.nextInt(tmp.size())));
    }
  
    /**
     * Returns the number of cards remaining in the deck.
     *
     * @return int
     */
    public int cardsRemaining()
    {
      return cards.size();
    }
  
    /**
     * Remove the next card from the deck
     *
     * @return Card
     */
    public Card remove()
    {
      return cards.poll();
    }
  }
  
  
  
  1.1      date: 2006/10/11 04:43:22;  author: sbryzak2;  state: Exp;jboss-seam/examples/remoting/poker/src/org/jboss/seam/example/poker/Game.java
  
  Index: Game.java
  ===================================================================
  package org.jboss.seam.example.poker;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import static org.jboss.seam.ScopeType.APPLICATION;
  import org.jboss.seam.annotations.Name;
  import org.jboss.seam.annotations.Scope;
  import org.jboss.seam.annotations.Startup;
  import org.jboss.seam.annotations.Create;
  
  /**
   * The game.  This is where everything happens.
   *
   * @author Shane Bryzak
   */
  @Name("game")
  @Scope(APPLICATION)
  @Startup
  public class Game
  {
    private List<String> players = new ArrayList<String>();
  
    @Create
    public void createGame()
    {
      players.clear();
    }
  
    public synchronized boolean login(String playerName)
    {
      if (!players.contains(playerName))
      {
        players.add(playerName);
        return true;
      }
      else
        return false;
    }
  
  
  }
  
  
  
  1.1      date: 2006/10/11 04:43:22;  author: sbryzak2;  state: Exp;jboss-seam/examples/remoting/poker/src/org/jboss/seam/example/poker/PlayerAction.java
  
  Index: PlayerAction.java
  ===================================================================
  package org.jboss.seam.example.poker;
  
  import javax.ejb.Remove;
  import javax.ejb.Stateful;
  
  import org.jboss.seam.annotations.Destroy;
  import org.jboss.seam.annotations.In;
  import org.jboss.seam.annotations.Name;
  import static org.jboss.seam.ScopeType.APPLICATION;
  import javax.ejb.Stateless;
  import org.jboss.seam.contexts.Contexts;
  import org.jboss.seam.contexts.Context;
  
  /**
   * The player action bean
   *
   * @author Shane Bryzak
   */
  @Name("playerAction")
  @Stateless
  public class PlayerAction implements PlayerLocal
  {
    @In(scope = APPLICATION) Game game;
  
    public boolean login(String playerName)
    {
      Context ctx = Contexts.getApplicationContext();
      return game.login(playerName);
    }
  
  //  @Remove @Destroy
  //  public void remove() {}
  }
  
  
  
  1.1      date: 2006/10/11 04:43:22;  author: sbryzak2;  state: Exp;jboss-seam/examples/remoting/poker/src/org/jboss/seam/example/poker/PlayerLocal.java
  
  Index: PlayerLocal.java
  ===================================================================
  package org.jboss.seam.example.poker;
  
  import org.jboss.seam.annotations.WebRemote;
  
  /**
   * Local interface for player actions
   *
   * @author Shane Bryzak
   */
  public interface PlayerLocal
  {
    @WebRemote
    boolean login(String playerName);
  }
  
  
  



More information about the jboss-cvs-commits mailing list