Search in sources :

Example 6 with Location

use of location.Location in project ChessProject by DylanSantora.

the class ChessBoard method bishopMove135.

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

Example 7 with Location

use of location.Location in project ChessProject by DylanSantora.

the class ChessBoard method rookMove270.

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

Example 8 with Location

use of location.Location in project ChessProject by DylanSantora.

the class ChessBoard method bishopMove315.

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

Example 9 with Location

use of location.Location in project ChessProject by DylanSantora.

the class ChessBoard method bishopMove45.

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

Example 10 with Location

use of location.Location in project CodenameOne by codenameone.

the class StubLocationManager method addGeoFencing.

@Override
public void addGeoFencing(final Class GeofenceListenerClass, Geofence gf) {
    if (gf.getId() != null) {
        String id = gf.getId();
        int index = -1;
        for (Geofence f : geoFences) {
            if (id.equals(f.getId())) {
                index = geoFences.indexOf(f);
                break;
            }
        }
        if (index >= 0) {
            geoFences.remove(index);
        }
        if (gf.getRadius() < 0) {
            throw new IllegalArgumentException("Attempt to add geofence with negative radius");
        }
        if (gf.getRadius() < 100) {
            Log.p("Adding Geofence with a radius of " + gf.getRadius() + " metres.  On an actual device, the effective radius will vary.  Typical Android and iOS devices have a minimum geofence radius of approximately 100m");
        }
        long expires = gf.getExpiration();
        geoFences.add(gf);
        if (geofenceTimer == null) {
            geofenceTimer = new java.util.Timer();
            geofenceTask = new TimerTask() {

                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 {
                                    loc.setLongitude(JavaSEPort.locSimulation.getLongitude());
                                    loc.setLatitude(JavaSEPort.locSimulation.getLatitude());
                                }
                                // Do exits first
                                for (final Geofence f : geoFences) {
                                    if (!isInRegion(loc, f) && insideFences.contains(f.getId())) {
                                        insideFences.remove(f.getId());
                                        try {
                                            final GeofenceListener l = (GeofenceListener) GeofenceListenerClass.newInstance();
                                            new Thread() {

                                                public void run() {
                                                    // In a separate thread to simulate that
                                                    // this might not happen on EDT
                                                    l.onExit(f.getId());
                                                }
                                            }.start();
                                        } catch (Throwable t) {
                                            Log.e(t);
                                        }
                                    }
                                }
                                // Do entrances next
                                for (final Geofence f : geoFences) {
                                    if (isInRegion(loc, f) && !insideFences.contains(f.getId())) {
                                        insideFences.add(f.getId());
                                        try {
                                            final GeofenceListener l = (GeofenceListener) GeofenceListenerClass.newInstance();
                                            new Thread() {

                                                public void run() {
                                                    // In a separate thread to simulate that
                                                    // this might not happen on EDT
                                                    l.onEntered(f.getId());
                                                }
                                            }.start();
                                        } catch (Throwable t) {
                                            Log.e(t);
                                        }
                                    }
                                }
                            } catch (IOException ex) {
                                Logger.getLogger(StubLocationManager.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                    });
                }
            };
            geofenceTimer.schedule(geofenceTask, new Date(System.currentTimeMillis() + 10000L), 10000L);
        }
    } else {
        Log.p("Attempt to add Geofence with null ID", Log.WARNING);
    }
}
Also used : GeofenceListener(com.codename1.location.GeofenceListener) Timer(java.util.Timer) IOException(java.io.IOException) Date(java.util.Date) TimerTask(java.util.TimerTask) Geofence(com.codename1.location.Geofence) 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