Exemplo n.º 1
0
    void EndDrag()
    {
        OnEndDrag.Invoke();
        Dragging = false;
        FieldMapController fieldMapColtroller = FieldMap.GetComponent <FieldMapController>();
        Vector2            pos = fieldMapColtroller.GetCellPosFromShipPos(transform.position);
        bool isValid           = fieldMapColtroller.CheckValidShipPos(gameObject, pos);

        if (!isValid)
        {
            ResetShip();
        }
        else
        {
            GameObject cell     = fieldMapColtroller.GetCellByPos(pos);
            Vector3    position = new Vector3(
                Camera.main.WorldToScreenPoint(cell.transform.position).x,
                Camera.main.WorldToScreenPoint(cell.transform.position).y,
                ZPosition
                );
            transform.position = Camera.main.ScreenToWorldPoint(position);
            fieldMapColtroller.SetShipIntoArray(gameObject);
            RotateButton.gameObject.SetActive(false);
        }
        fieldMapColtroller.ResetCellStatus();
        SoundManager.Instance.PlaySound(SoundManager.Sound.BOAT_TO_WATER);
    }
Exemplo n.º 2
0
    // Start is called before the first frame update
    void Start()
    {
        FieldMap = Instantiate(
            FieldMapPrefab,
            transform.position,
            Quaternion.identity,
            gameObject.transform
            );
        FieldMap.GetComponent <FieldMapController>().SceneController = gameObject;
        FieldMap.GetComponent <FieldMapController>().Init();
        InitShip(0, 4, new Vector3(18, 9, 34.5f));
        InitShip(1, 3, new Vector3(38, 9, 34.5f));
        InitShip(2, 3, new Vector3(58, 9, 34.5f));
        InitShip(3, 2, new Vector3(78, 9, 34.5f));
        InitShip(4, 2, new Vector3(18, 9, -12.0f));
        InitShip(5, 2, new Vector3(38, 9, -12.0f));
        InitShip(6, 1, new Vector3(58, 9, -12.0f));
        InitShip(7, 1, new Vector3(18, 9, -40.0f));
        InitShip(8, 1, new Vector3(38, 9, -40.0f));
        InitShip(9, 1, new Vector3(58, 9, -40.0f));

        // Set up water quality
        int waterQuality = (int)SettingsManager.GetComponent <SettingsManager>().WaterQuality;

        if (waterQuality >= 2)
        {
            WaterHigh.SetActive(true);
            WaterLow.SetActive(false);
        }
        else
        {
            WaterHigh.SetActive(false);
            WaterLow.SetActive(true);
        }
        if (waterQuality == 2)
        {
            WaterHigh.GetComponent <Water>().Enabled = false;
        }
        if (waterQuality == 3)
        {
            WaterHigh.GetComponent <Water>().Enabled = true;
        }

        SoundManager.Instance.PlaySound(SoundManager.Sound.BACKGROUND_PREGAME, true);
        SoundManager.Instance.PlaySound(SoundManager.Sound.BACKGROUND_OCEAN, true);

        // handle play with BOT
        if (!Connection.Instance.isOnline)
        {
            FieldMapController fieldMapCon = FieldMap.GetComponent <FieldMapController>();
            fieldMapCon.AutoArrangeShips();
            string serializedShips = fieldMapCon.GetSerializedShips();
            fieldMapCon.ResetAllShips();
            BOTGameManager.Instance.Ready(serializedShips);
        }

        InvokeRepeating("UpdateRemainingTime", 1.0f, 1.0f);
    }
Exemplo n.º 3
0
    public void ResetShip()
    {
        FieldMapController fieldMapColtroller = FieldMap.GetComponent <FieldMapController>();

        transform.position = InitialPosition;
        SetDirection(4);
        fieldMapColtroller.RemoveShipFromArray(gameObject);
        RotateButton.gameObject.SetActive(true);
    }
Exemplo n.º 4
0
 // Check if cell is not be fired yet, and relate cells not contain revealed ship
 private bool CheckIfShouldFireCell(FieldMapController fieldMapCon, CellController cellCon)
 {
     // Check if cell is not be fired yet
     if (cellCon.Fired)
     {
         return(false);
     }
     // Check if relate cells not contain revealed ship
     (int, int)[] possibleOffsets =
Exemplo n.º 5
0
    public void BOTAttack()
    {
        FieldMapController myFieldMapCon = MyFieldMap.GetComponent <FieldMapController>();

        (int predRow, int predCol) = PredictCell(myFieldMapCon);
        TargetModel target = new TargetModel(predRow, predCol, Connection.Instance.MyId);

        BOTGameManager.Instance.Attack(target);
    }
Exemplo n.º 6
0
    void InitOp()
    {
        // Init op map
        OpFieldMap = Instantiate(
            FieldMapPrefab,
            transform.position,
            Quaternion.identity,
            gameObject.transform
            );
        FieldMapController opFieldMapController = OpFieldMap.GetComponent <FieldMapController>();

        opFieldMapController.SceneController = gameObject;
        opFieldMapController.IsMyField       = false;
        opFieldMapController.LeftOffset      = 34.5f;
        opFieldMapController.BottomOffset    = BottomOffset;
        opFieldMapController.Init();

        // Init op ships
        Logger.Log("OP ships: " + GameManager.Instance.GetShips(false));
        ShipModel[] shipsModels = opFieldMapController.DeserializeShips(GameManager.Instance.GetShips(false));
        foreach (ShipModel shipModel in shipsModels)
        {
            GameObject prefab = Ship1Prefab;
            if (shipModel.length == 1)
            {
                prefab = Ship1Prefab;
            }
            if (shipModel.length == 2)
            {
                prefab = Ship2Prefab;
            }
            if (shipModel.length == 3)
            {
                prefab = Ship3Prefab;
            }
            if (shipModel.length == 4)
            {
                prefab = Ship4Prefab;
            }

            GameObject ship = Instantiate(
                prefab,
                Vector3.zero,
                prefab.transform.rotation,
                opFieldMapController.gameObject.transform
                );
            ship.GetComponent <Transform>().transform.localPosition = new Vector3(0, 9, 0);
            ship.GetComponent <ShipController>().FieldMap           = OpFieldMap;
            ship.GetComponent <ShipController>().id = shipModel.id;
            ship.GetComponent <ShipController>().UpdateColor(!GameManager.Instance.isHost);
            ship.GetComponent <ShipController>().FixedPos();
            // We don't need ship's Box Collider for InGame
            Destroy(ship.GetComponent <BoxCollider>());
            ship.GetComponent <ShipController>().SetShipToMap(shipModel.rootRow, shipModel.rootCol, shipModel.dir);
            ship.SetActive(false);
        }
    }
Exemplo n.º 7
0
    public void Deserialize(string json)
    {
        FieldMapController fieldMapColtroller = FieldMap.GetComponent <FieldMapController>();
        ShipModel          model = JsonUtility.FromJson <ShipModel>(json);

        this.root      = fieldMapColtroller.mapArr[model.rootRow, model.rootCol];
        this.direction = new Direction(model.dir);
        this.length    = model.length;
        this.id        = model.id;
    }
Exemplo n.º 8
0
    public void SetShipToMap(int row, int col, int dir)
    {
        FieldMapController fieldMapColtroller = FieldMap.GetComponent <FieldMapController>();
        GameObject         cell = fieldMapColtroller.GetCellByPos(row, col);

        transform.position = new Vector3(
            cell.transform.position.x,
            transform.position.y,
            cell.transform.position.z
            );
        SetDirection(dir);
        root = cell;
        fieldMapColtroller.SetShipIntoArray(gameObject);
        RotateButton.gameObject.SetActive(false);
    }
Exemplo n.º 9
0
 private void Update()
 {
     if (Draggable)
     {
         if (Dragging)
         {
             Vector3 position = new Vector3(
                 Input.mousePosition.x,
                 Input.mousePosition.y,
                 ZPosition
                 );
             transform.position = Camera.main.ScreenToWorldPoint(position);
             FieldMapController fieldMapColtroller = FieldMap.GetComponent <FieldMapController>();
             Vector2            pos = fieldMapColtroller.GetCellPosFromShipPos(transform.position);
             fieldMapColtroller.CheckValidShipPos(gameObject, pos);
         }
     }
 }