Facebook
From holzbart, 5 Years ago, written in C#.
Embed
Download Paste or View Raw
Hits: 204
  1. using System;
  2. using System.Timers;
  3.  
  4. namespace ConsoleApp2
  5. {
  6.     class Program
  7.     {
  8.  
  9.         static void Main(string[] args)
  10.         {
  11.             //defining variables and references
  12.             Random rnd = new Random();
  13.             const string pool = "    0123456789!$%&~#";
  14.  
  15.             int width, height, timeinput;
  16.             decimal time = 0;
  17.             bool breakoff = false;
  18.  
  19.             Console.ForegroundColor = ConsoleColor.DarkGreen;
  20.  
  21.             //userinput
  22.             Console.WriteLine("Enter Width: (in characters)");
  23.             width = Convert.ToInt32(Console.ReadLine());
  24.  
  25.             Console.WriteLine("Enter Height: (in characters)");
  26.             height = Convert.ToInt32(Console.ReadLine());
  27.  
  28.             Console.WriteLine("Enter Runtime in min:");
  29.             timeinput = Convert.ToInt32(Console.ReadLine());
  30.  
  31.             Console.Clear();
  32.  
  33.             //setting up array for matrix
  34.             string[,] Zeile = new string[height, width];
  35.             int[] Indexspeicher = new int[width];
  36.  
  37.             do //endless loop (timer, forcequit)
  38.             {
  39.                 if (time%5 == 0)
  40.                 {
  41.                     for (int indexgen = 0; indexgen < width; indexgen++)
  42.                     {
  43.                         Indexspeicher[indexgen] = rnd.Next(2);
  44.                     }
  45.                 }
  46.  
  47.                 //fill matrix with random chars
  48.                 for (int row = 0; row < height; row++)
  49.                 {
  50.                     for (int chargen = 0; chargen < width; chargen++)
  51.                     {
  52.                         if(Indexspeicher[chargen] == 1)
  53.                         {
  54.                             var c = pool[rnd.Next(0, pool.Length)];
  55.                             Zeile[row, chargen] = Convert.ToString(c);
  56.                         }
  57.                     }
  58.                 }
  59.  
  60.                 //write matrix to string, less vsync
  61.                 int rowLength = Zeile.GetLength(0);
  62.                 int colLength = Zeile.GetLength(1);
  63.                 string output = "";
  64.                 for (int i = 0; i < rowLength; i++)
  65.                 {
  66.                     if (i > 0)
  67.                     {
  68.                         output += "\n";
  69.                     }
  70.                     for (int j = 0; j < colLength; j++)
  71.                     {
  72.                         output += string.Format("{0} ", Zeile[i, j]);
  73.                     }
  74.                 }
  75.  
  76.                 //format and output
  77.                 Console.WriteLine(output);
  78.                 Console.Write(Environment.NewLine + Environment.NewLine);
  79.  
  80.                 //forcequit
  81.                 if (Console.KeyAvailable)
  82.                     if (Console.ReadKey().KeyChar == 'Q')
  83.                         break;
  84.  
  85.                 //timer
  86.                 System.Threading.Thread.Sleep(1000);
  87.                 Console.Clear();
  88.                 time += 1;
  89.                 if (time >= (timeinput * 60))
  90.                 {
  91.                     breakoff = true;
  92.                 }
  93.  
  94.             } while (breakoff == false);
  95.         }
  96.     }
  97. }