java - how to make double sided images -
i trying create card game take 2 cards deck , flip them @ same time reveal card few seconds flip them on im having trouble getting cards p know have front , back. right have deck , 2 cards right need deck facing down , 2 cards facing down installing flipped. when load picture makes cards same picture. know have set in deck class sort of flag dont know how?
public class deck { private random random = new random (); protected card cards[] = new card[52] ; private imageicon = new imageicon("card bitmaps/back.gif"); protected boolean flip = false; protected int numcards = 0; public deck() { int = 0; (int s = 1; s<5 ; s++) { (int n=1; n<14 ; n++) { cards[i] = new card(n,s); i++; numcards = numcards + 1; } } } public void giveslapzone (deck d) { numcards = numcards - 1; d.takecardslapzone(cards[numcards]); return; } public void takecardslapzone(card c) { cards[numcards] = c; numcards = numcards + 1; } public void shuffle () { (int = 0; i<numcards; i++) { int j = random.nextint(numcards); card temp = cards[i]; cards[i] = cards[j]; cards[j] = temp; } } public void draw (container c ,graphics g, int x , int y ) { (int = 0; i<numcards; i++) { cards[i].draw(c, g, x,y) ; if (flip==false) back.painticon(c,g,x,y); } } }
think through in real world. object has images on 2 sides ?card
. target object card
, not deck
. now, how design class card
can have images ? adding references image should hold :
public class card { //extends/implements etc private image frontimage; //image number etc. private image backimage; //image shown when card faced down. //--and on..
now, in flipping animation, need draw card using images either side depending on side shown user. also, 1 quick note. given image in of cards decks same, use static final image hold global backimage , re-use on cards.
Comments
Post a Comment