Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

cardpile.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 
00021 #include "cardpile.h"
00022 #include "card.h"
00023 
00024 #include <qpe/config.h>
00025 
00026 
00027 
00028 CardPile::CardPile(int x, int y) : pileX(x), pileY(y), dealing(FALSE), PileResize(FALSE) {
00029     pileWidth = 0;
00030     pileHeight = 0;
00031     pileNextX = pileX;
00032     pileNextY = pileY;
00033     pileCenterX = x + pileWidth / 2;
00034     pileCenterY = y + pileHeight / 2;
00035     pileRadius = (pileWidth > pileHeight) ? pileWidth : pileHeight;
00036     pileOffsetDown = 13;
00037 }
00038 
00039 
00040 int CardPile::distanceFromPile(int x, int y) {
00041     return (pileCenterX-x)*(pileCenterX-x)+(pileCenterY-y)*(pileCenterY-y);
00042 }
00043 
00044 
00045 int CardPile::distanceFromNextPos(int x, int y) {
00046     return (pileNextX-x)*(pileNextX-x)+(pileNextY-y)*(pileNextY-y);
00047 }
00048 
00049 
00050 Card *CardPile::cardInfront(Card *c) {
00051     CardPile *p = c->getCardPile();
00052     if (p) {
00053         p->at(p->find(c));
00054         return p->next();
00055     } else {
00056         return NULL;
00057     }
00058 }
00059 
00060 
00061 bool CardPile::kingOnTop() {
00062     Card *top = cardOnTop();
00063     return top && top->getValue() == king;
00064 }
00065 
00066 
00067 bool CardPile::addCardToTop(Card *c) {
00068     if (dealing || isAllowedOnTop(c)) {
00069         append((const Card *)c);
00070         cardAddedToTop(c);
00071         return TRUE;
00072     }
00073     return FALSE;
00074 }
00075 
00076 
00077 bool CardPile::addCardToBottom(Card *c) {
00078     if (dealing || isAllowedOnBottom(c)) {
00079         prepend((const Card *)c);
00080         cardAddedToBottom(c);
00081         return TRUE;
00082     }
00083     return FALSE;
00084 }
00085 
00086 
00087 bool CardPile::removeCard(Card *c) {
00088     if (dealing || isAllowedToBeMoved(c)) {
00089         take(find(c));
00090         cardRemoved(c);
00091         return TRUE;
00092     }
00093     return FALSE;
00094 }
00095 
00096 
00097 void CardPile::writeConfig( Config& cfg, QString name ) {
00098     int numberOfCards = 0;
00099     cfg.setGroup( name );
00100     Card *card = cardOnBottom();
00101     while ( card ) {
00102         QString cardStr;
00103         cardStr.sprintf( "%i", numberOfCards );
00104         int val  = (int)card->getValue()-1 + ((int)card->getSuit()-1)*13 + (int)card->getDeckNumber()*52;
00105         cfg.writeEntry( "Card" + cardStr, val );
00106         cfg.writeEntry( "CardFacing" + cardStr, card->isFacing() );
00107         card = cardInfront( card );
00108         numberOfCards++;
00109     }
00110     cfg.writeEntry("NumberOfCards", numberOfCards);
00111 }
00112 
00113 

Generated on Sat Nov 5 16:17:26 2005 for OPIE by  doxygen 1.4.2