Esempio n. 1
0
        public void moveShipOnMap(Map map, Ship ship)
        {
            ship.xCoordinate = 2;
            ship.yCoordinate = 1;
            ship.atBottom    = false;
            ship.atRight     = false;
            ship.vertical    = false;
            ship.horizontal  = true;



            while (moveShip)
            {
                Console.ResetColor();
                Console.WriteLine("Player {0}: {1} - Where do you want to move your {2}?  [m] control menu", this.playerNumber, this.name, ship.shipName);
                try
                {
                    ConsoleKeyInfo keyPressed = Console.ReadKey(true);
                    if (keyPressed.KeyChar.Equals('x'))
                    {
                        moveShip = false;
                    }
                    else if (keyPressed.KeyChar.Equals('q'))
                    {
                        moveShip = setHere;
                        Console.WriteLine();
                        map.drawMap();
                        CoorLogi.saveShipCoordinate(map, ship);
                    }
                    else if (keyPressed.KeyChar.Equals('w'))
                    {
                        ship.moveShipUp(map, ship);
                    }
                    else if (keyPressed.KeyChar.Equals('s'))
                    {
                        ship.moveShipDown(map, ship);
                    }
                    else if (keyPressed.KeyChar.Equals('d'))
                    {
                        ship.moveShipRight(map, ship);
                    }
                    else if (keyPressed.KeyChar.Equals('a'))
                    {
                        ship.moveShipLeft(map, ship);
                    }
                    else if (keyPressed.KeyChar.Equals('r'))
                    {
                        ship.rotateShip(map, ship);
                    }
                    else if (keyPressed.KeyChar.Equals('m'))
                    {
                        Console.WriteLine();
                        controls.getControlMenu();
                    }
                    else
                    {
                        Console.WriteLine("Invalid Entry");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("You moved your ship off the map. Please move it back. ");
                    map.drawMap();
                }
            }
            moveShip = true;
            setHere  = false;
        }