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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations