Ejemplo n.º 1
0
        private static void HandlePlayerTwoControls(IUserInterface keyboard, Engine engine)
        {
            keyboard.OnUpPressedPlayerTwo += (sender, eventInfo) =>
            {
                Console.SetCursorPosition(startRow, startCol);
                Console.WriteLine("Player2, make a move please!");
                engine.MovePlayerTwoUp();
            };

            keyboard.OnDownPressedPlayerTwo += (sender, eventInfo) =>
            {
                Console.SetCursorPosition(startRow, startCol);
                Console.WriteLine("Player2, make a move please!");
                engine.MovePlayerTwoDown();
            };

            keyboard.OnLeftPressedPlayerTwo += (sender, eventInfo) =>
            {
                Console.SetCursorPosition(startRow, startCol);
                Console.WriteLine("Player2, make a move please!");
                engine.MovePlayerTwoLeft();
            };

            keyboard.OnRightPressedPlayerTwo += (sender, eventInfo) =>
            {
                Console.SetCursorPosition(startRow, startCol);
                Console.WriteLine("Player2, make a move please!");
                engine.MovePlayerTwoRight();
            };
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            IUserInterface keyboard = new KeyboardInterface();
            IRenderer renderer = new Renderer(WorldRows - 44, WorldCols - 18);

            Engine engine = new Engine(renderer, keyboard, 300);

            for (int i = startRow; i < endRow; i++)
            {
                for (int j = startCol; j < endCol; j++)
                {
                    Grid newGrid = new Grid(new Position(i, j));
                    engine.AddObject(newGrid);
                }
            }

            engine.GeneratePlayersOnField();
            Thread.Sleep(80);
            engine.GenerateFruitsOnField();

            HandlePlayerOneControls(keyboard, engine);
            HandlePlayerTwoControls(keyboard, engine);

            engine.Run();
        }