Esempio n. 1
0
        static void Main(string[] args)
        {
            CharMap cm = new CharMap();
            Frame so = new Frame();
            System.Diagnostics.Debug.WriteLine(cm == null);
            Player player = new Player(cm);
            Enemy troll = new Enemy(cm, 10);
            KeyListener list = new KeyListener();
            player.AddCharacter();
            so.Output(cm);

            while (playing)
            {
                Thread.Sleep(10);
                list.ReadKey(player,so,cm);

            }
        }
        public void ReadKey(Player p,Frame so,CharMap cm)
        {
            ConsoleKeyInfo key = new ConsoleKeyInfo();
            while(key.Key != ConsoleKey.Escape)
            {

                key = Console.ReadKey();
                switch(key.Key)
                {
                    case ConsoleKey.LeftArrow:

                        if(p.GamePlayer.Char != (char)PlayerMov.Left)
                        {
                            p.GamePlayer.Char = (char)PlayerMov.Left;
                            break;
                        }
                        p.Move(-1, 0);
                        break;

                    case ConsoleKey.RightArrow:

                        if (p.GamePlayer.Char != (char)PlayerMov.Right)
                        {
                            p.GamePlayer.Char = (char)PlayerMov.Right;
                            break;
                        }
                        p.Move(1, 0);
                        break;

                    case ConsoleKey.DownArrow:

                        if (p.GamePlayer.Char != (char)PlayerMov.Down)
                        {
                            p.GamePlayer.Char = (char)PlayerMov.Down;
                            break;
                        }
                        p.Move(0, 1);
                        break;

                    case ConsoleKey.UpArrow:

                        if(p.GamePlayer.Char != (char)PlayerMov.Up)
                        {
                            p.GamePlayer.Char = (char)PlayerMov.Up;
                            break;
                        }
                        p.Move(0, -1);
                        break;

                    case ConsoleKey.Escape:
                        Program.playing = false;
                        break;
                    default:
                        Console.Write("\b \b");
                        break;
                }
                p.GamePlayer.Repaint = true;

                so.Output(cm);
            }
        }