示例#1
0
MoveHint *YukonSolver::translateMove( const MOVE &m )
{
    Pile *frompile = 0;
    frompile = deal->store[m.from];

    Card *card = frompile->at( frompile->cardsLeft() - m.card_index - 1);

    if ( m.totype == O_Type )
    {
        Pile *target = 0;
        Pile *empty = 0;
        for (int i = 0; i < 4; i++) {
            Card *c = deal->target[i]->top();
            if (c) {
                if ( c->suit() == card->suit() )
                {
                    target = deal->target[i];
                    break;
                }
            } else if ( !empty )
                empty = deal->target[i];
        }
        if ( !target )
            target = empty;
        return new MoveHint( card, target, m.pri );
    } else {
        return new MoveHint( card, deal->store[m.to], m.pri );
    }
}
示例#2
0
void Game::NextTurn()
{
	playerOnesTurn = !playerOnesTurn;

	string currentPlayerName = playerOnesTurn ? player1.GetName() : player2.GetName();
	cout << "There are " << pile.GetSticks() << " sticks left." << endl;
	
	bool validValue = false;
	int sticksToRemove;
	while( !validValue )
	{
		cout << endl;
		cout << "It is " << currentPlayerName << "'s turn." << endl;
		cout << "How many sticks do you want to remove? : ";
		cin >> sticksToRemove;
		if( sticksToRemove > 0 &&
			sticksToRemove <= 4 &&
			sticksToRemove <= pile.GetSticks() )
		{
			validValue = true;
		}
		else
		{
			cout << sticksToRemove << " is not a valid number." << endl;
		}
	}
	pile.RemoveSticks( sticksToRemove );
}
示例#3
0
// See whether the card under the cursor can be moved somewhere else
// Returns 'true' if it can be moved, 'false' otherwise
bool Game::CanYouGo(int x, int y)
{
    Pile* pile = WhichPile(x, y);
    if (pile && pile != m_pack)
    {
        Card* card = pile->GetTopCard();

        if (card)
        {
            int i;
            for(i = 0; i < 8; i++)
            {
                if (m_foundations[i]->AcceptCard(card) && m_foundations[i] != pile)
                {
                    return true;
                }
            }
            for(i = 0; i < 10; i++)
            {
                if (m_bases[i]->GetTopCard() &&
                    m_bases[i]->AcceptCard(card) &&
                    m_bases[i] != pile)
                {
                    return true;
                }
            }
        }
    }
    return false;
}
示例#4
0
Pile<T>& Pile<T>::clone(){
    Pile *copy = new Pile();
    for(unsigned int i = 0 ; i < this->size() ; ++i){
        T *temp = *this->value(i)->clone();
        copy->push(*temp);
    }
    return &copy;
}
示例#5
0
void Computer::push(Litteral& L)
{
     pushHistorique(*pileActuelle, true);
     Pile *newP = new Pile(*pileActuelle);
     newP->push(L);
     pileActuelle = newP;

}
示例#6
0
void process_pile(DrawableCard *CT[DECK_SIZE], Pile &P) {
  static int cards_seen = 0;
  for (int i = P.get_size(); i > 0; i--) {
    cards_seen++;
    Card &C = P.get_card(i-1);
    CT[card_idx_peek(C)] = peek_drawable(C);
  }
  return;
}
示例#7
0
bool FileSystemActor::isSourceValid()
{
	FileSystemActor *fsData = NULL;
	Actor *data = NULL;

	for (uint i = 0; i < source.size(); i++)
	{
		// Check to see if the icon is a filesystem icon
		if (source[i]->isBumpObjectType(BumpActor))
		{
			data = (Actor *) source[i];

			if (data->isActorType(FileSystem))
			{
				fsData = (FileSystemActor *) source[i];

				// Exclude Virtual folders
				if (fsData->isFileSystemType(Virtual)) return false;
				if (fsData->isFileSystemType(LogicalVolume)) return false;
				if (fsData == this) return false;
			}
			else if (data->isActorType(Webpage) && RecycleBin == winOS->GetIconTypeFromFileName(getFullPath()))
				return true; // can drop WebActor into Recycling Bin to delete
			else
				return false;

		}else if (source[i]->isBumpObjectType(BumpPile))
		{
			Pile *pile = (Pile *) source[i];

			// Check for any items that cannot be moved (ie. Virtual folders)
			for (uint i = 0; i < pile->getNumItems(); i++)
			{
				if (!(*pile)[i]->isPilable(HardPile))
				{
					return false;
				}
			}

			// Ignore gridded items because they are on the dynamic plane, above
			// all other items on the floor.
			if (pile->getPileState() == Grid) return false;

			// Allow Piles
			return true;
		
		}else{
			// Logical items are not allowed
			return false;
		}
	}

	return true;
}
示例#8
0
T& Pile<T>::MEAN(const unsigned int x) const{
    T& tmp = this->SUM(x);
    Operation::Div * div = new Operation::Div();
    Pile<T> pileTmp;
    pileTmp.addPile(tmp);
    pileTmp.addPile(new Nombre::Entier(x));
    T* res = div->calcul(pileTmp);
    delete div;
    delete pileTmp;
    T& ref = *res;
    return ref;
}
示例#9
0
// See whether the card under the cursor can be moved somewhere else
// Returns 'true' if it can be moved, 'false' otherwise
bool Game::CanYouGo(int x, int y)
{
    Pile* pile = WhichPile(x, y);
    if (pile && pile != m_pack)
    {
        Card* card = pile->GetTopCard();

        if (card)
        {
            int i;
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
            for(i = 0; i < 8; i++)
            {
                if (m_foundations[i]->AcceptCard(card) && m_foundations[i] != pile)
                {
                    return true;
                }
            }
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
            for(i = 0; i < 10; i++)
            {
                if (m_bases[i]->GetTopCard() &&
                    m_bases[i]->AcceptCard(card) &&
                    m_bases[i] != pile)
                {
                    return true;
                }
            }
        }
    }
    return false;
}
示例#10
0
void Pile::copierDans(Pile& P) const
{
    for(int i = 0; i<taille; i++) // On parcours dans l'ordre d'ajout du plus vieux au plus récent
    {
        P.push(*litteraux[i]);
    }
}
示例#11
0
//############# OPERATION ##################
void Pile::clone(Pile & p) const{

    for(int i = 0; i<this->size(); i++){
        Constante * c = this->at(i);
        if(typeid(*c) ==typeid(CEntier)){
             p.push((Constante * )new CEntier(*((CEntier*) c)));
        }else if(typeid(*c) ==typeid(CRationnel)){
            p.push((Constante * )new CRationnel(*((CRationnel*) c)));
        }else if(typeid(*c) ==typeid(CReel)){
            p.push((Constante * )new CReel(*((CReel*) c)));
        }else if(typeid(*c) ==typeid(CComplexe)){
            p.push((Constante * )new CComplexe(*((CComplexe*) c)));
        }else if(typeid(*c) ==typeid(CExpression)){
            p.push((Constante * ) new CExpression(*((CExpression*) c)));
        }
    }
}
示例#12
0
MoveHint *IdiotSolver::translateMove( const MOVE &m )
{
    if ( m.from >=4 )
        return 0;
    Pile *frompile = deal->m_play[m.from];

    Card *card = frompile->at( frompile->cardsLeft() - m.card_index - 1);
    Q_ASSERT( card );

    Pile *target = 0;
    if ( m.to == 5 )
        target = deal->m_away;
    else
        target = deal->m_play[m.to];

    return new MoveHint( card, target, m.pri );
}
示例#13
0
void Pile::move_from(Pile &from, int num) {
  assert(num <= from.get_size());
  iterator iter_from = from.cards.begin();
  for (int i = 0; i < num; i++) {
    iter_from++;
  }
  cards.splice(cards.begin(), from.cards, from.cards.begin(), iter_from);
}
示例#14
0
string Game::GameOver()
{
	if( pile.GetSticks() == 0 )
	{
		return playerOnesTurn ? player1.GetName( ) : player2.GetName( );
	}
	return "";
}
示例#15
0
bool Expression::valide() const //Verifie que la syntaxe de l'expression est conforme a la notation polonaise inversee
{
    Pile stack;
    Expression* copy =  dynamic_cast<Expression*>(clone());
    Cellule* cell = copy->tete;
    Donnee* data1;
    Donnee* data2;
    while(cell)
    {
        //On teste si le contenu de la cellule est de type Numerique
        const Numerique* test = dynamic_cast<const Numerique*>(cell->getContent());
        if (test)
            stack.empiler(cell->getContent());
        else    //Il d'agit d'un operateur
        {
            const OperateurBinaire* opbinaire = dynamic_cast<const OperateurBinaire*>(cell->getContent());
            if(opbinaire)   //Il s'agit d'un operateur binaire
            {
                if (stack.longueur()<2)
                    return false;
                data1 = stack.depiler();
                data2 = stack.depiler();
                const Numerique* test1 = dynamic_cast<const Numerique*>(data1);
                const Numerique* test2 = dynamic_cast<const Numerique*>(data2);
                if (!(test1 && test2))
                        return false;
                stack.empiler(data1);
            }
            else    //C'est un operateur unaire
            {
                if (stack.longueur()<1)
                    return false;
                data1 = stack.depiler();
                const Numerique* test = dynamic_cast<const Numerique*>(data1);
                if (!test)
                    return false;
                stack.empiler(data1);
            }
        }
        cell = cell->getSucc();
    }
    data1 = stack.depiler();
    const Numerique* test = dynamic_cast<const Numerique*>(data1);
    if(test)
        return true;
    return false;
}
示例#16
0
bool Straight::isPokerPlayable(Hand& selection, Pile& playPile){
  Hand topHand = playPile.getTopHand();
  if(topHand.size() == '\0'){
    return true;
  }else if(topHand.size() != 5){
    return false;
  }
  //Highest ranking card at the top of the sequence wins
  if((selection.getCard(0)->getRank() > topHand.getCard(0)->getRank())){
    return true;
  }
}
示例#17
0
Pile<T>& Pile<T>::pileResultat() const{
    Pile<T> p = this->clone();
    Pile<T> res;
    for(int i=0;i<p.size();i++) {
        if(p.at(i).isOperateur()) {
            if(p.at(i).isBinaire()) {
                p.DROP();
                p.DROP();
                p.DROP();
            }
            else { // unaire
                p.DROP();
                p.DROP();
            }
        }
        else {
            res.addPile(p.pop());
        }
    }
    delete p;
    Pile<T>& ref = res;
    return ref;
}
示例#18
0
bool FileSystemManager::hasCommonRoots(const FileSystemActor * actor, const vector<BumpObject *>& dropObjects) const
{
	// XXX: see http://msdn.microsoft.com/en-us/library/aa364952.aspx
	vector<BumpObject *> dropObjs = dropObjects;
	FileSystemActor * firstValid = NULL;
	for (int i = 0; i < dropObjs.size() && !firstValid; ++i)
	{
		if (dropObjs[i]->isBumpObjectType(BumpActor))
		{
			Actor * a = (Actor *) dropObjs[i];
			if (a->isActorType(FileSystem))
				firstValid = (FileSystemActor *) a;
		}
		if (dropObjs[i]->isBumpObjectType(BumpPile))
		{
			Pile * p = (Pile *) dropObjs[i];
			vector<BumpObject *> items = p->getPileItems();
			for (int j = 0; j < items.size(); ++j)
			{
				dropObjs.push_back(items[j]);
			}
		}
	}

	if (firstValid)
	{
#ifdef WIN32
		int d1 = PathGetDriveNumber((LPCTSTR) actor->getTargetPath().utf16());
		int d2 = PathGetDriveNumber((LPCTSTR) firstValid->getTargetPath().utf16());
		return	(d1 == d2);
#else
	#error NOT IMPLEMENTED
#endif
	}
	return false;
}
示例#19
0
文件: Tableau.cpp 项目: thar/Klondike
Tableau::Tableau(Pile &pile) : PilesGroup(7)
{
    for(unsigned int i = 0; i < getNumberOfPiles(); i++)
    {
        Pile tempPile = pile.popPile(i+1);
        Pile topCard = tempPile.popPile(1);
        topCard.turnCardsUp();
        tempPile.appendPile(topCard);
        actionPush(tempPile, i);
    }
}
void Collection_Onglet::chargerContexte() {
    QString file = "save.dat";
    QFile fread(file);
    fread.open(QFile::ReadOnly | QFile::Text);

    QDomDocument doc;
    doc.setContent(&fread, false);
    QDomElement racine = doc.documentElement();
    racine = racine.firstChildElement();
    while(!racine.isNull()) {
        if(racine.tagName()== "onglet"){
            //creation onglet
            Onglet* o = new Onglet();
            QDomElement element = racine.firstChildElement();
            while(!element.isNull()) {
                DataGestion * dg = new DataGestion();
                if(element.tagName()=="paffichage") {
                    Pile<QString> ps;
                    QDomElement data = element.firstChildElement();
                    while(!data.isNull()) {
                        Pile<QString> tmp1;
                        if(element.tagName()=="data") {
                            QString valeur = data.text();
                            tmp1.addPile(&valeur);
                        }
                        for(int i=0;i<tmp1.size();i++){
                            ps.addPile(tmp1.pop());
                        }
                    }
                    dg->setAffichage(ps);
                }
                else if(element.tagName()=="pstockage") {
                    Pile<Nombre::Data> pst;
                    QDomElement data = element.firstChildElement();
                    while(!data.isNull()) {
                        Pile<QString> tmp1;
                        if(element.tagName()=="data") {
                            QString valeur = data.text();
                            tmp1.addPile(&valeur);
                        }
                        for(int i=0;i<tmp1.size();i++){
                            pst.addPile(dg->getFactory().creer(*tmp1.pop()));
                        }
                    }
                    dg->setStockage(pst);
                }
                else if(element.tagName()=="pretablir") {
                    Pile<Nombre::Data> pr;
                    QDomElement data = element.firstChildElement();
                    while(!data.isNull()) {
                        Pile<QString> tmp1;
                        if(element.tagName()=="data") {
                            QString valeur = data.text();
                            tmp1.addPile(&valeur);
                        }
                        for(int i=0;i<tmp1.size();i++){
                            pr.addPile(dg->getFactory().creer(*tmp1.pop()));
                        }
                    }
                    dg->setStockage(pr);
                }
                else if(element.tagName()=="degre") {
                    QString d = element.text();
                    if(d=="O")
                        o->setDegre(true);
                    else
                        o->setDegre(false);
                }
                else if(element.tagName()=="complexe") {
                    QString c = element.text();
                    if(c=="O")
                        o->setComplexe(true);
                    else
                        o->setComplexe(false);
                }
                else if(element.tagName()=="type") {
                    QString t = element.text();
                    if(t=="integer")
                        o->setType(Integer);
                    else if(t=="real")
                        o->setType(Real);
                    else if(t=="ratio")
                        o->setType(Ratio);
                }
                o->setDataGestion(*dg);
                element = element.nextSiblingElement();
            }
            this->ajouterOnglet(o);
        }
        racine = racine.nextSiblingElement();
    }
    fread.close();
}
示例#21
0
vector<BumpObject *> FileSystemActor::onDrop(vector<BumpObject *> &objList)
{
	QString fPath;
	FileSystemActor *fsData;
	Pile *pile;
	FileSystemPile *fsPile;
	Vec3 topPt;
	bool moveItem = true;
	bool operationSucceeded = false;
	vector<FileSystemActor *> failedObj, fsObjList;
	vector<BumpObject *> failedBumpObjs;
	vector<FileSystemActor *> hardPileOwners;

	if (!isSourceValid())
	{
		return objList;
	}
	else
	{	
		// Convert Piles to Free Items
		for (int i = 0; i < objList.size(); i++)
		{
			// Do Pile to free Item conversions
			if (objList[i]->getObjectType() == ObjectType(BumpPile, HardPile, Stack))
			{
				// If its a Hard Pile, get its owner and use it instead of pile members
				fsPile = (FileSystemPile *) objList[i];

				objList.erase(objList.begin() + i);
				objList.push_back(fsPile->getOwner());
				hardPileOwners.push_back(fsPile->getOwner());

				fsPile->folderize(false);

				i--;

			}else if (objList[i]->getObjectType() == ObjectType(BumpPile, SoftPile, Stack))
			{
				pile = (Pile *) objList[i];

				objList.erase(objList.begin() + i);
				i--;

				// If its a Soft Pile, use its members instead of the pile
				for (uint j = 0; j < pile->getNumItems(); j++)
				{
					objList.push_back((*pile)[j]);
				}
			}
		}

		if (isFileSystemType(Executable))
		{
			for (uint i = 0; i < objList.size(); i++)
			{
				// Create a parameter list separated by spaces
				fsData = (FileSystemActor *) objList[i];

				if (!fsData || !scnManager->containsObject(fsData))
					continue;

				fPath.append(fsData->getFullPath());
				fPath.append(" ");
			}

			// We just tossed into an executable
			// QString lnkTarget, dummyLnkArgs, lnkWorkingDir;
			QString lnkArgs = fPath;
			/*
			if (isFileSystemType(Link))
			{
				fsManager->getShortcutTarget(getFullPath(), &lnkTarget, &dummyLnkArgs, &lnkWorkingDir);
				fsManager->launchFileAsync(lnkTarget, lnkArgs, lnkWorkingDir);
			}
			else
			*/
				fsManager->launchFileAsync(filePath, lnkArgs);

		}else if (isFileSystemType(Folder))
		{
			bool itemNeedsPrompt = false;
			bool onlyPhotoFrame = true;

			int iconType = winOS->GetIconTypeFromFileName(getFullPath());
			bool isRecycleBin = iconType == RecycleBin;
			bool isMyDocuments = iconType == MyDocuments;

			// Convert BumpObject to FileSystemActors, delete WebActors since they are not FileSystemActors
			for (uint i = 0; i < objList.size(); i++)
			{
				if (objList[i]->isObjectType(ObjectType(BumpActor, Webpage)))
				{
					if (isRecycleBin)
					{
						sel->remove(objList[i]);
						objList[i]->markDragCancelled(true);
						objList[i]->onDragEnd();
						FadeAndDeleteActor((Actor *)objList[i]);
						objList.erase(objList.begin() + i);
					}
					else
						_ASSERT(0);
				}
				else
				{
					fsObjList.push_back((FileSystemActor *) objList[i]);

					if (fsObjList[i]->getObjectType() == ObjectType(BumpActor, FileSystem, PhotoFrame))
						itemNeedsPrompt = true;
					else
						onlyPhotoFrame = false;
				}
			}

			if (isFileSystemType(Virtual))
			{
				// Handle tossing into the recycle bin
				if (isRecycleBin || isMyDocuments)
				{
					if (itemNeedsPrompt)
					{
						dlgManager->clearState();
						dlgManager->setPrompt(QT_TR_NOOP("A Photo Frame was detected in the selection, would you like to delete it?"));
						dlgManager->setCaption(QT_NT("BumpTop"));

						if (dlgManager->promptDialog(DialogYesNo))
						{
							vector<FileSystemActor *>::iterator iter = fsObjList.begin();
							while (iter != fsObjList.end())
							{
								FileSystemActor * fsActor = *iter;
								if (fsActor->getObjectType() == ObjectType(BumpActor, FileSystem, PhotoFrame))
								{
									// Remove the photo frame by deferring deletion until after the anim is over
									fsActor->fadeOut();
									animManager->removeAnimation(fsActor);
									animManager->addAnimation(AnimationEntry(fsActor, (FinishedCallBack) DeleteActorAfterAnim, NULL, true));

									iter = fsObjList.erase(iter);
								}
								else
									iter++;
							}
						}
						else
						{
							vector<FileSystemActor *>::iterator iter = fsObjList.begin();
							while (iter != fsObjList.end())
							{
								FileSystemActor * fsActor = *iter;
								if (fsActor->getObjectType() == ObjectType(BumpActor, FileSystem, PhotoFrame))
								{
									failedObj.push_back(fsActor);
									iter = fsObjList.erase(iter);
								}
								else
									iter++;
							}
						}
					}

					if (!fsObjList.empty())
					{
						if (isRecycleBin)
							operationSucceeded = fsManager->deleteFiles(fsObjList, failedObj, !onlyPhotoFrame);
						else
							operationSucceeded = fsManager->moveFiles(fsObjList, winOS->GetSystemPath(iconType), failedObj, true);
					}
				}
			}else{
				if (!isCopyIntoActor(objList)) // Shift forces move, Ctrl forces copy, common root defaults to move
				{
					// Handle tossing into a regular folder
					operationSucceeded = fsManager->moveFiles(fsObjList, getTargetPath(), failedObj, true);
					if (operationSucceeded)
					{
						printUnique("FileSystemActor::onDrop", QT_TR_NOOP("%1 file(s) moved to %2").arg(fsObjList.size()).arg(getText()));
					}
				}
				else
				{
					// Handle tossing into a regular folder on another resource (will copy instead of move)
					operationSucceeded = fsManager->copyFiles(fsObjList, getTargetPath(), failedObj, true);
					if (operationSucceeded)
					{
						printUnique("FileSystemActor::onDrop", QT_TR_NOOP("%1 file(s) copied to %2").arg(fsObjList.size()).arg(getText()));
					}

					// Animate back to the original starting pose
					animateObjectsBackToPreDropPose(objList);
				}
			}
		}

		if (!operationSucceeded)
		{
			// re-pileize hard piles if move failed
			vector<FileSystemActor *>::iterator iter = hardPileOwners.begin();
			while (iter != hardPileOwners.end())
			{
				(*iter)->pileize();
				iter++;
			}
		}

		// record this drop
		statsManager->getStats().bt.interaction.dragAndDrop.toActor++;
	}

	// Convert from a list of FileSYstemActors to BumpObjects
	for (uint i = 0; i < failedObj.size(); i++)
	{
		failedBumpObjs.push_back(failedObj[i]);
	}

	return failedBumpObjs;
}
示例#22
0
// Called when the left button is released after dragging a card
// Scan the piles to see if this card overlaps a pile and can be added
// to the pile. If the card overlaps more than one pile on which it can be placed
// then put it on the nearest pile.
void Game::LButtonUp(wxDC& dc, int x, int y)
{
    if (m_srcPile)
    {
        // work out the position of the dragged card
        x += m_xOffset;
        y += m_yOffset;

        Pile* nearestPile = 0;
        int distance = (CardHeight + CardWidth) * (CardHeight + CardWidth);

        // find the nearest pile which will accept the card
        int i;
        for (i = 0; i < 8; i++)
        {
            if (DropCard(x, y, m_foundations[i], m_liftedCard))
            {
                if (m_foundations[i]->CalcDistance(x, y) < distance)
                {
                    nearestPile = m_foundations[i];
                    distance = nearestPile->CalcDistance(x, y);
                }
            }
        }
        for (i = 0; i < 10; i++)
        {
            if (DropCard(x, y, m_bases[i], m_liftedCard))
            {
                if (m_bases[i]->CalcDistance(x, y) < distance)
                {
                    nearestPile = m_bases[i];
                    distance = nearestPile->CalcDistance(x, y);
                }
            }
        }

        // Restore the area under the card
        wxMemoryDC memoryDC;
        memoryDC.SelectObject(*m_bmap);
        dc.Blit(m_xPos, m_yPos, CardWidth, CardHeight,
               &memoryDC, 0, 0, wxCOPY);

        // Draw the card in its new position
        if (nearestPile)
        {
            // Add to new pile
            nearestPile->AddCard(dc, m_liftedCard);
            if (nearestPile != m_srcPile)
            {
                DoMove(dc, m_srcPile, nearestPile);
            }
        }
        else
        {
            // Return card to src pile
            m_srcPile->AddCard(dc, m_liftedCard);
        }
        m_srcPile = 0;
        m_liftedCard = 0;
    }
}
示例#23
0
Pile::Pile(const Pile& P) : litteraux(new Litteral*[P.getTailleMax()]),tailleMax(P.getTailleMax()),taille(0)
{
    P.copierDans(*this);
}
示例#24
0
// Called when the left button is double clicked
// If a card is under the pointer and it can move elsewhere then move it.
// Move onto a foundation as first choice, a populated base as second and
// an empty base as third choice.
// NB Cards in the m_pack cannot be moved in this way - they aren't in play
// yet
void Game::LButtonDblClk(wxDC& dc, int x, int y)
{
    Pile* pile = WhichPile(x, y);
    if (!pile) return;

    // Double click on m_pack is the same as left button down
    if (pile == m_pack)
    {
        LButtonDown(dc, x, y);
    }
    else
    {
        Card* card = pile->GetTopCard();

        if (card)
        {
            int i;

            // if the card is an ace then try to place it next
            // to an ace of the same suit
            if (card->GetPipValue() == 1)
            {
                for(i = 0; i < 4; i++)
                {
                    Card* m_topCard = m_foundations[i]->GetTopCard();
                    if ( m_topCard )
                    {
                        if (m_topCard->GetSuit() == card->GetSuit() &&
                            m_foundations[i + 4] != pile &&
                            m_foundations[i + 4]->GetTopCard() == 0)
                        {
                            pile->RemoveTopCard(dc);
                            m_foundations[i + 4]->AddCard(dc, card);
                            DoMove(dc, pile, m_foundations[i + 4]);
                            return;
                        }
                    }
                }
            }

            // try to place the card on a foundation
            for(i = 0; i < 8; i++)
            {
                if (m_foundations[i]->AcceptCard(card) && m_foundations[i] != pile)
                {
                    pile->RemoveTopCard(dc);
                    m_foundations[i]->AddCard(dc, card);
                    DoMove(dc, pile, m_foundations[i]);
                    return;
                }
            }
            // try to place the card on a populated base
            for(i = 0; i < 10; i++)
            {
                if (m_bases[i]->AcceptCard(card) &&
                    m_bases[i] != pile &&
                    m_bases[i]->GetTopCard())
                {
                    pile->RemoveTopCard(dc);
                    m_bases[i]->AddCard(dc, card);
                    DoMove(dc, pile, m_bases[i]);
                    return;
                }
            }
            // try to place the card on any base
            for(i = 0; i < 10; i++)
            {
                if (m_bases[i]->AcceptCard(card) && m_bases[i] != pile)
                {
                    pile->RemoveTopCard(dc);
                    m_bases[i]->AddCard(dc, card);
                    DoMove(dc, pile, m_bases[i]);
                    return;
                }
            }
        }
    }
}
示例#25
0
// fabrique soit une constante soit un opérateur (et l'éxécute).
void Calculatrice::fabriquer(const QString& text, enumType type) const {
    Pile* p = &Pile::getInstance();
    PileAffichage* pA = &PileAffichage::getInstance();

    switch (type) {
        case ENTIER:{
            Constante* res = new Entier(text.toInt());
            p->push(res);

            // ajout log dans le fichier de log
            LogSystem::add("Push dans la pile : " + res->toString(),FAIBLE);

            // on push dans la pile d'affichage
            pA->push(text);

            break;
        }
        case REEL:{
            Constante* res = new Reel(text.toDouble());
            p->push(res);

            // ajout log dans le fichier de log
            LogSystem::add("Push dans la pile : " + res->toString(),FAIBLE);

            // on push dans la pile d'affichage
            pA->push(text);


            break;
        }
        case RATIONNEL:{
            // séparation num / den
            QStringList tmp = text.split("/");
            Constante* res = new Rationnel(tmp.value(0).toInt(), tmp.value(1).toInt());
            p->push(res);

            // ajout log dans le fichier de log
            LogSystem::add("Push dans la pile : " + res->toString(),FAIBLE);

            // on push dans la pile d'affichage
            pA->push(text);


            break;
        }
        case COMPLEXE:{
            // séparation re  $  im
            QStringList tmp = text.split("$");

            // push la partie réelle du complexe
            if (this->isEntier(tmp.value(0))) {
                this->fabriquer(tmp.value(0),ENTIER);
            } else if (this->isReel(tmp.value(0))) {
                this->fabriquer(tmp.value(0),REEL);
            } else if (this->isRationnel(tmp.value(0))) {
                this->fabriquer(tmp.value(0),RATIONNEL);
            }

            // push la partie imaginaire du complexe
            if (this->isEntier(tmp.value(1))) {
                this->fabriquer(tmp.value(1),ENTIER);
            } else if (this->isReel(tmp.value(1))) {
                this->fabriquer(tmp.value(1),REEL);
            } else if (this->isRationnel(tmp.value(1))) {
                this->fabriquer(tmp.value(1),RATIONNEL);
            }

            // pop les deux parties
            const NonComplexe* c1 = dynamic_cast<const NonComplexe*>(p->pop());
            const NonComplexe* c2 = dynamic_cast<const NonComplexe*>(p->pop());

            // construction du complexe et push.
            Complexe* res = new Complexe(*c2, *c1);
            p->push(res);

            // ajout log dans le fichier de log
            LogSystem::add("Push dans la pile : " + res->toString(),FAIBLE);

            // on push dans la pile d'affichage
            pA->push(text);

            break;

        }
        case OPERATEUR:{
            Operateur* res = new Operateur(text);

            // ajout log dans le fichier de log
            LogSystem::add("Traitement opération : " + text,FAIBLE);

            // on push dans la pile d'affichage
            pA->push(text);

            res->effectuerOperation();
            break;
        }
        case EXPRESSION:{
            QString tmp(text);
            tmp.replace(QString("'"), QString(""));
            Constante* res = new Expression(tmp);
            p->push(res);

            // ajout log dans le fichier de log
            LogSystem::add("Push dans la pile : " + res->toString(),FAIBLE);

            // on push dans la pile d'affichage
            pA->push(text);

            break;
        }
        default:{
            QMessageBox::critical(0,"Erreur !", "Fabrication d'objet impossible!");
            // ajout log dans le fichier de log
            LogSystem::add("Fabrication d'objet impossible",ELEVEE);
            break;
        }
    }
}
示例#26
0
// Called when the left button is double clicked
// If a card is under the pointer and it can move elsewhere then move it.
// Move onto a foundation as first choice, a populated base as second and
// an empty base as third choice.
// NB Cards in the m_pack cannot be moved in this way - they aren't in play
// yet
void Game::LButtonDblClk(wxDC& dc, int x, int y)
{
    Pile* pile = WhichPile(x, y);
    if (!pile) return;

    // Double click on m_pack is the same as left button down
    if (pile == m_pack)
    {
        LButtonDown(dc, x, y);
    }
    else
    {
        Card* card = pile->GetTopCard();

        if (card)
        {
            int i;

            // if the card is an ace then try to place it next
            // to an ace of the same suit
            if (card->GetPipValue() == 1)
            {
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
                for(i = 0; i < 4; i++)
                {
                    Card* m_topCard = m_foundations[i]->GetTopCard();
                    if ( m_topCard )
                    {
                        if (m_topCard->GetSuit() == card->GetSuit() &&
                            m_foundations[i + 4] != pile &&
                            m_foundations[i + 4]->GetTopCard() == 0)
                        {
                            pile->RemoveTopCard(dc);
                            m_foundations[i + 4]->AddCard(dc, card);
                            DoMove(dc, pile, m_foundations[i + 4]);
                            return;
                        }
                    }
                }
            }

            // try to place the card on a foundation
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
            for(i = 0; i < 8; i++)
            {
                if (m_foundations[i]->AcceptCard(card) && m_foundations[i] != pile)
                {
                    pile->RemoveTopCard(dc);
                    m_foundations[i]->AddCard(dc, card);
                    DoMove(dc, pile, m_foundations[i]);
                    return;
                }
            }
            // try to place the card on a populated base
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
            for(i = 0; i < 10; i++)
            {
                if (m_bases[i]->AcceptCard(card) &&
                    m_bases[i] != pile &&
                    m_bases[i]->GetTopCard())
                {
                    pile->RemoveTopCard(dc);
                    m_bases[i]->AddCard(dc, card);
                    DoMove(dc, pile, m_bases[i]);
                    return;
                }
            }
            // try to place the card on any base
#if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */
#   pragma ivdep
#   pragma swp
#   pragma unroll
#   pragma prefetch
#   if 0
#       pragma simd noassert
#   endif
#endif /* VDM auto patch */
            for(i = 0; i < 10; i++)
            {
                if (m_bases[i]->AcceptCard(card) && m_bases[i] != pile)
                {
                    pile->RemoveTopCard(dc);
                    m_bases[i]->AddCard(dc, card);
                    DoMove(dc, pile, m_bases[i]);
                    return;
                }
            }
        }
    }
}