GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — chess-java/Pawn.java at main · lindazeng979/chess-java Expand file tree/ Copy pathPawn.javaMore file actions 82 lines (80 loc) · 2.51 KB / Copy pathPawn.javaFile metadata and controls82 lines (80 loc) · 2.51 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 import java.awt.Color; import java.util.*; /** * Represents a pawn in chess. * * @author Linda Zeng * @version 4.9.23 */ public class Pawn extends Piece { /** * Constructs a pawn * with given color and filename. * It is valued at 1. * * @param col color of pawn * @param fileName file with image of pawn */ public Pawn(Color col, String filename) { super(col, filename, 1); } /** * Indicates which locations * the pawn can move to. * It can move up 1. Capture * diagonally by 1. Move up * 2 at the start. * * @return an ArrayList of * locations this can * move to */ public ArrayList<Location> destinations() { ArrayList<Location> res = new ArrayList<Location>(); Location front; Location side1; Location side2; if (getColor() == Color.WHITE) { front = new Location(getLocation().getRow() - 1, getLocation().getCol()); side1 = new Location(getLocation().getRow() - 1, getLocation().getCol() + 1); side2 = new Location(getLocation().getRow() - 1, getLocation().getCol() - 1); if(getLocation().getRow() == 6) { Location more = new Location(getLocation().getRow() - 2, getLocation().getCol()); if (getBoard().get(more) == null) { res.add(more); } } } else { front = new Location(getLocation().getRow() + 1, getLocation().getCol()); side1 = new Location(getLocation().getRow() + 1, getLocation().getCol() + 1); side2 = new Location(getLocation().getRow() + 1, getLocation().getCol() - 1); if (getLocation().getRow() == 1) { Location more = new Location(getLocation().getRow() + 2, getLocation().getCol()); if (getBoard().get(more) == null) { res.add(more); } } } if (getBoard().isValid(front) && getBoard().get(front) == null) res.add(front); if (getBoard().isValid(side1) && getBoard().get(side1) != null && getBoard().get(side1).getColor() != getColor()) { res.add(side1); } if (getBoard().isValid(side2) && getBoard().get(side2) != null && getBoard().get(side2).getColor() != getColor()) { res.add(side2); } return res; } } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |