Search in sources :

Example 16 with Location

use of location.Location in project ChessProject by DylanSantora.

the class ChessBoard method queenMove.

public ArrayList<Location> queenMove(Location loc) {
    ArrayList<Location> moveLocs = new ArrayList<Location>();
    int r = loc.getRow();
    int c = loc.getCol();
    ArrayList<Location> moveLocs90 = rookMove90(loc);
    ArrayList<Location> moveLocs180 = rookMove180(loc);
    ArrayList<Location> moveLocs270 = rookMove270(loc);
    ArrayList<Location> moveLocs360 = rookMove360(loc);
    for (Location loc90 : moveLocs90) {
        moveLocs.add(loc90);
    }
    for (Location loc180 : moveLocs180) {
        moveLocs.add(loc180);
    }
    for (Location loc270 : moveLocs270) {
        moveLocs.add(loc270);
    }
    for (Location loc360 : moveLocs360) {
        moveLocs.add(loc360);
    }
    ArrayList<Location> moveLocs45 = bishopMove45(loc);
    ArrayList<Location> moveLocs135 = bishopMove135(loc);
    ArrayList<Location> moveLocs225 = bishopMove225(loc);
    ArrayList<Location> moveLocs315 = bishopMove315(loc);
    for (Location loc45 : moveLocs45) {
        moveLocs.add(loc45);
    }
    for (Location loc135 : moveLocs135) {
        moveLocs.add(loc135);
    }
    for (Location loc225 : moveLocs225) {
        moveLocs.add(loc225);
    }
    for (Location loc315 : moveLocs315) {
        moveLocs.add(loc315);
    }
    return moveLocs;
}
Also used : ArrayList(java.util.ArrayList) Location(location.Location)

Example 17 with Location

use of location.Location in project ChessProject by DylanSantora.

the class ChessBoard method rookMove90.

public ArrayList<Location> rookMove90(Location loc) {
    ArrayList<Location> moveLocs90 = new ArrayList<Location>();
    int r = loc.getRow();
    int c = loc.getCol();
    int tempC = c + 1;
    int rookColor = myBoard[r][c].getChessPiece().getMyColor();
    Boolean blocked90 = false;
    while (blocked90 == false) {
        if ((tempC < 8) && (tempC > -1)) {
            if ((myBoard[r][tempC].getChessPiece().getMyColor() == rookColor) && (!blocked90)) {
                blocked90 = true;
                break;
            } else if ((myBoard[r][tempC].getChessPiece().getMyColor() == (0)) && (!blocked90)) {
                moveLocs90.add(new Location(r, tempC));
            } else if ((myBoard[r][tempC].getChessPiece().getMyColor() - rookColor) == -2 || (myBoard[r][tempC].getChessPiece().getMyColor() - rookColor) == 2 && (!blocked90)) {
                System.out.println("-2 || +2");
                blocked90 = true;
                moveLocs90.add(new Location(r, tempC));
            }
        }
        if (!blocked90) {
            tempC++;
        }
        if (blocked90) {
            break;
        }
        if (!((tempC < 8) && (tempC > -1))) {
            blocked90 = true;
        }
    }
    return moveLocs90;
}
Also used : ArrayList(java.util.ArrayList) Location(location.Location)

Example 18 with Location

use of location.Location in project ChessProject by DylanSantora.

the class ChessBoard method pawnMove.

public ArrayList<Location> pawnMove(Location loc) {
    ArrayList<Location> moveLocs = new ArrayList<Location>();
    int r = loc.getRow();
    int c = loc.getCol();
    System.out.println("in pawnMove()");
    if (myBoard[r][c].getChessPiece().getMyColor() == -1) {
        if (myBoard[r + 1][c].getChessPiece().getMyColor() == 0) {
            moveLocs.add(new Location(r + 1, c));
        }
        if (r == 1 && myBoard[r + 1][c].getChessPiece().getMyColor() == 0) {
            if (myBoard[r + 2][c].getChessPiece().getMyColor() == 0) {
                moveLocs.add(new Location(r + 2, c));
            }
        }
        if (r < 8 && c > 0) {
            if (myBoard[r + 1][c - 1].getChessPiece().getMyColor() == 1) {
                moveLocs.add(new Location(r + 1, c - 1));
            }
        }
        if (r < 8 && c < 7) {
            if (myBoard[r + 1][c + 1].getChessPiece().getMyColor() == 1) {
                moveLocs.add(new Location(r + 1, c + 1));
            }
        }
    }
    if (myBoard[r][c].getChessPiece().getMyColor() == (1)) {
        if (myBoard[r - 1][c].getChessPiece().getMyColor() == (0)) {
            moveLocs.add(new Location(r - 1, c));
        }
        if (r == 6 && myBoard[r - 1][c].getChessPiece().getMyColor() == (0)) {
            if (myBoard[r - 2][c].getChessPiece().getMyColor() == 0) {
                moveLocs.add(new Location(r - 2, c));
            }
        }
        if (r > 0 && c > 0) {
            if (myBoard[r - 1][c - 1].getChessPiece().getMyColor() == (-1)) {
                moveLocs.add(new Location(r - 1, c - 1));
            }
        }
        if (r > 0 && c < 7) {
            if (myBoard[r - 1][c + 1].getChessPiece().getMyColor() == (-1)) {
                moveLocs.add(new Location(r - 1, c + 1));
            }
        }
    }
    System.out.println("out of pawnMove()");
    return moveLocs;
}
Also used : ArrayList(java.util.ArrayList) Location(location.Location)

Example 19 with Location

use of location.Location in project CodenameOne by codenameone.

the class StubLocationManager method bindListener.

@Override
protected void bindListener() {
    checkLocationRegistration();
    setStatus(AVAILABLE);
    final LocationListener l = getLocationListener();
    task = new TimerTask() {

        @Override
        public void run() {
            Display.getInstance().callSerially(new Runnable() {

                public void run() {
                    Location loc;
                    try {
                        loc = getCurrentLocation();
                        if (JavaSEPort.locSimulation == null) {
                            loc.setLongitude(loc.getLongitude() + 0.001);
                            loc.setLatitude(loc.getLatitude() + +0.001);
                        } else {
                            int s = JavaSEPort.locSimulation.getState();
                            if (s != StubLocationManager.super.getStatus()) {
                                l.providerStateChanged(s);
                                setStatus(s);
                            }
                        }
                        l.locationUpdated(loc);
                    } catch (IOException ex) {
                        Logger.getLogger(StubLocationManager.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            });
        }
    };
    timer = new Timer();
    timer.schedule(task, 3000, 3000);
}
Also used : TimerTask(java.util.TimerTask) Timer(java.util.Timer) LocationListener(com.codename1.location.LocationListener) IOException(java.io.IOException) Location(com.codename1.location.Location)

Example 20 with Location

use of location.Location in project CodenameOne by codenameone.

the class MIDPLocationManager method convert.

private Location convert(javax.microedition.location.Location loc) {
    QualifiedCoordinates coor = loc.getQualifiedCoordinates();
    Location retVal = new Location();
    retVal.setAccuracy(coor.getHorizontalAccuracy());
    retVal.setAltitude(coor.getAltitude());
    if (currentCoordinates != null) {
        retVal.setDirection(coor.azimuthTo(currentCoordinates));
    }
    retVal.setLatitude(coor.getLatitude());
    retVal.setLongitude(coor.getLongitude());
    retVal.setTimeStamp(loc.getTimestamp());
    retVal.setVelocity(loc.getSpeed());
    currentCoordinates = coor;
    return retVal;
}
Also used : QualifiedCoordinates(javax.microedition.location.QualifiedCoordinates) Location(com.codename1.location.Location)

Aggregations

Location (location.Location)17 ArrayList (java.util.ArrayList)16 Location (com.codename1.location.Location)5 IOException (java.io.IOException)3 Timer (java.util.Timer)2 TimerTask (java.util.TimerTask)2 QualifiedCoordinates (javax.microedition.location.QualifiedCoordinates)2 Geofence (com.codename1.location.Geofence)1 GeofenceListener (com.codename1.location.GeofenceListener)1 LocationListener (com.codename1.location.LocationListener)1 BrowserComponent (com.codename1.ui.BrowserComponent)1 JSRef (com.codename1.ui.BrowserComponent.JSRef)1 ActionEvent (com.codename1.ui.events.ActionEvent)1 ActionListener (com.codename1.ui.events.ActionListener)1 Point (com.codename1.ui.geom.Point)1 SuccessCallback (com.codename1.util.SuccessCallback)1 Date (java.util.Date)1