Search in sources :

Example 6 with Location

use of com.codename1.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 com.codename1.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 com.codename1.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 com.codename1.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 com.codename1.location.Location in project CodenameOne by codenameone.

the class Capture method capturePhoto.

/**
 * <p>Invokes the camera and takes a photo synchronously while blocking the EDT, the sample below
 * demonstrates a simple usage and applying a mask to the result</p>
 * <script src="https://gist.github.com/codenameone/b18c37dfcc7de752e0e6.js"></script>
 * <img src="https://www.codenameone.com/img/developer-guide/graphics-image-masking.png" alt="Picture after the capture was complete and the resulted image was rounded. The background was set to red so the rounding effect will be more noticeable" />
 *
 * @param width the target width for the image if possible, some platforms don't support scaling. To maintain aspect ratio set to -1
 * @param height the target height for the image if possible, some platforms don't support scaling. To maintain aspect ratio set to -1
 * @return the photo file location or null if the user canceled
 */
public static String capturePhoto(int width, int height) {
    CallBack c = new CallBack();
    if ("ios".equals(Display.getInstance().getPlatformName()) && (width != -1 || height != -1)) {
        // workaround for threading issues in iOS https://github.com/codenameone/CodenameOne/issues/2246
        capturePhoto(c);
        Display.getInstance().invokeAndBlock(c);
        if (c.url == null) {
            return null;
        }
        ImageIO scale = Display.getInstance().getImageIO();
        if (scale != null) {
            try {
                String path = c.url.substring(0, c.url.indexOf(".")) + "s" + c.url.substring(c.url.indexOf("."));
                OutputStream os = FileSystemStorage.getInstance().openOutputStream(path);
                scale.save(c.url, os, ImageIO.FORMAT_JPEG, width, height, 1);
                Util.cleanup(os);
                FileSystemStorage.getInstance().delete(c.url);
                return path;
            } catch (IOException ex) {
                Log.e(ex);
            }
        }
    } else {
        c.targetWidth = width;
        c.targetHeight = height;
        capturePhoto(c);
        Display.getInstance().invokeAndBlock(c);
    }
    return c.url;
}
Also used : OutputStream(java.io.OutputStream) IOException(java.io.IOException) ImageIO(com.codename1.ui.util.ImageIO)

Aggregations

ArrayList (java.util.ArrayList)18 Location (location.Location)17 Location (com.codename1.location.Location)5 IOException (java.io.IOException)5 Point (com.codename1.ui.geom.Point)4 Component (com.codename1.ui.Component)3 ActionEvent (com.codename1.ui.events.ActionEvent)3 ConnectionRequest (com.codename1.io.ConnectionRequest)2 BrowserComponent (com.codename1.ui.BrowserComponent)2 ActionListener (com.codename1.ui.events.ActionListener)2 QualifiedCoordinates (javax.microedition.location.QualifiedCoordinates)2 Paint (com.codename1.charts.compat.Paint)1 Point (com.codename1.charts.models.Point)1 XYSeries (com.codename1.charts.models.XYSeries)1 Orientation (com.codename1.charts.renderers.XYMultipleSeriesRenderer.Orientation)1 XYSeriesRenderer (com.codename1.charts.renderers.XYSeriesRenderer)1 BindTarget (com.codename1.cloud.BindTarget)1 CodenameOneImplementation (com.codename1.impl.CodenameOneImplementation)1 BufferedOutputStream (com.codename1.io.BufferedOutputStream)1 FileSystemStorage (com.codename1.io.FileSystemStorage)1