示例#1
0
        public async Task <bool> OpenAsync()
        {
            if (Open)
            {
                return(Open);
            }

            var root = await ReadJson();

            Species = root.Members.Select(x => x.Species).Distinct().OrderBy(x => x).ToArray();

            Genders = root.Members.Select(x => x.Gender).Distinct().OrderBy(x => x).ToArray();

            foreach (var ship in Ships = root.Ships)
            {
                ship.Image = UpdateImagePaths(ship.Show, ship.Images);
            }

            foreach (var member in Members = root.Members)
            {
                member.Image = UpdateImagePaths(member.Show, member.Images);
            }

            foreach (var show in Shows = root.Shows)
            {
                UpdateImagePaths(show.Abbreviation, show.Images);
                show.Image = Ships.First(x => x.Show == show.Abbreviation)?.Images?.First();
            }

            return(Open = true);

            Image UpdateImagePaths(string show, params Image[] images)
示例#2
0
        public ShotResult ProcessShot(Coordinates coords, Label response)
        {
            var tile = Board.Tiles.At(coords.Row, coords.Column);

            if (!tile.Occupied)
            {
                response.Text = $"{Name} says: Miss!";
                response.Refresh();
                tile.ShotResult = ShotResult.Miss;
                return(ShotResult.Miss);
            }
            var ship = Ships.First(x => x.TileOccupation == tile.TileOccupation);

            ship.Hits++;
            tile.ShotResult = ShotResult.Hit;
            response.Text   = $"{Name} says: Hit!";

            if (ship.IsDestoyed)
            {
                response.Text = $"{Name} says: You sunk my {ship.Name}!";
            }

            response.Refresh();
            return(ShotResult.Hit);
        }
示例#3
0
        // Reacting to Shots Fired
        public Tuple <ShotResult, string> ProcessShot(Coordinates coordinates)
        {
            var firedCell = GameBoard.Cells.At(coordinates.row, coordinates.column);
            var message   = "";

            if (!firedCell.IsOccupied)
            {
                Console.WriteLine(Name + " says: \"Miss!\"");
                firedCell.OccupationType = OccupationType.Miss;
                return(new Tuple <ShotResult, string>(ShotResult.Miss, ""));
            }

            // -> hit the ship
            var ship = Ships.First(x => x.OccupationType == firedCell.OccupationType);

            ship.Hits++;

            firedCell.OccupationType = OccupationType.Hit; // Mark the cell on the Own Board


            Console.WriteLine(Name + " says: \"Hit!\"");

            if (ship.IsSunk)
            {
                shipsLost++;
                //Console.WriteLine(Name + " says: \"You sunk my " + ship.Name + "!\"");
                message = "You sunk AI's " + ship.Name + "!\"";
            }

            return(new Tuple <ShotResult, string> (ShotResult.Hit, message));
        }
示例#4
0
        // Reacting to Shots Fired
        public ShotResult ProcessShot(Coordinates coordinates)
        {
            var firedCell = GameBoard.Cells.At(coordinates.row, coordinates.column);


            if (!firedCell.IsOccupied)
            {
                Console.WriteLine(Name + " says: \"Miss!\"");
                firedCell.OccupationType = OccupationType.Miss;
                return(ShotResult.Miss);
            }

            // -> hit the ship
            var ship = Ships.First(x => x.OccupationType == firedCell.OccupationType);

            ship.Hits++;

            firedCell.OccupationType = OccupationType.Hit; // Mark the cell on the Own Board


            Console.WriteLine(Name + " says: \"Hit!\"");

            if (ship.IsSunk)
            {
                shipsLost++;
                Console.WriteLine(Name + " says: \"You sunk my " + ship.Name + "!\"");
                // Console.WriteLine("    Player " + Name + " LOST " + shipsLost);
            }

            return(ShotResult.Hit);
        }
示例#5
0
        public ShotResult ProcessShot(Coordinate coordinate)
        {
            if (!PlayerGrid.Search(coordinate.Row, coordinate.Column).IsOccupied)
            {
                return(ShotResult.Miss);
            }
            Ship ship = Ships.First(x => x.State == PlayerGrid.Search(coordinate.Row, coordinate.Column).State);

            ship.Hits++;
            return(ship.IsSunk ? ShotResult.Sunk : ShotResult.Hit);
        }
示例#6
0
        public ShotResult ProcessShot(Coordinates coords)
        {
            var panel = GameBoard.Panels.At(coords.Row, coords.Column);

            if (!panel.IsOccupied)
            {
                return(ShotResult.Miss);
            }

            var ship = Ships.First(x => x.PanelIds.Any(p => p.Equals(panel.PanelId)));

            ship.Hits++;

            return(ShotResult.Hit);
        }
示例#7
0
        public ShotResult ProcessShot(Coordinates coords)
        {
            var panel = GameBoard.Panels.At(coords.Row, coords.Column);

            if (!panel.IsOccupied)
            {
                Console.WriteLine(Name + " says: \"Miss!\"");
                return(ShotResult.Miss);
            }
            var ship = Ships.First(x => x.OccupationType == panel.OccupationType);

            ship.Hits++;
            Console.WriteLine(Name + " says: \"Hit!\"");
            if (ship.IsSunk)
            {
                Console.WriteLine(Name + " says: \"You sunk my " + ship.Name + "!\"");
            }
            return(ShotResult.Hit);
        }
示例#8
0
        public AttackResult HandleAttack(int row, int column)
        {
            var aimedSquare = GameBoard.GetSquare(row, column);

            if (aimedSquare.HasBeenShot)
            {
                return(AttackResult.AlreadyShot);
            }

            aimedSquare.HasBeenShot = true;

            if (aimedSquare.IsOccupied)
            {
                var shipType = aimedSquare.ShipType;
                Ships.First(w => w.Type == shipType).HitCount++;

                return(AttackResult.Hit);
            }

            return(AttackResult.Miss);
        }
示例#9
0
        //Shot is the shot result on the PCs Ocean
        public ShotResult Shot(Coordinates coordinates)
        {
            var cell = Ocean.CellAtCoordinate(coordinates.Row, coordinates.Column);

            if (!cell.IsOccupied)
            {
                Console.WriteLine(Name + " says: \"Miss!\"");
                cell.OccupationType = OccupationType.Miss;
                return(ShotResult.Miss);
            }
            var ship = Ships.First(x => x.OccupationType == cell.OccupationType);

            ship.Hits++;
            Console.WriteLine(Name + " says: \"Hit!\"");
            if (ship.IsDestroyed)
            {
                Console.WriteLine(Name + " says: \"You Destroy my " + ship.Name + "!\"");
            }
            cell.OccupationType = OccupationType.Hit;
            return(ShotResult.Hit);
        }
示例#10
0
        /// <summary>
        /// Method returns a result of the attempted shot by the oponent
        /// </summary>
        /// <param name="coords"></param>
        /// <returns></returns>
        public ShotResult ProcessShot(Coordinates coords)
        {
            var Cell = GameBoard.Cells.At(coords.Row, coords.Column);

            if (!Cell.IsOccupied)
            {
                return(ShotResult.Miss);
            }
            var ship = Ships.First(x => x.OccupationType == Cell.OccupationType);

            ship.Hits++;

            if (ship.IsSunk)
            {
                return(ShotResult.Sink);
            }
            else
            {
                return(ShotResult.Hit);
            }
        }
示例#11
0
        public ShotResult MissOrHitShot(Point point)
        {
            var coordinate = Map.Coordinates.GetAt(point.X, point.Y);

            if (!coordinate.isOccupiedByShip)
            {
                Console.WriteLine(Name + " says \"You Miss! Haha!\"");
                return(ShotResult.Miss);
            }

            var ship = Ships.First(x => x.CoordinateType == coordinate.CoordinateType);

            ship.Hits++;

            Console.WriteLine(Name + " says \"Ouch! You shot my ship!");
            if (ship.isSink)
            {
                Console.WriteLine(Name + " says \"You Sunk my " + ship.Name + "!");
            }

            return(ShotResult.Hit);
        }
示例#12
0
        public ShotResult ProcessShot(Coordinates coords)
        {
            // Check if the panel for a given row & col is occupied (has a ship)
            var panel = GameBoard.Panels.At(coords.Row, coords.Column);

            if (!panel.IsOccupied)
            {
                Console.WriteLine(Name + " says: \"Miss!\"");
                return(ShotResult.Miss);
            }

            // Find the ship of the found OccupationType during a hit, increment the hits
            var ship = Ships.First(x => x.OccupationType == panel.OccupationType);

            ship.Hits++;
            Console.WriteLine(Name + " says: \"Hit!\"");

            // Check if the ship has Sunk - damaged on all the panels.
            if (ship.IsSunk)
            {
                Console.WriteLine(Name + " says: \"You sunk my " + ship.Name + "!\"");
            }
            return(ShotResult.Hit);
        }