Пример #1
0
    void AddToConstructableTilesIfAvailable(int x, int y)
    {
        /* Attempts to add a new PotentialShipTile at (x, y).
         *
         * Only adds a new PST if no PST or ShipTile currently exists there.
         */
        ShipTile old_tile = player_ship.tilemap.Get(x, y);

        if (!old_tile)
        {
            if (!_ConstructableTiles.Exists(tile => tile.x == x && tile.y == y))
            {
                GameObject        potential_tile_obj = Instantiate(ParticleDict.get().potential_ship_tile) as GameObject;
                PotentialShipTile potential_tile     = potential_tile_obj.GetComponent <PotentialShipTile>();
                potential_tile.editor_index            = _ConstructableTiles.Count;
                potential_tile.transform.parent        = player_ship.transform;
                potential_tile.transform.localPosition = new Vector3(x, y, 0);
                TileCoordinates tile_coordinates = new TileCoordinates {
                    x = x,
                    y = y,
                    potential_tile = potential_tile
                };
                _ConstructableTiles.Add(tile_coordinates);
            }
        }
    }
Пример #2
0
        private BaseTile CreateTileByString(string tileName)
        {
            BaseTile tile;

            switch (tileName)
            {
            case "Tile":
                tile = new Tile();
                break;

            case "Start":
                tile = new StartTile();
                _startTiles.Add(tile);
                break;

            case "Rest":
                tile = new RestTile();
                break;

            case "Switch":
                tile = new SwitchTile();
                _switches.Add(tile);
                break;

            case "Ship":
                tile = new ShipTile();
                break;

            default:
                tile = new Tile();
                break;
            }
            return(tile);
        }
Пример #3
0
        /// <summary>
        /// Sprawdza sasiednie pole.
        /// </summary>
        /// <param name="index">Indeks pola na liscie.</param>
        /// <returns>Jesli zolnierz moze wejsc na pole zwraca true,
        /// false w przeciwnym przypadku.</returns>
        private bool Check(int index)
        {
            if (!leftBornTile)
            {
                return(true);
            }
            IslandTile tiles = refToLevel.LevelTiles[index] as IslandTile;

            if (tiles == null)
            {
                ShipTile tiles2 = refToLevel.LevelTiles[index] as ShipTile;
                if (tiles2 == null)
                {
                    return(false);
                }
                else
                {
                    return(tiles2.Traversable);
                }
            }
            else
            {
                return(tiles.Traversable);
            }
        }
Пример #4
0
    public void OnDragStop()
    {
        if (tile == null)
        {
            return;
        }

        if (CanShipBePlaced(length))
        {
            PlaceShip(length);

            shipTile = draggableImage.transform.parent.GetComponentInParent <ShipTile>();
            shipTile.length--;
            draggableImage.gameObject.SetActive(false);

            if (shipTile.length == 0)
            {
                start++;
            }
            shipTile.UpdateText();
        }
        else
        {
            draggableImage.anchoredPosition = Vector2.zero;
            image.color = Color.white;
        }
        draggableImage = null;
        if (start == 4)
        {
            StartGame();
        }
        length = 0;
    }
Пример #5
0
 public override void TorpedoHit(Ammunition ammo, ShipTile tile)
 {
     _shipState = ShipState.Destroyed;
     //niszczymy obiekt
     _shipTiles[0].Destroy();
     //wysylamy informacje do Controllera.
     _refToLevel.Controller.OnShipBeginSinking(_shipTiles[0]);
 }
Пример #6
0
 /// <summary>
 /// Dodaje element do statku.
 /// </summary>
 /// <param name="tile">Element nalezacy do tego statku.</param>
 public void AddShipTile(ShipTile tile)
 {
     _shipTiles.Add(tile);
     if (tile is ISinkComponent)
     {
         _sinkComponents.Add(tile as ISinkComponent);
     }
 }
Пример #7
0
 public ShipTile(ShipTile t)
 {
     this.wall        = t.wall;
     this.location    = t.location;
     this.col         = t.col;
     this.strength    = t.strength;
     this.shipId      = t.shipId;
     originalLocation = location;
 }
Пример #8
0
	public void AddToConstruction(ShipTile new_tile, ShipTile.Coordinates coordinates) {
	/* Called when a new ShipTile is constructed to register it with this ShipConstruction's child ShipTiles. */
		new_tile.transform.parent = ShipTileEditor.main.player_ship.transform;
		new_tile.coordinates = coordinates;
		new_tile.SetPositionByCoordinates();
		tiles.Add(new_tile);
		tilemap.Insert(
				new_tile.coordinates.x,
				new_tile.coordinates.y,
				new_tile);
	}
Пример #9
0
 public void AddToConstruction(ShipTile new_tile, ShipTile.Coordinates coordinates)
 {
     /* Called when a new ShipTile is constructed to register it with this ShipConstruction's child ShipTiles. */
     new_tile.transform.parent = ShipTileEditor.main.player_ship.transform;
     new_tile.coordinates      = coordinates;
     new_tile.SetPositionByCoordinates();
     tiles.Add(new_tile);
     tilemap.Insert(
         new_tile.coordinates.x,
         new_tile.coordinates.y,
         new_tile);
 }
Пример #10
0
        /// <summary>
        /// Sprawdza kolizje z terenem, bunkrami , barakami, beczkami, etc.
        /// </summary>
        /// <author>Michal Ziober</author>
        private void CheckCollisionWithGroundAndShips()
        {
            if (Center.Y < MinYPosition && waterTravelDistance > 0)
            {
                int index = Mathematics.PositionToIndex(Center.X);
                if (index > -1 && index < refToLevel.LevelTiles.Count)
                {
                    //jesli nie ma kolizji z zadnym obiektem
                    if (refToLevel.LevelTiles[index].InCollision(this.boundRectangle) == CollisionType.None)
                    {
                        return;
                    }

                    //jesli nie da sie zniszczyc dany obiekt torpeda.
                    if (this.IsInWater)
                    {
                        if (!CanBeDestroyed(index) && !(refToLevel.LevelTiles[index] is OceanTile))
                        {
                            refToLevel.Controller.OnTileBombed(refToLevel.LevelTiles[index], this);
                            Destroy();
                        }
                        else
                        {
                            LevelTile destroyTile = refToLevel.LevelTiles[index];
                            if (destroyTile is BeginShipTile || destroyTile is EndShipTile)
                            {
                                if (waterTravelDistance < this.minWaterTravelDistance)
                                {
                                    SinkTorpedo(null);
                                    return;
                                }

                                ShipTile st = destroyTile as ShipTile;
                                if (!st.IsDestroyed && !st.IsSunkDown && st.Depth <= this.Bounds.Height)
                                {
                                    if (st.ShipOwner.IsLastHit)//jesli mozemy zatopic okret
                                    {
                                        refToLevel.Controller.OnTileDestroyed(destroyTile, this);
                                    }
                                    st.ShipOwner.TorpedoHit(this, destroyTile as ShipTile);//trafiamy w okret torpeda
                                    refToLevel.Statistics.HitByTorpedo++;
                                    //refToLevel.KillVulnerableSoldiers(index, 6);
                                }
                                //niszcze bombe.
                                //Destroy();
                                state = MissileState.Destroyed;
                            }
                        }
                    }
                }
            }
        }
Пример #11
0
 public static ShipTile Impact(ShipTile a, ShipTile b)
 {
     if (a.strength >= b.strength)
     {
         //Debug.Log("A Stronger");
         a.strength -= b.strength;
         return(a);
     }
     else
     {
         //Debug.Log("B Stronger");
         b.strength -= a.strength;
         return(b);
     }
 }
Пример #12
0
	public void ShipTileClicked(ShipTile shiptile) {
		/* Called when a ShipTile is clicked by the player.

		If the state is 'playing', ignore this.
		If the state is 'constructing', set state to 'editing' and create an editor context.
		If the state is 'editing', something went wrong; that shouldn't ever happen.
		*/
		if (guistate == GUIState.playing) {
			return;
		} else if (guistate == GUIState.constructing) {
			guistate = GUIState.editing;
			menu = shiptile.AttachEditorContextMenu();
			ShipTileEditor.main.SetConstructableTileVisibility(false);
		} else if (guistate == GUIState.editing) {
			throw new Exception("ShipTile clicked during 'editing' phase; this shouldn't happen.");
		}
	}
Пример #13
0
        public override void TorpedoHit(Ammunition ammo, ShipTile tile)
        {
            _shipState++;
            //  _shipState++;
            // _shipState++;
            if (_shipState == ShipState.Destroyed)
            {
                //niszczymy obiekt
                _shipTiles[0].Destroy();
                //wysylamy informacje do Controllera.
                SoundManager.Instance.PlayExposionSound();
                _refToLevel.Controller.OnShipBeginSinking(_shipTiles[0]);
            }
            else
            {
                //	SoundManager.Instance.PlayExposionSound();



                // TODO: zniszczyæ dzia³ko na statku (problem z tym ze ShipTiles nie zawiera bunkrow)

                /*Random r =new Random();
                 * int destroyTile = r.Next(0,this.ShipTiles.Count - 1);
                 *
                 * // trafienie z lewej
                 * if(tile == ShipTiles[0])
                 * {
                 *
                 *      for(int i=0; i<ShipTiles.Count; i++)
                 *      {
                 *              if(ShipTiles[i] is ShipBunkerTile)
                 *              {
                 *                      if(ShipTiles[i] as ShipBunkerTile)
                 *                      {
                 *
                 *                      }
                 *              }
                 *      }
                 * }
                 */

                _refToLevel.Controller.OnTileBombed(_shipTiles[0], ammo);
                _refToLevel.Controller.OnShipDamaged(_shipTiles[0], _shipState);
            }
        }
Пример #14
0
    public void DragThis(RectTransform t)
    {
        if (t != draggableImage || draggableImage == null)
        {
            draggableImage = t;
            vertical       = true;
            image          = t.GetComponentInChildren <Image>();
        }
        if (shipTile == null)
        {
            shipTile = draggableImage.GetComponentInParent <ShipTile>();
            length   = shipTile.shipsLength;
        }
        t.transform.position = Input.mousePosition;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, 10, layer))
        {
            if (hit.transform.gameObject != tile)
            {
                tile = hit.transform.GetComponent <Tile>();
                if (tile.HasShip || !tile.Available || !(length > 0 && CanShipBePlaced(length)))
                {
                    image.color = Color.red;
                }
                else
                {
                    image.color = Color.white;
                }
            }
        }
        else
        {
            if (tile == null)
            {
                return;
            }
            tile        = null;
            shipTile    = null;
            image.color = Color.white;
        }
    }
Пример #15
0
 public void ShipTileClicked(ShipTile shiptile)
 {
     /* Called when a ShipTile is clicked by the player.
      *
      * If the state is 'playing', ignore this.
      * If the state is 'constructing', set state to 'editing' and create an editor context.
      * If the state is 'editing', something went wrong; that shouldn't ever happen.
      */
     if (guistate == GUIState.playing)
     {
         return;
     }
     else if (guistate == GUIState.constructing)
     {
         guistate = GUIState.editing;
         menu     = shiptile.AttachEditorContextMenu();
         ShipTileEditor.main.SetConstructableTileVisibility(false);
     }
     else if (guistate == GUIState.editing)
     {
         throw new Exception("ShipTile clicked during 'editing' phase; this shouldn't happen.");
     }
 }
Пример #16
0
    private async Task <List <ShipTile> > Smash(int force, List <List <ShipTile> > tilesToMove)
    {
        List <int> tilesToRemove = new List <int>();
        ShipTile   t = null;
        ShipTile   ot, ft;
        Vector2Int currentChunk = Vector2Int.zero;
        List <int> dists        = new List <int>();
        List <List <ShipTile> > newTilesToMove = new List <List <ShipTile> >();

        foreach (List <ShipTile> list in tilesToMove)
        {
            newTilesToMove.Add(list.OrderBy(o => o.location.x).ToList());
            dists.Add(0);
        }
        bool            hit    = false;
        int             dist   = 0;
        List <ShipTile> output = new List <ShipTile>();

        while (force > 0)
        {
            for (int i = 0; i < newTilesToMove.Count; i++)
            {
                if (newTilesToMove[i].Count > 0)
                {
                    ShipTile tip = newTilesToMove[i][0];
                    tip.location -= Vector3Int.right;
                    ft            = ot = null;
                    currentChunk  = ChunkFinder(tip.location);
                    if (chunkTiles.ContainsKey(currentChunk))
                    {
                        if (chunkTiles[currentChunk].ContainsKey(tip.location))
                        {
                            ot = chunkTiles[currentChunk][tip.location];
                            if (ot.shipId != tip.shipId)
                            {
                                ft = ShipTile.Impact(ot, tip);

                                force--;
                                if (ft.shipId == ot.shipId)
                                {
                                    if (newTilesToMove[i].Count > 1)
                                    {
                                        newTilesToMove[i][1].location -= Vector3Int.right * (dists[i] - 1);//tip.location;//  += Vector3Int.right;
                                    }
                                    chunkTiles[currentChunk][ot.location].strength = ft.strength;
                                    newTilesToMove[i].RemoveAt(0);
                                }
                                else
                                {
                                    newTilesToMove[i][0].strength = ft.strength;
                                    chunkTiles[currentChunk].Remove(tip.location);
                                }
                            }
                        }
                    }
                    dists[i]++;
                }
            }
            dist++;
        }
        output = new List <ShipTile>();
        await new WaitForUpdate();
        for (int i = 0; i < newTilesToMove.Count; i++)
        {
            for (int j = 1; j < newTilesToMove[i].Count; j++)
            {
                newTilesToMove[i][j].location -= Vector3Int.right * (dists[i]);
            }
            output.AddRange(newTilesToMove[i]);
        }
        return(output);
    }
Пример #17
0
 /// <summary>
 /// Obsluga trafienia przez torpede.
 /// </summary>
 public abstract void TorpedoHit(Ammunition ammo, ShipTile tile);
Пример #18
0
 // Start is called before the first frame update
 void Start()
 {
     ShipTile[,] ship = new ShipTile[64, 64];
 }
Пример #19
0
 public void OnShipDamaged(ShipTile tile, ShipState state)
 {
 }
Пример #20
0
 public void OnShipBeginSinking(ShipTile tile)
 {
 }
Пример #21
0
 /// <summary>
 /// Statek tonie
 /// </summary>
 /// <param name="tile"></param>
 public void OnShipSinking(ShipTile tile)
 {
     AddJob(MethodBase.GetCurrentMethod().Name, new object[] { tile });
 }
Пример #22
0
 /// <summary>
 /// Metoda zglasza kolejny poziom zniszczen statku.
 /// </summary>
 /// <param name="tile">Element statku. Reprezentuje zniszczenia dla calego statku.</param>
 /// <param name="state">Reprezentuja aktualny poziom zniszczen dla danego statku.</param>
 public void OnShipDamaged(ShipTile tile, ShipState state)
 {
     AddJob(MethodBase.GetCurrentMethod().Name, new object[] { tile, state });
 }
Пример #23
0
    public async Task InitializeMap(Ship a, Ship b)
    {
        Debug.Log("Initing: " + Time.realtimeSinceStartup);
        mapTiles   = new Dictionary <Vector2Int, ShipTile>();
        chunkTiles = new Dictionary <Vector2Int, Dictionary <Vector3Int, ShipTile> >();
        Vector2Int currentChunk;

        foreach (ShipTile t in a.GetTiles())
        {
            currentChunk = ChunkFinder(t.location);
            if (chunkTiles.ContainsKey(currentChunk))
            {
                chunkTiles[currentChunk][t.location] = t;
            }
            else
            {
                chunkTiles.Add(currentChunk, new Dictionary <Vector3Int, ShipTile>());
                chunkTiles[currentChunk][t.location] = t;
            }
        }
        Debug.Log("Ship 1 Inited: " + Time.realtimeSinceStartup);
        await new WaitForSeconds(1);
        Vector3Int      offset      = a.Offset();
        List <ShipTile> tilesToMove = new List <ShipTile>();

        foreach (ShipTile t in b.GetTiles())
        {
            t.location += offset;
            tilesToMove.Add(t);
        }
        tilesToMove.OrderBy(o => o.location.x).ThenBy(o => o.location.y).ThenBy(o => o.location.z);
        Dictionary <Vector2Int, List <ShipTile> > rows = new Dictionary <Vector2Int, List <ShipTile> >();
        List <List <ShipTile> > rowList = new List <List <ShipTile> >();
        Vector2Int key = Vector2Int.zero;
        Dictionary <Vector2Int, int> indices = new Dictionary <Vector2Int, int>();

        foreach (ShipTile t in tilesToMove)
        {
            key.x = t.location.y;
            key.y = t.location.z;
            if (!indices.ContainsKey(key))
            {
                indices.Add(key, rows.Keys.Count);
                rows[key] = new List <ShipTile>();
                rows[key].Add(t);
            }
            else
            {
                rows[key].Add(t);
            }
        }
        foreach (List <ShipTile> tiles in rows.Values)
        {
            rowList.Add(tiles);
        }
        Debug.Log("Ship 2 Inited: " + Time.realtimeSinceStartup);
        await new WaitForBackgroundThread();
        Task <List <ShipTile> > smashed = Smash(force, rowList);

        foreach (ShipTile t in await smashed)
        {
            currentChunk = ChunkFinder(t.location);
            if (chunkTiles.ContainsKey(currentChunk))
            {
                if (chunkTiles[currentChunk].ContainsKey(t.location))
                {
                    ShipTile conflictChunk = chunkTiles[currentChunk][t.location];
                    int      index         = 0;
                    foreach (List <ShipTile> list in rowList)
                    {
                        if (list.Contains(conflictChunk))
                        {
                            index = list.IndexOf(list.First(o => o.location == conflictChunk.location)); // newTilesToMove[i].IndexOf(newTilesToMove[i].First(o => o.location.x == newTilesToMove[i].Min(no => no.location.x)));
                        }
                    }
                }
                chunkTiles[currentChunk][t.location] = t;
            }
            else
            {
                chunkTiles.Add(currentChunk, new Dictionary <Vector3Int, ShipTile>());
                chunkTiles[currentChunk][t.location] = t;
            }
        }
        await new WaitForUpdate();
        Debug.Log("Inited: " + Time.realtimeSinceStartup);
        await GenerateColliders();
    }
Пример #24
0
 public void OnShipSinking(ShipTile tile)
 {
 }