Пример #1
0
void CTable::Init()
{


	unsigned char i = 0;

	win_counter = 0;

	BBSetBackground( BACK_C );

	this->act_slot = BLOCK;
	memset( changed, 0xFF, sizeof( changed ) );


	block.RemoveAll();
	block.Fill();

	for( i = 0; i < 7; i++ )
		block.Shuffle();

	for( i = 0; i < 7; i++ )
		tableau[i].RemoveAll();

	for( i = 0; i < 4; i++ )
		foundation[i].RemoveAll();

	hand.RemoveAll();

	wastepile.RemoveAll();

	unsigned char	filled;

	for( filled = 1; filled < 7; filled++ )
	{
		for( i = filled; i < 7 ; i++ )
		{
			CCard tmp = block.PopCard();
			tableau[i].PushCard( tmp, true );
		}
	}

	for( i = 0; i < 7 ; i++ )
	{
		CCard tmp = block.PopCard();
		tmp.Flip();
		tableau[i].PushCard( tmp, true );
	}

	act_slot = BLOCK;

	ChangeSelection( true );

}
Пример #2
0
void CTable::DoAction()
{

	CBuffer buffer;
	CCard	tmp;

	CSlot* fnd = NULL;
	CSlot* tab = NULL;

	switch( act_slot )
	{
	case BLOCK :
		/* move 3 cards to wastepile */

		//check IncreaseSelection and DecreaseSelection
		//regarding increaseSelection (all) or (+1)

		if( 0 != hand.GetCardsStored() ) return;

		buffer.RemoveAll();

		if( block.GetCardsStored() != 0 )
		{
			tmp = block.PopCard();
			tmp.Flip();
			wastepile.PushCard( tmp );

			if( 3 == ShowCards )
			{
				tmp = block.PopCard();
				tmp.Flip();
				wastepile.PushCard( tmp );

				tmp = block.PopCard();
				tmp.Flip();
				wastepile.PushCard( tmp );
			}

			act_slot = WASTEPILE;

		}
		else
		{
			if( wastepile.GetCardsStored() )
			{
				tmp = wastepile.PopCard();

				while( tmp.IsValid() )
				{
					tmp.Flip();
					block.PushCard( tmp, true );
					tmp = wastepile.PopCard();
				}

			}
		}
		changed[ WASTEPILE ] = true;
		changed[ BLOCK ] = true;

		ChangeSelection( );

		return;

	case WASTEPILE :
		/* put one card to hand */
		/* or put back from the hand */

		if( hand.GetCardsStored() )
		{
			if( hand.GetSource() == &wastepile )
			{
				tmp = hand.PopCard();
				wastepile.PushCard( tmp, true );

				hand.SetSource( NULL );
			}

		}
		else
		{
			tmp = wastepile.PopCard();
			if( false == tmp.IsValid() ) break;

			if( false == hand.PushCard( tmp ) )
			{
				wastepile.PushCard( tmp, true );
			}

			hand.SetSource( &wastepile );
		}

		changed[ WASTEPILE ] = true;
		changed[ HAND ] = true;

		return;

	case FOUNDATION1 :
	case FOUNDATION2 :
	case FOUNDATION3 :
	case FOUNDATION4 :  fnd = &foundation[act_slot - FOUNDATION1];	break;
	case TABLEAU1 :
	case TABLEAU2 :
	case TABLEAU3 :
	case TABLEAU4 :
	case TABLEAU5 :
	case TABLEAU6 :
	case TABLEAU7 :		tab = &tableau[act_slot - TABLEAU1]; break;
	}

	if( fnd )
	{
		if( 0 == hand.GetCardsStored() )
		{

			tmp = fnd->PopCard();

			if( false == tmp.IsValid() ) return;

			hand.PushCard( tmp );

			hand.SetSource( fnd );
			changed[ act_slot ] = true;
			changed[ HAND ] = true;

			CheckWin( false );

			ChangeSelection( );

			return;
		}
		else
		{
			if( fnd == hand.GetSource() )
			{
				tmp = hand.PopCard();

				fnd->PushCard( tmp, true );

				changed[ act_slot ] = true;
				changed[ HAND ] = true;

				CheckWin( true );

				ChangeSelection( );

				return;
			}
			else
			{
				tmp = hand.PeekCard();


				if( false == fnd->PushCard( tmp ) ) return;

				hand.RemoveAll();

				changed[HAND] = true;
				changed[act_slot] = true;

				CheckWin( true );


				ChangeSelection();

				return;
			}
		}

	}

	if( tab )
	{
		if( 0 == hand.GetCardsStored() )
		{
			tmp = tab->PeekCard();

			if( tmp.IsValid() && tmp.IsFaceDown() )
			{
				tmp = tab->PopCard();
				tmp.Flip();
				tab->PushCard( tmp, true );
				changed[ act_slot ] = true;
				ChangeSelection();
				return;
			}

			tab->GetSelectedCards( &buffer );

			tmp = buffer.PopCard();

			while( tmp.IsValid() )
			{
				hand.PushCard( tmp );
				tmp = buffer.PopCard();
			}

			hand.SetSource( tab );
			changed[ act_slot ] = true;
			changed[ HAND ] = true;

			ChangeSelection( );

			return;
		}
		else
		{

			if( tab == hand.GetSource() )
			{


				hand.PeekAllCards( &buffer );

				hand.RemoveAll();


				tmp = buffer.PopCard();

				while( tmp.IsValid() )
				{

					tab->PushCard( tmp, true );

					tmp = buffer.PopCard();
				}
				changed[ act_slot ] = true;
				changed[ HAND ] = true;


				ChangeSelection( );


				return;
			}
			else
			{


				hand.PeekAllCards( &buffer );


				tmp = buffer.PopCard();


				if( false == tab->PushCard( tmp ) ) return;


				tmp = buffer.PopCard();

				while( tmp.IsValid() )
				{

					tab->PushCard( tmp );

					tmp = buffer.PopCard();
				}


				hand.RemoveAll();

				changed[HAND] = true;
				changed[act_slot] = true;

				ChangeSelection();

				return;
			}
		}
	}

}