@Override public void paintComponent(java.awt.Graphics context) { super.paintComponent(context); final Canvas canvas = new Canvas(context); GameView.getInstance().paintAll(canvas); }
private void handleReleaseView(Point point) { assert point != null; assert mouseLast != null; assert Game.hasInstance(); assert !Game.getInstance().isPaused(); final int dx = point.x - mouseLast.x; final int dy = point.y - mouseLast.y; final GameView view = GameView.getInstance(); if (view.hasActiveTile()) { assert !dragBoard; deactivateOnRelease = view.dropActiveTile(point, deactivateOnRelease); repaint(); } else if (dragBoard) { view.translate(dx, dy); dragBoardPixelCount += Math.abs(dx) + Math.abs(dy); if (dragBoardPixelCount < DRAG_THRESHOLD) { /* * Board drags shorter than six pixels (clicks, basically) * also serve to alter or un-target the target cell. */ view.toggleTargetCell(point); } // done dragging the board dragBoard = false; setCursor(Cursor.getDefaultCursor()); repaint(); } }
public void showHintBox() { final GameView view = GameView.getInstance(); final HintBox box = new HintBox(frame); final HintStrength oldValue = view.getHintStrength(); final GameStyle style = Game.getStyle(); final HintStrength newValue = box.run(oldValue, style); view.setHintStrength(newValue); }
public void showAttrBox() { final GameView view = GameView.getInstance(); final AttrBox box = new AttrBox(frame); final DisplayModes oldValue = view.getDisplayModes(); final DisplayModes newValue = box.run(oldValue); view.setDisplayModes(newValue); repaint(); }
private void handleDragView(Point point) { assert point != null; assert Game.hasInstance(); assert !Game.getInstance().isPaused(); assert GameView.hasInstance(); if (GameView.getInstance().hasActiveTile()) { assert !dragBoard; repaint(); } else if (dragBoard) { final int dx = point.x - mouseLast.x; final int dy = point.y - mouseLast.y; GameView.getInstance().translate(dx, dy); dragBoardPixelCount += Math.abs(dx) + Math.abs(dy); repaint(); } }
public void offerNewGame() { GameOpt gameOpt; if (Game.hasInstance()) { // Copy the game options of the active instance. gameOpt = new GameOpt(Game.getInstance().getOpt()); gameOpt.setRules(Rules.REPLAY); } else { // Start with the default game options. gameOpt = new GameOpt(); } final int maxHands = ParmBox3.HANDS_DEALT_MAX; final HandOpt handOpts[] = new HandOpt[maxHands]; for (int iHand = 0; iHand < maxHands; iHand++) { HandOpt handOpt; if (Game.hasInstance() && iHand < gameOpt.getHandsDealt()) { final ReadHand hand = Game.getInstance().getHand(iHand); handOpt = new HandOpt(hand.getOpt()); } else { handOpt = new HandOpt("User"); } handOpts[iHand] = handOpt; } final Wizard wizard = new Wizard(frame); final ParmBox1 parmBox1 = new ParmBox1(wizard); wizard.addCard(parmBox1); final WizardCard parmBox2 = new ParmBox2(wizard); wizard.addCard(parmBox2); final WizardCard parmBox3 = new ParmBox3(wizard); wizard.addCard(parmBox3); final WizardCard handBox = new HandBox(wizard); wizard.addCard(handBox); // pack and go final boolean completed = wizard.run(parmBox1, gameOpt, handOpts); if (!completed) { Console.print("New game aborted.\n"); return; } final GameView view = GameView.getInstance(); view.saveHand(); final GameStyle oldStyle = Game.getStyle(); new Game(gameOpt, handOpts); view.newGame(oldStyle); }
@Override public void mouseMoved(MouseEvent event) { assert event != null; assert GameView.hasInstance(); assert !dragBoard; assert !leftButtonDown; final Point point = event.getPoint(); if (GameView.getInstance().hasActiveTile()) { assert mouseLast != null; handleDragView(point); } mouseLast = point; }
private void leftButtonRelease(Point point) { assert point != null; assert GameView.hasInstance(); assert mouseLast != null; final Game game = Game.getInstance(); if (game != null) { if (game.isPaused()) { GameView.getInstance().startClock(); } else { handleReleaseView(point); } } leftButtonDown = false; mouseLast = point; }
@Override public void keyPressed(KeyEvent event) { assert event != null; final int keyCode = event.getKeyCode(); final GameView view = GameView.getInstance(); switch (keyCode) { case KeyEvent.VK_DOWN: view.moveTarget(Direction.SOUTH); break; case KeyEvent.VK_LEFT: view.moveTarget(Direction.WEST); break; case KeyEvent.VK_RIGHT: view.moveTarget(Direction.EAST); break; case KeyEvent.VK_UP: view.moveTarget(Direction.NORTH); break; } }
private void handleClickView(Point point) { assert point != null; assert Game.hasInstance(); assert !Game.getInstance().isPaused(); assert GameView.hasInstance(); assert !dragBoard; final GameView view = GameView.getInstance(); if (view.hasActiveTile()) { // Continue moving the active tile. assert mouseLast != null; assert deactivateOnRelease; repaint(); return; } final Tile tile = view.findPlayableTile(point); if (tile != null) { /* * The local user clicked on a playable tile. * Activate the tile and start dragging it around. */ view.activate(tile); deactivateOnRelease = false; repaint(); } else if (!view.isInHandRect(point) && !view.isInSwapRect(point)) { // Start dragging the board around. dragBoard = true; view.deactivate(); dragBoardPixelCount = 0; setCursor(DRAG_CURSOR); repaint(); } }
/** * Handles Swing timer pops. * * @param event */ @Override public void actionPerformed(java.awt.event.ActionEvent event) { GameView.getInstance().updateClock(); timer.restart(); }