Esempio n. 1
0
    public void StartSession()
    {
        if (!_isActive)
        {
            this.Step = StepOrders.None;

            this.PlayerPlacement = CheckFleetPlacement(this.PlayerPlacement, this.PlayerField, this.Inventory);
            this.PlayerField.Clear();
            this.PlayerField.Fill(this.PlayerPlacement);

            this.EnemyPlacement = CheckFleetPlacement(this.EnemyPlacement, this.EnemyField, this.Inventory);
            this.EnemyField.Clear();
            this.EnemyField.Fill(this.EnemyPlacement);

            _botLogic = new EnemyStepLogic();

            this.Step = UnityEngine.Random.Range(0, 2) == 0 ? StepOrders.Player : StepOrders.Enemy;

            StartCoroutine(SessionProcess());
            _isActive = true;
        }
    }
Esempio n. 2
0
    private IEnumerator SessionProcess()
    {
        if (this.Step == StepOrders.Enemy)
        {
            yield return(new WaitForSeconds(ENEMY_DELAY));
        }

        while (true)
        {
            switch (this.Step)
            {
            case StepOrders.None:
                break;

            case StepOrders.Player:
                break;

            case StepOrders.Enemy:
                yield return(new WaitForSeconds(ENEMY_DELAY));

                Vector2Int target = _botLogic.GetTargetPoint(this.PlayerField);

                if (_botLogic.StepState == EnemyStepLogic.StepStates.Correct)
                {
                    MakeStep(this.PlayerField, target.x, target.y);
                }
                else
                {
                    this.Step = StepOrders.None;
                }

                break;
            }

            yield return(null);
        }
    }
Esempio n. 3
0
    public void MakeStep(BattleField field, int x, int y)
    {
        if (field.FieldFilling[x, y] != FillTypes.WreckedShip && field.FieldFilling[x, y] != FillTypes.Shot)
        {
            field.SetShot(x, y);

            if (field.FieldFilling[x, y] == FillTypes.WreckedShip)
            {
                Ship ship = field.FindShip(x, y);

                if (ship != null)
                {
                    ship.SetDamage(x, y);

                    if (ship.Lives <= 0)
                    {
                        field.PutShipToPool(ship);
                    }
                    if (field.Fleet.Count <= 0)
                    {
                        this.Step = StepOrders.None;
                        OnGameOver.SafeInvoke();
                    }
                }
                else
                {
                    Debug.LogError("This ship should not be NULL");
                }
            }

            if (field.FieldFilling[x, y] != FillTypes.WreckedShip)
            {
                this.Step = this.Step == StepOrders.Player ? StepOrders.Enemy : StepOrders.Player;
            }
        }
    }
Esempio n. 4
0
 public void StopSession()
 {
     StopAllCoroutines();
     _isActive = false;
     this.Step = StepOrders.None;
 }