コード例 #1
0
ファイル: Game_Board.cs プロジェクト: icemonk2985/MatchThree
    public void MoveTiles(Game_Tile _Tile, float _angle)
    {
        int i = (int)_Tile.vec_TilePosition.x / 2;
        int j = (int)_Tile.vec_TilePosition.y / 2;

        TileTypes _TempTile = _Tile.Tile;

        //Moving the Tile
        if ((_Tile.transform.position.x > _Tile.vec_TilePosition.x + 1 ||
             _Tile.transform.position.x < _Tile.vec_TilePosition.x - 1 ||
             _Tile.transform.position.y > _Tile.vec_TilePosition.y + 1 ||
             _Tile.transform.position.y < _Tile.vec_TilePosition.y - 1))
        {
            if (45 < _angle && _angle < 135f)
            {
                //Move Tile Up

                _Tile.Tile = arr_GameBoardTiles[i, j + 1].Tile;
                arr_GameBoardTiles[i, j + 1].Tile = _TempTile;

                //_Tile.GetComponent<SpriteRenderer>().sprite = GamePlayManager.instance.TileSpriteChange(_Tile.Tile);
                //arr_GameBoardTiles[i, j + 1].GetComponent<SpriteRenderer>().sprite = GamePlayManager.instance.TileSpriteChange(arr_GameBoardTiles[i, j + 1].Tile);

                return;
            }
            else if (-135 < _angle && _angle < -45f)
            {
                //Move Tile Down

                _Tile.Tile = arr_GameBoardTiles[i, j - 1].Tile;
                arr_GameBoardTiles[i, j - 1].Tile = _TempTile;

                // _Tile.GetComponent<SpriteRenderer>().sprite = GamePlayManager.instance.TileSpriteChange(_Tile.Tile);
                //arr_GameBoardTiles[i, j - 1].GetComponent<SpriteRenderer>().sprite = GamePlayManager.instance.TileSpriteChange(arr_GameBoardTiles[i, j - 1].Tile);

                return;
            }
            else if (135 < _angle || _angle < -135f)
            {
                //Move Tile Left

                _Tile.Tile = arr_GameBoardTiles[i - 1, j].Tile;
                arr_GameBoardTiles[i - 1, j].Tile = _TempTile;

                //_Tile.GetComponent<SpriteRenderer>().sprite = GamePlayManager.instance.TileSpriteChange(_Tile.Tile);
                //arr_GameBoardTiles[i-1, j].GetComponent<SpriteRenderer>().sprite = GamePlayManager.instance.TileSpriteChange(arr_GameBoardTiles[i-1, j].Tile);

                return;
            }
            else if (-45 < _angle && _angle < 45f)
            {
                //Move Tile Right

                _Tile.Tile = arr_GameBoardTiles[i + 1, j].Tile;
                arr_GameBoardTiles[i + 1, j].Tile = _TempTile;

                //_Tile.GetComponent<SpriteRenderer>().sprite = GamePlayManager.instance.TileSpriteChange(_Tile.Tile);
                //arr_GameBoardTiles[i+1, j ].GetComponent<SpriteRenderer>().sprite = GamePlayManager.instance.TileSpriteChange(arr_GameBoardTiles[i+1, j].Tile);
            }

            return;
        }
        else
        {
            return;
        }
    }
コード例 #2
0
    void Update()
    {
        if (Selected_Piece && Input.GetKeyDown(KeyCode.C))
        {
            if (Selected_Piece.GetComponent <SpriteRenderer>().color == Color_List[0])
            {
                Game_Board      = Water_Board;
                currentRoadType = RoadType.Water;
                Selected_Piece.GetComponent <SpriteRenderer>().color = Color_List[1];
            }
            else
            {
                Game_Board      = Land_Board;
                currentRoadType = RoadType.Land;
                Selected_Piece.GetComponent <SpriteRenderer>().color = Color_List[0];
            }

            Debug.Log(Selected_Piece.GetComponent <SpriteRenderer>().color);
        }

        snap_distance = Game_Board.Square_Length * 2;

        target_position   = Camera.main.ScreenToWorldPoint(ih.Mouse_Position);
        target_position.z = 0;

        CheckGridForSnapPosition();

        if (Input.GetMouseButtonDown(1) && position_is_snapped)  //right mouse click and position snapped
        {
            if (Placed_Tiles.Find(t => t.transform.position == target_position))
            {
                int index;
                index = Placed_Tiles.FindIndex(t => t.transform.position == target_position);
                Destroy(Placed_Tiles.Find(t => t.transform.position == target_position));
                Placed_Tiles.Remove(Placed_Tiles[index].gameObject);
            }
        }

        if (Selected_Piece)
        {
            Selected_Piece.transform.position = target_position;
            DetermineCurrentSprite();



            if (Input.GetMouseButtonDown(0) && position_is_snapped)              //left mouse click and position snapped
            {
                Selected_Piece.GetComponent <GameTile>().DetermineActiveNodes(); //find linkable nodes of piece held

                if (Placed_Tiles.Find(t => t.transform.position == target_position))
                {
                    Debug.Log(Placed_Tiles.Find(t => t.transform.position == target_position));

                    //Debug.Log("Placed Road Nodes: " + (Placed_Tiles.Find(t => t.transform.position == target_position).GetComponent<GameTile>().Active_Nodes.Count));
                    //Debug.Log("Held Road Nodes: " + (Selected_Piece.GetComponent<GameTile>().Active_Nodes.Count));


                    if (Placed_Tiles.Find(t => t.transform.position == target_position).GetComponent <GameTile>().Active_Nodes.Count < Selected_Piece.GetComponent <GameTile>().Active_Nodes.Count)
                    {
                    }
                    else
                    {
                    }
                }
                else
                {
                    foreach (Vector3 Active_Node in Selected_Piece.GetComponent <GameTile>().Active_Nodes)      //iterate through each node of piece held
                    {
                        foreach (GameObject Game_Tile in Placed_Tiles)                                          //iterate through each linkable tile on the board
                        {
                            foreach (Vector3 Linkable_Node in Game_Tile.GetComponent <GameTile>().Active_Nodes) //iterate through each node of current linkable tile
                            {
                                switch (currentRoadType)
                                {
                                case RoadType.Land:
                                    if (Active_Node == Linkable_Node && !Tile_Added && playerResourceManager.MountainAmount >= LandRoadBuildCost * Selected_Piece.GetComponent <GameTile>().Active_Nodes.Count)     //if nodes match on piece held and linkable tile, drop piece
                                    {
                                        Tile = Instantiate(Selected_Piece, target_position, Quaternion.identity) as GameObject;
                                        Tile.GetComponent <GameTile>().DetermineActiveNodes();
                                        Tiles_To_Place.Add(Tile);
                                        Tile_Added = true;

                                        playerResourceManager.MountainAmount -= LandRoadBuildCost * Selected_Piece.GetComponent <GameTile>().Active_Nodes.Count;
                                        Placed_Road_Positions.Add(target_position);
                                    }
                                    break;

                                case RoadType.Water:
                                    if (Active_Node == Linkable_Node && !Tile_Added && playerResourceManager.ForestAmount >= WaterRoadBuildCost * Selected_Piece.GetComponent <GameTile>().Active_Nodes.Count)     //if nodes match on piece held and linkable tile, drop piece
                                    {
                                        Tile = Instantiate(Selected_Piece, target_position, Quaternion.identity) as GameObject;
                                        Tile.GetComponent <GameTile>().DetermineActiveNodes();
                                        Tiles_To_Place.Add(Tile);
                                        Tile_Added = true;

                                        playerResourceManager.ForestAmount -= WaterRoadBuildCost * Selected_Piece.GetComponent <GameTile>().Active_Nodes.Count;
                                        Placed_Road_Positions.Add(target_position);
                                    }
                                    break;

                                default:
                                    break;
                                }
                            }
                        }
                    }
                    foreach (GameObject Game_Tile in Tiles_To_Place)
                    {
                        Placed_Tiles.Add(Game_Tile);

                        foreach (CityScript c in Cities)
                        {
                            if (!Placed_Tiles.Contains(c.gameObject))
                            {
                                foreach (Vector3 City_Node in c.City_Nodes)
                                {
                                    foreach (Vector3 Active_Node in Game_Tile.GetComponent <GameTile>().Active_Nodes)  //iterate through each node of piece held
                                    {
                                        if (Active_Node == City_Node)
                                        {
                                            Placed_Tiles.Add(c.gameObject);
                                            playerResourceManager.AddTileToCollection(c);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    Tiles_To_Place.Clear();

                    Tile_Added = false;
                }
            }

            if (Input.GetMouseButtonDown(1))
            {
                Destroy(Selected_Piece);
            }
        }

        if (Input.GetMouseButtonDown(0) && !Selected_Piece)
        {
            Selected_Piece = Instantiate(Reference_Tile, target_position, Quaternion.identity) as GameObject;
            Selected_Piece.GetComponent <SpriteRenderer>().color = Color_List[0];
            current_sprite_index = Sprite_List.IndexOf(Selected_Piece.GetComponent <SpriteRenderer>().sprite);
        }
    }