Exemplo n.º 1
0
        public void CreateArea()
        {
            CreateEmptyArea();
            IShipMaker shipMaker = new ShipMaker(Area, _areaMaker, ShipManager.CreateShips());

            Area          = shipMaker.CreateBattleAreaWithShip();
            ShipCount     = shipMaker.ShipCount;
            ShipContainer = shipMaker.ShipContainer;
        }
Exemplo n.º 2
0
 public ShipMaker(BattleArea area, IAreaMaker maker, LinkedList <ShipBase> ships)
 {
     Area          = area;
     Height        = maker.Height;
     Width         = maker.Width;
     this.maker    = maker;
     Ships         = ships;
     ShipContainer = new ShipsContainer();
 }
Exemplo n.º 3
0
 public void Init(
     ElementItem[,] userGrid,
     ElementItem[,] computerGrid,
     int gridSize,
     Action onSetStartPageState,
     ShipsManager shipsManager,
     List <StepMessageItem> stepMessageItems,
     SessionDataManager sessionDataManager,
     Action <PageState> setGamePage,
     Action resetGrid)
 {
     FreshStart();
     _shipsManager = shipsManager;
     _dragBlock    = _shipsManager.DragBlock;
     _resetShips   = _shipsManager.ResetShips;
     _restartButton.onClick.RemoveAllListeners();
     _restartButton.onClick.AddListener(() =>
                                        Restart(
                                            stepMessageItems,
                                            sessionDataManager,
                                            setGamePage,
                                            resetGrid));
     _backToStartMenuButton.onClick.RemoveAllListeners();
     _backToStartMenuButton.onClick.AddListener(onSetStartPageState.Invoke);
     _confirm.onClick.RemoveAllListeners();
     _confirm.onClick.AddListener(() =>
     {
         ConfirmShipsPositions();
         _shipsManager.SetRandomShips(gridSize, _shipsManager.ComputerShips, computerGrid);
     });
     _random.onClick.RemoveAllListeners();
     _random.onClick.AddListener(() =>
     {
         _shipsManager.SetRandomShipsForAll();
         ShipsContainer.SetActive(false);
         HideGameObjects.SetActive(true);
     });
     TryToActivateConfirmButton();
 }
Exemplo n.º 4
0
        public void MatchPlayerArea(BattleArea playerArea, BattleArea npcArea, string targetPoint, ShipsContainer shipsContainer)
        {
            bool isDestroyShip = false;
            int  y             = Coordinates.MapToLiteral(targetPoint[0].ToString());
            int  x             = int.Parse(targetPoint.Substring(1));

            IField npcTarget = npcArea.BattleFields[x, y].Field;

            if (!(npcTarget is BoundField))
            {
                if (npcTarget is ShipField)
                {
                    Guid guid = (npcArea.BattleFields[x, y].Field as ShipField).ShipType.Guid;
                    playerArea.BattleFields[x, y] = new BattleField(new ShipField(new RegularShip(true, guid)));

                    List <ShipBase> listOfShips = shipsContainer.GetShipsByGuid(guid);
                    listOfShips.First(d => (d.ShipsPoints.X == x && d.ShipsPoints.Y == y)).IsDestroy = true;

                    foreach (ShipBase s in listOfShips)
                    {
                        if (!s.IsDestroy)
                        {
                            isDestroyShip = false;
                            break;
                        }
                        isDestroyShip = true;
                    }

                    if (isDestroyShip)
                    {
                        foreach (ShipBase s in listOfShips)
                        {
                            playerArea.BattleFields[s.ShipsPoints.X, s.ShipsPoints.Y] = new BattleField(new ShipDestroyField());

                            foreach (Point p in s.NearShipPoints)
                            {
                                playerArea.BattleFields[p.X, p.Y] = new BattleField(new MissField());
                            }
                        }
                    }
                }
                else
                {
                    playerArea.BattleFields[x, y] = new BattleField(new MissField());
                }
            }
        }
Exemplo n.º 5
0
 public GameAreaManager(BattleArea area, GameShipManager shipManager)
 {
     Area          = area;
     ShipManager   = shipManager;
     ShipContainer = new ShipsContainer();
 }
Exemplo n.º 6
0
 private void ConfirmShipsPositions()
 {
     ShipsContainer.SetActive(false);
     HideGameObjects.SetActive(true);
 }
Exemplo n.º 7
0
 private void FreshStart()
 {
     WinnerPanel.SetActive(false);
     HideGameObjects.SetActive(false);
     ShipsContainer.SetActive(true);
 }