/** * The treasureChests have their own method to place seeds in * * @param treasurePanel where the seeds are being placed in * @param seedAmount how many seeds are being placed into the pit */ private void addSeedsToTreasureChest(AbsolutePanel treasurePanel, int seedAmount) { treasurePanel.clear(); for (int i = 0; i < seedAmount; i++) { final Image seed = new Image(); seed.setResource(gameImages.redSeed()); DOM.setStyleAttribute(seed.getElement(), "backgroundSize", "20px 20px"); int[] point = getTargetPointTreasureChest(i); treasurePanel.add(seed, point[0], point[1]); } Label countLabel = new Label(seedAmount + ""); countLabel.setWidth(TREASURE_CHEST_WIDTH + "px"); countLabel.setHorizontalAlignment(Label.ALIGN_CENTER); treasurePanel.add(countLabel, 0, 22 * 3); }
/** To animate a seed from one pit to another */ @Override public void animateFromPitToPit( PlayerColor startSide, int startCol, PlayerColor endSide, int endCol, double delay, boolean finalAnimation) { int startRow = startSide.isNorth() ? 0 : 1; int actualStartCol = (startRow == 0) ? 5 - startCol : startCol; int endRow = endSide.isNorth() ? 0 : 1; int actualEndCol = (endRow == 0) ? 5 - endCol : endCol; AbsolutePanel startPanel = (AbsolutePanel) gameGrid.getWidget(startRow, actualStartCol); final Image seed; seed = (Image) startPanel.getWidget(startPanel.getWidgetCount() - 2); int startXStartPanel = startPanel.getWidgetLeft(seed); int startYStartPanel = startPanel.getWidgetTop(seed); int startX = 2 + actualStartCol * 2 + TREASURE_CHEST_WIDTH + PIT_WIDTH * actualStartCol + PADDING * (actualStartCol * 2 + 3) + startXStartPanel; int startY = 2 + PADDING + startRow * (PIT_HEIGHT + 2 * PADDING + 2) + startYStartPanel; AbsolutePanel endPanel; int[] endPointEndPanel; int endXEndPanel; int endYEndPanel; int endX; int endY; if (endCol < 6) { endPanel = (AbsolutePanel) gameGrid.getWidget(endRow, actualEndCol); endPointEndPanel = getTargetPoint(endPanel.getWidgetCount() - 1); endXEndPanel = endPointEndPanel[0]; endYEndPanel = endPointEndPanel[1]; endX = 2 + actualEndCol * 2 + TREASURE_CHEST_WIDTH + PIT_WIDTH * actualEndCol + PADDING * (actualEndCol * 2 + 3) + endXEndPanel; endY = 2 + PADDING + endRow * (PIT_HEIGHT + 2 * PADDING + 2) + endYEndPanel; } else { Grid hGrid = endRow == 0 ? treasureGridN : treasureGridS; endPanel = (AbsolutePanel) hGrid.getWidget(0, 0); endPointEndPanel = getTargetPointTreasureChest(endPanel.getWidgetCount() - 1); endXEndPanel = endPointEndPanel[0]; endYEndPanel = endPointEndPanel[1]; endX = 2 + PADDING + (TREASURE_CHEST_WIDTH + PIT_WIDTH * 6 + PADDING * 14 + 6 * 2) * endRow + endXEndPanel; endY = 2 + PADDING + endYEndPanel; } animation = new SeedMovingAnimation( seed, gameImages.redSeed(), startPanel, endPanel, startXStartPanel, startYStartPanel, endXEndPanel, endYEndPanel, startX, startY, endX, endY, finalAnimation, this, dotSound); animation.run(1000, Duration.currentTimeMillis() + delay); }
/** Initializes the Graphics */ public Graphics( FBCore fbCore, String userToken, String userEmail, String nickName, String playerRating, String playerRD) { initWidget(uiBinder.createAndBindUi(this)); treasureGridN = new Grid(1, 1); treasureGridN.setHeight(TREASURE_CHEST_HEIGHT + PADDING * 2 + "px"); treasureGridN.setCellPadding(PADDING); treasureGridS = new Grid(1, 1); treasureGridS.setHeight(TREASURE_CHEST_HEIGHT + PADDING * 2 + "px"); treasureGridS.setCellPadding(PADDING); AbsolutePanel treasurePanelN = new AbsolutePanel(); treasurePanelN.setSize(TREASURE_CHEST_WIDTH + "px", TREASURE_CHEST_HEIGHT + "px"); treasureGridN.setWidget(0, 0, treasurePanelN); AbsolutePanel treasurePanelS = new AbsolutePanel(); treasurePanelS.setSize(TREASURE_CHEST_WIDTH + "px", TREASURE_CHEST_HEIGHT + "px"); treasureGridS.setWidget(0, 0, treasurePanelS); gameGrid = new Grid(2, 6); gameGrid.resize(2, 6); for (int row = 0; row < 2; row++) { for (int col = 0; col < 6; col++) { AbsolutePanel pitPanel = new AbsolutePanel(); pitPanel.setSize(PIT_WIDTH + "px", PIT_HEIGHT + "px"); addSeeds(pitPanel, 0); if (row == 0) { handlerRegs[row][col] = pitPanel.addDomHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { // presenter.makeMove(colB); } }, ClickEvent.getType()); gameGrid.setWidget(row, 5 - col, pitPanel); // setPitEnabled(PlayerColor.NORTH, col, false); } else { handlerRegs[row][col] = pitPanel.addDomHandler( new ClickHandler() { @Override public void onClick(ClickEvent event) { // presenter.makeMove(colB); } }, ClickEvent.getType()); gameGrid.setWidget(row, col, pitPanel); // setPitEnabled(PlayerColor.SOUTH, col, true); } } } gameGrid.setCellPadding(20); gameAbsolutePanel.add(treasureGridN); gameAbsolutePanel.add(gameGrid, TREASURE_CHEST_WIDTH + 2 * PADDING, 0); gameAbsolutePanel.add( treasureGridS, TREASURE_CHEST_WIDTH + 14 * PADDING + PIT_WIDTH * 6 + 6 * 2, 0); gameAbsolutePanel.setSize( 12 + TREASURE_CHEST_WIDTH * 2 + 16 * PADDING + PIT_WIDTH * 6 + "px", 4 + 4 * PADDING + 2 * PIT_HEIGHT + "px"); gameAbsolutePanel.getElement().getStyle().setProperty("margin", "auto"); DOM.setStyleAttribute(gameAbsolutePanel.getElement(), "backgroundColor", "#b0c4de"); Image bgImg = new Image(); bgImg.setResource(gameImages.board()); DOM.setStyleAttribute( gameAbsolutePanel.getElement(), "backgroundImage", "url(" + bgImg.getUrl() + ")"); // Create a CellList. ContactCell contactCell = new ContactCell(); // Set a key provider that provides a unique key for each contact. If key is used to identify // contacts when fields (such as // the name and address) change. cellList = new CellList<ContactInfo>(contactCell, ContactInfo.KEY_PROVIDER); cellList.setPageSize(30); cellList.setKeyboardPagingPolicy(KeyboardPagingPolicy.INCREASE_RANGE); cellList.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.BOUND_TO_SELECTION); // Add a selection model so we can select cells. final SingleSelectionModel<ContactInfo> selectionModel = new SingleSelectionModel<ContactInfo>(ContactInfo.KEY_PROVIDER); cellList.setSelectionModel(selectionModel); selectionModel.addSelectionChangeHandler( new SelectionChangeEvent.Handler() { public void onSelectionChange(SelectionChangeEvent event) { showPlayGameElements(selectionModel.getSelectedObject()); } }); // Set the cellList as the display of the pagers. This example has two pagers. pagerPanel is a // scrollable pager that extends // the range when the user scrolls to the bottom. rangeLabelPager is a pager that displays the // current range, but does not // have any controls to change the range. contactsPanel.setDisplay(cellList); // rangeLabelPager.setDisplay(cellList); presenter = new Presenter(this, fbCore, userEmail.toLowerCase(), userToken); turnLabel.setHorizontalAlignment(Label.ALIGN_CENTER); warnLabel.setHorizontalAlignment(Label.ALIGN_CENTER); aiMovesLabel.setHorizontalAlignment(Label.ALIGN_CENTER); hideStartGameElements(); initializeAudios(); initializeHandlers(); // presenter.setState(Presenter.deserializeState(stateStr)); setUserNameLabelText("Name: " + nickName + " (" + playerRating + "|" + playerRD + ")"); initializeUILanguage(); }