/** * Program: Solo, a computer solitarie card game. * By: MD, md@tomatesasesinos.com * Copyright 2007 * * License: GPL http://www.gnu.org/licences/gpl.html * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * * File: graficos.h * Contents: The main program */ #include "globals.h" int main(int argc, char *argv[]) { iniciarJuego(); solitarioSDL(); return 0; } void iniciarJuego(void) { int i,j; //Iniciamos la semilla aleatoria srand(time(0)); //Llenando baraja for(i=0;i<52;i++) baraja[i]=i; //Limpiando de cartas el tablero for(i=0;i1) posicion=rand()%total; else posicion=0; naipe=quitarBaraja(posicion); /**/ if(reparto[donde]==1) { if(bocaArriba[donde]) meterPos(donde,naipe,BOCARRIBA); else meterPos(donde,naipe,BOCABAJO); }else meterPos(donde,naipe,BOCABAJO); reparto[donde]--; if(reparto[donde]==0) { while((donde<13)&&(reparto[donde]==0)) donde++; } } } int quitarBaraja(int pos) { int retorno=baraja[pos]; int i; for(i=pos;i<51;i++) { baraja[i]=baraja[i+1]; } baraja[i]=SINCARTA; return retorno; } void sacarCartaSacar(void) { meterPos(OLVIDAR,tablero[SACAR][0].numCarta,BOCARRIBA); retirarPos(SACAR); } void retirarPos(int posTablero) { int i; if((posTablero>=COLUMNA1)&&(tablero[posTablero][0].bocaArriba)) escalerasTablero[posTablero-COLUMNA1]--; for(i=0;i<51;i++) { tablero[posTablero][i]=tablero[posTablero][i+1]; } tablero[posTablero][51].numCarta=SINCARTA; cartasTablero[posTablero]--; } void rellenarPilaSacar(void) { int i; //Es diferente las posiciones en una matriz a la cantidad, para 3 elementos hay 0,1,2 posiciones por eso cartasTablero[OLVIDAR] se usa con < en el for y con -1 en las cuentas for(i=0;i=COLUMNA1) //No se pueden arrastrar gurpos de cartas en escalera a los palos { if((naipeDestino==SINCARTA)&&(numNaipeOrigenPrimero==REY)) legal=1; else { if(!tablero[destino][0].bocaArriba) { if(numNaipeOrigenPrimero==REY) legal=1; }else { if(((paloOrigenPrimero%2)!=(paloDestino%2))&&((numNaipeOrigenPrimero+1)==numNaipeDestino)) legal=1; } } } if(legal) { for(i=profundidadOrigen;i>=0;i--) meterPos(destino,tablero[origen][i].numCarta,BOCARRIBA); for(i=0;i<=profundidadOrigen;i++) retirarPos(origen); } } int moverPalos(int posTablero) { int retorno=0; int naipe=tablero[posTablero][0].numCarta; int palo=naipe/13; int numNaipe=naipe%13; //Numero de la carta dentro del palo int i; for(i=PALO1;i0) { if((tablero[i][0].numCarta/13)==palo) { //Para ver si es justo el anterior al que intentamos colocar if((tablero[i][0].numCarta%13)+1==numNaipe) break; } }else { if(tablero[i][0].numCarta==SINCARTA) break; } } if(i!=FINMONTONES) { meterPos(i,tablero[posTablero][0].numCarta,BOCARRIBA); retirarPos(posTablero); retorno=1; } return retorno; } void meterPos(int posTablero,int naipe,int bocaArriba) { hacerSitio(posTablero); tablero[posTablero][0].numCarta=naipe; tablero[posTablero][0].bocaArriba=bocaArriba; cartasTablero[posTablero]++; if((posTablero>=COLUMNA1)&&(bocaArriba)) escalerasTablero[posTablero-COLUMNA1]++; } void hacerSitio(int posTablero) { int i; for(i=50;i>=0;i--) { tablero[posTablero][i+1]=tablero[posTablero][i]; } } int victoria(void) { int retorno=1; int i; for(i=PALO1;i