public World() { Console.CursorVisible = false; HasWon = false; CurrentRoom = new Room(); Score += 1000; // Players and enemies Player1 = new Player('@', new Coordinate(1, 1), ConsoleColor.Green); EnemyEntity enemy1 = new EnemyEntity('¶', new Coordinate(8, 17), ConsoleColor.DarkRed, 100); EnemyEntity enemy2 = new EnemyEntity('¶', new Coordinate(8, 4), ConsoleColor.DarkCyan, 200); // Add the walls of the level CurrentRoom.BuildWalls(); // Draw them to the displaygrid CurrentRoom.DrawTraps(); CurrentRoom.DrawWalls(); Coin coin1 = new Coin(3, 15, ConsoleColor.Yellow, 'o', 100); Coin coin2 = new Coin(2, 6, ConsoleColor.Yellow, 'o', 100); Coin coin3 = new Coin(1, 13, ConsoleColor.Yellow, 'o', 100); Coin superCoin = new Coin(8, 1, ConsoleColor.Red, 'O', 250); Lever lever1 = new Lever(new Coordinate(4, 18), ConsoleColor.Magenta, CurrentRoom.RemoveWall, "Wall5"); Lever lever3 = new Lever(new Coordinate(4, 1), ConsoleColor.Green, CurrentRoom.RemoveWall, ""); Lever lever2 = new Lever(new Coordinate(8, 18), ConsoleColor.Green, CurrentRoom.RemoveWall, "Wall9"); Lever trap1 = new Lever(new Coordinate(1, 10), ConsoleColor.Yellow, CurrentRoom.RemoveTrap, "Spike"); ItemKey redKey = new ItemKey(4, 8, ConsoleColor.Red, '¥'); ItemKey yellowKey = new ItemKey(13, 8, ConsoleColor.Yellow, '¥'); Door doorRed = new Door(14, 5, ConsoleColor.Red, redKey); Exit doorGold = new Exit(10, 8, ConsoleColor.Yellow, yellowKey); do { Console.CursorLeft = 0; Console.CursorTop = 0; // Update the players view range. Player1.UpdateVisible(); // Draw the map and inventory to console. CurrentRoom.Draw(); Player1.DrawInventory(); // Get user input and move the player and update view range again. Player1.Move(); Player1.UpdateVisible(); enemy1.Move(); enemy2.Move(); // Checks if there are any items that can be picked up. Player1.CheckTile(); } while (Player1.IsAlive && Score >= 0 && !HasWon); Console.Clear(); if (!HasWon) { Console.WriteLine("Game Over!"); } else { Console.WriteLine("You won!"); Console.WriteLine($"Your score was: {Score}"); } System.Threading.Thread.Sleep(1000); Console.ReadKey(); }
private static void InitialDirectX() { rand = new Random(); player = new Player(20, 20, 25, 0); items = new List <Item>(); // for(int i = 0; i< rand.Next(2,4); i++) int k = rand.Next(1, 2); int j = rand.Next(0, 1); for (int i = 0; i < 5; i++) { Item item = new Item(RandomGenerate.GetCoord((k * i + j) % 9).X, RandomGenerate.GetCoord((k * i + j) % 9).Y); items.Add(item); } exit = new Exit(RandomGenerate.GetCoord(rand.Next(9, 12)).X, RandomGenerate.GetCoord(rand.Next(9, 12)).Y); polygons = new List <Polygon>(); uniqueAngles = new List <float>(); uniqueAnglesNotOnFOV = new List <float>(); intersects = new List <ParamPoint>(); backViewSide = new List <PointF>(); mouseRay = new Ray { Begin = new PointF(player.X, player.Y), Mouse = new PointF(Cursor.Position.X, Cursor.Position.Y) }; raysFOG = new List <Ray>(); raysBACK = new List <Ray>(); // creat form; renderForm = new RenderForm(title); // set windows size renderForm.Size = new System.Drawing.Size(892, 498); renderForm.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; // creat swapchain var swapChainDesc = new SwapChainDescription() { BufferCount = 4, Flags = SwapChainFlags.AllowModeSwitch, IsWindowed = true, ModeDescription = new ModeDescription(0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm), OutputHandle = renderForm.Handle, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }; D3D.FeatureLevel[] featureLevel = { D3D.FeatureLevel.Level_9_3, D3D.FeatureLevel.Level_10_1, D3D.FeatureLevel.Level_11_1 }; Device.CreateWithSwapChain(D3D.DriverType.Hardware, DeviceCreationFlags.BgraSupport, featureLevel, swapChainDesc, out device, out swapChain); Surface backbuffer = Surface.FromSwapChain(swapChain, 0); factory2d = new Factory2D(FactoryType.MultiThreaded); var dpi = factory2d.DesktopDpi; renderTarget = new RenderTarget(factory2d, backbuffer, new RenderTargetProperties() { DpiX = dpi.Width, DpiY = dpi.Height, MinLevel = FeatureLevel.Level_9, PixelFormat = new PixelFormat(Format.R8G8B8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Ignore), Type = RenderTargetType.Default, Usage = RenderTargetUsage.None }); // auto resize windows system renderForm.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; renderTarget.AntialiasMode = AntialiasMode.Aliased; renderTarget.TextAntialiasMode = TextAntialiasMode.Aliased; using (SharpDX.DirectWrite.Factory textFactory = new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Shared)) { textFormat = new Text( textFactory, "MS Sans Serif", SharpDX.DirectWrite.FontWeight.SemiBold, SharpDX.DirectWrite.FontStyle.Normal, SharpDX.DirectWrite.FontStretch.Medium, 16.0f); } renderForm.Click += RenderForm_Click; renderForm.KeyUp += RenderForm_KeyUp; renderForm.KeyDown += RenderForm_KeyDown; renderForm.Load += RenderForm_Load; renderForm.MouseMove += RenderForm_MouseMove; }