Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication4
  8. {
  9.     class Program
  10.     {
  11.  
  12.  
  13.         static void Mrizka(int cislo, int[,] pole, int x, int y)
  14.         {
  15.            
  16.             if (cislo == 3)
  17.             {
  18.                 cislo = 2;
  19.             }
  20.  
  21.             for (int i = 0; i < pole.GetLength(0); i++)
  22.             {
  23.  
  24.                 for (int j = 0; j < pole.GetLength(1); j++)
  25.                 {
  26.                     Console.Write("|---");
  27.  
  28.                 }
  29.                 Console.WriteLine("|");
  30.                 for (int j = 0; j < pole.GetLength(0); j++)
  31.                 {
  32.                     if (x == j && y == i)
  33.                         Console.Write("| " + cislo + " ");
  34.                     else
  35.                         Console.Write("| " + " " + " ");
  36.                 }
  37.                 Console.WriteLine("|");
  38.             }
  39.             for (int k = 0; k < pole.GetLength(1); k++)
  40.             {
  41.                 Console.Write("|---");
  42.             }
  43.             Console.WriteLine("|");
  44.         }
  45.         static void Main(string[] args)
  46.         {
  47.             int[,] pole = new int[5, 5];
  48.             ConsoleKeyInfo key = new ConsoleKeyInfo();
  49.             int x = 0;
  50.             int y = 0;
  51.             Random nh = new Random();
  52.            int cislo = nh.Next(2, 5);
  53.             while (key.Key != ConsoleKey.Escape)
  54.             {
  55.                 Console.Clear();
  56.                 if (key.Key == ConsoleKey.UpArrow)
  57.                     y--;
  58.                 else if (key.Key == ConsoleKey.DownArrow)
  59.                     y++;
  60.                 else if (key.Key == ConsoleKey.RightArrow)
  61.                     x++;
  62.                 else if (key.Key == ConsoleKey.LeftArrow)
  63.                     x--;
  64.                 else if (key.Key == ConsoleKey.Enter)
  65.                     pole[y, x] = 1;
  66.  
  67.                 Mrizka(cislo,pole, x, y);
  68.                 key = Console.ReadKey();
  69.             }
  70.  
  71.  
  72.             Console.ReadLine();
  73.  
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement