Пример #1
0
        public QuickSelectPane() : base(Settings.Config.WindowWidth - Settings.Config.ToolPaneWidth + 1, 3)
        {
            textSurface.Font = Settings.Config.ScreenFont;
            textSurface.DefaultBackground = Settings.Color_MenuBack;
            textSurface.DefaultForeground = Settings.Color_TitleText;

            currentCharSet = 0;

            keys = new AsciiKey[] { AsciiKey.Get(Microsoft.Xna.Framework.Input.Keys.F1), AsciiKey.Get(Microsoft.Xna.Framework.Input.Keys.F2), AsciiKey.Get(Microsoft.Xna.Framework.Input.Keys.F3),
                                    AsciiKey.Get(Microsoft.Xna.Framework.Input.Keys.F4), AsciiKey.Get(Microsoft.Xna.Framework.Input.Keys.F5), AsciiKey.Get(Microsoft.Xna.Framework.Input.Keys.F6),
                                    AsciiKey.Get(Microsoft.Xna.Framework.Input.Keys.F7), AsciiKey.Get(Microsoft.Xna.Framework.Input.Keys.F8), AsciiKey.Get(Microsoft.Xna.Framework.Input.Keys.F9),
                                    AsciiKey.Get(Microsoft.Xna.Framework.Input.Keys.F10), AsciiKey.Get(Microsoft.Xna.Framework.Input.Keys.F11), AsciiKey.Get(Microsoft.Xna.Framework.Input.Keys.F12) };

            if (System.IO.File.Exists("quickselect.json"))
            {
                CharacterSets = SadConsole.Serializer.Load <int[][]>("quickselect.json");
                Characters    = CharacterSets[0];
            }
            else
            {
                Characters       = new int[] { (char)176, (char)177, (char)178, (char)219, (char)223, (char)220, (char)221, (char)222, (char)254, (char)250, (char)249, (char)0 };
                CharacterSets    = new int[3][];
                CharacterSets[0] = Characters;
                CharacterSets[1] = new int[] { (char)218, (char)191, (char)192, (char)217, (char)196, (char)179, (char)195, (char)180, (char)193, (char)194, (char)197, (char)0 };
                CharacterSets[2] = new int[] { (char)201, (char)187, (char)200, (char)188, (char)205, (char)186, (char)204, (char)185, (char)202, (char)203, (char)206, (char)0 };
            }

            UseMouse    = false;
            UseKeyboard = false;

            UsePixelPositioning = true;
            Position            = new Point(0, SadConsole.Global.WindowHeight - TextSurface.AbsoluteArea.Height);
        }
        public void Update(IList <AsciiKey> keysDown)
        {
            var dx = 0;
            var dy = 0;

            if (keysDown.Contains(AsciiKey.Get(Keys.Left)) || keysDown.Contains(AsciiKey.Get(Keys.A)))
            {
                dx = -1;
            }
            else if (keysDown.Contains(AsciiKey.Get(Keys.Right)) || keysDown.Contains(AsciiKey.Get(Keys.D)))
            {
                dx = 1;
            }

            if (keysDown.Contains(AsciiKey.Get(Keys.Up)) || keysDown.Contains(AsciiKey.Get(Keys.W)))
            {
                dy = -1;
            }
            else if (keysDown.Contains(AsciiKey.Get(Keys.Down)) || keysDown.Contains(AsciiKey.Get(Keys.S)))
            {
                dy = 1;
            }

            if (dx != 0 || dy != 0)
            {
                var position = this.Parent.Position;
                position.X += dx;
                position.Y += dy;
            }
        }
Пример #3
0
        override public void Update(double elapsedSeconds)
        {
            var keysPressed = SadConsole.Global.KeyboardState.KeysPressed;
            var keysDown    = SadConsole.Global.KeyboardState.KeysDown;

            var oldPlayerX = this.player.Position.X;
            var oldPlayerY = this.player.Position.Y;

            this.player.Get <MoveToKeyboardComponent>().Update(keysPressed);

            // Glorious hack. TODO: query the map tile for this + list of blocking objects
            if (!this.map[this.player.Position.X, this.player.Position.Y].IsWalkable)
            {
                this.player.Position.X = oldPlayerX;
                this.player.Position.Y = oldPlayerY;
            }

            if (oldPlayerX != this.player.Position.X || oldPlayerY != this.player.Position.Y)
            {
                EventBus.Instance.Broadcast("Player moved", player);
            }

            if (IsShiftKeyDown(keysDown) && keysDown.Any(k => k.Key == Keys.OemPeriod) &&
                this.map[this.player.Position.X, this.player.Position.Y] is StairsDownTile)
            {
                // TODO: un-hardcode the new current floor
                EventBus.Instance.Broadcast("Player used stairs", "1F");
            }

            if (keysPressed.Contains(AsciiKey.Get(Keys.Escape)))
            {
                System.Environment.Exit(0);
            }
        }
Пример #4
0
        public override bool ProcessKeyboard(KeyboardInfo info)
        {
            if (info.KeysPressed.Contains(AsciiKey.Get(Microsoft.Xna.Framework.Input.Keys.I)))
            {
                if (!inventoryConsole.IsVisible)
                {
                    inventoryConsole.Show();
                }
                else
                {
                    inventoryConsole.Hide();
                }
            }
            if (info.KeysPressed.Contains(AsciiKey.Get(Microsoft.Xna.Framework.Input.Keys.P)))
            {
                if (!characterStatusConsole.IsVisible)
                {
                    characterStatusConsole.Show();
                }
                else
                {
                    characterStatusConsole.Hide();
                }
            }

            if (!characterStatusConsole.ProcessKeyboard(info) && !inventoryConsole.ProcessKeyboard(info))
            {
                return(dungeonViewConsole.ProcessKeyboard(info));
            }
            return(true);
        }
Пример #5
0
        public override bool ProcessKeyboard(KeyboardInfo info)
        {
            if (!this.gameOver)
            {
                if (info.KeysPressed.Contains(AsciiKey.Get(Keys.Down)) || info.KeysPressed.Contains(AsciiKey.Get(Keys.S)))
                {
                    this.MovePlayerBy(new Point(0, 1), info);
                }
                else if (info.KeysPressed.Contains(AsciiKey.Get(Keys.Up)) || info.KeysPressed.Contains(AsciiKey.Get(Keys.W)))
                {
                    this.MovePlayerBy(new Point(0, -1), info);
                }

                if (info.KeysPressed.Contains(AsciiKey.Get(Keys.Right)) || info.KeysPressed.Contains(AsciiKey.Get(Keys.D)))
                {
                    this.MovePlayerBy(new Point(1, 0), info);
                }
                else if (info.KeysPressed.Contains(AsciiKey.Get(Keys.Left)) || info.KeysPressed.Contains(AsciiKey.Get(Keys.A)))
                {
                    this.MovePlayerBy(new Point(-1, 0), info);
                }
                else if (info.KeysPressed.Contains(AsciiKey.Get(Keys.Space)))
                {
                    this.MovePlayerBy(new Point(0, 0), info);
                }

                if (info.KeysPressed.Contains(AsciiKey.Get(Keys.Space)))
                {
                    var switches = this.objects.Where(o => o.Data is Switch);
                    var player   = this.objects.Single(o => o.Data is Player);
                    foreach (var s in switches)
                    {
                        if ((Math.Abs(s.Position.X - player.Position.X) + Math.Abs(s.Position.Y - player.Position.Y)) <= 1)
                        {
                            (s.Data as Switch).Flip();
                            this.currentMap.FlipSwitches();

                            foreach (var w in switches)
                            {
                                w.RenderCells[0].ActualForeground = new Color(s.Data.Colour.R, s.Data.Colour.G, s.Data.Colour.B);
                            }

                            showMessageCallback("You flip the switch.");
                        }
                    }
                }
            }
            else
            {
                if (info.KeysPressed.Any())
                {
                    Game.Stop();
                }
            }
            return(false);
        }
Пример #6
0
        protected void Queue(params Keys[] xnaKeys)
        {
            var state = new KeyboardState(xnaKeys, false, true);

            foreach (var xnaKey in xnaKeys)
            {
                var key = AsciiKey.Get(xnaKey, state);
                //var key = new AsciiKey { Character = (char)xnaKey, Key = xnaKey };
                _inQ.Enqueue(key);
            }
        }
Пример #7
0
        public override bool ProcessKeyboard(KeyboardInfo info)
        {
            //TODO: Have this use Colored strings and make it so an item of type Equipment is equippable.(or unequippable)
            if (this.IsVisible)
            {
                if (info.KeysPressed.Contains(AsciiKey.Get(Keys.J)))
                {
                    DropMode = DropMode == true ? false : true;
                }
                foreach (var k in inventory.inventory)
                {
                    if (info.KeysPressed.Contains(AsciiKey.Get((Keys)((int)char.ToUpper(k.Key)))))
                    {
                        if (DropMode)
                        {
                            SadConsole.Consoles.Window.Prompt(GetItemMessage(k), "Drop", "Cancel", (r) => { drop_prompt(r, k.Value); });
                        }
                        else
                        {
                            switch (k.Value.GetComponent <Item>(ComponentType.Item).ItemType)
                            {
                            case ItemType.Food:
                                SadConsole.Consoles.Window.Prompt(GetItemMessage(k), "Eat", "Cancel", (r) => { food_prompt(r, k.Value); });
                                break;

                            case ItemType.Equipment:
                                SadConsole.Consoles.Window.Prompt(GetItemMessage(k), "Equip/UnEquip", "Cancel", (r) => { equipment_prompt(r, k.Value); });
                                break;

                            case ItemType.Potion:
                                SadConsole.Consoles.Window.Prompt(GetItemMessage(k), "Drink", "Cancel", (r) => { potion_prompt(r, k.Value); });
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
            }
            return(base.ProcessKeyboard(info));
        }
Пример #8
0
 public override bool ProcessKeyboard(KeyboardInfo info)
 {
     if (info.KeysPressed.Contains(AsciiKey.Get(Microsoft.Xna.Framework.Input.Keys.Down)))
     {
         ViewConsole.MovePlayerBy(new Point(0, 1));
     }
     else if (info.KeysPressed.Contains(AsciiKey.Get(Microsoft.Xna.Framework.Input.Keys.Up)))
     {
         ViewConsole.MovePlayerBy(new Point(0, -1));
     }
     else if (info.KeysPressed.Contains(AsciiKey.Get(Microsoft.Xna.Framework.Input.Keys.Right)))
     {
         ViewConsole.MovePlayerBy(new Point(1, 0));
     }
     else if (info.KeysPressed.Contains(AsciiKey.Get(Microsoft.Xna.Framework.Input.Keys.Left)))
     {
         ViewConsole.MovePlayerBy(new Point(-1, 0));
     }
     return(false);
 }
        public void UpdateMovesPlayerPositionToWasdKeys()
        {
            var e         = new Entity();
            var component = new MoveToKeyboardComponent(e);

            e.Position.X = 3;
            e.Position.Y = 3;

            var keys = new List <AsciiKey>()
            {
                AsciiKey.Get(Keys.W)
            };

            component.Update(keys);
            Assert.That(e.Position.X, Is.EqualTo(3));
            Assert.That(e.Position.Y, Is.EqualTo(2));

            keys = new List <AsciiKey>()
            {
                AsciiKey.Get(Keys.D)
            };
            component.Update(keys);
            Assert.That(e.Position.X, Is.EqualTo(4));
            Assert.That(e.Position.Y, Is.EqualTo(2));

            keys = new List <AsciiKey>()
            {
                AsciiKey.Get(Keys.S)
            };
            component.Update(keys);
            Assert.That(e.Position.X, Is.EqualTo(4));
            Assert.That(e.Position.Y, Is.EqualTo(3));

            keys = new List <AsciiKey>()
            {
                AsciiKey.Get(Keys.A)
            };
            component.Update(keys);
            Assert.That(e.Position.X, Is.EqualTo(3));
            Assert.That(e.Position.Y, Is.EqualTo(3));
        }
        public void UpdateMovesPlayerPositionToArrowKeys()
        {
            var e         = new Entity();
            var component = new MoveToKeyboardComponent(e);

            e.Position.X = 5;
            e.Position.Y = 7;

            var keys = new List <AsciiKey>()
            {
                AsciiKey.Get(Keys.Up)
            };

            component.Update(keys);
            Assert.That(e.Position.X, Is.EqualTo(5));
            Assert.That(e.Position.Y, Is.EqualTo(6));

            keys = new List <AsciiKey>()
            {
                AsciiKey.Get(Keys.Right)
            };
            component.Update(keys);
            Assert.That(e.Position.X, Is.EqualTo(6));
            Assert.That(e.Position.Y, Is.EqualTo(6));

            keys = new List <AsciiKey>()
            {
                AsciiKey.Get(Keys.Down)
            };
            component.Update(keys);
            Assert.That(e.Position.X, Is.EqualTo(6));
            Assert.That(e.Position.Y, Is.EqualTo(7));

            keys = new List <AsciiKey>()
            {
                AsciiKey.Get(Keys.Left)
            };
            component.Update(keys);
            Assert.That(e.Position.X, Is.EqualTo(5));
            Assert.That(e.Position.Y, Is.EqualTo(7));
        }
        public void UpdateMovesPlayerToNextFloorIfPlayerStandsAboveStairsDownAndShiftDotKeysAreDown(Keys shiftKey)
        {
            // Arrange
            const int StairsX = 3;
            const int StairsY = 3;

            var player = new Entity();

            player.Set(new MoveToKeyboardComponent(player));
            var system = new MovementSystem(player);

            var map = new ArrayMap <AbstractMapTile>(5, 5);

            for (var y = 0; y < map.Height; y++)
            {
                for (var x = 0; x < map.Width; x++)
                {
                    map[x, y] = new FloorTile();
                }
            }

            map[StairsX, StairsY] = new StairsDownTile();
            EventBus.Instance.Broadcast("Map changed", map);

            player.Position.X = StairsX;
            player.Position.Y = StairsY;

            SadConsole.Global.KeyboardState.KeysDown.Add(AsciiKey.Get(shiftKey));
            SadConsole.Global.KeyboardState.KeysDown.Add(AsciiKey.Get(Keys.OemPeriod));

            bool usedStairs = false;

            EventBus.Instance.Register <string>("Player used stairs", (floorNumber) => usedStairs = true);

            // Act
            system.Update(0);

            // Assert
            Assert.That(usedStairs, Is.True);
        }
        public void UpdateChangesPlayerPositionIfNewPositionIsWalkable(bool isDestinationWalkable)
        {
            // Arrange
            var player = new Entity();
            var system = new MovementSystem(player);

            player.Set(new MoveToKeyboardComponent(player));
            player.Position.X = 3;
            system.Add(player);
            player.Position.Y = 3;

            var playerMoved = false;

            var map = new ArrayMap <AbstractMapTile>(5, 5);

            for (var y = 0; y < map.Height; y++)
            {
                for (var x = 0; x < map.Width; x++)
                {
                    map[x, y] = new FloorTile();
                }
            }

            map[player.Position.X - 1, player.Position.Y].IsWalkable = isDestinationWalkable;
            SadConsole.Global.KeyboardState.KeysPressed.Add(AsciiKey.Get(Keys.Left));

            // Update the map in the movement system
            EventBus.Instance.Broadcast("Map changed", map);
            EventBus.Instance.Register <Player>("Player moved", (data) => playerMoved = true);

            var expectedX = isDestinationWalkable ? player.Position.X - 1 : player.Position.X;

            // Act
            system.Update(0);

            // Assert
            Assert.That(player.Position.X, Is.EqualTo(expectedX));       // Position changed
            Assert.That(playerMoved, Is.EqualTo(isDestinationWalkable)); // Event fired (or not)
        }
Пример #13
0
        public override bool ProcessKeyboard(KeyboardInfo info)
        {
            bool keyHit = false;

            var newPosition = player.Position;

            if (info.KeysPressed.Contains(AsciiKey.Get(Keys.Up)))
            {
                newPosition.Y -= 1;
                keyHit         = true;
            }
            else if (info.KeysPressed.Contains(AsciiKey.Get(Keys.Down)))
            {
                newPosition.Y += 1;
                keyHit         = true;
            }

            if (info.KeysPressed.Contains(AsciiKey.Get(Keys.Left)))
            {
                newPosition.X -= 1;
                keyHit         = true;
            }
            else if (info.KeysPressed.Contains(AsciiKey.Get(Keys.Right)))
            {
                newPosition.X += 1;
                keyHit         = true;
            }

            // Test location
            if (map.IsWalkable(newPosition.X, newPosition.Y))
            {
                player.Position = newPosition;

                UpdatePlayerView();
            }

            return(keyHit || base.ProcessKeyboard(info));
        }
Пример #14
0
        public override bool ProcessKeyboard(KeyboardInfo info)
        {
            bool didPlayerAct = false;

            if (!Game.CommandSystem.IsPlayerTurn)
            {
                Game.CommandSystem.ActivateMonsters();
            }

            if (info.KeysPressed.Contains(AsciiKey.Get(Microsoft.Xna.Framework.Input.Keys.Down)))
            {
                MapConsole.MovePlayerBy(new Point(0, 1));
                didPlayerAct = true;
            }
            else if (info.KeysPressed.Contains(AsciiKey.Get(Microsoft.Xna.Framework.Input.Keys.Up)))
            {
                MapConsole.MovePlayerBy(new Point(0, -1));
                didPlayerAct = true;
            }

            if (info.KeysPressed.Contains(AsciiKey.Get(Microsoft.Xna.Framework.Input.Keys.Right)))
            {
                MapConsole.MovePlayerBy(new Point(1, 0));
                didPlayerAct = true;
            }
            else if (info.KeysPressed.Contains(AsciiKey.Get(Microsoft.Xna.Framework.Input.Keys.Left)))
            {
                MapConsole.MovePlayerBy(new Point(-1, 0));
                didPlayerAct = true;
            }

            if (didPlayerAct)
            {
                Game.CommandSystem.EndPlayerTurn();
            }

            return(false);
        }
Пример #15
0
        private void MovePlayerBy(Point amount, KeyboardInfo info = null)
        {
            var stopwatch = new System.Diagnostics.Stopwatch();

            stopwatch.Start();

            var currentFieldOfView = new RogueSharp.FieldOfView(this.currentMap.GetIMap());
            var playerView         = this.objects.Single(g => g.Name == "Player");

            var fovTiles = currentFieldOfView.ComputeFov(playerView.Position.X, playerView.Position.Y, Config.Instance.Get <int>("PlayerLightRadius"), true);

            this.MarkCurrentFovAsDiscovered(fovTiles);
            foreach (var obj in this.objects)
            {
                obj.IsVisible = false;
            }

            // Undo monster vision tile effect
            foreach (var monsterView in this.objects.Where(o => o.Data is Monster))
            {
                var data       = monsterView.Data as Monster;
                var monsterFov = currentFieldOfView.ComputeFov(data.X, data.Y, data.VisionSize, true);
                // If we can see them, they're discovered
                foreach (var cell in monsterFov)
                {
                    if (this.discoveredTiles.ContainsKey($"{cell.X}, {cell.Y}"))
                    {
                        this[cell.X, cell.Y].ApplyEffect(DiscoveredEffect);
                    }
                    else
                    {
                        this[cell.X, cell.Y].ApplyEffect(HiddenEffect);
                    }
                }
            }

            // Get the position the player will be at
            Point newPosition = playerView.Position + amount;

            // Is there a block there?
            if (currentMap.GetObjectsAt(newPosition.X, newPosition.Y).Any(e => e is Pushable))
            {
                // Is there an empty space behind it?
                var behindBlock = newPosition + amount;
                if (currentMap.IsWalkable(behindBlock.X, behindBlock.Y))
                {
                    // Push it (update data)
                    var obj = currentMap.GetObjectsAt(newPosition.X, newPosition.Y).Single(e => e is Pushable);
                    obj.Move(behindBlock.X, behindBlock.Y);
                    // Push it (move view object)
                    this.objects.Single(g => g.Data == obj).Move(behindBlock.X, behindBlock.Y);
                    this.CheckIfBlockPuzzleIsComplete();
                }
            }

            // Check to see if the position is within the map and walkable
            if (new Rectangle(0, 0, Width, Height).Contains(newPosition) && currentMap.IsWalkable(newPosition.X, newPosition.Y))
            {
                // Pull a block along if specified
                if (info.KeysDown.Contains(AsciiKey.Get(Keys.Space)))
                {
                    // Are you holding space? Did you move in a direction (eg. left) and there's a push block on the other side (eg. right)?
                    // If so, and if the target block position is walkable, pull it along. But this only works if you're pulling
                    // in the direction you're moving (eg. standing on top and pulling a block upward), NOT standing beside a block
                    // and pulling it upward or standing above a block and pulling to the left/right
                    var currentBlockPos = playerView.Position + new Point(amount.X * -1, amount.Y * -1);
                    if (currentMap.GetObjectsAt(currentBlockPos.X, currentBlockPos.Y).Any(e => e is Pullable))
                    {
                        // Given constraints above, target position is current player position
                        var obj = currentMap.GetObjectsAt(currentBlockPos.X, currentBlockPos.Y).Single(e => e is Pullable);
                        obj.Move(playerView.Position.X, playerView.Position.Y);
                        this.objects.Single(g => g.Data == obj).Move(playerView.Position.X, playerView.Position.Y);
                        this.CheckIfBlockPuzzleIsComplete();
                    }
                }

                // Move the player
                playerView.Position += amount;
                playerView.Data.Move(playerView.Position.X, playerView.Position.Y);
                CenterViewToPlayer();
            }

            var key = this.currentMap.GetObjectsAt(playerView.Position.X, playerView.Position.Y).Where(s => s is Key).SingleOrDefault();

            if (key != null)
            {
                // Not sure why two keys are spawned here
                var keys = this.objects.Where(s => s.Data == key).ToList();
                foreach (var k in keys)
                {
                    this.objects.Remove(k);
                    this.currentMap.Remove(key);
                }

                (this.objects.Single(o => o.Data is Player).Data as Player).Keys += 1;
                this.showMessageCallback("Got a key.");
            }

            // Door there, and we have a key? Unlock it!
            if ((playerView.Data as Player).Keys > 0 && this.currentMap.GetObjectsAt(newPosition.X, newPosition.Y).Any(o => o is LockedDoor))
            {
                var doorData = this.currentMap.GetObjectsAt(newPosition.X, newPosition.Y).Where(o => o is LockedDoor).ToList();
                var doors    = this.objects.Where(o => doorData.Contains(o.Data)).ToList();

                // Why, why WHY are there multiple copies?
                foreach (var door in doors)
                {
                    this.objects.Remove(door);
                    this.currentMap.Remove(door.Data);
                }
                showMessageCallback("You unlock the door.");
                (playerView.Data as Player).Keys -= 1;
            }

            fovTiles = currentFieldOfView.ComputeFov(playerView.Position.X, playerView.Position.Y, Config.Instance.Get <int>("PlayerLightRadius"), true);
            this.MarkCurrentFovAsVisible(fovTiles);

            // Monsters turn. Also, draw their field-of-view. Keep queuing turns until it's the player's turn again.
            var         monstersToMove = new List <IHasAgility>();
            IHasAgility next           = null;

            while (next != playerView.Data)
            {
                if (next != null)
                {
                    monstersToMove.Add(next);
                }
                next = turnCalculator.NextTurn();
            }

            while (monstersToMove.Any())
            {
                var m = monstersToMove[0];
                monstersToMove.RemoveAt(0);
                var monsterView = this.objects.Single(o => o.Data is Monster && o.Data == m);
                var data        = monsterView.Data as Monster;
                var hurtPlayer  = data.MoveWithAi(playerView.Data as Player);
                if (hurtPlayer)
                {
                    if ((playerView.Data as Player).IsDead)
                    {
                        showMessageCallback("The monster hits you! You die ...");
                        this.gameOver = true;
                    }
                    else
                    {
                        showMessageCallback("Monster hits you!");
                    }
                }
                else
                {
                    monsterView.Position = new Point(data.X, data.Y);
                    bool sawPlayer = false;

                    var monsterFov = currentFieldOfView.ComputeFov(data.X, data.Y, data.VisionSize, true);
                    foreach (var cell in monsterFov)
                    {
                        if (fovTiles.Any(f => f.X == data.X && f.Y == data.Y))
                        {
                            this[cell.X, cell.Y].ApplyEffect(MonsterVisionEffect);
                            if (playerView.Position.X == cell.X && playerView.Position.Y == cell.Y)
                            {
                                data.HuntPlayer();
                                monsterView.RenderCells.First().ActualForeground = new Color(255, 0, 0);
                                sawPlayer = true;
                            }
                        }
                        else
                        {
                            if (this.discoveredTiles.ContainsKey($"{data.X}, {data.Y}"))
                            {
                                this[cell.X, cell.Y].ApplyEffect(DiscoveredEffect);
                            }
                            else
                            {
                                this[cell.X, cell.Y].ApplyEffect(HiddenEffect);
                            }
                        }
                    }

                    if (!sawPlayer && monsterView.RenderCells.First().ActualForeground.R == 255)
                    {
                        monsterView.RenderCells.First().ActualForeground = new Color(data.Colour.R, data.Colour.G, data.Colour.B);
                    }
                }
            }

            stopwatch.Stop();
            var elapsed = stopwatch.Elapsed.TotalSeconds;

            Console.WriteLine($"Moving took {elapsed}s");
        }
Пример #16
0
        public override bool ProcessKeyboard(KeyboardInfo info)
        {
            if (info.KeysPressed.Contains(AsciiKey.Get(Keys.N)))
            {
                NewGameEvent?.Invoke(this, new EventArgs());
                return(true);
            }

            if (!_game.Player.IsAlive)
            {
                return(false);
            }

            if (info.KeysPressed.Contains(AsciiKey.Get(Keys.T)))
            {
                PlayerTeleportEvent?.Invoke(this, new EventArgs());
                return(true);
            }

            var keyHit    = false;
            var direction = new Point();

            if (info.KeysPressed.Contains(AsciiKey.Get(Keys.Up)) ||
                info.KeysPressed.Contains(AsciiKey.Get(Keys.NumPad8)) ||
                info.KeysPressed.Contains(AsciiKey.Get(Keys.NumPad7)) ||
                info.KeysPressed.Contains(AsciiKey.Get(Keys.NumPad9)))
            {
                direction.Y = -1;
                keyHit      = true;
            }
            if (info.KeysPressed.Contains(AsciiKey.Get(Keys.Down)) ||
                info.KeysPressed.Contains(AsciiKey.Get(Keys.NumPad2)) ||
                info.KeysPressed.Contains(AsciiKey.Get(Keys.NumPad1)) ||
                info.KeysPressed.Contains(AsciiKey.Get(Keys.NumPad3)))
            {
                direction.Y += 1;
                keyHit       = true;
            }
            if (info.KeysPressed.Contains(AsciiKey.Get(Keys.Left)) ||
                info.KeysPressed.Contains(AsciiKey.Get(Keys.NumPad4)) ||
                info.KeysPressed.Contains(AsciiKey.Get(Keys.NumPad7)) ||
                info.KeysPressed.Contains(AsciiKey.Get(Keys.NumPad1)))
            {
                direction.X -= 1;
                keyHit       = true;
            }
            if (info.KeysPressed.Contains(AsciiKey.Get(Keys.Right)) ||
                info.KeysPressed.Contains(AsciiKey.Get(Keys.NumPad6)) ||
                info.KeysPressed.Contains(AsciiKey.Get(Keys.NumPad9)) ||
                info.KeysPressed.Contains(AsciiKey.Get(Keys.NumPad3)))
            {
                direction.X += 1;
                keyHit       = true;
            }

            if (keyHit)
            {
                PlayerMoveEvent?.Invoke(this, new PlayerMoveEventArgs(direction));
            }

            return(keyHit);
        }
Пример #17
0
 private bool IsShiftKeyDown(List <AsciiKey> keysDown)
 {
     return(keysDown.Contains(AsciiKey.Get(Keys.LeftShift)) || keysDown.Contains(AsciiKey.Get(Keys.RightShift)));
 }