All pastes #250650 Raw Edit

Untitled

public text v1 · immutable
#250650 ·published 2006-11-17 04:12 UTC
rendered paste body
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>

int Tablero[6][6], Tapada[6][6];


void Posicion(int &x, int &y, int o)
{
  int x1,y1;
  
  if(o%6==0)
  {
    x=5;
    y=o/6-1;
  }
  else
  {
    x=o%6-1;
    y=o/6;
  }
  
  x1=6*x+4;
  y1=6*y+4;
  gotoxy(x1,y1);  
}

void Dibujatab()
{
  int x, y, num;
  
  for(int h=1,x=1;h<=7;h++,x+=6)
  {
    for(int v=1,y=1;v<=37;v++,y++)
      {
      gotoxy(x,y);
      cout <<"|";
      }
  }
  
  for(int v=1,x=1,y=1;v<=7;v++,y+=6)
  {
    gotoxy(x,y);
    for(int h=1;h<=37;h++)
      cout << "*";
  }
  
  for(int u=1,y=2,num=1;u<=6;u++,y+=6)
    for(int r=1,x=2;r<=6;r++,x+=6)
    {
      gotoxy(x,y);
      cout << num;
      num++;
    }
  
  for(int cont=1;cont<=36;cont++)
  {
    Posicion(x,y,cont);
    if(Tapada[y][x]==false)
      cout << Tablero[y][x];
    else
      cout << "&";
  }

  
}

void LlenaTablero()
{
   int r, c, cont, carta;
   
   for (r = 0; r < 6; r++)
      for (c = 0; c < 6; c++)
      {
         Tablero[r][c] = 0;
         Tapada[r][c] = true;
      }   


   randomize();   
   for (cont = 1, carta = 1; cont <= 18; )	// cont para 18 pares
   {
           
        r = random(6);		
        	  c = random(6);		
                
  
  if (Tablero[r][c] == 0) 
        {
            Tablero[r][c] = cont; 
            if (carta == 1)     
              carta = 2;	  
            else
            {   
                cont++;		   
                carta = 1;	   
            }    
        }    
   }     
}

void main()
{
  LlenaTablero();
  int par=0,turnos=0;
  char f;
  
  cout << "Maximiza la pantalla y da 'Enter para empezar'" << endl;
  getche();
  
  do
  {
    turnos++;
    clrscr();
    Dibujatab();
    
    int x1,y1,x2,y2;
    
    gotoxy(45,10);
    cout << "Escoge una carta: ";
    int op1;
    
    do
    {
      gotoxy(63,10);
      cout << "                  ";
      gotoxy(63,10);
      cin >> op1;
      Posicion(x1,y1,op1);
    }while(op1<1||op1>36||Tapada[y1][x1]==false);
    
    cout << Tablero[y1][x1];
    
    gotoxy(45,20);
    cout << "Escoge otra carta: ";
    int op2;
    
    do
    {
      gotoxy(64,20);
      cout << "                  ";
      gotoxy(64,20);
      cin >> op2;
      Posicion(x2,y2,op2);
    }while(op2==op1||op2<1||op2>36||Tapada[y2][x2]==false);
    
    cout << Tablero[y2][x2];
    
    if(Tablero[y1][x1]==Tablero[y2][x2])
    {
      Tapada[y1][x1]=false;
      Tapada[y2][x2]=false;
      par++;
    }
    

    if(par<18)
    {
    
      gotoxy(45,30);
      cout << "Desea continuar? ";
    
      do
      {
      gotoxy(62,30);
      cout << "             ";
      gotoxy(62,30);
      cin >> f;
      f=tolower(f);
      }while(f!='s'&&f!='n');
    }
    else
    {
      gotoxy(45,30);
      cout << "Felicidades, ganaste en " << turnos << " turnos!";
      getche();
    }
    
  }while(f=='s'&&par<18);
}