Card Game By Chris

<< Hit the Mole by Noah | OldProjectsTrailIndex | Shooter Game by Josh and Chris >>

Final Project Scratch Work

Card.java

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;


public class Card 
{
	private Image image;
	private boolean isFaceUp;
	private Rectangle rect;

	public Card(Image image, Rectangle rect)
	{
		this.image=image;
		this.rect=rect;
		isFaceUp=false;
	}

	public void flip()
	{
		isFaceUp=true;
	}

	public void draw(Graphics g)
	{
		g.drawImage(image, rect.x, rect.y, rect.width, rect.height, null);
	}


}

Hand.java

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.util.ArrayList;


public class Hand 
{
	private ArrayList<Card> cards;
	Image norm;
	Image odd;
	private int oddNumber=0;
	public Hand(Image norm, Image odd)
	{
		this.norm=norm;
		this.odd=odd;
		cards=new ArrayList<Card>();
		for(int i=0; i<(int)(Math.random()*5); i++)
		{
			Rectangle rect = new Rectangle(20+i*70,80,60,80);
			Card c = new Card(norm, rect);
			cards.add(c);
		}
		Rectangle rect2 = new Rectangle(20+(cards.size())*70, 80, 60, 80);
		Card d = new Card(odd, rect2);
		oddNumber=cards.size();
		cards.add(d);
		for(int j=cards.size()+1; j<=5; j++)
		{
			Rectangle rect3 = new Rectangle(20+(j-1)*70,80,60,80);
			Card c = new Card(norm, rect3);
			cards.add(c);
		}

	}
	public ArrayList<Card> getCards()
	{
		return cards;
	}

	public void display(Graphics g)
	{
		for(Card c: cards)
		{
			c.draw(g);
		}
	}

	public int getOddNumber()
	{
		return oddNumber;
	}

}

GameRunner.java

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;


public class GameRunner extends Applet
{
	private Hand hand;

	public void init()
	{
		Image butterfly=loadImageFromJar("butterfly.gif");
		hand=new Hand(butterfly, butterfly);
	}
	public Image loadImageFromJar(String fileName)
    {
    		Image img=null;
    		try {
			img = getImage( getClass().getResource("/"+fileName));
		} catch (NullPointerException e) {
			//e.printStackTrace();
		} 
    		return img;
    }

	public void paint(Graphics g)
	{
		g.setColor(Color.LIGHT_GRAY);
		g.fillRect(0, 0, getWidth(), getHeight());
		hand.display(g);
	}

}