El_Ko
Cadet 4th Year
- Registriert
- Apr. 2013
- Beiträge
- 114
Hallo,
Ich möchte ein Programm schreiben (ja in der Konsole und NUR in der Konsole) das es dem User ermöglicht Dame zu spielen,
jedoch komme ich nicht weiter, da ich eine NullReferenceException habe, was immer die auch zu heissen hat.
Der Code:
Nur zur info, da fehlt noch viel... unter anderem das Ziehen, die Regeln,... mein Probelm liegt beim zuweisen...
beim ausgeben der Felder
Ich möchte ein Programm schreiben (ja in der Konsole und NUR in der Konsole) das es dem User ermöglicht Dame zu spielen,
jedoch komme ich nicht weiter, da ich eine NullReferenceException habe, was immer die auch zu heissen hat.
Der Code:
Code:
namespace DameSpiel
{
public class Feld
{
public Char FeldFarbe;
public Boolean Stein;
public Char SteinFarbe;
}
class Program //Hauptprogramm
{
static public Feld[,] arcBrett = new Feld[10, 10];
static void Main(string[] args)
{
BrettZuweisung();
FeldOutput();
Console.ReadKey();
}
static public void BrettZuweisung() //Spielsteine für Spielbeginn setzen
{
try
{
for (int y = 0; y < 10; y++)
{
for (int x = 0; x < 10; x++)
{
if (y % 2 == 0)
{
if (x % 2 == 0)
{
arcBrett[x, y].FeldFarbe = 'S';
arcBrett[x, y].Stein = true;
arcBrett[x, y].FeldFarbe = ' ';
}
else if (x % 2 != 0)
{
arcBrett[x, y].FeldFarbe = 'W';
arcBrett[x, y].Stein = true;
arcBrett[x, y].FeldFarbe = ' ';
}
}
else if (y % 2 != 0)
{
if (x % 2 == 0)
{
arcBrett[x, y].FeldFarbe = 'W';
arcBrett[x, y].Stein = true;
arcBrett[x, y].FeldFarbe = ' ';
}
else if (x % 2 != 0)
{
arcBrett[x, y].FeldFarbe = 'S';
arcBrett[x, y].Stein = true;
arcBrett[x, y].FeldFarbe = ' ';
}
}
}
}
}
catch (NullReferenceException)
{
Console.WriteLine("Fehler: NullrefrenceException");
}
}
static public void FeldOutput() //Anzeigen
{
for (int y = 0; y < 10; y++)
{
for (int x = 0; x < 10; x++)
{
switch (arcBrett[x, y].FeldFarbe)
{
case 'S':
Console.BackgroundColor = ConsoleColor.Black;
if (arcBrett[x, y].Stein == true)
{
switch (arcBrett[x, y].SteinFarbe)
{
case 'S':
Console.ForegroundColor = ConsoleColor.White;
Console.Write("X");
break;
case 'W':
Console.ForegroundColor = ConsoleColor.White;
Console.Write("0");
break;
case ' ':
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(" ");
break;
}
}
else if (arcBrett[x, y].Stein == false)
{
Console.ForegroundColor = ConsoleColor.Magenta;
Console.Write(" ");
}
break;
case 'W':
Console.BackgroundColor = ConsoleColor.White;
if (arcBrett[x, y].Stein == true)
{
switch (arcBrett[x, y].SteinFarbe)
{
case 'S':
Console.ForegroundColor = ConsoleColor.Black;
Console.Write("X");
break;
case 'W':
Console.ForegroundColor = ConsoleColor.Black;
Console.Write("0");
break;
}
}
else if (arcBrett[x, y].Stein == false)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write(" ");
}
break;
}
}
}
}
}
}
beim ausgeben der Felder