Package Managers

Examples of Managers.GameManager


*/
public class StocksFormatter {

    public static ArrayNode getStockList(Game currentGame) {
        ArrayNode stockListJson = Json.newObject().arrayNode();
        List<Stock> stockList = Stock.find.filter().eq("isEnabled", 1).filter((new GameManager()).getStockList());
        GameManager gm = new GameManager();
        for (Stock stk : stockList) {
            ObjectNode stock = Json.newObject();
            stock.put("id", stk.getId());
            stock.put("ticker", stk.getTicker());
            stock.put("company", stk.getCompanyName());
            if(currentGame != null && currentGame.getVirtualCurrentDate() != null){
                stock.put("price", gm.getStockPriceAmount(stk.getTicker(), currentGame.getVirtualCurrentDate()));
            }else{
                stock.put("price", 0);
            }
           
            stockListJson.add(stock);
View Full Code Here


        Timestamp currentGameDate = TimeKeeper.round_to_day(game.getVirtualCurrentDate());
        StockPrice currentStockPrice;
        try {
            //get current stock price
            currentStockPrice = (new GameManager()).getStockPrice(ticker, currentGameDate);
            if (currentStockPrice == null) {
                return false;
            }
        } catch (IOException ex) {
            play.Logger.warn("could not retrieve stock Price\n", ex);
View Full Code Here

            return false;
        }

        StockPrice currentStockPrice;
        try {
            currentStockPrice = (new GameManager()).getStockPrice(ticker, game.getVirtualCurrentDate());
            if (currentStockPrice == null) {
                return false;
            }
        } catch (IOException ex) {
            play.Logger.warn("Could not sell stock... ", ex);
View Full Code Here

    public double getNetWorth() {
        double totalPortfolio = 0;
        // calculates portfolio value
        Timestamp referenceDate = game.isEnded() ? TimeKeeper.getLastTradingDay(game)
                : game.getVirtualCurrentDate();
        GameManager gm = new GameManager();
        for (PortfolioStock portfolioStock : portfolios) {
            int quantity = portfolioStock.getQuantity();

            StockPrice stockPrice;
            double stockPriceAmount = 0;
            try {
                stockPrice = gm.getStockPrice(portfolioStock.getStock().getTicker(), referenceDate);
                stockPriceAmount = game.isEnded()
                        ? stockPrice.getClose()
                        : stockPrice.getStockPrice();
            } catch (IOException ex) {
                play.Logger.warn("Could not get stock price: ", ex);
View Full Code Here

        return gmState;
    }

    protected ArrayNode getPortfolio() {
        ArrayNode stocks = Json.newObject().arrayNode();
        GameManager gm = new GameManager();
        for (PortfolioStock portfoilioStock : gameState.getCurrentPlayer().getPortfolios()) {
            ObjectNode stockNode = Json.newObject();
            stockNode.put("id", portfoilioStock.getId());
            String ticker = portfoilioStock.getStock().getTicker();
            stockNode.put("ticker", ticker);
            stockNode.put("company", portfoilioStock.getStock().getCompanyName());
            stockNode.put("quantity", portfoilioStock.getQuantity());
            StockPrice currentStockPrice = null;
            try {
                currentStockPrice = gm.getStockPrice(ticker, gameState.getGame().getVirtualCurrentDate());
            } catch (IOException ex) {
                play.Logger.warn("error occured while retrieving price", ex);
            }
            stockNode.put("currentPrice", currentStockPrice != null ? currentStockPrice.getStockPrice() : 0);
            //stockNode.put("purchasePrice", purchasePrice);
View Full Code Here

        return playerNode;
    }

    public static ObjectNode getGameStateJson(Integer gameId) {
        try {
            GameState gs = (new GameManager()).getGameState(gameId);
            if (gs == null) {
                return null;
            }
            GameStateJSONFormatter gsj = new GameStateJSONFormatter(gs);
            return gsj.getJSON();
View Full Code Here

    public static Result index() {
        return ok(application_index.render(Form.form(LoginForm.class), Form.form(RegisterForm.class), null));
    }

    public static Result dashboard() {
        GameManager gm = new GameManager();
        return ok(application_dashboard.render(gm.getListOfAvailableGames(),Form.form(GameForm.class)));
    }
View Full Code Here

        }

        if (Ebean.find(Stock.class).findRowCount() == 0) {

          GameManager gameManager = new GameManager();
          if (Stock.findAll().isEmpty()) // Insert player first
          {
            List<Object> stocks = all.get("stocks");
            for (Object stockObj : stocks) {
              Stock stock = (Stock) stockObj;
              gameManager.addStock(stock.getTicker(),
                  stock.getCompanyName(),ApplicationConstants.TRUE);
            }

          }
        }
View Full Code Here

import models.data.User;

public class ManagementController extends Controller {

    public static Result index() {
        GameManager gm = new GameManager();
        User user = UserManager.getCurrentLoggedInUser();
        if (user != null && user.isAdmin()) {
            return ok(management.render(gm.getStockList(), "", "stockTab"));
        } else {
            return ok("You don't have acess to Admin DashBoard!");
        }

    }
View Full Code Here

    public static Result addStock() {
        User user = UserManager.getCurrentLoggedInUser();
        if (user != null && user.isAdmin()) {

            boolean success = true;
            GameManager gm = new GameManager();

            Form<StockForm> stockForm = Form.form(StockForm.class).bindFromRequest();
            if (stockForm.hasErrors()) {
                success = false;
            } else {
                try {
                    success = gm.addStock(stockForm.get().ticker, stockForm.get().companyName, stockForm.get().isEnabled);
                } catch (Exception e) {
                    success = false; //can not add into database
                }
            }
            if (success) {
                return ok(management.render(gm.getStockList(), "stock successfully added", "stockTab"));//return message indicating success
            } else {
                return ok(management.render(gm.getStockList(), "Failed adding stock", "stockTab")); //not success in general
            }

        } else {
            return ok("You don't have acess to Admin DashBoard!");
        }
View Full Code Here

TOP

Related Classes of Managers.GameManager

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.