private void OnCommandRecieved(IUserInput sender, InputEventArgs args) { this.allowMove = true; bool movingAttemp = false; ConsoleKey command = args.input.Key; MovingArgs arg = new MovingArgs(); if (command == this.Up) { movingAttemp = true; if (this.PosY > 0) { arg.dy = -1; } } if (command == this.Down) { movingAttemp = true; if (this.PosY < this.Board.Height) { arg.dy = 1; } } if (command == this.Left) { movingAttemp = true; if (this.PosX > 0) { arg.dx = -1; } } if (command == this.Right) { movingAttemp = true; if (this.PosX < this.Board.Width) { arg.dx = 1; } } if (movingAttemp) { this.TryMove?.Invoke(this, arg); if (this.allowMove) { this.PosX += arg.dx; this.PosY += arg.dy; this.OnMove?.Invoke(this, arg); } } }
private void Hero_OnMove(IHero sender, MovingArgs args) { if (sender.PosX == 0) { leftColor = (sender as ColoredConsoleHero)?.Color ?? defaultColor; } if (sender.PosX == this.Width) { rightColor = (sender as ColoredConsoleHero)?.Color ?? defaultColor; } if (sender.PosY == 0) { topColor = (sender as ColoredConsoleHero)?.Color ?? defaultColor; } if (sender.PosY == this.Height) { bottomColor = (sender as ColoredConsoleHero)?.Color ?? defaultColor; } }