void CTable::Load() { int SavShowCards = 0; FILE* sav = fopen( GAMESDIR "/solitair.sav", "rb" ); if( sav == NULL ) return; fread( &SavShowCards, 1, sizeof( SavShowCards ), sav ); if( ( SavShowCards != 3 ) && ( SavShowCards != 1 ) ) { return; } ShowCards = SavShowCards; fread( &win_counter, 1, sizeof( win_counter ), sav ); CCard card; unsigned char CardsStored; CBuffer buffer; //Restore BLOCK block.RemoveAll(); fread( &CardsStored, 1, sizeof( CardsStored ), sav ); buffer.RemoveAll(); for( unsigned char i = 0; i < CardsStored; i++ ) { fread( &card, 1, sizeof( card ), sav ); buffer.PushCard( card, true ); } for( unsigned char i = 0; i < CardsStored; i++ ) { block.PushCard( buffer.PopCard(), true ); } //Restore Wastepile fread( &CardsStored, 1, sizeof( CardsStored ), sav ); buffer.RemoveAll(); for( unsigned char i = 0; i < CardsStored; i++ ) { fread( &card, 1, sizeof( card ), sav ); buffer.PushCard( card, true ); } for( unsigned char i = 0; i < CardsStored; i++ ) { wastepile.PushCard( buffer.PopCard(), true ); } //Restore HAND int HSource; fread( &HSource, 1, sizeof( HSource ), sav ); switch( HSource ) { case 0: hand.SetSource(NULL); break; case BLOCK: hand.SetSource(&block); break; case WASTEPILE: hand.SetSource(&wastepile); break; case FOUNDATION1: hand.SetSource(&foundation[0]); break; case FOUNDATION2: hand.SetSource(&foundation[1]); break; case FOUNDATION3: hand.SetSource(&foundation[2]); break; case FOUNDATION4: hand.SetSource(&foundation[3]); break; case TABLEAU1: hand.SetSource(&tableau[0]); break; case TABLEAU2: hand.SetSource(&tableau[1]); break; case TABLEAU3: hand.SetSource(&tableau[2]); break; case TABLEAU4: hand.SetSource(&tableau[3]); break; case TABLEAU5: hand.SetSource(&tableau[4]); break; case TABLEAU6: hand.SetSource(&tableau[5]); break; case TABLEAU7: hand.SetSource(&tableau[6]); break; } fread( &CardsStored, 1, sizeof( CardsStored ), sav ); buffer.RemoveAll(); for( unsigned char i = 0; i < CardsStored; i++ ) { fread( &card, 1, sizeof( card ), sav ); buffer.PushCard( card, true ); } for( unsigned char i = 0; i < CardsStored; i++ ) { hand.PushCard( buffer.PopCard(), true ); } //Restore Tableaus for( int j = 0; j < 7; j++ ) { fread( &CardsStored, 1, sizeof( CardsStored ), sav ); buffer.RemoveAll(); for( unsigned char i = 0; i < CardsStored; i++ ) { fread( &card, 1, sizeof( card ), sav ); buffer.PushCard( card, true ); } for( unsigned char i = 0; i < CardsStored; i++ ) { tableau[j].PushCard( buffer.PopCard(), true ); } } //Restore Foundations for( int j = 0; j < 4; j++ ) { fread( &CardsStored, 1, sizeof( CardsStored ), sav ); buffer.RemoveAll(); for( unsigned char i = 0; i < CardsStored; i++ ) { fread( &card, 1, sizeof( card ), sav ); buffer.PushCard( card, true ); } for( unsigned char i = 0; i < CardsStored; i++ ) { foundation[j].PushCard( buffer.PopCard(), true ); } } fclose( sav ); }
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; } } } }