Advertisement
vovanhoangtuan

Bầu cua - Phương Hoàng

Apr 29th, 2020
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.27 KB | None | 0 0
  1. using System;
  2.  
  3. namespace TH_B3_bt2
  4. {
  5.     class Program
  6.     {
  7.         protected static int origRow;
  8.         protected static int origCol;
  9.  
  10.         protected static void WriteAt(string s, int x, int y)
  11.         {
  12.             try
  13.             {
  14.                 Console.SetCursorPosition(origCol + x, origRow + y);
  15.                 Console.Write(s);
  16.             }
  17.             catch (ArgumentOutOfRangeException e)
  18.             {
  19.                 Console.Clear();
  20.                 Console.WriteLine(e.Message);
  21.             }
  22.         }
  23.  
  24.         static void Main(string[] args)
  25.         {
  26.             Console.OutputEncoding = System.Text.Encoding.UTF8;
  27.             Console.Clear();
  28.             origRow = Console.CursorTop;
  29.             origCol = Console.CursorLeft;
  30.             //
  31.             int xchon = 0, ychon = 0;
  32.             render(xchon, ychon);
  33.  
  34.  
  35.             while (true)
  36.             {
  37.                 var ch = Console.ReadKey(false).Key;
  38.                 Console.Clear();
  39.  
  40.                 Random ran = new Random();
  41.                 int n = ran.Next(0, 6);
  42.  
  43.                 int chon = 0;
  44.                 if (xchon >= 0 && xchon <= 4 && ychon <= 4 && ychon >= 0)
  45.                     chon = 1;
  46.                 if (xchon >= 4 && xchon <= 8 && ychon <= 4 && ychon >= 0)
  47.                     chon = 2;
  48.                 if (xchon >= 8 && xchon <= 12 && ychon <= 4 && ychon >= 0)
  49.                     chon = 3;
  50.                 if (xchon >= 0 && xchon <= 4 && ychon <= 8 && ychon >= 4)
  51.                     chon = 4;
  52.                 if (xchon >= 4 && xchon <= 8 && ychon <= 8 && ychon >= 4)
  53.                     chon = 5;
  54.                 if (xchon >= 8 && xchon <= 12 && ychon <= 8 && ychon >= 4)
  55.                     chon = 6;
  56.  
  57.                 Console.SetCursorPosition(0, 18);
  58.  
  59.                 switch (ch)
  60.                 {
  61.  
  62.                     case ConsoleKey.UpArrow:
  63.                         ychon -= 1;
  64.                         render(xchon, ychon);
  65.                         break;
  66.  
  67.                     case ConsoleKey.DownArrow:
  68.                         ychon += 1;
  69.                         render(xchon, ychon);
  70.                         break;
  71.  
  72.                     case ConsoleKey.LeftArrow:
  73.                         xchon -= 1;
  74.                         render(xchon, ychon);
  75.                         break;
  76.                     case ConsoleKey.RightArrow:
  77.                         xchon += 1;
  78.                         render(xchon, ychon);
  79.                         break;
  80.                     case ConsoleKey.Enter:
  81.                         Console.WriteLine($"PC: {n} \nYou: {chon}");
  82.                         if (n == chon) Console.Write("You Win!!");
  83.                         else Console.WriteLine("You Lose!!");
  84.                         return;
  85.                 }
  86.             }
  87.  
  88.         }
  89.  
  90.         static void render(int i, int j)
  91.         {
  92.             WriteAt("+", 0, 0);
  93.             WriteAt("|", 0, 1);
  94.             WriteAt("|", 0, 2);
  95.             WriteAt("|", 0, 3);
  96.             WriteAt("+", 0, 4);
  97.             //
  98.             //
  99.             WriteAt("-", 1, 4);
  100.             WriteAt("-", 2, 4);
  101.             WriteAt("-", 3, 4);
  102.             WriteAt("+", 4, 4);
  103.             WriteAt("-", 5, 4);
  104.             WriteAt("-", 6, 4);
  105.             WriteAt("-", 7, 4);
  106.  
  107.  
  108.             WriteAt("|", 4, 3);
  109.             WriteAt("|", 4, 2);
  110.             WriteAt("|", 4, 1);
  111.             WriteAt("+", 4, 0);
  112.  
  113.             WriteAt("-", 1, 0);
  114.             WriteAt("-", 2, 0);
  115.             WriteAt("-", 3, 0);
  116.             ////
  117.             ///
  118.             WriteAt("-", 5, 0);
  119.             WriteAt("-", 6, 0);
  120.             WriteAt("-", 7, 0);
  121.             WriteAt("+", 8, 0);
  122.  
  123.             WriteAt("-", 9, 0);
  124.             WriteAt("-", 10, 0);
  125.             WriteAt("-", 11, 0);
  126.             WriteAt("+", 12, 0);
  127.  
  128.             WriteAt("|", 0, 5);
  129.             WriteAt("|", 0, 6);
  130.             WriteAt("|", 0, 7);
  131.             WriteAt("+", 0, 8);
  132.             WriteAt("-", 1, 8);
  133.             WriteAt("-", 2, 8);
  134.             WriteAt("-", 3, 8);
  135.  
  136.             WriteAt("|", 4, 5);
  137.             WriteAt("|", 4, 6);
  138.             WriteAt("|", 4, 7);
  139.             WriteAt("+", 4, 8);
  140.             WriteAt("-", 5, 8);
  141.             WriteAt("-", 6, 8);
  142.             WriteAt("-", 7, 8);
  143.  
  144.             WriteAt("|", 8, 3);
  145.             WriteAt("|", 8, 2);
  146.             WriteAt("|", 8, 1);
  147.             WriteAt("+", 8, 4);
  148.             WriteAt("-", 9, 4);
  149.             WriteAt("-", 10, 4);
  150.             WriteAt("-", 11, 4);
  151.  
  152.             WriteAt("|", 8, 5);
  153.             WriteAt("|", 8, 6);
  154.             WriteAt("|", 8, 7);
  155.             WriteAt("+", 8, 8);
  156.             WriteAt("-", 9, 8);
  157.             WriteAt("-", 10, 8);
  158.             WriteAt("-", 11, 8);
  159.  
  160.             WriteAt("|", 12, 3);
  161.             WriteAt("|", 12, 2);
  162.             WriteAt("|", 12, 1);
  163.             WriteAt("+", 12, 4);
  164.  
  165.             WriteAt("|", 12, 6);
  166.             WriteAt("|", 12, 7);
  167.             WriteAt("|", 12, 5);
  168.             WriteAt("+", 12, 8);
  169.  
  170.             WriteAt("Bau", 5, 2);
  171.             WriteAt("Cua", 5, 6);
  172.             WriteAt("Nai", 1, 2);
  173.             WriteAt("Tom", 9, 6);
  174.             WriteAt("Ga", 9, 2);
  175.             WriteAt("Ca", 1, 6);
  176.             Console.SetCursorPosition(i, j);
  177.             Console.Write("*");
  178.         }
  179.  
  180.     }
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement