StartupLogoPlayer.cs 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace JR62THD_V2 {
  7. class StartupLogoPlayer {
  8. public static void play() {
  9. string AsciiMap = Properties.Resources.ascii_map;
  10. const int AsciiMapHeight = 28; // <-- ASCII Map each line chars count
  11. const int AsciiMapWidth = 42; // <-- ASCII Map lines count
  12. const int AsciiMapLinesOffset = 2; // <-- each line ends with "\n\r" characters
  13. //Console.WriteLine("Press any key to continue");
  14. //Console.ReadKey(true);
  15. Console.Clear();
  16. //Default console color:
  17. Console.ForegroundColor = ConsoleColor.White;
  18. Console.BackgroundColor = ConsoleColor.Black;
  19. //an array of forground-colors for each sequence of animation
  20. ConsoleColor[] palet = { ConsoleColor.White, ConsoleColor.White, ConsoleColor.Black };
  21. Random rnd = new Random();
  22. Console.CursorVisible = false;
  23. for (int seq = 0; seq<=3; seq++) {
  24. //counting sequences of animation
  25. //when all posible positions for cursor had been wrote a sequence compeleted
  26. List<int[]> pos = new List<int[]>();
  27. for (int t = 2; t <= Console.BufferHeight - 3; t++)
  28. for (int l = 2; l <= Console.BufferWidth - 3; l++)
  29. pos.Add(new int[] { l, t });
  30. //a list of all posible cursor positions
  31. //I used a list to make sure that each position will use just once and also know when this sequence will finish
  32. //this sequence foreground color
  33. ConsoleColor foregroundColor = palet[seq >= palet.Length ? palet.Length - 1 : seq];
  34. //a dictionary of characters foreground and background color
  35. Dictionary<char, ConsoleColor[]> CharsColorDict = new Dictionary<char, ConsoleColor[]>();
  36. CharsColorDict['.'] = new ConsoleColor[]{
  37. (seq >= 2 ? ConsoleColor.Black : ConsoleColor.White), //foreground color
  38. (seq<=5?ConsoleColor.Blue:(ConsoleColor)(seq%15)) //background color, this will change in each sequence
  39. };
  40. CharsColorDict['#'] = new ConsoleColor[]{
  41. (seq >= 2 ? ConsoleColor.Gray : ConsoleColor.White), //foreground color
  42. ConsoleColor.White //background color
  43. };
  44. while (pos.Count > 0) {
  45. //choosing a random position:
  46. int r = rnd.Next(pos.Count - 1);
  47. int[] p = pos[r];
  48. pos.RemoveAt(r);
  49. Console.SetCursorPosition(p[0], p[1]);
  50. //calculating postion of cursor in ASCII map:
  51. int l = p[0] - ((Console.BufferWidth - AsciiMapWidth) / 2); //left
  52. int t = p[1] - ((Console.BufferHeight - AsciiMapHeight) / 2); //top
  53. Console.ForegroundColor = foregroundColor;
  54. Console.BackgroundColor = ConsoleColor.Black;
  55. if (seq >= 1 && l >= 0 && t >= 0 && l < 42 && t < 28) {
  56. // Index = (top * (lines_width + lines_offset) ) + left
  57. int index = t * (AsciiMapWidth + AsciiMapLinesOffset) + l;
  58. char c = AsciiMap[index];
  59. if (CharsColorDict.ContainsKey(c)) {
  60. Console.ForegroundColor = CharsColorDict[c][0];
  61. Console.BackgroundColor = CharsColorDict[c][1];
  62. }
  63. }
  64. Console.Write((char)rnd.Next((int)'!', (int)'z')); //a random character
  65. //System.Threading.Thread.Sleep(1); //wait after each sequence
  66. }
  67. }
  68. }
  69. }
  70. }