Package models.data

Examples of models.data.Game


    player.setId(1);
   
    Mockito.when(UserManager.getCurrentLoggedInUser()).thenReturn(
        player);
   
    Game game = gameManager.createFixedTimeChallengeGame(gameForm);
    Assert.assertTrue(game != null);
//    PowerMockito.verifyStatic();
//    UserManager.getCurrentLoggedInUser();
   
//    Mockito.when(game.getId()).thenReturn(1);
View Full Code Here


   */
  public void createGameFailure() {
    System.out.println("*****");
    Mockito.when(UserManager.getCurrentLoggedInUser()).thenReturn(null);
    System.out.println("here");
    Game game = gameManager.createFixedTimeChallengeGame(gameForm);
    System.out.println("here again");
    Assert.assertTrue(game == null);
  }
View Full Code Here

     *
     * @param gameId
     * @return
     */
    public boolean startGame(int gameId) {
        Game game = Game.findById(gameId);

        if (game == null) {
            return false;
        } else if (!game.getOwner().equals(UserManager.getCurrentLoggedInUser())) {
            play.Logger.warn("attemt to start game not owned.");
            return false;
        } else {
            DateTime dt = new DateTime();
            //game length is in days
            int randStartDaysAgo = (int) (Math.random() * ApplicationConstants.MAX_DAYS_BACK)
                    + game.getGameLength()
                    + ApplicationConstants.DAYS_PADDING_FROM_REALITY;

            dt = dt.minusDays(randStartDaysAgo);
            Timestamp temp = new Timestamp(dt.getMillis());// the start of game is one year ago
            while (!TimeKeeper.isTradingDay(temp)) {
                temp = new Timestamp(temp.getTime() + TimeKeeper.aDayInMS);
                play.Logger.info("Skipping... " + temp);
            }

            game.setVirtualStartDate(temp);
            game.setRealStartTime(new Timestamp(System.currentTimeMillis()));
            game.setGameStatus(GameStatusEnum.STARTED.getValue());
            game.save();
            return true;
        }

    }
View Full Code Here

        Form<GameForm> gameForm = Form.form(GameForm.class).bindFromRequest();
        if (gameForm.hasErrors()) { //form contains error
            return badRequest(application_dashboard.render(gm.getListOfAvailableGames(), gameForm));
        }
        //no error     
        Game newGame = gm.createFixedTimeChallengeGame(gameForm.get());
        if (newGame != null) {
            flash("game_created", "Game has been successfully created!");
            return redirect(routes.GameController.playGame(newGame.getId()));
        } else {
            gameForm.reject("Can not create game");
            return badRequest(application_dashboard.render(gm.getListOfAvailableGames(), gameForm));
        }
View Full Code Here

        }

    }

    public static Result playGame(int gameId) {
        Game game = Game.find.byId(gameId + "");
        User currentUser = UserManager.getCurrentLoggedInUser();
        if (game == null) {
            return notFound(game_playGame_notFound.render());
        }

        if (!game.canJoinGame(currentUser)) {
            return badRequest(game_playGame_cant_join.render(game, false));
        }

        GamePlayer gamePlayer = game.getPlayerInGame(currentUser);
        if (gamePlayer == null) {
            Logger.info("joining game");
            gamePlayer = game.joinGame(currentUser);
            if (gamePlayer != null) {
                Logger.info("Successfully joined game.");
            } else {
                return badRequest(game_playGame_cant_join.render(game, true));
            }
View Full Code Here

        GameCheck gc = new GameCheck(gameId, true);
        if (gc.hasErrors) {
            return gc.getResult();
        }

        Game game = gc.currentGame;
        if (!game.cancelGame()) {
            return badRequest("{error: \"not cancellable...\"}");
        }
        response().setContentType("application/json");
        return ok(GameStateJSONFormatter.getGameStateJson(gameId).toString());
    }
View Full Code Here

  /**
     * test to Retrieve a Gmae using id.
     */
  public void validefindById(){
    int id=0;
    Game temp=Game.findById(id);
    Assert.assertTrue(temp.getId()==id);
  }
View Full Code Here

  /**
     * test if a player can still join a game
     *
     */
    public void validecanJoinGame() {
      Assert.assertTrue((new Game()).canJoinGame(new Player()));
    }
View Full Code Here

    }
    /**
     * Test if a player join game normally
     */
    public void validjoinGame() {
      Assert.assertTrue((new Game()).joinGame(new Player())!=null);
    }
View Full Code Here

TOP

Related Classes of models.data.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.