Пример #1
0
        private void fireTorpedo(Point destination) {
            // Don't fire torpedo if one is already in the water
            if(gamePanel.currentTorpedo != null) {
                return;
            }

            Debug.WriteLine("Fire torpedo to <" + destination.X + ", " + destination.Y + ">");

            Point startPos = new Point(gamePanel.Width / 2, gamePanel.Height);
            Torpedo torpedo = new Torpedo(startPos, destination);
            gamePanel.currentTorpedo = torpedo;
        }
        private Ship getTorpedoCollisionShip(Torpedo torpedo) {
            foreach(Ship ship in gamePanel.ships) {
                if ((torpedo.position.X >= ship.position.X && torpedo.position.X <= ship.position.X + ship.width) &&
                    (torpedo.position.Y <= ship.position.Y + ship.height)) {
                    return ship;
                }
            }

            return null;
        }
        private void doTorpedoCollision(Torpedo torpedo, Ship ship) {
            Debug.WriteLine("Collision! Torpedo@" + "<" + torpedo.position.X + "," + torpedo.position.Y + ">" + 
                            "Ship@" + "<" + ship.position.X + "," + ship.position.Y + ">");

            // Add score to player
            gameController.addScoreToPlayer(ship.scoreValue);

            // Remove the ship.
            gameController.removeShip(ship);

            // Remove the torpedo.
            gameController.explodeTorpedo();
        }