/* * guiCard.java */ package boondock.holdem.Gui; import java.awt.*; import boondock.holdem.Cards.*; /** * Class that develops cards to draw. * * @author Jonathan O'Keefe * @author Scott Semonian * @author Matt Brinza * @author Hamid R. Tahsildoost * * @author The Boondock Saints * @author No Limit Texas Holdem */ public class guiCard { private int x, y; private String rank, suit; private final int CARD_HEIGHT = 40, CARD_WIDTH = 27; private boolean showCard; /** * Defines the location and Card information of a graphical card * * @param xLoc The x-coordinate for the top-left point of the card. * @param yLoc The y-coordinate for the top-left poitn of the card. * @param cardInfo The card's rank and suit. (i.e. "10S") * @param visible Shows card face-up if true, face-down if false. */ public guiCard(int xLoc, int yLoc, String cardInfo, boolean visible) { int length = cardInfo.length(); rank = cardInfo.substring(0,length-1); suit = (cardInfo.substring(length-1,length)); x = xLoc; y = yLoc; showCard = visible; } /** * Draws the card on a Graphics element. * * @param g2 The Graphics element onto which the card will be drawn. */ public void draw(Graphics2D g2) { if(showCard) { g2.setColor(Color.white); g2.fillRoundRect(x,y,CARD_WIDTH,CARD_HEIGHT,4,4); g2.setColor(Color.black); g2.drawRoundRect(x,y,CARD_WIDTH,CARD_HEIGHT,4,4); g2.setColor(Color.red); if(suit.equals("S") || suit.equals("C")) g2.setColor(Color.black); g2.setFont(new Font("serif", Font.BOLD, 15)); if(rank.equals("10")) g2.drawString(rank, x+5, y+15); else if(rank.equals("Q") || rank.equals("K")) g2.drawString(rank, x+7, y+15); else if(rank.equals("A")) g2.drawString(rank, x+8, y+15); else g2.drawString(rank, x+10, y+15); drawSuit(x+9, y+19, suit, g2); } else { g2.setColor(new Color(128,0,0)); g2.fillRoundRect(x,y,CARD_WIDTH,CARD_HEIGHT,4,4); g2.setColor(Color.black); g2.drawRoundRect(x,y,CARD_WIDTH,CARD_HEIGHT,4,4); } } private void drawSuit(int xLoc, int yLoc, String s, Graphics2D g2) { if(s.equals("C")) { g2.setColor(Color.black); g2.fillOval(xLoc+1,yLoc,8,8); g2.fillOval(xLoc-4,yLoc+7,8,8); g2.fillOval(xLoc+6,yLoc+7,8,8); g2.fillRect(xLoc+3,yLoc+5,4,12); g2.fillRect(xLoc+2,yLoc+17,6,2); } else if(s.equals("S")) { Polygon spade = new Polygon(); spade.addPoint(xLoc+4,yLoc); spade.addPoint(xLoc-5,yLoc+8); spade.addPoint(xLoc+13,yLoc+8); g2.setColor(Color.black); g2.fillOval(xLoc-4,yLoc+5,8,12); g2.fillOval(xLoc+5,yLoc+5,8,12); g2.fillRect(xLoc+2,yLoc+4,5,11); g2.fillRect(xLoc+3,yLoc+14,3,4); g2.fillRect(xLoc+1,yLoc+17,7,2); g2.fillPolygon(spade); } else if(s.equals("H")) { Polygon heart = new Polygon(); heart.addPoint(xLoc-4,yLoc+9); heart.addPoint(xLoc+4,yLoc+19); heart.addPoint(xLoc+12,yLoc+9); g2.setColor(Color.red); g2.fillOval(xLoc-5,yLoc+1,10,10); g2.fillOval(xLoc+4,yLoc+1,10,10); g2.fillOval(xLoc+1,yLoc+5,5,5); g2.fillPolygon(heart); } else { Polygon diamond = new Polygon(); diamond.addPoint(xLoc+4,yLoc-1); diamond.addPoint(xLoc-3,yLoc+9); diamond.addPoint(xLoc+4,yLoc+19); diamond.addPoint(xLoc+11,yLoc+9); g2.setColor(Color.red); g2.fillPolygon(diamond); } } }