/*=================================== playGame -- play a game of 2048 with an EXISTING T048 object created ====================================*/ public int playGame() { displayInstructions(); System.out.println(_board); while (!isGameOver()) playTurn(); if (_board.contains(2048)) return 3; else if (_board.contains(1024)) return 2; else if (_board.contains(512)) return 1; else return 0; }
@Override public void mouseClicked(MouseEvent e) { if (board.contains(e.getPoint())) { if (ledP == true) { ledP = false; componentList.add(0, new LED(0)); ((LED) componentList.get(0)) .setBounds( snapper.snapToX(e.getX()) + 1, snapper.snapToY(e.getY()) - 11, 100, 100); area.removeAll(); repaint(); redrawAll(); repaint(); } else if (wireP == true) { if (!wireStep2) { x1 = snapper.wSnapToX(e.getX(), e.getY()); System.out.println(snapper.wSnapToX(e.getX(), e.getY())); y1 = snapper.wSnapToY(e.getY()); wireStep2 = true; } else { wireStep2 = false; x2 = snapper.wSnapToX(e.getX(), e.getY()); y2 = snapper.wSnapToY(e.getY()); componentList.add(0, new Wire(x1, y1, x2, y2)); ((Wire) componentList.get(0)).setLocation(0, 0); area.removeAll(); repaint(); redrawAll(); repaint(); wireP = false; } } else if (chipP == true) { chipP = false; componentList.add(0, new ANDChip()); ((ANDChip) componentList.get(0)) .setLocation(snapper.cSnapToX(e.getX()), snapper.cSnapToY()); area.removeAll(); repaint(); redrawAll(); repaint(); } } }
public boolean isGameOver() { return _board.contains(2048) || noMoves(); }
public static Set<Coordinate> getPossibleCoordinates( Coordinate startingCoord, Board board, boolean includeThreateningOwnPiece) { Set<Coordinate> coordinates = new LinkedHashSet<Coordinate>(); Color startingColor = board.getPiece(startingCoord).getColor(); // add entries to the top left for (int i = 1; i < 8; i++) { Coordinate coord = startingCoord.transform(-i, +i); if (!board.contains(coord)) break; Piece piece = board.getPiece(coord); if (piece.isNone()) { coordinates.add(coord); } else if (includeThreateningOwnPiece && piece.getColor() == startingColor) { coordinates.add(coord); break; } else if (!includeThreateningOwnPiece && piece.getColor() == startingColor) { break; } else { coordinates.add(coord); break; } } // add entries to the top right for (int i = 1; i < 8; i++) { Coordinate coord = startingCoord.transform(+i, +i); if (!board.contains(coord)) break; Piece piece = board.getPiece(coord); if (piece.isNone()) { coordinates.add(coord); } else if (includeThreateningOwnPiece && piece.getColor() == startingColor) { coordinates.add(coord); break; } else if (!includeThreateningOwnPiece && piece.getColor() == startingColor) { break; } else { coordinates.add(coord); break; } } // add entries to the bottom left for (int i = 1; i < 8; i++) { Coordinate coord = startingCoord.transform(-i, -i); if (!board.contains(coord)) break; Piece piece = board.getPiece(coord); if (piece.isNone()) { coordinates.add(coord); } else if (includeThreateningOwnPiece && piece.getColor() == startingColor) { coordinates.add(coord); break; } else if (!includeThreateningOwnPiece && piece.getColor() == startingColor) { break; } else { coordinates.add(coord); break; } } // add entries to the bottom right for (int i = 1; i < 8; i++) { Coordinate coord = startingCoord.transform(+i, -i); if (!board.contains(coord)) break; Piece piece = board.getPiece(coord); if (piece.isNone()) { coordinates.add(coord); } else if (includeThreateningOwnPiece && piece.getColor() == startingColor) { coordinates.add(coord); break; } else if (!includeThreateningOwnPiece && piece.getColor() == startingColor) { break; } else { coordinates.add(coord); break; } } return coordinates; }