AYUDA y EJERCICIO - Truco de cartas en C#
Edu:
No se si conocen el truco de las cartas que vas creando 3 mazos poniendo:
MAZO 1 - - MAZO 2- - MAZO3
abajo -CartaNº1 - CartaNº2 - CartaNº3
arriba -CartaNº4 - CartaNº5 - CartaNº6
arriba de arriba -CartaNº7 - CartaNº8 - CartaNº9
Y el otro tiene q elegir una carta, pensarla no decirla, y decir en q mazo se encuentra la carta que penso. Entonces si por ejemplo penso la carta Nº7, dira que se encuentra en el mazo numero 1 y entonces lo q hace el repartidor es meter ese mazo en el medio de los tres para luego repartir asi:
MAZO 1 - - MAZO 2- - MAZO3
abajo -CartaNº9 - CartaNº6 - CartaNº3
arriba -CartaNº7 - CartaNº4 - CartaNº1
arriba de arriba -CartaNº8 - CartaNº5 - CartaNº2
Eso lo haces 3 veces y aclaro q el numero de cartas con el q se tiene q hacer son con 21 cartas. Porque entonces luego de la tercera vez que fue diciendo en q mazo estaba la que pensaba y vos ibas poniendo ese mazo en el medio de los 3 para luego repartir denuevo... Ya una vez metida la ultima vez el mazo en el medio ( la tercera vez) cuentas 11 cartas empezando desde arriba claro, y esa sera la carta q nuestro amigo penso.
Ahora si no lo conocian practiquenlo con cartas primero y luego a ver si pueden hacerlo en C# modo consola xD
Edu:
A mi me interesan como pueden lograrlos ustedes pero si pueden terminar el mio o mirar como lo he echo hasta donde llegue, estaria bueno ya que no puedo seguir :S talvez alguien lo arregla y lo muestra como su propia solucion.
Pero talvez algunos quieren entrenerse un buen rato y por eso lo dejo para el q quiera verlo y el q no que intente por su cuenta xD
Espero que se unan muchos, aca les dejo hasta donde llegue yo, espero tambien q alguien me lo termine xD
[spoiler]
Código
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
private static int[] Mazo = new int[21];
private static int[] SegundaR = new int[21];
private static int[] TerceraR = new int[21];
private static int[] CuartaR = new int[21];
private static int[] Pozo1 = new int[7];
private static int[] Pozo2 = new int[7];
private static int[] Pozo3 = new int[7];
private static int opc;
private static int j = 0;
private static int g = 0;
private static int h = 0;
private static int f = 20;
public static void Mostrar2(int[] pozon1, int[] pozon2, int[] pozon3, int numpozon)
{
Mostrar(pozon1,pozon2,pozon3,numpozon);
}
public static void Mostrar(int[] pozito1, int[] pozito2, int[] pozito3, int numpozo)
{
int mistake = 0;
do
{
Console.Clear();
Console.WriteLine();
Console.WriteLine(" - Elegiste el pozo numero {0}", numpozo);
Console.WriteLine();
try
{
Console.WriteLine("- POZO 1 -");
Console.WriteLine();
for (int i = 0; i < pozito1.Length; i++)
{
Console.WriteLine("Carta Nº: {0}", pozito1[i]);
}
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("- POZO 2 -");
Console.WriteLine();
for (int i = 0; i < pozito2.Length; i++)
{
Console.WriteLine("Carta Nº: {0}", pozito2[i]);
}
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("- POZO 3 -");
Console.WriteLine();
for (int i = 0; i < pozito3.Length; i++)
{
Console.WriteLine("Carta Nº: {0}", pozito3[i]);
}
Console.WriteLine(); Console.WriteLine();
Console.Write(" - Vuelve a escribir el pozo donde se encuentra tu numero: ");
opc = int.Parse(Console.ReadLine());
if ((opc != 1) && (opc != 2) && (opc != 3))
{
Console.Clear();
Console.WriteLine();
Console.WriteLine(" - NUMERO INCORRECTO, SON 3 POZOS SOLAMENTE xD");
mistake = 0;
Console.WriteLine();
Console.WriteLine(" Presione una tecla para volver..");
Console.ReadKey();
}
else mistake = 1;
}
catch
{ }
} while (mistake == 0);
int k = 0;
switch (opc)
{
case 1:
f = 20;
h = 0;
g = 0;
for (int i = 7; i < 14; i++)
{
TerceraR[k] = SegundaR[i];
k++;
}
for (int i = 0; i < 7; i++)
{
TerceraR[k] = SegundaR[i];
k++;
}
for (int i = 14; i < 21; i++)
{
TerceraR[k] = SegundaR[i];
k++;
}
for (int i = 0; i < 7; i++)
{
Pozo1[i] = SegundaR[f];
f--;
Pozo2[g] = SegundaR[f];
f--;
Pozo3[h] = SegundaR[f];
g++;
h++;
f--;
}
Mostrar2(Pozo1, Pozo2, Pozo3, 1);
break;
case 2:
f = 20;
h = 0;
g = 0;
for (int i = 14; i < 21; i++)
{
TerceraR[k] = SegundaR[i];
k++;
}
for (int i = 7; i < 14; i++)
{
TerceraR[k] = SegundaR[i];
k++;
}
for (int i = 0; i < 7; i++)
{
TerceraR[k] = SegundaR[i];
k++;
}
for (int i = 0; i < 7; i++)
{
Pozo1[i] = SegundaR[f];
f--;
Pozo2[g] = SegundaR[f];
f--;
Pozo3[h] = SegundaR[f];
g++;
h++;
f--;
}
Mostrar2(Pozo1, Pozo2, Pozo3, 2);
break;
case 3:
f = 20;
h = 0;
g = 0;
for (int i = 0; i < 7; i++)
{
TerceraR[k] = SegundaR[i];
k++;
}
for (int i = 14; i < 21; i++)
{
TerceraR[k] = SegundaR[i];
k++;
}
for (int i = 7; i < 14; i++)
{
TerceraR[k] = SegundaR[i];
k++;
}
for (int i = 0; i < 7; i++)
{
Pozo1[i] = SegundaR[f];
f--;
Pozo2[g] = SegundaR[f];
f--;
Pozo3[h] = SegundaR[f];
g++;
h++;
f--;
}
Mostrar2(Pozo1, Pozo2, Pozo3, 3);
break;
}
Console.ReadKey();
}
public static bool NumExists(int Num, int MaxPos)
{
bool resultado = false;
for (int i = 0; i < MaxPos; i++)
if (Mazo[i] == Num)
{
resultado = true;
break;
}
return resultado;
}
public static void RandomNumbers()
{
Random Rnd = new Random(unchecked((int)DateTime.Now.Ticks));
for (int i = 0; i < Mazo.Length; i++)
do
{
Mazo[i] = Rnd.Next(1,22);
} while (NumExists(Mazo[i], i) == true);
Rnd = null;
}
static void Main(string[] args)
{
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.Green;
Console.Title = "Adivinador";
Console.WindowHeight = 40;
Console.WindowWidth = 90;
int error = 0;
do
{
RandomNumbers();
Console.Clear();
Console.WriteLine();
Console.WriteLine(" - Se han repartido las cartas, piensa en una y recuerdala que tratare de adivinarla");
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("- POZO 1 -");
Console.WriteLine();
try
{
for (int i = 0; i < 7; i++)
Console.WriteLine("Carta Nº: {0}", Mazo[i]);
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("- POZO 2 -");
Console.WriteLine();
for (int i = 7; i < 14; i++)
Console.WriteLine("Carta Nº: {0}", Mazo[i]);
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("- POZO 3 -");
Console.WriteLine();
for (int i = 14; i < 21; i++)
Console.WriteLine("Carta Nº: {0}", Mazo[i]);
Console.WriteLine(); Console.WriteLine();
Console.Write(" - Tu carta elegida esta en el pozo numero: ");
int opc = int.Parse(Console.ReadLine());
error = 1;
switch (opc)
{
case 1:
f = 20;
h = 0;
g = 0;
for (int i = 7; i < 14; i++)
{
SegundaR[j] = Mazo[i];
j++;
}
for (int i = 0; i < 7; i++)
{
SegundaR[j] = Mazo[i];
j++;
}
for (int i = 14; i < 21; i++)
{
SegundaR[j] = Mazo[i];
j++;
}
for (int i = 0; i < 7; i++)
{
Pozo1[i] = SegundaR[f];
f--;
Pozo2[g] = SegundaR[f];
f--;
Pozo3[h] = SegundaR[f];
g++;
h++;
f--;
}
Mostrar(Pozo1, Pozo2, Pozo3, 1);
break;
case 2:
f = 20;
h = 0;
g = 0;
for (int i = 14; i < 21; i++)
{
SegundaR[j] = Mazo[i];
j++;
}
for (int i = 7; i < 14; i++)
{
SegundaR[j] = Mazo[i];
j++;
}
for (int i = 0; i < 7; i++)
{
SegundaR[j] = Mazo[i];
j++;
}
for (int i = 0; i < SegundaR.Length; i++)
{
Pozo1[i] = SegundaR[f];
f--;
Pozo2[g] = SegundaR[f];
f--;
Pozo3[h] = SegundaR[f];
g++;
h++;
f--;
}
Mostrar(Pozo1, Pozo2, Pozo3, 2);
break;
case 3:
f = 20;
h = 0;
g = 0;
for (int i = 0; i < 7; i++)
{
SegundaR[j] = Mazo[i];
j++;
}
for (int i = 14; i < 21; i++)
{
SegundaR[j] = Mazo[i];
j++;
}
for (int i = 7; i < 14; i++)
{
SegundaR[j] = Mazo[i];
j++;
}
for (int i = 0; i < SegundaR.Length; i++)
{
Pozo1[i] = SegundaR[f];
f--;
Pozo2[g] = SegundaR[f];
f--;
Pozo3[h] = SegundaR[f];
g++;
h++;
f--;
}
Mostrar(Pozo1, Pozo2, Pozo3, 3);
break;
default:
Console.Clear();
Console.WriteLine();
Console.WriteLine(" - NUMERO INCORRECTO, SON 3 POZOS SOLAMENTE xD");
error = 0;
Console.WriteLine();
Console.WriteLine(" Presione una tecla para volver..");
break;
}
Console.ReadKey();
}
catch
{ }
} while (error == 0);
}
}
}
[/spoiler]
Edu:
Se me hizo larguisimo el post perdonen, pero nadie se ha animado, no entiendo porq xD, yo si fuera un gran programador como mucho de ustedes me gustaria hacer todos los ejercicios q me propongan, les doy la oportunidad de q repasen, practiquen, comprueben si saben o no, y de paso ayudarme y no quieren xD
Lo dejare al post, talvez dentro de 2 años se anima alguien xD
[D4N93R]:
Esta el post de retos en .Net, si te animas puedes postear ahí, en el primer post están las reglas. Está en el subforo de Ejercicios :)
Edu:
Bueno pero como ves tambien es una ayuda, es decir estaria bueno q puedan completar o arreglar mi code para q funcione, no me vengan tampoco con lo de q nadie te va a hacer las cosas q tenes q estudiar y bla bla bla, porq ya esta planteada mi idea el error q tengo es lo q quiero si me pueden dar una mano, y este post recibio 280 visitas ya xD se ve q nadie se anima
Navegación
[#] Página Siguiente