示例#1
0
        public static AttackResult AttackPlayer(Player player, Pos pos)
        {
            player.MovesAgainstThisPlayer.Add(pos);
            var ship = GetShipOrNull(player, pos);

            return(ShipLogic.AttackAtPos(ship, pos));
        }
示例#2
0
        public static bool CheckValidShipPlacementPos(Player player, Pos pos, int shipSize, ShipDirection direction)
        {
            // Check if position is off board
            if (!CheckIfPosInBoard(pos))
            {
                return(false);
            }

            // Find ship's furthest point
            var maxPos = new Pos(
                pos.X + (direction == ShipDirection.Right ? shipSize - 1 : 0),
                pos.Y + (direction == ShipDirection.Right ? 0 : shipSize - 1)
                );

            // Check if max position is off board
            if (!CheckIfPosInBoard(maxPos))
            {
                return(false);
            }

            // Check if any ships already exist at that location
            foreach (var ship in player.Ships)
            {
                if (ShipLogic.CheckIfIntersect(ship, pos, shipSize, direction))
                {
                    return(false);
                }
            }

            return(true);
        }
示例#3
0
        public static bool IsAlive(Player player)
        {
            // Count each ship block individually, checking if there is at least one that's not hit
            foreach (var ship in player.Ships)
            {
                if (!ShipLogic.IsDestroyed(ship))
                {
                    return(true);
                }
            }

            return(false);
        }
示例#4
0
        public static Ship GetShipOrNull(Player player, Pos pos)
        {
            if (player.Ships == null)
            {
                return(null);
            }

            foreach (var ship in player.Ships)
            {
                if (ShipLogic.IsAtPos(ship, pos))
                {
                    return(ship);
                }
            }

            return(null);
        }
示例#5
0
 public static void ResetShips(Player player)
 {
     player.Ships = ShipLogic.GenGameShipList();
 }