// cardapp.cpp #include "rect.h" char *SUITS[] = {"","heart","club","spade","diamond"}; char *RANKS[] = {"","ace","1","2","3","4","5","6","7","8","9","10","jack","queen","king"}; const CardWidth = 75; const CardHeight = 100; class card : public rect { void setSRF(int s, int r, int f) { suit = s; rank = r; faceUp = f; if ( faceUp < 0 || 1 < faceUp ) faceUp = 1; if ( suit < 1 || 4 < suit ) suit = 1; if ( rank < 1 || 13 < rank ) rank = 1; } public: int suit; int rank; int faceUp; card(POINTT u, int s=1, int r=1) : rect(u,u+POINTT(CardWidth,CardHeight)) { setSRF(s,r,0); } // card(int x, int y, int s, int r) { card(POINTT(x,y), s, r); } card(int px, int py, int s=1, int r=1) : rect(px,py,px+CardWidth,py+CardHeight) { setSRF(s,r,0); } virtual void draw(window *w) { rect::draw(w); if ( faceUp ) { w->wout << setpos(XY_(upper,5,5)) << SUITS[suit] << setpos(XY_(upper,5,30)) << RANKS[rank]; } else { w->setPen(red,solidLine,4); w->line(XY_(upper,4,4),XY_(lower,-4,-4)); w->line(XY_(upper,CardWidth-4,4),XY_(upper,4,CardHeight-4)); } } void flip() { faceUp = 1- faceUp; } void moveTo(int x,int y) { rect::moveTo(x,y,x+CardWidth,y+CardHeight);} }; // card class cardApplication : public application { public: cardApplication(char *apName, char *apTitle, HANDLE thisInst, HANDLE prevInst): application(apName, apTitle, thisInst, prevInst){}; void mouseDown(int,int); void paint(); }; // cardApplication rect a(50,100,150,200); card b(200,100,2,7); rect *c = new card(300,100,3,5); void cardApplication::mouseDown(int x,int y) { if ( b.includes(x,y) ) b.flip(); else b.moveTo(x,y); clearAndUpdate(); } void cardApplication::paint() { a.draw(this); b.draw(this); c->draw(this); } int PASCAL WinMain(HANDLE thisInst, HANDLE prevInst, LPSTR, int) { cardApplication theApp("PENS","Card Application",thisInst,prevInst); return theApp.run(); }