/// <summary> /// Zeichnet Superman in die Konsole /// </summary> public void Draw() { for (int y = 0; y < 3; y++) { gr.WriteToBuffer(location.X, location.Y + y, superman[y], Store.colors[Settings.Default.SupermanAuswahl]); } }
/// <summary> /// Zeichnet jeden Stern aus der Liste in die Konsole /// </summary> public void Draw() { for (int i = 0; i < listPoints.Count; i++) { gr.WriteToBuffer(listPoints[i].X, listPoints[i].Y, STAR_ICON, Color); } }
public void Draw() { foreach (var powerup in listPowerup) { char powerUpChar = ' '; ConsoleAttribute powerupColor = ConsoleAttribute.FG_WHITE; switch (powerup.Item1) { case Powerup.Health: powerUpChar = PowerupChars.Health; powerupColor = PowerupColors.Health; break; case Powerup.Points: powerUpChar = PowerupChars.Points; powerupColor = PowerupColors.Points; break; case Powerup.Defense: powerUpChar = PowerupChars.Defense; powerupColor = PowerupColors.Defense; break; } gr.WriteToBuffer(powerup.Item2.X, powerup.Item2.Y, powerUpChar, powerupColor); } }
/// <summary> /// Zeichnet das Hauptmenü auf die Konsole /// </summary> public void Show() { // Main loop while (true) { ConsoleKeyInfo kInfo; do { gr.ClearBuffer(); // Positioniert das Logo mittig oben in der Konsole for (int i = 0; i < SUPERMAN_LOGO.Length; i++) { int length = SUPERMAN_LOGO[i].Length; for (int j = 0; j < length; j++) { // Offset 2 damit es nicht ganz oben am Rand ist sondern etwas drunter gr.SetCursorPosition(((gr.CONSOLE_WIDTH - length) / 2 + j), i + 2); if (SUPERMAN_LOGO[i][j] == 'ö') { // Hintergrund vom Superman Logo soll gelb sein gr.WriteToBuffer('#', ConsoleAttribute.FG_YELLOW); } else { // Der Rest rot gr.WriteToBuffer(SUPERMAN_LOGO[i][j], ConsoleAttribute.FG_RED); } } } // Menüpunkt anzeigen for (int i = 0; i < menuAuswahl.Length; i++) { gr.SetCursorPosition((gr.CONSOLE_WIDTH - menuAuswahl[i].Length) / 2, (gr.CONSOLE_HEIGHT / 2) + i); if (selectedIndex == i) { // Die Frabe des ausgewählten Menüpunkts ändern gr.WriteToBuffer(menuAuswahl[i], ConsoleAttribute.FG_GREEN); } else { // Standard Farbe gr.WriteToBuffer(menuAuswahl[i], ConsoleAttribute.FG_WHITE); } } gr.DrawBufferToConsole(); // Menüabfrage ob hoch oder runter bewegt wird kInfo = Console.ReadKey(true); if (kInfo.Key == ConsoleKey.UpArrow && selectedIndex > 0) { selectedIndex--; if (selectedIndex == 3) { selectedIndex = 2; } else if (selectedIndex == 7) { selectedIndex = 6; } } else if (kInfo.Key == ConsoleKey.DownArrow && selectedIndex < (menuAuswahl.Length - 1)) { selectedIndex++; if (selectedIndex == 3) { selectedIndex = 4; } else if (selectedIndex == 7) { selectedIndex = 8; } } } while (kInfo.Key != ConsoleKey.Enter); switch (selectedIndex) { case 0: // Normal Game game = new Game(gr); game.Start(Spielmodus.Normal); break; case 1: // Endlos Game game2 = new Game(gr); game2.Start(Spielmodus.Endlos); break; case 2: // Hardcore Game game3 = new Game(gr); game3.Start(Spielmodus.Hardcore); break; case 3: break; case 4: // Highscore Normal Highscore highscore = new Highscore(gr, Spielmodus.Normal); highscore.Draw(); break; case 5: // Highscore Endlos Highscore highscore2 = new Highscore(gr, Spielmodus.Endlos); highscore2.Draw(); break; case 6: // Highscore Hardcore Highscore highscore3 = new Highscore(gr, Spielmodus.Hardcore); highscore3.Draw(); break; case 7: break; case 8: // Store Store store = new Store(gr); store.Draw(); break; case 9: // Werkeinstellungen ResetSettings(); break; case 10: Environment.Exit(0); break; } } }
/// <summary> /// Zeigt den Loginscreen auf der Konsole an /// </summary> public void Show() { while (!loggedIn) { gr.ClearBuffer(); // Positioniert die Überschrift mittig in der Konsole for (int i = 0; i < STAR_OF_THE_UNIVERSE_SMALL.Length; i++) { gr.WriteToBuffer((gr.CONSOLE_WIDTH - STAR_OF_THE_UNIVERSE_SMALL[i].Length) / 2, i + 5, STAR_OF_THE_UNIVERSE_SMALL[i], ConsoleAttribute.FG_GREEN); } // Positioniert das wort "Passwort: " zentriert in Abhängigkeit von der Passwortlänge * 2 gr.WriteToBuffer((gr.CONSOLE_WIDTH - ("Passwort: " + PASSWORD + PASSWORD).Length) / 2, (gr.CONSOLE_HEIGHT / 2) - 1, "Passwort: "); for (int i = 0; i < PASSWORD.Length; i++) { if (input.Length > i) { // Für jedes eingegebene Zeichen soll ein "*" angezeigt werden gr.WriteToBuffer("* "); } else { // Für jedes leere Zeichen soll ein "_" angezeigt werden gr.WriteToBuffer("_ "); } } // Schreibt den gesamten Buffer in die Konsole gr.DrawBufferToConsole(); ConsoleKeyInfo kInfo = Console.ReadKey(true); if (kInfo.Key == ConsoleKey.Backspace) { if (input.Length > 0) { // Das letzte Zeichen löschen input = input.Remove(input.Length - 1, 1); } } else if (input.Length < PASSWORD.Length && kInfo.KeyChar >= 33 && kInfo.KeyChar <= 126) { // neues Zeichen hinzufügen input += kInfo.KeyChar; } else if (kInfo.Key == ConsoleKey.Enter) { if (input == PASSWORD) { loggedIn = true; // Passwort richtig, gehe raus aus der Schleife } else { input = ""; } } else if (kInfo.Key == ConsoleKey.Escape) { Environment.Exit(0); } } }
/// <summary> /// Zeichnet den Store auf die Konsole /// </summary> public void Draw() { this.currentSelectionIndex = Settings.Default.SupermanAuswahl; ConsoleKeyInfo kInfo = new ConsoleKeyInfo(); do { gr.ClearBuffer(); // Zeichnet das "Store" Logo mittig oben for (int i = 0; i < STORE_LOGO.Length; i++) { // Offset 5 damit es nicht ganz oben am Rand ist sondern etwas drunter gr.WriteToBuffer((gr.CONSOLE_WIDTH - STORE_LOGO[i].Length) / 2, i + 5, STORE_LOGO[i], ConsoleAttribute.FG_YELLOW); } int xCenter = gr.CONSOLE_WIDTH / 2; int yCenter = gr.CONSOLE_HEIGHT / 2; gr.WriteToBuffer(xCenter - (preise.Length * 7 / 2) - "Preis: ".Length - 5, yCenter + 5, "Preis: "); // Geht durch jede Auswahl durch und Zeichne for (int i = 0; i < preise.Length; i++) { // 3x3 -> mit rand = 5x5 // abstand von 2 px -> 7x5 int xOffsetToLeft = (preise.Length / 2) - i; int x = (xCenter - 2) - (xOffsetToLeft * 7); DrawSupermanAt(x, yCenter, colors[i]); // Jeweiligen Preis anzeigen if (!GetAuswahlByIndex(i)) { gr.WriteToBuffer(x, yCenter + 5, preise[i], ConsoleAttribute.FG_YELLOW); } } // Zeigt an welche Farbe zurzeit aktiv ist int xAuswahl = (gr.CONSOLE_WIDTH / 2) - (((preise.Length / 2) - Settings.Default.SupermanAuswahl) * 7) - 1; gr.WriteToBuffer(xAuswahl - ("Aktiv".Length / 2), yCenter - 3, "Aktiv", ConsoleAttribute.FG_RED); // Zeichnet das gerade ausgewählte Item mit einem Rechteck DrawRectangle(); // Zeichnet die aktuelle Anzahl an Sternen string stars = Settings.Default.Stars.ToString(); gr.WriteToBuffer((gr.CONSOLE_WIDTH - "Sterne: ".Length - stars.Length) / 2, yCenter + 15, "Sterne: "); gr.WriteToBuffer(stars, ConsoleAttribute.FG_YELLOW); // Zeichnet die Animation DrawAnimation(); gr.DrawBufferToConsole(); if (!Console.KeyAvailable) { continue; } kInfo = Console.ReadKey(true); if (kInfo.Key == ConsoleKey.Enter) { bool auswahlFreigeschaltet = false; switch (currentSelectionIndex) { case 0: auswahlFreigeschaltet = Settings.Default.Superman1; break; case 1: auswahlFreigeschaltet = Settings.Default.Superman2; break; case 2: auswahlFreigeschaltet = Settings.Default.Superman3; break; case 3: auswahlFreigeschaltet = Settings.Default.Superman4; break; default: auswahlFreigeschaltet = Settings.Default.Superman5; break; } // Wenn schon freigeschaltet, dann nur auswählen, ansonsten Kaufen if (auswahlFreigeschaltet) { Settings.Default.SupermanAuswahl = currentSelectionIndex; Settings.Default.Save(); } else { // Prüfen ob genug "Sterne" vorhanden sind if (Settings.Default.Stars >= preise[currentSelectionIndex]) { // Kaufen Settings.Default.Stars -= preise[currentSelectionIndex]; Settings.Default.SupermanAuswahl = currentSelectionIndex; switch (currentSelectionIndex) { case 0: Settings.Default.Superman1 = true; break; case 1: Settings.Default.Superman2 = true; break; case 2: Settings.Default.Superman3 = true; break; case 3: Settings.Default.Superman4 = true; break; default: Settings.Default.Superman5 = true; break; } Settings.Default.Save(); } } } else if (kInfo.Key == ConsoleKey.RightArrow) { // Auswahlrechteck nach rechts bewegen if (currentSelectionIndex < preise.Length - 1) { currentSelectionIndex++; } } else if (kInfo.Key == ConsoleKey.LeftArrow) { // Auswahlrechteck nach links bewegen if (currentSelectionIndex > 0) { currentSelectionIndex--; } } } while (kInfo.Key != ConsoleKey.Escape && kInfo.Key != ConsoleKey.Backspace); }
/// <summary> /// Zeichnet den Rand des Spiels /// </summary> private void DrawBorder() { int x = (gr.CONSOLE_WIDTH - GAME_WIDTH) / 2; int y = (gr.CONSOLE_HEIGHT - GAME_HEIGHT) / 2; // Top gr.WriteToBuffer(x + 1, y, new string(ConsoleGraphics.HORIZONTAL_BORDER, GAME_WIDTH - 2), borderColor); // Bottom Border gr.WriteToBuffer(x + 1, y + GAME_HEIGHT, new string(ConsoleGraphics.HORIZONTAL_BORDER, GAME_WIDTH - 2), borderColor); // Left/Right Border for (int i = 0; i < GAME_HEIGHT + 1; i++) { if (i == 0) { // top left gr.WriteToBuffer(x, y + i, ConsoleGraphics.EDGE_TOP_LEFT, borderColor); // top right gr.WriteToBuffer(x + GAME_WIDTH - 1, y + i, ConsoleGraphics.EDGE_TOP_RIGHT, borderColor); } else if (i == GAME_HEIGHT) { // bottom left gr.WriteToBuffer(x, y + i, ConsoleGraphics.CROSS_TO_RIGHT, borderColor); // bottom right gr.WriteToBuffer(x + GAME_WIDTH - 1, y + i, ConsoleGraphics.CROSS_TO_LEFT, borderColor); } else { // left gr.WriteToBuffer(x, y + i, ConsoleGraphics.VERTICAL_BORDER, borderColor); // right gr.WriteToBuffer(x + GAME_WIDTH - 1, y + i, ConsoleGraphics.VERTICAL_BORDER, borderColor); } } }