private static void InitSchaakbord(Schaakstuk[,] schaakbord) { // maak schaakbord leeg for (int r = 0; r < schaakbord.GetLength(0); r++) { for (int k = 0; k < schaakbord.GetLength(1); k++) { schaakbord[r, k] = null; } } // plaats witte schaakstukken ('bovenaan') schaakbord[0, 0] = new Schaakstuk(SchaakstukType.Toren, SchaakstukKleur.Wit); schaakbord[0, 1] = new Schaakstuk(SchaakstukType.Paard, SchaakstukKleur.Wit); schaakbord[0, 2] = new Schaakstuk(SchaakstukType.Loper, SchaakstukKleur.Wit); schaakbord[0, 3] = new Schaakstuk(SchaakstukType.Koning, SchaakstukKleur.Wit); schaakbord[0, 4] = new Schaakstuk(SchaakstukType.Koningin, SchaakstukKleur.Wit); schaakbord[0, 5] = new Schaakstuk(SchaakstukType.Loper, SchaakstukKleur.Wit); schaakbord[0, 6] = new Schaakstuk(SchaakstukType.Paard, SchaakstukKleur.Wit); schaakbord[0, 7] = new Schaakstuk(SchaakstukType.Toren, SchaakstukKleur.Wit); //pionen for (int i = 0; i < schaakbord.GetLength(1); i++) { schaakbord[1, i] = new Schaakstuk(SchaakstukType.Pion, SchaakstukKleur.Wit); schaakbord[6, i] = new Schaakstuk(SchaakstukType.Pion, SchaakstukKleur.Zwart); } // plaats zwarte schaakstukken ('onderaan') schaakbord[7, 0] = new Schaakstuk(SchaakstukType.Toren, SchaakstukKleur.Zwart); schaakbord[7, 1] = new Schaakstuk(SchaakstukType.Paard, SchaakstukKleur.Zwart); schaakbord[7, 2] = new Schaakstuk(SchaakstukType.Loper, SchaakstukKleur.Zwart); schaakbord[7, 3] = new Schaakstuk(SchaakstukType.Koning, SchaakstukKleur.Zwart); schaakbord[7, 4] = new Schaakstuk(SchaakstukType.Koningin, SchaakstukKleur.Zwart); schaakbord[7, 5] = new Schaakstuk(SchaakstukType.Loper, SchaakstukKleur.Zwart); schaakbord[7, 6] = new Schaakstuk(SchaakstukType.Paard, SchaakstukKleur.Zwart); schaakbord[7, 7] = new Schaakstuk(SchaakstukType.Toren, SchaakstukKleur.Zwart); }
private static void ToonSchaakbord(Schaakstuk[,] schaakbord) { Console.Clear(); // save colors ConsoleColor backgroundBackup = Console.BackgroundColor; ConsoleColor foregroundBackup = Console.ForegroundColor; // print letters bovenaan schaakbord Console.WriteLine(" A B C D E F G H "); for (int r = 0; r < schaakbord.GetLength(0); r++) { Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Gray; Console.Write("{0}", r + 1); for (int k = 0; k < schaakbord.GetLength(1); k++) { // toggle background color if ((r + k)%2 == 0) Console.BackgroundColor = ConsoleColor.DarkYellow; else Console.BackgroundColor = ConsoleColor.Gray; Schaakstuk schaakstuk = schaakbord[r, k]; if (schaakstuk == null) { Console.Write(" "); continue; } // stel de fontkleur in, afhankelijk van de kleur van het schaakstuk if (schaakstuk.kleur == SchaakstukKleur.Wit) Console.ForegroundColor = ConsoleColor.White; else if (schaakstuk.kleur == SchaakstukKleur.Zwart) Console.ForegroundColor = ConsoleColor.Black; else Console.ForegroundColor = ConsoleColor.Cyan; // print het schaakstuk switch (schaakstuk.type) { case SchaakstukType.Koning: Console.Write(" K "); break; case SchaakstukType.Koningin: Console.Write(" Q "); break; case SchaakstukType.Loper: Console.Write(" L "); break; case SchaakstukType.Paard: Console.Write(" P "); break; case SchaakstukType.Pion: Console.Write(" p "); break; case SchaakstukType.Toren: Console.Write(" T "); break; } } Console.WriteLine(); } // restore colors Console.BackgroundColor = backgroundBackup; Console.ForegroundColor = foregroundBackup; }