• Sábado 20 de Abril de 2024, 16:30

Autor Tema:  Problema con llamar a una clase  (Leído 994 veces)

jonaSoft

  • Nuevo Miembro
  • *
  • Mensajes: 22
  • Nacionalidad: cl
    • Ver Perfil
    • http://jmonroy.wordpress.com/
Problema con llamar a una clase
« en: Lunes 2 de Febrero de 2009, 22:23 »
0
Al llamar a una clase me llama a toda la interfaz de tal clase , como evito eso?, porque necesito sumar el puntaje de la clase nivel1 con el puntaje de la clase nivel2.


Nivel1.cs

Código: Text
  1.  
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7.  
  8. namespace HasteMillonario
  9. {
  10.     class Nivel1
  11.     {
  12.         public Interfaz interfaz;
  13.         public Nivel2 nivel2;
  14.         string[] menuItems = { "1. Matricial,Laser,inyeccion de tinta",
  15.                                "2. Matriz,laser tuntual,inyeccion de puntos",
  16.                                "3  Matricial,laser a tinta,una lexmark"};
  17.         string pregunta ="¿Cuales son los 3 tipos de impresoras existente?";
  18.  
  19.         private int puntaje;
  20.         public int vpregunta = 1000, i = 0,Y=1;
  21.      
  22.         public int Puntaje
  23.         {
  24.             get { return puntaje; }
  25.             set { puntaje = value; }
  26.         }
  27.         public Nivel1()
  28.         {
  29.             while (!Console.KeyAvailable)
  30.             {
  31.                 Console.Clear();
  32.                 Console.SetCursorPosition(18, 3);
  33.                 Console.ForegroundColor = ConsoleColor.White;
  34.                 Console.Write("  Tu puntaje=$ " + puntaje + "        Valor pregunta=$ " + vpregunta + "n");
  35.                 interfazNivel();
  36.             }
  37.         }
  38.  
  39.         public void interfazNivel()
  40.         {
  41.             Console.SetCursorPosition(18, 5);
  42.             Console.ForegroundColor = ConsoleColor.Yellow;
  43.             Console.WriteLine(pregunta);
  44.             interfaz = new Interfaz();
  45.             Console.ForegroundColor = ConsoleColor.Blue;
  46.             interfaz.Marco(1, 99, 1, 35);
  47.             interfaz.Marco(18, 69, 8, 16);
  48.             for (int f = 0; f < 3; f++)
  49.             {
  50.                 Console.ForegroundColor = ConsoleColor.Yellow;
  51.                 Console.SetCursorPosition(26, 11 + f);
  52.                 Console.WriteLine(menuItems[f]);
  53.             }
  54.             interfaz.Resalta(Y, menuItems);
  55.             switch (Console.ReadKey().Key)
  56.             {
  57.                 case ConsoleKey.UpArrow:
  58.                     if (Y == 1) Y = 3; else Y--;
  59.                     break;
  60.                 case ConsoleKey.DownArrow:
  61.                     if (Y == 3) Y = 1; else Y++;
  62.                     break;
  63.                 case ConsoleKey.Enter:
  64.                     Ejecuta(Y);
  65.                     break;
  66.             }
  67.         }
  68.         public void Ejecuta(int Opc)
  69.         {
  70.             switch (Opc)
  71.             {
  72.                 case 1:
  73.                     nivel2 = new Nivel2();
  74.                     puntaje = puntaje + vpregunta;
  75.                     break;
  76.                 case 2:
  77.                     Console.Clear();
  78.                     break;
  79.                 case 3:
  80.                     Console.Clear();
  81.                     break;
  82.             }
  83.             Console.ReadKey();
  84.         }
  85.  
  86.     }
  87. }
  88.  
  89.  
  90.  

Nivel2.cs

Código: Text
  1.  
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace HasteMillonario
  8. {
  9.     class Nivel2
  10.     {
  11.         public Interfaz interfaz;
  12.         public Nivel1 nivel1;
  13.  
  14.         string[] menuItems = { "1. clear,date,direct,del.",
  15.                                "2. cd,cls,copy,tree.",
  16.                                "3. disk copy,rem,rd,moveto"};
  17.         string pregunta = "¿Indique cuales son los comandos correctos en ms-dos?";
  18.  
  19.         public int puntaje = 0, vpregunta = 1000, i = 0,Y=1;
  20.        
  21.  
  22.         public Nivel2()
  23.         {
  24.             [b]//puntaje = nivel1.Puntaje;[/b]
  25.             while (!Console.KeyAvailable)
  26.             {
  27.                 Console.Clear();
  28.                 Console.SetCursorPosition(18, 3);
  29.                 Console.ForegroundColor = ConsoleColor.White;
  30.                 Console.Write("  Tu puntaje=$ " + puntaje+ "Valor pregunta=$ " + vpregunta + "n");
  31.                 interfazNive2();
  32.             }
  33.         }
  34.         public void interfazNive2()
  35.         {
  36.             Console.SetCursorPosition(18, 5);
  37.             Console.ForegroundColor = ConsoleColor.Yellow;
  38.             Console.WriteLine(pregunta);
  39.             interfaz = new Interfaz();
  40.             Console.ForegroundColor = ConsoleColor.Blue;
  41.             interfaz.Marco(1, 99, 1, 35);
  42.             interfaz.Marco(18, 69, 8, 16);
  43.             for (int f = 0; f < 3; f++)
  44.             {
  45.                 Console.ForegroundColor = ConsoleColor.Yellow;
  46.                 Console.SetCursorPosition(26, 11 + f);
  47.                 Console.WriteLine(menuItems[f]);
  48.             }
  49.             interfaz.Resalta(Y, menuItems);
  50.             switch (Console.ReadKey().Key)
  51.             {
  52.                 case ConsoleKey.UpArrow:
  53.                     if (Y == 1) Y = 3; else Y--;
  54.                     break;
  55.                 case ConsoleKey.DownArrow:
  56.                     if (Y == 3) Y = 1; else Y++;
  57.                     break;
  58.                 case ConsoleKey.Enter:
  59.                     Ejecuta(Y);
  60.                     break;
  61.             }
  62.         }
  63.         public void Ejecuta(int Opc)
  64.         {
  65.             switch (Opc)
  66.             {
  67.                 case 1:
  68.                  
  69.                     break;
  70.                 case 2:
  71.                     Console.Clear();
  72.                     break;
  73.                 case 3:
  74.                     Console.Clear();
  75.                     break;
  76.             }
  77.             Console.ReadKey();
  78.         }
  79.  
  80.     }
  81. }
  82.  
  83.  
  84.  

Program.cs
Código: Text
  1.  
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7.  
  8. namespace HasteMillonario
  9. {
  10.     static class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             HasteMillonario game = new HasteMillonario();
  15.         }
  16.     }
  17. }
  18.  
  19.  
  20.  
  21.  

HasteMillonario.cs
Código: Text
  1.  
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading;
  8.  
  9. namespace HasteMillonario
  10. {
  11.     class HasteMillonario
  12.     {
  13.         public Interfaz interfaz;
  14.         string[] menuItems = { "Jugar", "Creditos", "Salir" };
  15.        
  16.  
  17.         public HasteMillonario()
  18.         {
  19.             int Y = 1;
  20.             Console.Title = "$$$ Haste Millonario $$$";
  21.             Console.ForegroundColor = ConsoleColor.DarkGreen;
  22.             Console.SetWindowSize(110, 40);
  23.             interfaz = new Interfaz();
  24.             string title = "$$$ Haste Millonario $$$+";
  25.  
  26.             while (!Console.KeyAvailable)
  27.             {
  28.                 Console.BackgroundColor = ConsoleColor.Blue;
  29.                 Console.Clear();
  30.                 Console.SetCursorPosition((Console.WindowWidth - title.Length) / 2,
  31.                                             Console.WindowHeight / 2);
  32.                 Console.BackgroundColor = ConsoleColor.Gray;
  33.                 Console.ForegroundColor = ConsoleColor.Red;
  34.                 Console.Write(title);
  35.  
  36.                 Thread.Sleep(500);
  37.  
  38.                 Console.BackgroundColor = ConsoleColor.Black;
  39.                 Console.Clear();
  40.                 Console.SetCursorPosition((Console.WindowWidth - title.Length) / 2,
  41.                                             Console.WindowHeight / 2);
  42.                 Console.BackgroundColor = ConsoleColor.Red;
  43.                 Console.ForegroundColor = ConsoleColor.Gray;
  44.                 Console.Write(title);
  45.                 Thread.Sleep(500);
  46.             }
  47.             Console.ReadKey(true);
  48.  
  49.             while (!Console.KeyAvailable)
  50.             {
  51.                 Console.ForegroundColor = ConsoleColor.Blue;
  52.                 Console.BackgroundColor = ConsoleColor.Black;
  53.                 Console.Clear();
  54.                 interfaz.Marco(1, 99, 1, 35);
  55.                 Console.SetCursorPosition(22, 5);
  56.                 Console.Write("**** Menu ****");
  57.                 for (int f = 0; f < 3; f++)
  58.                 {
  59.                     Console.SetCursorPosition(26, 11 + f);
  60.                     Console.WriteLine(menuItems[f]);
  61.                 }
  62.                 interfaz.Marco(18, 39, 8, 16);
  63.                 interfaz.Resalta(Y, menuItems);
  64.  
  65.                 switch (Console.ReadKey().Key)
  66.                 {
  67.                     case ConsoleKey.UpArrow:
  68.                         if (Y == 1) Y = 3; else Y--;
  69.                     break;
  70.                     case  ConsoleKey.DownArrow:
  71.                         if (Y == 3) Y = 1; else Y++;
  72.                     break;
  73.                     case ConsoleKey.Enter:
  74.                         interfaz.Ejecuta(Y);
  75.                     break;
  76.                 }
  77.             }
  78.         }
  79.      
  80.     }
  81. }
  82.  
  83.  
  84.  
  85.  

Faltan 2 clases mas , pero no creo que sean necesarias, bueno eso ojala pueda salir de esta duda ya que he postiado el mismo tema en otros foros y nadien entiende.

Saludos.