Package Project1.Game

Examples of Project1.Game.Game


     * @param String creatorEmail - The name of the user who is creating the game.
     * @return Game game - The newly created game.
     */
    @Override
    public Game createNewGame(final String creatorEmail) {
        final Game game = new Game(creatorEmail, games.size() + 1);
        //game.setTokSessionId();
        games.add(game);
        return game;
    }
View Full Code Here


     * @param String creatorEmail - The email of the user who created the game.
     * @return Game creatorsGame - The game created by the user.
     */
    @Override
    public Game getGameMadeByCreator(final String creatorEmail) {
        Game creatorsGame = null;
        for (int i = 0; i < games.size(); i++) {
            if (creatorEmail.equals(games.get(i).getCreatorEmail())) {
                creatorsGame = games.get(i);
            }
        }
View Full Code Here

     * @param String email - The email of the user to find.
     * @return Game gameWithUser - The game with a given user in it.
     */
    @Override
    public Game getGameWithUserInIt(final String email) {
        Game gameWithUser = null;
        for (Game game : games) {
            final List<Player> players = game.getPlayers();
            for (Player player : players) {
                if (player.getPlayerEmail().equals(email)) {
                    gameWithUser = game;
View Full Code Here

    /* (non-Javadoc)
     * @see org.directwebremoting.ScriptSessionFilter#match(org.directwebremoting.ScriptSession)
     */
    @Override
    public boolean match(final ScriptSession session) {
        final Game gameToMatch = (Game) session.getAttribute("game");
        final String emailToMatch = (String) session.getAttribute("email");
        return (gameToMatch != null && gameToMatch.equals(game) && !(emailToMatch).equals(email));
    }
View Full Code Here

     */
    @Override
    public void setScriptSessionGame() {
        final ScriptSession scriptSession = WebContextFactory.get().getScriptSession();
        final HttpSession session = WebContextFactory.get().getSession();
        final Game game = (Game) session.getAttribute("game");
        final String email = (String) session.getAttribute("email");
        scriptSession.setAttribute("game", game);
        scriptSession.setAttribute("email", email);
    }
View Full Code Here

   
    @Before
    public void setUp() {
       
        player=new Player(4,4,4,false);
        game=new Game("username",001);
        action=new Action(player,"BAH","value",game,session);
    }
View Full Code Here

     */
    @Test
    public void testSetScriptSessionGame() {
        System.out.println("setScriptSessionGame");
  
        final Game game=new Game("user@gmail.com",1);
        context.checking(new Expectations(){
            {
                one(session).getAttribute("game");
                will(returnValue(game));
            }
        });
       
        Game resultgame=(Game) session.getAttribute("game");
        assertEquals(game,resultgame);
       
  
        context.checking(new Expectations(){
            {
View Full Code Here

     * @param action - The Action object to be performed.
     */
    public static void performAction(final Action action) {
        final String actionType = action.getActionType();
        final String value = action.getValue();
        Game game = action.getGame();
        final HttpSession session = action.getSession();
        if ("startgame".equals(actionType)) {
            game.setPlaying(true);
            game.startGame();
        }
        if ("setmap".equals(actionType)) {
            game = SessionListener.getSessionTracker().getGameTracker().createNewGame((String) session.getAttribute("email"));
            game.setMap(new Map(value));
            session.setAttribute("game", game);
        }
        if ("setmapname".equals(actionType)) {
            game.getMap().setMapName(value);
        }
        if ("setgamecreator".equals(actionType)) {
            game.setCreatorName(value);
            game.tellLobby();
        }
        if ("joingame".equals(actionType)) {
            game = SessionListener.getSessionTracker().getGameTracker().getGameMadeByCreator(value);
            game.addUserToGame((String) session.getAttribute("email"));
            session.setAttribute("game", game);
        }
        if("takeTurn".equals(actionType)) {
            try {
                game.playerTakesTurn(value);
            } catch (ParserConfigurationException ex) {
                System.err.print(ex);
            } catch (SAXException ex) {
                System.err.print(ex);
            } catch (IOException ex) {
                System.err.print(ex);
            }
        }
        if ("startDoubleMove".equals(actionType)) {
            game.startDoubleTurn();
        }
        if ("cancelDoubleMove".equals(actionType)) {
            game.cancelDoubleTurn();
        }
        if("cannotMove".equals(actionType)) {
            game.getPlayers().get(Integer.parseInt(value)).setCanMove(false);
        }
        if("checkGameEnd".equals(actionType)) {
            game.checkPlayersLose();
        }
        if("leaveGame".equals(actionType)) {
            if (game != null) {
                for (Player player : game.getPlayers()) {
                    if (player.getPlayerEmail().equals(value)) {
                        player.leaveGame();
                        if (game.getWhosTurn() == game.getPlayers().indexOf(player)) {
                            game.determineWhosTurnItIsNext();
                        }
                    }
                }
                session.setAttribute("game", null);
                if (!game.isFinished()) {
                    game.checkEnd();
                }
            }
        }
    }
View Full Code Here

TOP

Related Classes of Project1.Game.Game

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.