Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace BauCua
- {
- 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 = Encoding.Unicode;
- origRow = Console.CursorTop;
- origCol = Console.CursorLeft;
- int x = 0, y = 0;
- render(x, y);
- while (true)
- {
- object ch = Console.ReadKey(false).Key;
- switch (ch)
- {
- case ConsoleKey.Escape:
- Environment.Exit(0);
- return;
- case ConsoleKey.UpArrow:
- y--;
- render(x, y);
- break;
- case ConsoleKey.DownArrow:
- y++;
- render(x, y);
- break;
- case ConsoleKey.RightArrow:
- x++;
- render(x, y);
- break;
- case ConsoleKey.LeftArrow:
- x--;
- render(x, y);
- break;
- case ConsoleKey.Enter:
- xuly(x, y);
- break;
- }
- }
- }
- static void xuly(int x, int y)
- {
- string[] cobac = {"Nai", "Bầu", "Gà", "Cá", "Cua", "Tôm"};
- Random ran = new Random();
- int so = ran.Next(0, 5);
- int current = 0;
- if (y >= 0 && y <= 4)
- {
- if (x < 5) current = 0;
- else if (x <= 10) current = 1;
- else if (x <= 15) current = 2;
- }
- else if (y <= 8)
- {
- if (x < 5) current = 3;
- else if (x <= 10) current = 4;
- else if (x <= 15) current = 5;
- }
- Console.SetCursorPosition(0, 10);
- Console.WriteLine($"PC : {cobac[so]} \nYou: {cobac[current]} ");
- if (so == current) Console.WriteLine("Bạn thắng rồi !! Hehe");
- else Console.WriteLine("Bạn thua rồi !! Sad :( ");
- }
- static void render(int x, int y)
- {
- Console.Clear();
- for (int i = 1; i < 16; i++)
- {
- for (int j = 0; j <= 8; j += 4)
- {
- WriteAt("-", i, j);
- }
- }
- for (int i = 1; i < 8; i++)
- {
- for (int j = 0; j <= 15; j += 5)
- {
- WriteAt("|", j, i);
- }
- }
- for (int i = 0; i <= 15; i += 5)
- {
- for (int j = 0; j <= 8; j += 4)
- {
- WriteAt("+", i, j);
- }
- }
- WriteAt("Nai", 2, 2);
- WriteAt("Bầu", 7, 2);
- WriteAt("Gà", 12, 2);
- WriteAt("Cá", 2, 6);
- WriteAt("Cua", 7, 6);
- WriteAt("Tôm", 12, 6);
- Console.SetCursorPosition(x, y);
- Console.Write("*");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement