/* Autors: Ralfs Emīls Saldnieks 110.gr. Projekta nosk.: Worms 2d Apraksts: Worms spele, kas console izvadas ar braille simboliem. Veidots: 25.05.2026. Papildus: Jaizmanto visual studio, jo online kompaileris vienmer ka konsoles izmeru atgriez 0. */ using System; namespace Game { enum Blocks { Air, Block, } class Object { public double posX; public double posY; public double vy; public Object(double x = 0.0, double y = 0.0, double velocity_y = 0.0){ posX = x; posY = y; vy = velocity_y; } } class Player:Object { public Player(double x, double y, double velocity_y) : base(x, y, velocity_y){} public void drawGravity(List element_list, Screen screen){ double g = 1.0; int y = (int)posY; int x = (int)posX; double vy = 3.0; double vx = 3.0; int t = 0; while(screen.screen[y,x] && t < 10) { y = (int)(y-vy); x = (int)(x+vx); vy -= g; if(y=0 && x= 0) screen.screen[y,x] = true; //element_list.Add(new Object(x,y)); t++; } } } public class KeyboardInput { private HashSet pressedKeys = new HashSet(); private object lockObj = new object(); private Thread inputThread; private bool running = true; public KeyboardInput() { inputThread = new Thread(ReadKeysLoop); inputThread.IsBackground = true; inputThread.Start(); } private void ReadKeysLoop() { while (running) { if (Console.KeyAvailable) { var keyInfo = Console.ReadKey(true); char key = char.ToLower(keyInfo.KeyChar); lock (lockObj) { pressedKeys.Add(key); } ThreadPool.QueueUserWorkItem(_ => { Thread.Sleep(120); lock (lockObj) { pressedKeys.Remove(key); } }); } Thread.Sleep(15); } } public bool IsKeyPressed(char key) { lock (lockObj) { return pressedKeys.Contains(char.ToLower(key)); } } public void Stop() { running = false; } } class WorldGrid { public Blocks[,] grid; public WorldGrid(int sizeY, int sizeX){ grid = new Blocks[sizeY, sizeX]; Random rnd = new Random(); for(int i = 0; i < grid.GetLength(0); ++i){ for(int j = 0; j < grid.GetLength(1); ++j){ if(rnd.Next(10) == 1)grid[i,j] = Blocks.Block; else grid[i,j] = Blocks.Air; } } } } class Screen { public bool[,] screen; public Screen() {} public void ClearScreen(WorldGrid world_grid) { screen = new bool[world_grid.grid.GetLength(0)*4,world_grid.grid.GetLength(1)*4]; for(int i = 0; i < screen.GetLength(0); ++i){ for(int j = 0; j < screen.GetLength(1); ++j){ if(world_grid.grid[i/4,j/4] == Blocks.Block)screen[i,j] = true; } } } private char CalculateBraille(bool[] dots){ int sum = 0; for (int i = 0; i < 8; i++){ if (dots[i]){ sum += (int)Math.Pow(2, i); } } return (char)(0x2800 + sum); } public void DrawScreen(List element_list) { foreach (Object e in element_list) { screen[(int)e.posY, (int)e.posX] = true; } element_list.Clear(); for (int y = 0; y < screen.GetLength(0) / 4; y++){ for (int x = 0; x < screen.GetLength(1) / 2; x++){ bool[] dots = new bool[8]; // Sagatavo ekrāna vērtības lai pārvērstu tos braille simbolos // 0 3 // 1 4 // 2 5 // 6 7 if (screen[y * 4, x * 2]) dots[0] = true; if (screen[y * 4 + 1, x * 2]) dots[1] = true; if (screen[y * 4 + 2, x * 2]) dots[2] = true; if (screen[y * 4, x * 2 + 1]) dots[3] = true; if (screen[y * 4 + 1, x * 2 + 1]) dots[4] = true; if (screen[y * 4 + 2, x * 2 + 1]) dots[5] = true; if (screen[y * 4 + 3, x * 2]) dots[6] = true; if (screen[y * 4 + 3, x * 2 + 1]) dots[7] = true; Console.SetCursorPosition(x, y); Console.Write(CalculateBraille(dots)); } if(y != screen.GetLength(0)/4-1)Console.WriteLine(); } } } class Program { static void Main(string[] args){ WorldGrid world_grid = new WorldGrid(Console.WindowHeight,Console.WindowWidth/2); Screen screen_ctl = new Screen(); screen_ctl.ClearScreen(world_grid); List element_list = new List(); Console.CursorVisible = false; KeyboardInput input = new KeyboardInput(); Player player = new Player(50,50, 1.0); Console.Clear(); while(true){ if (input.IsKeyPressed('a')) player.posX -= 1.0; if (input.IsKeyPressed('d')) player.posX += 1.0; if(world_grid.grid[((int)(player.posY)+Math.Max((int)player.vy,1))/4,(int)(player.posX)/4] == Blocks.Block){ if(input.IsKeyPressed('w')) player.vy = -2.5; else player.vy = 0.0; } player.posY += player.vy; if(player.vy <= 3.0) player.vy += 0.25; if (input.IsKeyPressed('e')) { player.drawGravity(element_list, screen_ctl); } if(player.posY<0)player.posY = 0; if(player.posX<0)player.posX = 0; element_list.Add(new Object(player.posX, player.posY)); screen_ctl.DrawScreen(element_list); screen_ctl.ClearScreen(world_grid); Thread.Sleep(100); } } } }