/// <summary> /// Overwrites the given position with the given character. /// </summary> /// <param name="position">The position to write to.</param> /// <param name="character">The character to write.</param> private static void RefreshChar(Position position, char character) { try { Console.SetCursorPosition(position.Y, position.X); // Display the ghost in color. if (coloredMap) { // Handles the characters. switch (character) { case '#': Console.ForegroundColor = ConsoleColor.DarkCyan; break; case 'x': Console.ForegroundColor = ConsoleColor.Blue; break; case '+': Console.ForegroundColor = ConsoleColor.Red; break; case ' ': break; } Console.Write(character); Console.ForegroundColor = ConsoleColor.Gray; } // Display the ghost in black and white. else { Console.Write(character); } Console.SetCursorPosition(0, 24); } catch { } }
/// <summary> /// Validates the next step of the snake. /// </summary> /// <param name="newposition">The new position.</param> /// <param name="troncolor">The tron's color.</param> private static void ValidateNextStep(Position newposition, Tron.TronColors troncolor) { try { switch (map[newposition.X, newposition.Y]) { case ' ': foreach (Tron oneTron in trons) { if (oneTron.TronColor == troncolor) { // Draw the tron on the map and the display. oneTron.Position = newposition; RefreshChar(oneTron.Position, oneTron.Draw()); map[oneTron.Position.X, oneTron.Position.Y] = oneTron.Draw(); } } break; case 'x': case '+': case '#': foreach (Tron oneTron in trons) { if (oneTron.TronColor == troncolor) { // Sets the tron's alive status to false. oneTron.IsAlive = false; } } gameStatus = GameStages.Menu; break; } } catch { } }
/// <summary> /// Repositions the Tron. /// </summary> /// <param name="newposition">The new position of the Tron.</param> public void Reposition(Position newposition) { try { // Sets the position's value to the new position. this.position.X = newposition.X; this.position.Y = newposition.Y; } catch { } }
/// <summary> /// Changes the text at the given position. /// </summary> /// <param name="position">The position to write.</param> /// <param name="text">The test to write.</param> private static void ChangeText(Position position, string text) { try { Console.SetCursorPosition(position.Y, position.X); Console.BackgroundColor = ConsoleColor.Gray; Console.ForegroundColor = ConsoleColor.Black; Console.Write(text); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Gray; Console.SetCursorPosition(1, 9); } catch { } }
/// <summary> /// Initializes a new instance of the <see cref="Tron"/> class. /// </summary> /// <param name="position">The position of the Tron.</param> /// <param name="troncolor">The color of the Tron.</param> /// <param name="direction">The direction of the Tron.</param> /// <param name="isalive">The tron is alive.</param> public Tron(Position position, TronColors troncolor, Directions direction, bool isalive) { this.Position = position; this.TronColor = troncolor; this.Direction = direction; this.IsAlive = isalive; }