Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Threading;
  4.  
  5. namespace testovaci
  6. {
  7.     class MainClass
  8.     {
  9.         private static void Prochazej(int delka = 10, int pozice = 0, int citac = 0)
  10.         {
  11.             if (delka == Math.Abs (pozice)) {
  12.                 Console.WriteLine (pozice > 0 ? "Doma." : "V hospodě.");
  13.                 Console.WriteLine ("Počet kroků: {0}", citac);
  14.                 return;
  15.             }
  16.             var nahoda = new Random ();
  17.             var prochazka = Enumerable.Range (1, 2 * delka-1).
  18.                 Select (i => i == (delka + pozice) ? '#' : '-').
  19.                 ToArray ();
  20.             Thread.Sleep (50);
  21.             Console.Clear ();
  22.             Console.WriteLine (prochazka);
  23.             pozice += nahoda.Next (1, 100) < 70 ? -1 : 1;
  24.             Prochazej (pozice: pozice, citac: citac+1);
  25.         }
  26.         public static void Main (string[] args)
  27.         {
  28.             do
  29.             {
  30.                 Prochazej();
  31.                 Console.WriteLine("Skončit stiskem Q, jinak znovu!");
  32.             }   while (Console.ReadKey().KeyChar != 'q');
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement