Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace TH_B3_bt2
- {
- class Program
- {
- protected static int origRow;
- protected static int origCol;
- protected static void WriteAt(string s, int x, int y)
- {
- try
- {
- Console.SetCursorPosition(origCol + x, origRow + y);
- Console.Write(s);
- }
- catch (ArgumentOutOfRangeException e)
- {
- Console.Clear();
- Console.WriteLine(e.Message);
- }
- }
- static void Main(string[] args)
- {
- Console.OutputEncoding = System.Text.Encoding.UTF8;
- Console.Clear();
- origRow = Console.CursorTop;
- origCol = Console.CursorLeft;
- //
- int xchon = 0, ychon = 0;
- render(xchon, ychon);
- while (true)
- {
- var ch = Console.ReadKey(false).Key;
- Console.Clear();
- Random ran = new Random();
- int n = ran.Next(0, 6);
- int chon = 0;
- if (xchon >= 0 && xchon <= 4 && ychon <= 4 && ychon >= 0)
- chon = 1;
- if (xchon >= 4 && xchon <= 8 && ychon <= 4 && ychon >= 0)
- chon = 2;
- if (xchon >= 8 && xchon <= 12 && ychon <= 4 && ychon >= 0)
- chon = 3;
- if (xchon >= 0 && xchon <= 4 && ychon <= 8 && ychon >= 4)
- chon = 4;
- if (xchon >= 4 && xchon <= 8 && ychon <= 8 && ychon >= 4)
- chon = 5;
- if (xchon >= 8 && xchon <= 12 && ychon <= 8 && ychon >= 4)
- chon = 6;
- Console.SetCursorPosition(0, 18);
- switch (ch)
- {
- case ConsoleKey.UpArrow:
- ychon -= 1;
- render(xchon, ychon);
- break;
- case ConsoleKey.DownArrow:
- ychon += 1;
- render(xchon, ychon);
- break;
- case ConsoleKey.LeftArrow:
- xchon -= 1;
- render(xchon, ychon);
- break;
- case ConsoleKey.RightArrow:
- xchon += 1;
- render(xchon, ychon);
- break;
- case ConsoleKey.Enter:
- Console.WriteLine($"PC: {n} \nYou: {chon}");
- if (n == chon) Console.Write("You Win!!");
- else Console.WriteLine("You Lose!!");
- return;
- }
- }
- }
- static void render(int i, int j)
- {
- WriteAt("+", 0, 0);
- WriteAt("|", 0, 1);
- WriteAt("|", 0, 2);
- WriteAt("|", 0, 3);
- WriteAt("+", 0, 4);
- //
- //
- WriteAt("-", 1, 4);
- WriteAt("-", 2, 4);
- WriteAt("-", 3, 4);
- WriteAt("+", 4, 4);
- WriteAt("-", 5, 4);
- WriteAt("-", 6, 4);
- WriteAt("-", 7, 4);
- WriteAt("|", 4, 3);
- WriteAt("|", 4, 2);
- WriteAt("|", 4, 1);
- WriteAt("+", 4, 0);
- WriteAt("-", 1, 0);
- WriteAt("-", 2, 0);
- WriteAt("-", 3, 0);
- ////
- ///
- WriteAt("-", 5, 0);
- WriteAt("-", 6, 0);
- WriteAt("-", 7, 0);
- WriteAt("+", 8, 0);
- WriteAt("-", 9, 0);
- WriteAt("-", 10, 0);
- WriteAt("-", 11, 0);
- WriteAt("+", 12, 0);
- WriteAt("|", 0, 5);
- WriteAt("|", 0, 6);
- WriteAt("|", 0, 7);
- WriteAt("+", 0, 8);
- WriteAt("-", 1, 8);
- WriteAt("-", 2, 8);
- WriteAt("-", 3, 8);
- WriteAt("|", 4, 5);
- WriteAt("|", 4, 6);
- WriteAt("|", 4, 7);
- WriteAt("+", 4, 8);
- WriteAt("-", 5, 8);
- WriteAt("-", 6, 8);
- WriteAt("-", 7, 8);
- WriteAt("|", 8, 3);
- WriteAt("|", 8, 2);
- WriteAt("|", 8, 1);
- WriteAt("+", 8, 4);
- WriteAt("-", 9, 4);
- WriteAt("-", 10, 4);
- WriteAt("-", 11, 4);
- WriteAt("|", 8, 5);
- WriteAt("|", 8, 6);
- WriteAt("|", 8, 7);
- WriteAt("+", 8, 8);
- WriteAt("-", 9, 8);
- WriteAt("-", 10, 8);
- WriteAt("-", 11, 8);
- WriteAt("|", 12, 3);
- WriteAt("|", 12, 2);
- WriteAt("|", 12, 1);
- WriteAt("+", 12, 4);
- WriteAt("|", 12, 6);
- WriteAt("|", 12, 7);
- WriteAt("|", 12, 5);
- WriteAt("+", 12, 8);
- WriteAt("Bau", 5, 2);
- WriteAt("Cua", 5, 6);
- WriteAt("Nai", 1, 2);
- WriteAt("Tom", 9, 6);
- WriteAt("Ga", 9, 2);
- WriteAt("Ca", 1, 6);
- Console.SetCursorPosition(i, j);
- Console.Write("*");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement