Exemple #1
0
    //---------------------------------------------------------------------------
    public void CreateBoard(int width, int height)
    {
        BoardDoneBeingCreated = false;
        NonFloorPieces = new GamePiece[width, height];
        FloorPieces = new GamePiece[width, height];
        AllPiecesList = new List<GamePiece>(width * height);
        AllPlayerOwnedPieces = new List<Character>();
        AllAIOwnedPieces = new List<Character>();
        VisionHidePieces = new SpriteRenderer[width, height];
        for (var h = 0; h < width; ++h)
        {
            for (var v = 0; v < height; ++v)
            {
                VisionHidePieces[h, v] = GameObject.Instantiate(VisionHidePrefab);
                VisionHidePieces[h, v].transform.position = GetWorldPositionForBoardPosition(h, v);
            }
        }

        // setup the camera limits
        var cameraController = Camera.main.GetComponent<CameraController>();
        if (cameraController)
        {
            var farthestPiece = GetWorldPositionForBoardPosition(width-1, height-1);
            cameraController.MinCameraX = cameraController.MinCameraY = 0;
            cameraController.MaxCameraX = farthestPiece.x;
            cameraController.MaxCameraY = farthestPiece.y;
        }
    }
	private void Clicked(GamePiece gamePiece)
	{
		if (canClick) 
		{
			var additionPiece = (clockWise ? gamePiece.CounterClockwisePiece : gamePiece.ClockwisePiece);
			gamePiece.Value += additionPiece.Value;
			SetUpNextRound (gamePiece);

			//Debug.Log (clockWise + " " + additionPiece.Value);

			if(canClick)
			{
				AddTotalScore ();
				TextManager.UpdateDirection (ref clockWise);
				TextManager.UpdateOperation (greaterThan);
			}
			else
			{
				RemoveClickEventsToPieces ();
				TextManager.GameOver();

				RestartButton.gameObject.SetActive (true);
				RestartButton.onClick.AddListener(delegate { RestartGameEvent(); });
			}
		}
	}
Exemple #3
0
 public void createAnimalPiece()
 {
     var startPiece = new GamePiece(GetAvailablePosition()  ); // Position provide by
     GameObject NewAnimal = CreatePiece_Animal(startPiece, Color.blue);
     NewAnimal.transform.parent = Actor_Animals.transform ;
     NewAnimal.name = "NewAnimal_Luna";
     //Actor_Humans
     _gamePieces_Animals.Add(NewAnimal);
 }
Exemple #4
0
    public void createHumanPiece( HumanBehaviour.HUMAN_TYPE m_HumanType )
    {
        // Todo:  check the position
        //var startPiece = new GamePiece(new Point(2, 2)); // Position provide by
        var startPiece = new GamePiece(GetAvailablePosition()  ); // Position provide by
        GameObject NewHuman = CreatePiece_Human(startPiece, m_HumanType);

        NewHuman.transform.parent = Actor_Humans.transform ;
        NewHuman.name = "Human_Adam";
        //Actor_Humans
        _gamePieces_Humans.Add(NewHuman);
    }
    public void FlyToPiece(GamePiece piece)
    {
        var rightclicked = Input.GetMouseButton(1);
        if(rightclicked)
            return;

        // cancel any camera velocity
        mouseVelocity = Vector3.zero;

        // start flying
        flyTimeRemaining = FlyTime;
        startPosition = Camera.main.transform.position;
        targetPosition = GameManager.Instance.Board.GetWorldPositionForBoardPiece(piece);
        targetPosition.z = startPosition.z;
    }
Exemple #6
0
 // Private Methods
 public void ClearBoard()
 {
     for (int x = 0; x < GameBoardWidth; x++)
     {
         for (int y = 0; y < GameBoardHeight; y++)
         {
             boardSquares[x, y] = new GamePiece("Empty");
         }
     }
     for (int y = 0; y < GameBoardHeight; y++)
     {
         for (int x = 0; x < GameBoardWidth; x++)
         {
             RandomPiece(x, y);
         }
     }
 }
	private void SetUpNextRound(GamePiece gamePiece)
	{
		int index = 0;
		int nextGamePieceIndex;

		for (int i = 0; i < GamePieces.Length; i++) 
		{
			if(GamePieces[i] == gamePiece)
			{
				index = i;
				break;
			}
		}

		if ((index + 1) == GamePieces.Length)
			nextGamePieceIndex = 0;
		else
			nextGamePieceIndex = index + 1;

		if (clockWise) 
		{
			if(greaterThan)
			{
				if(GamePieces[index].Value < GamePieces[nextGamePieceIndex].Value)
					canClick = false;
			}
			else
			{
				if(GamePieces[index].Value > GamePieces[nextGamePieceIndex].Value)
					canClick = false;
			}
		} 
		else 
		{
			if(greaterThan)
			{
				if(GamePieces[nextGamePieceIndex].Value < GamePieces[index].Value)
					canClick = false;
			}
			else
			{
				if(GamePieces[nextGamePieceIndex].Value > GamePieces[index].Value)
					canClick = false;
			}
		}
	}
    public override bool onOccupy(GamePiece piece)
    {
        if (piece is Player && (piece as Player).isPainting)
        {
            isPainted = !isPainted;
            this.Paint();
            ScoresScript.UpdateScore(); //ian was here
            AudioClip sfxToPlay = isPainted ? DripSound : SuckSound;
            AudioSource.PlayClipAtPoint(sfxToPlay, Camera.main.transform.position, 0.5f);

        }
        else if (piece is Player && !(piece as Player).isPainting)
        {
            AudioSource.PlayClipAtPoint(ConcreteSound, Camera.main.transform.position, 1.0f);
        }
        RoomManager.roomManager.CheckAllCanvi();
        return base.onOccupy(piece);
    }
Exemple #9
0
    IEnumerator SwitchTilesRoutine(Tile clickedTile, Tile targetTile)
    {
        if (m_playerInputEnable)
        {
            GamePiece clickedPiece = m_allGamePieces[clickedTile.xIndex, clickedTile.yIndex];
            GamePiece targetPiece  = m_allGamePieces[targetTile.xIndex, targetTile.yIndex];

            if (targetPiece != null && clickedPiece != null)
            {
                clickedPiece.Move(targetTile.xIndex, targetTile.yIndex, swapTime);
                targetPiece.Move(clickedTile.xIndex, clickedTile.yIndex, swapTime);

                yield return(new WaitForSeconds(swapTime));

                List <GamePiece> clickedPieceMatches = FindMatchesAt(clickedTile.xIndex, clickedTile.yIndex);
                List <GamePiece> targetPieceMatches  = FindMatchesAt(targetTile.xIndex, targetTile.yIndex);
                List <GamePiece> colorMatches        = new List <GamePiece>();

                if (IsColoredBomb(clickedPiece) && !IsColoredBomb(targetPiece))
                {
                    clickedPiece.matchValue = targetPiece.matchValue;
                    colorMatches            = FindAllMatchValue(clickedPiece.matchValue);
                }
                else if (!IsColoredBomb(clickedPiece) && IsColoredBomb(targetPiece))
                {
                    targetPiece.matchValue = clickedPiece.matchValue;
                    colorMatches           = FindAllMatchValue(targetPiece.matchValue);
                }
                else if (IsColoredBomb(clickedPiece) && IsColoredBomb(targetPiece))
                {
                    foreach (GamePiece piece in m_allGamePieces)
                    {
                        if (!colorMatches.Contains(piece))
                        {
                            colorMatches.Add(piece);
                        }
                    }
                }
                if (targetPieceMatches.Count == 0 && clickedPieceMatches.Count == 0 && colorMatches.Count == 0)
                {
                    clickedPiece.Move(clickedTile.xIndex, clickedTile.yIndex, swapTime);
                    targetPiece.Move(targetTile.xIndex, targetTile.yIndex, swapTime);
                }
                else
                {
                    if (GameManager.Instance != null)
                    {
                        GameManager.Instance.movesLeft--;
                        GameManager.Instance.UpdateMoves();
                    }
                    yield return(new WaitForSeconds(swapTime));

                    #region Old ClearPieceAt method call
                    //ClearPieceAt (clickedPieceMatches);
                    //ClearPieceAt (targetPieceMatches);

                    //CollapseColumn(clickedPieceMatches);
                    //CollapseColumn(targetPieceMatches);

                    //HighlightMatchesAt(clickedTile.xIndex,clickedTile.yIndex);
                    //HighlightMatchesAt(targetTile.xIndex,targetTile.yIndex);
                    #endregion
                    Vector2 swipeDirection = new Vector2(targetTile.xIndex - clickedTile.xIndex, targetTile.yIndex - targetTile.yIndex);
                    m_clickedTileBomb = DropBomb(clickedTile.xIndex, clickedTile.yIndex, swipeDirection, clickedPieceMatches);
                    m_targetTileBomb  = DropBomb(targetTile.xIndex, targetTile.yIndex, swipeDirection, targetPieceMatches);

                    if (m_clickedTileBomb != null && targetPiece != null)
                    {
                        if (!IsColoredBomb(m_clickedTileBomb.GetComponent <GamePiece>()))
                        {
                            m_clickedTileBomb.GetComponent <GamePiece>().ChangeColor(targetPiece);
                        }
                    }
                    if (m_targetTileBomb != null && clickedPiece != null)
                    {
                        if (!IsColoredBomb(m_targetTileBomb.GetComponent <GamePiece>()))
                        {
                            m_targetTileBomb.GetComponent <GamePiece>().ChangeColor(clickedPiece);
                        }
                    }

                    ClearAndRefillBoard(clickedPieceMatches.Union(targetPieceMatches).ToList().Union(colorMatches).ToList());
                }
            }
        }
    }
        public bool[,] GetAvailableMovePositions(bool team, GamePiece piece)
        {
            bool[,] board = new bool[8, 8];

            Vector2Int piecePos = piece.position;

            if (piece.piece == GamePieceEnum.Pawn)  // Pawn
            {
                if (PositionIsAvailable(team, piecePos + new Vector2Int(-1, 0), piece.attack, piece) > 0)
                {
                    board[piecePos.x - 1, piecePos.y] = true;
                }

                if (PositionIsAvailable(team, piecePos + new Vector2Int(1, 0), piece.attack, piece) > 0)
                {
                    board[piecePos.x + 1, piecePos.y] = true;
                }

                if (PositionIsAvailable(team, piecePos + new Vector2Int(0, -1), piece.attack, piece) > 0)
                {
                    board[piecePos.x, piecePos.y - 1] = true;
                }

                if (PositionIsAvailable(team, piecePos + new Vector2Int(0, 1), piece.attack, piece) > 0)
                {
                    board[piecePos.x, piecePos.y + 1] = true;
                }
            }
            else if (piece.piece == GamePieceEnum.Rook)    // Rook
            {
                int p;

                // Right
                for (int i = piecePos.x + 1; i < GAME_BOARD_SIZE; i++)
                {
                    p = PositionIsAvailable(team, new Vector2Int(i, piecePos.y), piece.attack, piece);

                    if (p > 0)
                    {
                        board[i, piecePos.y] = true;

                        if (p == 2)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                // Left
                for (int i = piecePos.x - 1; i >= 0; i--)
                {
                    p = PositionIsAvailable(team, new Vector2Int(i, piecePos.y), piece.attack, piece);

                    if (p > 0)
                    {
                        board[i, piecePos.y] = true;

                        if (p == 2)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                // Up
                for (int i = piecePos.y + 1; i < GAME_BOARD_SIZE; i++)
                {
                    p = PositionIsAvailable(team, new Vector2Int(piecePos.x, i), piece.attack, piece);

                    if (p > 0)
                    {
                        board[piecePos.x, i] = true;

                        if (p == 2)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                // Down
                for (int i = piecePos.y - 1; i >= 0; i--)
                {
                    p = PositionIsAvailable(team, new Vector2Int(piecePos.x, i), piece.attack, piece);

                    if (p > 0)
                    {
                        board[piecePos.x, i] = true;

                        if (p == 2)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else if (piece.piece == GamePieceEnum.Knight)    // Knight
            {
                if (PositionIsAvailable(team, piecePos + new Vector2Int(-1, 2), piece.attack, piece) > 0)
                {
                    board[piecePos.x - 1, piecePos.y + 2] = true;
                }

                if (PositionIsAvailable(team, piecePos + new Vector2Int(1, 2), piece.attack, piece) > 0)
                {
                    board[piecePos.x + 1, piecePos.y + 2] = true;
                }

                if (PositionIsAvailable(team, piecePos + new Vector2Int(-2, 1), piece.attack, piece) > 0)
                {
                    board[piecePos.x - 2, piecePos.y + 1] = true;
                }

                if (PositionIsAvailable(team, piecePos + new Vector2Int(2, 1), piece.attack, piece) > 0)
                {
                    board[piecePos.x + 2, piecePos.y + 1] = true;
                }

                if (PositionIsAvailable(team, piecePos + new Vector2Int(-1, -2), piece.attack, piece) > 0)
                {
                    board[piecePos.x - 1, piecePos.y - 2] = true;
                }

                if (PositionIsAvailable(team, piecePos + new Vector2Int(1, -2), piece.attack, piece) > 0)
                {
                    board[piecePos.x + 1, piecePos.y - 2] = true;
                }

                if (PositionIsAvailable(team, piecePos + new Vector2Int(-2, -1), piece.attack, piece) > 0)
                {
                    board[piecePos.x - 2, piecePos.y - 1] = true;
                }

                if (PositionIsAvailable(team, piecePos + new Vector2Int(2, -1), piece.attack, piece) > 0)
                {
                    board[piecePos.x + 2, piecePos.y - 1] = true;
                }
            }
            else if (piece.piece == GamePieceEnum.Bishop)
            {
                int p;

                // Right up
                for (int i = 1; i <= GAME_BOARD_SIZE; i++)
                {
                    p = PositionIsAvailable(team, new Vector2Int(piecePos.x + i, piecePos.y + i), piece.attack, piece);

                    if (p > 0)
                    {
                        board[piecePos.x + i, piecePos.y + i] = true;

                        if (p == 2)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                // Left up
                for (int i = 1; i <= GAME_BOARD_SIZE; i++)
                {
                    p = PositionIsAvailable(team, new Vector2Int(piecePos.x - i, piecePos.y + i), piece.attack, piece);

                    if (p > 0)
                    {
                        board[piecePos.x - i, piecePos.y + i] = true;

                        if (p == 2)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                // Right down
                for (int i = 1; i <= GAME_BOARD_SIZE; i++)
                {
                    p = PositionIsAvailable(team, new Vector2Int(piecePos.x + i, piecePos.y - i), piece.attack, piece);

                    if (p > 0)
                    {
                        board[piecePos.x + i, piecePos.y - i] = true;

                        if (p == 2)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                // Left down
                for (int i = 1; i <= GAME_BOARD_SIZE; i++)
                {
                    p = PositionIsAvailable(team, new Vector2Int(piecePos.x - i, piecePos.y - i), piece.attack, piece);

                    if (p > 0)
                    {
                        board[piecePos.x - i, piecePos.y - i] = true;

                        if (p == 2)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else if (piece.piece == GamePieceEnum.Queen)
            {
                int p;

                // Right
                for (int i = piecePos.x + 1; i < GAME_BOARD_SIZE; i++)
                {
                    p = PositionIsAvailable(team, new Vector2Int(i, piecePos.y), piece.attack, piece);

                    if (p > 0)
                    {
                        board[i, piecePos.y] = true;

                        if (p == 2)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                // Left
                for (int i = piecePos.x - 1; i >= 0; i--)
                {
                    p = PositionIsAvailable(team, new Vector2Int(i, piecePos.y), piece.attack, piece);

                    if (p > 0)
                    {
                        board[i, piecePos.y] = true;

                        if (p == 2)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                // Up
                for (int i = piecePos.y + 1; i < GAME_BOARD_SIZE; i++)
                {
                    p = PositionIsAvailable(team, new Vector2Int(piecePos.x, i), piece.attack, piece);

                    if (p > 0)
                    {
                        board[piecePos.x, i] = true;

                        if (p == 2)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                // Down
                for (int i = piecePos.y - 1; i >= 0; i--)
                {
                    p = PositionIsAvailable(team, new Vector2Int(piecePos.x, i), piece.attack, piece);

                    if (p > 0)
                    {
                        board[piecePos.x, i] = true;

                        if (p == 2)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                // Right up
                for (int i = 1; i <= GAME_BOARD_SIZE; i++)
                {
                    p = PositionIsAvailable(team, new Vector2Int(piecePos.x + i, piecePos.y + i), piece.attack, piece);

                    if (p > 0)
                    {
                        board[piecePos.x + i, piecePos.y + i] = true;

                        if (p == 2)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                // Left up
                for (int i = 1; i <= GAME_BOARD_SIZE; i++)
                {
                    p = PositionIsAvailable(team, new Vector2Int(piecePos.x - i, piecePos.y + i), piece.attack, piece);

                    if (p > 0)
                    {
                        board[piecePos.x - i, piecePos.y + i] = true;

                        if (p == 2)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                // Right down
                for (int i = 1; i <= GAME_BOARD_SIZE; i++)
                {
                    p = PositionIsAvailable(team, new Vector2Int(piecePos.x + i, piecePos.y - i), piece.attack, piece);

                    if (p > 0)
                    {
                        board[piecePos.x + i, piecePos.y - i] = true;

                        if (p == 2)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                // Left down
                for (int i = 1; i <= GAME_BOARD_SIZE; i++)
                {
                    p = PositionIsAvailable(team, new Vector2Int(piecePos.x - i, piecePos.y - i), piece.attack, piece);

                    if (p > 0)
                    {
                        board[piecePos.x - i, piecePos.y - i] = true;

                        if (p == 2)
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            else if (piece.piece == GamePieceEnum.King)
            {
                if (PositionIsAvailable(team, piecePos + new Vector2Int(-1, 0), piece.attack, piece) > 0)
                {
                    board[piecePos.x - 1, piecePos.y] = true;
                }

                if (PositionIsAvailable(team, piecePos + new Vector2Int(1, 0), piece.attack, piece) > 0)
                {
                    board[piecePos.x + 1, piecePos.y] = true;
                }

                if (PositionIsAvailable(team, piecePos + new Vector2Int(0, -1), piece.attack, piece) > 0)
                {
                    board[piecePos.x, piecePos.y - 1] = true;
                }

                if (PositionIsAvailable(team, piecePos + new Vector2Int(0, 1), piece.attack, piece) > 0)
                {
                    board[piecePos.x, piecePos.y + 1] = true;
                }

                if (PositionIsAvailable(team, piecePos + new Vector2Int(-1, -1), piece.attack, piece) > 0)
                {
                    board[piecePos.x - 1, piecePos.y - 1] = true;
                }

                if (PositionIsAvailable(team, piecePos + new Vector2Int(1, -1), piece.attack, piece) > 0)
                {
                    board[piecePos.x + 1, piecePos.y - 1] = true;
                }

                if (PositionIsAvailable(team, piecePos + new Vector2Int(-1, 1), piece.attack, piece) > 0)
                {
                    board[piecePos.x - 1, piecePos.y + 1] = true;
                }

                if (PositionIsAvailable(team, piecePos + new Vector2Int(1, 1), piece.attack, piece) > 0)
                {
                    board[piecePos.x + 1, piecePos.y + 1] = true;
                }
            }

            return(board);
        }
    // Update is called once per frame
    public void Update()
    {
        // Get map tile when click on map
        if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
        {
            Vector3Int tileCoords = gameMapObject.GetMouseTileCoords(playerCamera.camera, Input.mousePosition);
            player.SetSelectedCard(null);
            Debug.Log("got tile coords: " + tileCoords);

            // Click on map tile
            if (tileCoords != null)
            {
                GameHex   gameHex = gameMap.GetHexAtTileCoords(tileCoords);
                GamePiece piece   = gameHex.piece;
                Debug.Log("got piece: " + piece);

                // Piece is on tile
                if (piece != null)
                {
                    Debug.Log("piece id: " + piece.GetPlayerId() + " player id: " + player.playerId);

                    // Piece is current player's
                    if (piece.GetPlayerId() == player.playerId && player.isTurn)
                    {
                        // Piece is already selected
                        if (piece == player.selectedPiece)
                        {
                            Debug.Log("piece is selected piece, clearing");
                            player.ClearSelectedPiece();
                            actionMapObject.PaintActionMap();
                        }
                        else if (piece.hasActions)
                        {
                            Debug.Log("piece can move, creating map");
                            player.SetSelectedPiece(piece);
                            actionMapObject.PaintActionMap();
                        }
                    }

                    // Piece is another player's
                    // SHOW UNIT DETAILS
                }
                else
                {
                    player.ClearSelectedPiece();
                }
            }
        }

        // Get map tile when right click on map
        if (Input.GetMouseButtonDown(1) && !EventSystem.current.IsPointerOverGameObject())
        {
            Vector3Int tileCoords = gameMapObject.GetMouseTileCoords(playerCamera.camera, Input.mousePosition);
            Debug.Log("got tile coords: " + tileCoords);

            // Click on map tile
            if (tileCoords != null)
            {
                // Play card from hand
                if (player.hasSelectedCard && player.actionMap.PlayableToTileAtTileCoords(tileCoords))
                {
                    Debug.Log("playing selected card");
                    PlaySelectedCardAtTile(tileCoords);
                }

                // Move or attack piece
                if (player.HasSelectedPiece())
                {
                    Debug.Log("player has selected piece");

                    // Move to tile
                    if (player.actionMap.MoveableToTileAtTileCoords(tileCoords))
                    {
                        Debug.Log("moving selected piece");
                        MovePiece(tileCoords);
                    }

                    // Attack tile
                    else if (player.actionMap.AttackableTileAtTileCoords(tileCoords))
                    {
                        Debug.Log("attacking piece");
                        AttackPiece(tileCoords);
                    }
                }
            }
        }
    }
Exemple #12
0
    //---------------------------------------------------------------------------
    public List<GamePiece> GetShortestPath(GamePiece startingPiece, int hPos, int vPos, int targetHPos, int targetVPos, int movesLeft)
    {
        if (!PosInBounds(hPos, vPos))
            return null;

        // get the current piece
        var currentPiece = GetFloorPieceIfAvailable(hPos, vPos, startingPiece);

        // can't move here!
        if (currentPiece == null)
            return null;

        // add this piece
        var ret = new List<GamePiece>();
        ret.Add(currentPiece);

        // if we reached the goal return
        if (hPos == targetHPos && vPos == targetVPos)
        {
            return ret;
        }

        // no moves left and haven't hit the target oops give up here
        if (movesLeft <= 0)
            return null;

        // recurse and get the shortest list
        var listOfLists = new List<List<GamePiece>>();
        listOfLists.Add(GetShortestPath(startingPiece, hPos - 0, vPos - 1, targetHPos, targetVPos, movesLeft - 1));
        listOfLists.Add(GetShortestPath(startingPiece, hPos - 0, vPos + 1, targetHPos, targetVPos, movesLeft - 1));
        listOfLists.Add(GetShortestPath(startingPiece, hPos - 1, vPos - 0, targetHPos, targetVPos, movesLeft - 1));
        listOfLists.Add(GetShortestPath(startingPiece, hPos + 1, vPos - 0, targetHPos, targetVPos, movesLeft - 1));
        var shortestList = GetShortestList(listOfLists);

        // no path from here to the end?  return null.
        if(shortestList == null)
            return null;

        ret.AddRange(shortestList);
        return ret;
    }
Exemple #13
0
    //---------------------------------------------------------------------------
    public void SetPiece(int hPos, int vPos, GamePiece piece, bool leaveCorpse = false)
    {
        // Check if something is already in that spot
        var currentPiece = NonFloorPieces[hPos, vPos];
        if (currentPiece && !currentPiece.IsFloorPiece)
        {
            // Remove whatever is in that spot.
            OnPieceRemoved(this, currentPiece);
            if(!leaveCorpse)
                GameObject.Destroy(currentPiece.gameObject);
            NonFloorPieces[hPos, vPos] = null;
            AllPiecesList.Remove(currentPiece);
            AllAIOwnedPieces.Remove(currentPiece as Character);
            AllPlayerOwnedPieces.Remove(currentPiece as Character);
        }

        // Make sure we weren't just cleaning up the old piece.
        if (piece == null)
            return;

        // add and position the piece.
        piece.transform.position = GetWorldPositionForBoardPosition(hPos, vPos);
        if (piece.IsFloorPiece)
            FloorPieces[hPos, vPos] = piece;
        else
            NonFloorPieces[hPos, vPos] = piece;
        AllPiecesList.Add(piece);
        piece.BoardHPos = hPos;
        piece.BoardVPos = vPos;

        var character = piece as Character;
        if (character)
        {
            if (character.Controller.IsAIControlled())
                AllAIOwnedPieces.Add(character);
            else
                AllPlayerOwnedPieces.Add(character);

            if(BoardDoneBeingCreated)
                character.Controller.UpdateVisiblePieces();
        }

        OnPieceAdded(this, piece);
    }
Exemple #14
0
    // decide the logic
    //
    void CalculateGameLogic()
    {
        //if(BoardClass == null) return;

        /// first: get all the tile and data nearby (max totally 6 )

            // 1. get the tile i stand now.
            Tile TileStand = BoardClass._game.AllTiles.Single(o => o.X == Piece.Location.X && o.Y == Piece.Location.Y); // get the tile

            // First , find if the Animal Stand on the same place
            GameObject AnimalOnTile = BoardClass._gamePieces_Animals.Find( o => ( (AnimalBehaviour)o.GetComponent("AnimalBehaviour")).Piece.X == TileStand.X  && ( (AnimalBehaviour)o.GetComponent("AnimalBehaviour")).Piece.Y == TileStand.Y );
            // the same place ... Battle !
            if(AnimalOnTile)
            {
                //TileStand.Tile_StandStatus = TILE_STAND_STATUS.TILE_STAND_STATUS_BOTH;
                TileStand.IsBattleField = true;

                    if( UnityEngine.Random.Range( 0 , 2) ==0  )
                        m_bDistroy = true;
                    else
                        ((AnimalBehaviour)AnimalOnTile.GetComponent("AnimalBehaviour")).m_bDistroy = true;

                // stay at the same place
                    m_HumanPiece_Behaviour_Prev = m_HumanPiece_Behaviour ;
                    m_HumanPiece_Behaviour = HUMAN_BEHAVIOUR.HUMAN_BEHAVIOUR_FIGHT;
                    Position_Destination =BoardBehavior.GetWorldCoordinates(TileStand.Location.X, TileStand.Location.Y, 0f);

                    // to decide who win / lose

                    return;
            }

            // or just do normal process
            TileStand.CanPass = true; // release this tile
            TileStand.Tile_StandStatus = TILE_STAND_STATUS.TILE_STAND_STATUS_NONE;

            // 2.get all the neighbours
            int nNewX = Piece.X;
            int nNewY = Piece.Y;
            List <Tile>AvailableTiles =  TileStand.Neighbours.ToList();
            // 2. include self  , calculate all it's attribute , apply to probability
            AvailableTiles.Add(TileStand);

            //3.  decide which tile will be taken
            int nRandomChoose =  UnityEngine.Random.Range(0 , AvailableTiles.Count);
            Debug.Log( "CalculateGameLogic:"+ Piece.X + ","+Piece.Y +"neib # "+AvailableTiles.Count+",choose:"+ nRandomChoose );

            nNewX = AvailableTiles[nRandomChoose].X;
            nNewY = AvailableTiles[nRandomChoose].Y;
            //Piece_Destination = new GamePiece( nNewX , nNewY);

            // 4.
            AvailableTiles[nRandomChoose].CanPass = false; // occupy now
            AvailableTiles[nRandomChoose].Tile_StandStatus =TILE_STAND_STATUS.TILE_STAND_STATUS_HUMAN; /// hey now i stand on this tile

            // 5. decide the action depends on probability
            m_HumanPiece_Behaviour_Prev = m_HumanPiece_Behaviour ;

            if(AvailableTiles[nRandomChoose].TileStatus  == TILE_STATUS.TILE_STATUS_TERRIAN)
            {
                if (AvailableTiles[nRandomChoose].TerrianType == TERRIAN_STATUS.MINE)
                {
                    m_HumanPiece_Behaviour = HUMAN_BEHAVIOUR.HUMAN_BEHAVIOUR_GETRESOURCE;
                }
                else // if no mine =>
                {
                    AvailableTiles[nRandomChoose].TileStatus = TILE_STATUS.TILE_STATUS_BUILDING;  // set this tile as
                // decide the behavior by probability //m_Human
                    m_HumanPiece_Behaviour = HUMAN_BEHAVIOUR.HUMAN_BEHAVIOUR_BUILD; // hey  , now we are make building
                }
            }
            else
            if(AvailableTiles[nRandomChoose].TileStatus  == TILE_STATUS.TILE_STATUS_BUILDING)
            {
            // the same
            //AvailableTiles[nRandomChoose].TileStatus = TILE_STATUS.TILE_STATUS_BUILDING;  //
            // Use It to Generate Point
                m_HumanPiece_Behaviour = HUMAN_BEHAVIOUR.HUMAN_BEHAVIOUR_BUILD_USE; // hey  , now we are make building
            }
            else
            if(AvailableTiles[nRandomChoose].TileStatus  == TILE_STATUS.TILE_STATUS_TERRIAN && AvailableTiles[nRandomChoose].TerrianType == TERRIAN_STATUS.MINE)
            {
                m_HumanPiece_Behaviour = HUMAN_BEHAVIOUR.HUMAN_BEHAVIOUR_GETRESOURCE;
            }

            /// To process the AI activity
            Piece = new GamePiece(new Point(nNewX, nNewY));
            //transform.position =  BoardBehavior.GetWorldCoordinates(Piece.X, Piece.Y, 0f);
            Position_Destination =BoardBehavior.GetWorldCoordinates(Piece.X, Piece.Y, 0f);

        // also to resigted this tile , means it's occupy by user now
    }
Exemple #15
0
    //---------------------------------------------------------------------------
    public List<GamePiece> GetAvailableMovePositionsRecursive(GamePiece startingPiece, ref List<GamePiece> alreadyIn, int hPos, int vPos, int movesLeft)
    {
        // are we out of moves or out of bounds?
        if (movesLeft <= 0 || hPos < 0 || vPos < 0 || hPos >= NonFloorPieces.GetLength(0) || vPos >= NonFloorPieces.GetLength(1))
            return alreadyIn;

        var openFloor = GetFloorPieceIfAvailable(hPos, vPos, startingPiece);
        if (openFloor != null)
        {
            // Is this a new spot?  If it is, add and recurse, if it's not, don't.
            if (!alreadyIn.Contains(openFloor))
            {
                alreadyIn.Add(openFloor);
            }
            GetAvailableMovePositionsRecursive(startingPiece, ref alreadyIn, hPos - 0, vPos - 1, movesLeft - 1);
            GetAvailableMovePositionsRecursive(startingPiece, ref alreadyIn, hPos - 0, vPos + 1, movesLeft - 1);
            GetAvailableMovePositionsRecursive(startingPiece, ref alreadyIn, hPos - 1, vPos - 0, movesLeft - 1);
            GetAvailableMovePositionsRecursive(startingPiece, ref alreadyIn, hPos + 1, vPos - 0, movesLeft - 1);
        }

        return alreadyIn;
    }
Exemple #16
0
 public void AddPiece(GamePiece gamePiece)
 {
     _gamePieces.Add(gamePiece);
 }
Exemple #17
0
 public int GetIndex(GamePiece gamePiece)
 {
     return(_gamePieces.IndexOf(gamePiece));
 }
Exemple #18
0
    public List <GamePiece> GetMatch(GamePiece piece, int newX, int newY)
    {
        if (piece.IsColored())
        {
            ColorPiece.ColorType color            = piece.ColorComponent.Color;
            List <GamePiece>     horizontalPieces = new List <GamePiece> ();
            List <GamePiece>     verticalPieces   = new List <GamePiece> ();
            List <GamePiece>     matchingPieces   = new List <GamePiece> ();

            // First check horizontal
            horizontalPieces.Add(piece);

            for (int dir = 0; dir <= 1; dir++)
            {
                for (int xOffset = 1; xOffset < xDim; xOffset++)
                {
                    int x;

                    if (dir == 0)                       // Left
                    {
                        x = newX - xOffset;
                    }
                    else                         // Right
                    {
                        x = newX + xOffset;
                    }

                    if (x < 0 || x >= xDim)
                    {
                        break;
                    }

                    if (pieces [x, newY].IsColored() && pieces [x, newY].ColorComponent.Color == color)
                    {
                        horizontalPieces.Add(pieces [x, newY]);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (horizontalPieces.Count >= 3)
            {
                for (int i = 0; i < horizontalPieces.Count; i++)
                {
                    matchingPieces.Add(horizontalPieces [i]);
                }
            }


            // Traverse vertically if we found a match (for L and T shapes)
            //if (horizontalPieces.Count >= 3)
            //{
            //	for (int i = 0; i < horizontalPieces.Count; i++) {
            //		for (int dir = 0; dir <= 1; dir++) {
            //			for (int yOffset = 1; yOffset < yDim; yOffset++) {
            //				int y;

            //				if (dir == 0) { // Up
            //					y = newY - yOffset;
            //				} else { // Down
            //					y = newY + yOffset;
            //				}

            //				if (y < 0 || y >= yDim) {
            //					break;
            //				}

            //				if (pieces [horizontalPieces [i].X, y].IsColored () && pieces [horizontalPieces [i].X, y].ColorComponent.Color == color) {
            //					verticalPieces.Add (pieces [horizontalPieces [i].X, y]);
            //				} else {
            //					break;
            //				}
            //			}
            //		}

            //		if (horizontalPieces.Count < 2) {
            //			horizontalPieces.Clear ();
            //		} else {
            //			for (int j = 0; j < horizontalPieces.Count; j++) {
            //				matchingPieces.Add (horizontalPieces[j]);
            //			}

            //			break;
            //		}
            //	}
            //}

            //if (matchingPieces.Count >= 5)
            //{
            //    Spawnitem(matchingPieces);
            //    Spawnitem(matchingPieces);
            //    Spawnitem(matchingPieces);
            //    AudioSource audiosouce = this.gameObject.GetComponent<AudioSource>();
            //    audiosouce.Play();
            //    return matchingPieces;
            //}
            //else if (matchingPieces.Count == 4)
            //{
            //    Spawnitem(matchingPieces);
            //    Spawnitem(matchingPieces);
            //    AudioSource audiosouce = this.gameObject.GetComponent<AudioSource>();
            //    audiosouce.Play();
            //    return matchingPieces;
            //}
            //else if (matchingPieces.Count == 3)
            //{
            //    Spawnitem(matchingPieces);
            //    AudioSource audiosouce = this.gameObject.GetComponent<AudioSource>();
            //    audiosouce.Play();
            //    return matchingPieces;
            //}



            // Didn't find anything going horizontally first,
            // so now check vertically
            horizontalPieces.Clear();
            verticalPieces.Clear();
            verticalPieces.Add(piece);

            for (int dir = 0; dir <= 1; dir++)
            {
                for (int yOffset = 1; yOffset < yDim; yOffset++)
                {
                    int y;

                    if (dir == 0)                       // Up
                    {
                        y = newY - yOffset;
                    }
                    else                         // Down
                    {
                        y = newY + yOffset;
                    }

                    if (y < 0 || y >= yDim)
                    {
                        break;
                    }

                    if (pieces [newX, y].IsColored() && pieces [newX, y].ColorComponent.Color == color)
                    {
                        verticalPieces.Add(pieces [newX, y]);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (verticalPieces.Count >= 3)
            {
                for (int i = 0; i < verticalPieces.Count; i++)
                {
                    matchingPieces.Add(verticalPieces [i]);
                }
            }

            //// Traverse horizontally if we found a match (for L and T shapes)
            //if (verticalPieces.Count >= 3)
            //{
            //	for (int i = 0; i < verticalPieces.Count; i++) {
            //		for (int dir = 0; dir <= 1; dir++) {
            //			for (int xOffset = 1; xOffset < xDim; xOffset++) {
            //				int x;

            //				if (dir == 0) { // Left
            //					x = newX - xOffset;
            //				} else { // Right
            //					x = newX + xOffset;
            //				}

            //				if (x < 0 || x >= xDim) {
            //					break;
            //				}

            //				if (pieces [x, verticalPieces[i].Y].IsColored () && pieces [x, verticalPieces[i].Y].ColorComponent.Color == color) {
            //					horizontalPieces.Add (pieces [x, verticalPieces[i].Y]);
            //				} else {
            //					break;
            //				}
            //			}
            //		}

            //		if (horizontalPieces.Count < 2) {
            //			horizontalPieces.Clear ();
            //		} else {
            //			for (int j = 0; j < horizontalPieces.Count; j++) {
            //				matchingPieces.Add (horizontalPieces [j]);
            //			}

            //			break;
            //		}
            //	}
            //}

            if (matchingPieces.Count >= 5)
            {
                Spawnitem(matchingPieces);
                Spawnitem(matchingPieces);
                Spawnitem(matchingPieces);
                AudioSource audiosouce = this.gameObject.GetComponent <AudioSource>();
                audiosouce.Play();
                return(matchingPieces);
            }
            else if (matchingPieces.Count == 4)
            {
                Spawnitem(matchingPieces);
                Spawnitem(matchingPieces);
                AudioSource audiosouce = this.gameObject.GetComponent <AudioSource>();
                audiosouce.Play();
                return(matchingPieces);
            }
            else if (matchingPieces.Count == 3)
            {
                Spawnitem(matchingPieces);
                AudioSource audiosouce = this.gameObject.GetComponent <AudioSource>();
                audiosouce.Play();
                return(matchingPieces);
            }
        }

        return(null);
    }
Exemple #19
0
    //public Animator flipAnimator { get; set; }

    public void setInfo(GamePiece gamePiece)
    {
        pieceInfo     = gamePiece;
        currentVisual = pieceInfo.ownedBy;
    }
Exemple #20
0
 public void PressPiece(GamePiece piece)     // on mouseDown : OnMouseDown is called when the user has pressed the mouse button while over the GUIElement or Collider.
 {
     pressedPiece = piece;
 }
    public static void ExecuteAction(bool t, ClientAction action)
    {
        GamePiece pieceAtPos = gameBoard.GetPieceAtPosition(action.actionFromPos);

        switch (action.actionIndex)
        {
        case 0:
            if (pieceAtPos == null)
            {
                gameBoard.CreatePawn(t, action.actionFromPos);
            }

            break;

        case 1:
            if (pieceAtPos != null)
            {
                GamePiece pieceAtNewPos = gameBoard.GetPieceAtPosition(action.actionToPos);

                if (pieceAtNewPos == null)
                {
                    pieceAtPos.position = action.actionToPos;
                }
                else
                {
                    if (pieceAtNewPos.team != t)
                    {
                        if (pieceAtNewPos.piece != GamePieceEnum.King)
                        {
                            // Eat
                            gameBoard.RemovePiece(pieceAtNewPos);
                            pieceAtPos.position = action.actionToPos;
                        }
                        else
                        {
                            // Damage King
                            pieceAtNewPos.health -= pieceAtPos.attack;

                            if (pieceAtNewPos.health > 0)
                            {
                                if (pieceAtPos.piece != GamePieceEnum.Knight)
                                {
                                    Vector2Int diff = pieceAtNewPos.position - pieceAtPos.position;
                                    int        newX = diff.x == 0 ? 0 : diff.x / Mathf.Abs(diff.x);
                                    int        newY = diff.y == 0 ? 0 : diff.y / Mathf.Abs(diff.y);
                                    diff = new Vector2Int(newX, newY);

                                    pieceAtPos.position = pieceAtNewPos.position - diff;
                                }
                                else
                                {
                                    // Knight special mechanics
                                    Vector2Int diff      = pieceAtNewPos.position - pieceAtPos.position;
                                    bool       dominantX = Mathf.Abs(diff.x) > 1;
                                    int        newX      = diff.x == 0 ? 0 : diff.x / Mathf.Abs(diff.x);
                                    int        newY      = diff.y == 0 ? 0 : diff.y / Mathf.Abs(diff.y);

                                    if (dominantX)
                                    {
                                        Vector2Int pref = pieceAtNewPos.position - new Vector2Int(newX, 0);
                                        if (gameBoard.PositionIsEmpty(pref))
                                        {
                                            pieceAtPos.position = pref;
                                        }
                                        else
                                        {
                                            pieceAtPos.position = pieceAtNewPos.position - new Vector2Int(0, newY);
                                        }
                                    }
                                    else
                                    {
                                        Vector2Int pref = pieceAtNewPos.position - new Vector2Int(0, newY);
                                        if (gameBoard.PositionIsEmpty(pref))
                                        {
                                            pieceAtPos.position = pref;
                                        }
                                        else
                                        {
                                            pieceAtPos.position = pieceAtNewPos.position - new Vector2Int(newX, 0);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                gameBoard.RemovePiece(pieceAtNewPos);
                                pieceAtPos.position = action.actionToPos;

                                EndGame(t);
                            }
                        }
                    }
                }

                pieceAtPos.frozen = true;
            }

            break;

        case 2:
            if (pieceAtPos != null && pieceAtPos.piece == GamePieceEnum.Pawn)
            {
                pieceAtPos.piece  = (GamePieceEnum)action.newID;
                pieceAtPos.frozen = true;
            }

            break;

        case 3:
            if (pieceAtPos != null && pieceAtPos.piece == GamePieceEnum.King)
            {
                pieceAtPos.health++;

                if (pieceAtPos.health > 5)
                {
                    pieceAtPos.health = 5;
                }
            }

            break;

        case 4:
            if (pieceAtPos != null && pieceAtPos.piece != GamePieceEnum.King)
            {
                pieceAtPos.health++;

                if (pieceAtPos.health > 3)
                {
                    pieceAtPos.health = 3;
                }
            }

            break;

        case 5:
            if (pieceAtPos != null && pieceAtPos.piece != GamePieceEnum.King)
            {
                pieceAtPos.attack++;

                if (pieceAtPos.attack > 3)
                {
                    pieceAtPos.attack = 3;
                }
            }

            break;
        }
    }
        private int PositionIsAvailable(bool team, Vector2Int pos, int attack, GamePiece myPiece)
        {
            if (pos.x < 0 || pos.x > GAME_BOARD_SIZE - 1 || pos.y < 0 || pos.y > GAME_BOARD_SIZE - 1)
            {
                return(0);
            }

            foreach (GamePiece piece in whitePieces)
            {
                if (piece.position == pos)
                {
                    if (!team)
                    {
                        if (piece.piece == GamePieceEnum.King)
                        {
                            if (myPiece.piece != GamePieceEnum.Knight)
                            {
                                return(2);
                            }
                            else
                            {
                                Vector2Int diff = piece.position - myPiece.position;
                                int        newX = diff.x == 0 ? 0 : diff.x / Mathf.Abs(diff.x);
                                int        newY = diff.y == 0 ? 0 : diff.y / Mathf.Abs(diff.y);

                                if (PositionIsEmpty(pos - new Vector2Int(newX, 0)) || PositionIsEmpty(pos - new Vector2Int(0, newY)))
                                {
                                    return(2);
                                }

                                return(0);
                            }
                        }
                        else
                        {
                            if (piece.health <= attack)
                            {
                                return(2);
                            }
                            else
                            {
                                return(0);
                            }
                        }
                    }
                    else
                    {
                        return(0);
                    }
                }
            }

            foreach (GamePiece piece in blackPieces)
            {
                if (piece.position == pos)
                {
                    if (team)
                    {
                        if (piece.piece == GamePieceEnum.King)
                        {
                            if (myPiece.piece != GamePieceEnum.Knight)
                            {
                                return(2);
                            }
                            else
                            {
                                Vector2Int diff = piece.position - myPiece.position;
                                int        newX = diff.x == 0 ? 0 : diff.x / Mathf.Abs(diff.x);
                                int        newY = diff.y == 0 ? 0 : diff.y / Mathf.Abs(diff.y);

                                if (PositionIsEmpty(pos - new Vector2Int(newX, 0)) || PositionIsEmpty(pos - new Vector2Int(0, newY)))
                                {
                                    return(2);
                                }

                                return(0);
                            }
                        }
                        else
                        {
                            if (piece.health <= attack)
                            {
                                return(2);
                            }
                            else
                            {
                                return(0);
                            }
                        }
                    }
                    else
                    {
                        return(0);
                    }
                }
            }

            return(1);
        }
Exemple #23
0
 void Awake()
 {
     piece = GetComponent <GamePiece> ();
 }
Exemple #24
0
 public void RemovePiece(GamePiece piece)
 {
     _gamePieces.Remove(piece);
 }
    public void QueuedOccupy(int Zposition, GamePiece piece)
    {
        if (Zposition > pieces.Count)
        {
            occupationQueue[Zposition] = piece;
            Debug.Log("adding " + piece.GetType() + " at " + Zposition);
        }
        else
        {
            if (!Occupy(piece)) throw new WTFException();
            occupationQueue[Zposition] = null;
            foreach (int i in occupationQueue.Keys.ToList())
            {
                GamePiece p = occupationQueue[i];
                if (p == null) continue;
                QueuedOccupy(i, p);

            }
        }
    }
 public override void UpdateComponent(GamePiece GamePiece)
 {
     Move(GamePiece);
 }
Exemple #27
0
    //---------------------------------------------------------------------------
    public void PlayerClickedSquare(GamePiece piece, bool aiPick = false)
    {
        if (activeCharacter == null || (activeCharacter.IsAIControlled() && !aiPick))
        {
            return;
        }

        // If the AI picks null it is a skip.
        if(piece == null && aiPick)
        {
            activeCharacter.PerformAction(null);
            return;
        }

        // is it empty?
        var floorAtClick = piece ? Board.FloorPieces[piece.BoardHPos, piece.BoardVPos] : null;
        if (floorAtClick)
        {
            // Is it available for movement?
            if (activeCharacter.AvailableMovePositions.Contains(floorAtClick))
            {
                // is this a noop movement?
                activeCharacter.CharacterMovementComplete += OnCharacterDoneMoving;
                activeCharacter.BeginMoveTo(floorAtClick);
            }
        }

        // Is it an attack?
        if (activeCharacter.AvailableAttackTargetFloorSquares.Contains(floorAtClick))
        {
            activeCharacter.PerformAction(floorAtClick);
        }
    }
Exemple #28
0
    // returns matching pieces from a ColorBomb
    public List <GamePiece> ProcessColorBombs(GamePiece clickedPiece, GamePiece targetPiece,
                                              bool clearNonBlockers = false)
    {
        // create a new List to hold potential color matches
        List <GamePiece> colorMatches = new List <GamePiece>();

        // reference to our two swapped GamePieces
        GamePiece colorBombPiece = null;
        GamePiece otherPiece     = null;

        // if the clicked GamePiece is a Color Bomb and the target GamePiece is not
        if (board.boardQuery.IsColorBomb(clickedPiece) && !board.boardQuery.IsColorBomb(targetPiece))
        {
            colorBombPiece = clickedPiece;
            otherPiece     = targetPiece;
        }
        //... if the target GamePiece is a Color Bomb, and the clicked GamePiece is not
        else if (!board.boardQuery.IsColorBomb(clickedPiece) && board.boardQuery.IsColorBomb(targetPiece))
        {
            colorBombPiece = targetPiece;
            otherPiece     = clickedPiece;
        }
        //... if they are both Color bombs
        else if (board.boardQuery.IsColorBomb(clickedPiece) && board.boardQuery.IsColorBomb(targetPiece))
        {
            foreach (GamePiece piece in board.allGamePieces)
            {
                if (!colorMatches.Contains(piece))
                {
                    colorMatches.Add(piece);
                }
            }
        }

        // if nether GamePiece is a color bomb, we do nothing and return an empty list of GamePieces

        // if one GamePiece is a color bomb...
        if (colorBombPiece != null)
        {
            // set the color bomb's matchValue
            colorBombPiece.matchValue = otherPiece.matchValue;

            // store a list of all GamePieces with that matchValue
            colorMatches = board.boardQuery.FindAllMatchValue(otherPiece.matchValue);
        }

        // if you are only clearing Blockers (not Collectibles)...
        if (!clearNonBlockers)
        {
            // get a list of Collectibles that are cleared at the bottom of the Board
            List <GamePiece> collectedAtBottom = board.boardQuery.FindAllCollectibles(true);

            // if the other GamePiece in the swap is a Collectible, return nothing
            if (collectedAtBottom.Contains(otherPiece))
            {
                return(new List <GamePiece>());
            }
            else
            {
                // otherwise, just remove all of the Collectibles from our list
                foreach (GamePiece piece in collectedAtBottom)
                {
                    colorMatches.Remove(piece);
                }
            }
        }
        // return list of GamePieces with the correct matchValue
        return(colorMatches);
    }
Exemple #29
0
    //---------------------------------------------------------------------------
    public void GetAvailableTargets(GamePiece startingPiece, int attackRange, bool throughWalls, bool pierce, out List<GamePiece> allCharactersInRange, out List<GamePiece> allFloorPiecesInRange, int hitMask, int piercableMask, int impenetrableMask)
    {
        allFloorPiecesInRange = new List<GamePiece>();
        allCharactersInRange = new List<GamePiece>();
        for (var hDiff = -attackRange; hDiff <= attackRange; ++hDiff)
        {
            for (var vDiff = -attackRange; vDiff <= attackRange; ++vDiff)
            {
                var targetPosH = startingPiece.BoardHPos + hDiff;
                var targetPosV = startingPiece.BoardVPos + vDiff;
                if (Mathf.Abs(hDiff) + Mathf.Abs(vDiff) <= attackRange && PosInBounds(targetPosH, targetPosV))
                {
                    // assume we can hit the square until we can't
                    var canHitThisSquare = true;

                    // Check for line of sight?
                    if (!throughWalls)
                    {
                        // ignore floor hits
                        var startVector = GetWorldPositionForBoardPosition(startingPiece.BoardHPos, startingPiece.BoardVPos);
                        var endVector = GetWorldPositionForBoardPosition(targetPosH, targetPosV);
                        var hits = Physics2D.RaycastAll(startVector, endVector - startVector, (endVector - startVector).magnitude, hitMask);

                        // check if it needs to stop due to piercing problems
                        foreach (var hit in hits)
                        {
                            // ignore hitting self
                            if (Mathf.Approximately(hit.fraction, 0f))
                                continue;

                            var isImpenetrableLayer = ((1 << hit.collider.gameObject.layer) & impenetrableMask) != 0;
                            var isPiercableLayer = ((1 << hit.collider.gameObject.layer) & piercableMask) != 0;

                            // if a piece was hit, check if it was at the target terminus (yes we can hit) or not (no we can't hit)
                            if (isImpenetrableLayer || (!pierce && isPiercableLayer))
                            {
                                var piece = hit.collider.GetComponent<GamePiece>();
                                if (piece)
                                {
                                    if (piece.BoardHPos != targetPosH || piece.BoardVPos != targetPosV)
                                    {
                                        canHitThisSquare = false;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if (canHitThisSquare)
                    {
                        var charThisSquare = NonFloorPieces[targetPosH, targetPosV];
                        var floorThisSquare = FloorPieces[targetPosH, targetPosV];
                        if (charThisSquare != null)
                            allCharactersInRange.Add(charThisSquare);
                        allFloorPiecesInRange.Add(floorThisSquare);
                    }
                }
            }
        }
    }
Exemple #30
0
    public bool FillStep()
    {
        bool movedPiece = false;

        //check if the piece under it was empty, and then move the piece down
        for (int y = yDim - 2; y >= 0; y--)
        {
            for (int loopX = 0; loopX < xDim; loopX++)
            {
                int x = loopX;
                if (inverse)
                {
                    x = xDim - 1 - loopX;
                }

                GamePiece piece = pieces[x, y];

                if (piece.isMovable())
                {
                    GamePiece pieceBelow = pieces[x, y + 1];

                    if (pieceBelow.Type == PieceType.EMPTY)
                    {
                        //The Destoy method we'll simply destroy the empty piece
                        //below before moving a new piece into it
                        Destroy(pieceBelow.gameObject);
                        piece.MovableComponent.Move(x, y + 1, fillTime);
                        pieces[x, y + 1] = piece;

                        SpawnNewPiece(x, y, PieceType.EMPTY);
                        movedPiece = true;
                    }
                    else
                    {
                        for (int diag = -1; diag <= 1; diag++)
                        {
                            if (diag != 0)
                            {
                                int diagX = x + diag;

                                if (inverse)
                                {
                                    diagX = x - diag;
                                }

                                if (diagX >= 0 && diagX < xDim)
                                {
                                    GamePiece diagonalPiece = pieces[diagX, y + 1];

                                    if (diagonalPiece.Type == PieceType.EMPTY)
                                    {
                                        bool hasPieceAbove = true;

                                        for (int aboveY = y; aboveY >= 0; aboveY--)
                                        {
                                            GamePiece pieceAbove = pieces[diagX, aboveY];

                                            if (pieceAbove.isMovable())
                                            {
                                                break;
                                            }
                                            else if (!pieceAbove.isMovable() && pieceAbove.Type != PieceType.EMPTY)
                                            {
                                                hasPieceAbove = false;
                                                break;
                                            }
                                        }

                                        //if the piece doesn't have piece above I need to fill it diagonally
                                        if (!hasPieceAbove)
                                        {
                                            Destroy(diagonalPiece.gameObject);
                                            piece.MovableComponent.Move(diagX, y + 1, fillTime);
                                            pieces[diagX, y + 1] = piece;
                                            SpawnNewPiece(x, y, PieceType.EMPTY);
                                            movedPiece = true;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        for (int x = 0; x < xDim; x++)
        {
            GamePiece pieceBelow = pieces[x, 0];

            if (pieceBelow.Type == PieceType.EMPTY)
            {
                Destroy(pieceBelow.gameObject);
                GameObject newPiece = (GameObject)Instantiate(piecePrefabDict[PieceType.NORMAL], GetWorldPosition(x, -1), Quaternion.identity);
                newPiece.transform.parent = transform;

                pieces[x, 0] = newPiece.GetComponent <GamePiece>();
                pieces[x, 0].Init(x, -1, this, PieceType.NORMAL);
                pieces[x, 0].MovableComponent.Move(x, 0, fillTime);
                pieces[x, 0].CharacterComponent.SetCharacter((CharacterPiece.CharacterType)Random.Range(0, pieces[x, 0].CharacterComponent.NumCharacters));
                movedPiece = true;
            }
        }

        return(movedPiece);
    }
Exemple #31
0
    public void MovePiecetoNewLocation(int hPos, int vPos, GamePiece piece)
    {
        if (NonFloorPieces[piece.BoardHPos, piece.BoardVPos] != piece)
        {
            Debug.LogError("Moving piece that isn't there! " + piece);
            return;
        }

        if (NonFloorPieces[hPos, vPos] != null)
        {
            Debug.LogError("Trying to move into already occupied space! " + hPos + ", " + vPos);
            return;
        }

        NonFloorPieces[piece.BoardHPos, piece.BoardVPos] = null;
        NonFloorPieces[hPos, vPos] = piece;
        piece.BoardHPos = hPos;
        piece.BoardVPos = vPos;
    }
Exemple #32
0
    public List <GamePiece> GetMatch(GamePiece piece, int newX, int newY)
    {
        if (piece.hasCaracther())
        {
            CharacterPiece.CharacterType characther       = piece.CharacterComponent.Character;
            List <GamePiece>             horizontalPieces = new List <GamePiece>();
            List <GamePiece>             verticalPieces   = new List <GamePiece>();
            List <GamePiece>             matchingPieces   = new List <GamePiece>();

            //First check horizontal
            horizontalPieces.Add(piece);

            for (int dir = 0; dir <= 1; dir++)
            {
                //xOffset =  xOffset is how far away the adjacent piece is from our central piece.
                for (int xOffset = 1; xOffset < xDim; xOffset++)
                {
                    int x;

                    if (dir == 0) //Left
                    {
                        x = newX - xOffset;
                    }
                    else  //Right
                    {
                        x = newX + xOffset;
                    }

                    if (x < 0 || x >= xDim)
                    {
                        break;
                    }

                    //check if the adjacent piece is a match.
                    if (pieces[x, newY].hasCaracther() && pieces[x, newY].CharacterComponent.Character == characther)
                    {
                        horizontalPieces.Add(pieces[x, newY]);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (horizontalPieces.Count >= 3)
            {
                for (int i = 0; i < horizontalPieces.Count; i++)
                {
                    matchingPieces.Add(horizontalPieces[i]);
                }
            }


            if (horizontalPieces.Count >= 3)
            {
                for (int i = 0; i < horizontalPieces.Count; i++)
                {
                    //Traverse vertically if a match is found
                    for (int dir = 0; dir <= 1; dir++)
                    {
                        for (int yOffset = 1; yOffset < yDim; yOffset++)
                        {
                            int y;

                            if (dir == 0)
                            { //Up
                                y = newY - yOffset;
                            }
                            else
                            { //Down
                                y = newY + yOffset;
                            }

                            //If the coordinate of the adjacent piece is outside of our grids dimensions,
                            //break out of the loop.
                            if (y < 0 || y >= yDim)
                            {
                                break;
                            }

                            //If the piece matches, we add it to the vertical pieces list.
                            //If the piece doesn't match, we break out of the loop.
                            if (pieces[horizontalPieces[i].X, y].hasCaracther() &&
                                pieces[horizontalPieces[i].X, y].CharacterComponent.Character == characther)
                            {
                                verticalPieces.Add(pieces[horizontalPieces[i].X, y]);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    //check if have enough vertical pieces to form a match
                    // we need two vertical pieces to form a match.
                    if (verticalPieces.Count < 2)
                    {
                        //If we don't have enough vertical pieces for a match, we clear the vertical pieces list
                        //so that we can get ready to iterate along the next horizontal matching piece.
                        verticalPieces.Clear();
                    }
                    else
                    {
                        for (int j = 0; j < verticalPieces.Count; j++)
                        {
                            matchingPieces.Add(verticalPieces[j]);
                        }

                        break;
                    }
                }
            }

            if (matchingPieces.Count >= 3)
            {
                return(matchingPieces);
            }


            //Didn't find anything going horizontally first,
            //so now check vertically
            horizontalPieces.Clear();
            verticalPieces.Clear();
            verticalPieces.Add(piece);

            for (int dir = 0; dir <= 1; dir++)
            {
                for (int yOffset = 1; yOffset < yDim; yOffset++)
                {
                    int y;

                    if (dir == 0)
                    {//Up
                        y = newY - yOffset;
                    }
                    else
                    {//Down
                        y = newY + yOffset;
                    }

                    if (y < 0 || y >= yDim)
                    {
                        break;
                    }

                    //check if the adjacent piece is a match.
                    if (pieces[newX, y].hasCaracther() &&
                        pieces[newX, y].CharacterComponent.Character == characther)
                    {
                        verticalPieces.Add(pieces[newX, y]);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (verticalPieces.Count >= 3)
            {
                for (int i = 0; i < verticalPieces.Count; i++)
                {
                    matchingPieces.Add(verticalPieces[i]);
                }
            }

            if (verticalPieces.Count >= 3)
            {
                for (int i = 0; i < verticalPieces.Count; i++)
                {
                    //Traverse vertically if a match is found
                    for (int dir = 0; dir <= 1; dir++)
                    {
                        for (int xOffset = 1; xOffset < xDim; xOffset++)
                        {
                            int x;

                            if (dir == 0)
                            { //Left
                                x = newX - xOffset;
                            }
                            else
                            { //Right
                                x = newX + xOffset;
                            }

                            //If the coordinate of the adjacent piece is outside of our grids dimensions,
                            //break out of the loop.
                            if (x < 0 || x >= xDim)
                            {
                                break;
                            }

                            //If the piece matches, we add it to the vertical pieces list.
                            //If the piece doesn't match, we break out of the loop.
                            if (pieces[x, verticalPieces[i].Y].hasCaracther() &&
                                pieces[x, verticalPieces[i].Y].CharacterComponent.Character == characther)
                            {
                                horizontalPieces.Add(pieces[x, verticalPieces[i].Y]);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    //check if have enough horizontal pieces to form a match
                    //need just two horizontal pieces to form a match.
                    if (horizontalPieces.Count < 2)
                    {
                        //If we don't have enough horizontal pieces for a match, we need to clear the horizontal pieces list
                        //so that we can get ready to iterate along the next horizontal matching piece.
                        horizontalPieces.Clear();
                    }
                    else
                    {
                        for (int j = 0; j < horizontalPieces.Count; j++)
                        {
                            matchingPieces.Add(horizontalPieces[j]);
                        }

                        break;
                    }
                }
            }

            if (matchingPieces.Count >= 3)
            {
                return(matchingPieces);
            }
        }

        //if no match is found
        return(null);
    }
Exemple #33
0
 //---------------------------------------------------------------------------
 public static int ManhattenDistance(GamePiece A, int hPosB, int vPosB)
 {
     return ManhattenDistance(A.BoardHPos, A.BoardVPos, hPosB, vPosB);
 }
 public virtual bool canBeOccupiedBy(GamePiece piece)
 {
     return true;
 }
 // Lost piece
 public void LostPiece(GamePiece piece)
 {
     gamePieceObjects.Remove(piece);
 }
 public virtual void onDeOccupy(GamePiece piece)
 {
 }
Exemple #37
0
    void FillBoard(int falseYOffset = 0, float moveTime = 0.1f)
    {
        List <GamePiece> addedPieces = new List <GamePiece>();

        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                if (m_allGamePieces[i, j] == null && m_allTiles[i, j].tileType != TileType.Obstacle)
                {
                    GamePiece piece = null;
                    if (falseYOffset == 0)
                    {
                        if (j == height - 1 && CanAddCollectilbe())
                        {
                            piece = FillRandomCollectibleAt(i, j);
                            collectibleCount++;
                        }
                        else
                        {
                            piece = FillRandomGamePieceAt(i, j);
                        }
                    }
                    else
                    {
                        if (j == height - 1 && CanAddCollectilbe())
                        {
                            piece = FillRandomCollectibleAt(i, j, falseYOffset, moveTime);
                            collectibleCount++;
                        }
                        else
                        {
                            piece = FillRandomGamePieceAt(i, j, falseYOffset, moveTime);
                        }
                    }
                    addedPieces.Add(piece);
                }
            }
        }

        int  maxIterations = 150;
        int  iterations    = 0;
        bool isFilled      = false;

        while (!isFilled)
        {
            List <GamePiece> matches = FindAllMatches();
            if (matches.Count == 0)
            {
                isFilled = true;
                break;
            }
            else
            {
                matches = matches.Intersect(addedPieces).ToList();
                if (falseYOffset == 0)
                {
                    ReplaceWithRandom(matches);
                }
                else
                {
                    ReplaceWithRandom(matches, falseYOffset, moveTime);
                }
            }
            if (iterations > maxIterations)
            {
                isFilled = true;
                Debug.LogWarning("BOARD.FillBoard max iterations reached! Aborting...");
            }
            iterations++;
        }
        //Debug.Log ("Iterations: "+iterations);
    }
 public virtual bool onOccupy(GamePiece piece)
 {
     return true;
 }
Exemple #39
0
    List <GamePiece> FindMatches(int startX, int startY, Vector2 searchDirection, int minLength = 3)
    {
        List <GamePiece> matches = new List <GamePiece>();

        GamePiece startPiece = null;

        if (IsWithinBounds(startX, startY))
        {
            startPiece = m_allGamePieces[startX, startY];
        }

        if (startPiece != null)
        {
            matches.Add(startPiece);
        }

        else
        {
            return(null);
        }

        int nextX;
        int nextY;

        int maxValue = (width > height) ? width: height;

        for (int i = 1; i < maxValue - 1; i++)
        {
            nextX = startX + (int)Mathf.Clamp(searchDirection.x, -1, 1) * i;
            nextY = startY + (int)Mathf.Clamp(searchDirection.y, -1, 1) * i;

            if (!IsWithinBounds(nextX, nextY))
            {
                break;
            }

            GamePiece nextPiece = m_allGamePieces[nextX, nextY];
            if (nextPiece == null)
            {
                break;
            }
            else
            {
                if (nextPiece.matchValue == startPiece.matchValue && !matches.Contains(nextPiece) && nextPiece.matchValue != MatchValue.None)
                {
                    matches.Add(nextPiece);
                }

                else
                {
                    break;
                }
            }
        }

        if (matches.Count >= minLength)
        {
            return(matches);
        }

        return(null);
    }
Exemple #40
0
    public List <GamePiece> GetMatch(GamePiece piece, int newX, int newY)
    {
        if (piece.IsColored())
        {
            ColorPiece.ColorType color            = piece.ColorComponent.Color;
            List <GamePiece>     horizontalPieces = new List <GamePiece>();
            List <GamePiece>     verticalPieces   = new List <GamePiece>();
            List <GamePiece>     matchingPieces   = new List <GamePiece>();


            //Checking for horizontal matches
            horizontalPieces.Add(piece);

            for (int dir = 0; dir <= 1; dir++)
            {
                for (int xOffset = 1; xOffset < xDim; xOffset++)
                {
                    int x;

                    if (dir == 0)
                    {  //left
                        x = newX - xOffset;
                    }
                    else
                    { // right
                        x = newX + xOffset;
                    }

                    if (x < 0 || x >= xDim)
                    {
                        break;
                    }

                    if (pieces[x, newY].IsColored() && pieces[x, newY].ColorComponent.Color == color)
                    {
                        horizontalPieces.Add(pieces[x, newY]);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (horizontalPieces.Count >= 3)
            {
                for (int i = 0; i < horizontalPieces.Count; i++)
                {
                    matchingPieces.Add(horizontalPieces[i]);
                }
            }

            // Traverse vertically if we found a match (for L and T shape)
            if (horizontalPieces.Count >= 3)
            {
                for (int i = 0; i < verticalPieces.Count; i++)
                {
                    for (int dir = 0; dir <= 1; dir++)
                    {
                        for (int yOffset = 1; yOffset < yDim; yOffset++)
                        {
                            int y;

                            if (dir == 0)
                            { //Up
                                y = newY - yOffset;
                            }
                            else   //Down
                            {
                                y = newY + yOffset;
                            }

                            if (y < 0 || y >= yDim)
                            {
                                break;
                            }

                            if (pieces[horizontalPieces[i].X, y].IsColored() && pieces[horizontalPieces[i].X, y].ColorComponent.Color == color)
                            {
                                verticalPieces.Add(pieces[horizontalPieces[i].X, y]);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }

                if (verticalPieces.Count < 2)
                {
                    verticalPieces.Clear();
                }
                else
                {
                    for (int j = 0; j < verticalPieces.Count; j++)
                    {
                        matchingPieces.Add(verticalPieces[j]);
                    }
                    //break;
                }
            }

            if (matchingPieces.Count >= 3)
            {
                return(matchingPieces);
            }


            //Checking for vertial matches
            horizontalPieces.Clear();
            verticalPieces.Clear();
            verticalPieces.Add(piece);

            for (int dir = 0; dir <= 1; dir++)
            {
                for (int yOffset = 1; yOffset < yDim; yOffset++)
                {
                    int y;

                    if (dir == 0)
                    {  //up
                        y = newY - yOffset;
                    }
                    else
                    { // down
                        y = newY + yOffset;
                    }

                    if (y < 0 || y >= yDim)
                    {
                        break;
                    }

                    if (pieces[newX, y].IsColored() && pieces[newX, y].ColorComponent.Color == color)
                    {
                        verticalPieces.Add(pieces[newX, y]);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            if (verticalPieces.Count >= 3)
            {
                for (int i = 0; i < verticalPieces.Count; i++)
                {
                    matchingPieces.Add(verticalPieces[i]);
                }
            }

            // Traverse horizontally if we found a match (for L and T shape)
            if (verticalPieces.Count >= 3)
            {
                for (int i = 0; i < verticalPieces.Count; i++)
                {
                    for (int dir = 0; dir <= 1; dir++)
                    {
                        for (int xOffset = 1; xOffset < yDim; xOffset++)
                        {
                            int x;

                            if (dir == 0)
                            { //Left
                                x = newX - xOffset;
                            }
                            else   //Right
                            {
                                x = newX + xOffset;
                            }

                            if (x < 0 || x >= xDim)
                            {
                                break;
                            }

                            if (pieces[x, verticalPieces[i].Y].IsColored() && pieces[x, verticalPieces[i].Y].ColorComponent.Color == color)
                            {
                                horizontalPieces.Add(pieces[x, verticalPieces[i].Y]);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }

                if (horizontalPieces.Count < 2)
                {
                    horizontalPieces.Clear();
                }
                else
                {
                    for (int j = 0; j < horizontalPieces.Count; j++)
                    {
                        matchingPieces.Add(horizontalPieces[j]);
                    }
                    //break;
                }
            }

            if (matchingPieces.Count >= 3)
            {
                return(matchingPieces);
            }
        }

        return(null);
    }
 public bool Occupy(GamePiece piece)
 {
     if (pieces.Contains(piece)) return false;
     if (IsSolidlyOccupied()) return false;
     foreach (GamePiece p in pieces)
     {
         if (!p.canBeOccupiedBy(piece)) return false;
     }
     pieces.Add(piece);
     piece.cell = this;
     foreach (GamePiece p in pieces.ToList())
     {
         if (p == piece) continue;
         p.onOccupy(piece);
     }
     return true;
 }
Exemple #42
0
    // 从下到上 最上面是0
    public bool FillStep()
    {
        bool movedPiece = false;

        for (int y = yDim - 2; y >= 0; y--)
        {
            for (int loopX = 0; loopX < xDim; loopX++)
            {
                int x = loopX;
                if (inverse)
                {
                    x = xDim - 1 - loopX;
                }

                GamePiece piece = pieces[x, y];
                if (piece.IsMovalbe())
                {
                    GamePiece pieceBelow = pieces[x, y + 1];
                    if (pieceBelow.Type == PieceType.EMPTY)
                    {
                        Destroy(pieceBelow.gameObject);
                        piece.MovableComponent.Move(x, y + 1, fillTime);
                        pieces[x, y + 1] = piece;
                        SpanNewPiece(x, y, PieceType.EMPTY);
                        movedPiece = true;
                    }
                    else // 如果下面不是empty的看看有么有控件挤进去
                    {
                        for (int diag = -1; diag <= 1; diag++)
                        {
                            if (diag != 0)
                            {
                                int diagX = x + diag;
                                if (inverse)
                                {
                                    diagX = x - diag;
                                }
                                if (diagX >= 0 && diagX < xDim)
                                {
                                    GamePiece diagonalPiece = pieces[diagX, y + 1];
                                    if (diagonalPiece.Type == PieceType.EMPTY)
                                    {
                                        bool hasPiceAbove = true;
                                        for (int aboveY = y; aboveY >= 0; aboveY--)
                                        {
                                            GamePiece pieceAbove = pieces[diagX, aboveY];
                                            if (pieceAbove.IsMovalbe())
                                            {
                                                break;
                                            }
                                            else if (!pieceAbove.IsMovalbe() && pieceAbove.Type != PieceType.EMPTY)
                                            {
                                                hasPiceAbove = false;
                                                break;
                                            }
                                        }
                                        if (!hasPiceAbove)
                                        {
                                            Destroy(diagonalPiece.gameObject);
                                            piece.MovableComponent.Move(diagX, y + 1, fillTime);
                                            pieces[diagX, y + 1] = piece;
                                            SpanNewPiece(x, y, PieceType.EMPTY);
                                            movedPiece = true;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        // 顶层特殊 因为顶层没有上面的一行了 所以我们创造一个没有的-1行来当做 然后移动到下面来
        for (int x = 0; x < xDim; x++)
        {
            GamePiece pieceBelow = pieces[x, 0];
            if (pieceBelow.Type == PieceType.EMPTY)
            {
                Destroy(pieceBelow.gameObject);
                GameObject newPiece = Instantiate(piecePrefabDict[PieceType.NORMAL], GetWorldPosition(x, -1), Quaternion.identity);
                newPiece.transform.parent = transform;
                pieces[x, 0] = newPiece.GetComponent <GamePiece>();
                pieces[x, 0].Init(x, -1, this, PieceType.NORMAL);
                pieces[x, 0].MovableComponent.Move(x, 0, fillTime);
                pieces[x, 0].ColorComponent.SetColor((ColorPiece.ColorType)Random.Range(0, pieces[x, 0].ColorComponent.NumColors));
                movedPiece = true;
            }
        }

        return(movedPiece);
    }
Exemple #43
0
 public bool IsAdjacent(GamePiece piece1, GamePiece piece2)
 {
     return (piece1.X == piece2.X && (piece1.Y == piece2.Y - 1 || piece1.Y == piece2.Y + 1))
             ||
             (piece1.Y == piece2.Y && (piece1.X == piece2.X - 1 || piece1.X == piece2.X + 1));
 }
Exemple #44
0
 public bool isAdjacent(GamePiece piece1, GamePiece piece2)
 {
     return((piece1.X == piece2.X && (int)Mathf.Abs(piece1.Y - piece2.Y) == 1) ||
            (piece1.Y == piece2.Y && (int)Mathf.Abs(piece1.X - piece2.X) == 1));
 }
Exemple #45
0
 public void EnterPiece(GamePiece gamePiece)
 {
     enterPiece = gamePiece;
 }
Exemple #46
0
    public void SwapPieces(GamePiece piece1, GamePiece piece2)
    {
        if (gameOver)
        {
            return;
        }
        if (piece1.IsMovalbe() && piece2.IsMovalbe())
        {
            pieces[piece1.X, piece1.Y] = piece2;
            pieces[piece2.X, piece2.Y] = piece1;
            if (GetMatch(piece1, piece2.X, piece2.Y) != null || GetMatch(piece2, piece1.X, piece1.Y) != null ||
                piece1.Type == PieceType.RAINBOW || piece2.Type == PieceType.RAINBOW)
            {
                int piece1X = piece1.X;
                int piece1Y = piece1.Y;
                piece1.MovableComponent.Move(piece2.X, piece2.Y, fillTime);
                piece2.MovableComponent.Move(piece1X, piece1Y, fillTime);

                if (piece1.Type == PieceType.RAINBOW && piece1.isClearable() && piece2.isColored())
                {
                    ClearColorPiece clearColor = piece1.GetComponent <ClearColorPiece>();
                    if (clearColor)
                    {
                        clearColor.Color = piece2.ColorComponent.Color;
                    }
                    ClearPiece(piece1.X, piece1.Y);
                }

                if (piece2.Type == PieceType.RAINBOW && piece2.isClearable() && piece1.isColored())
                {
                    ClearColorPiece clearColor = piece2.GetComponent <ClearColorPiece>();
                    if (clearColor)
                    {
                        clearColor.Color = piece1.ColorComponent.Color;
                    }
                    ClearPiece(piece2.X, piece2.Y);
                }

                ClearAllValidMatches();

                if (piece1.Type == PieceType.ROW_CLEAR || piece1.Type == PieceType.COLUMN_CLEAR)
                {
                    ClearPiece(piece1.X, piece1.Y);
                }

                if (piece2.Type == PieceType.ROW_CLEAR || piece2.Type == PieceType.COLUMN_CLEAR)
                {
                    ClearPiece(piece2.X, piece2.Y);
                }

                pressedPiece = null;
                enteredPiece = null;

                StartCoroutine(Fill());

                level.OnMove();
            }
            else
            {
                pieces[piece1.X, piece1.Y] = piece1;
                pieces[piece2.X, piece2.Y] = piece2;
            }
        }
    }
Exemple #47
0
 //---------------------------------------------------------------------------
 public bool PlayerCanSeePiece(GamePiece piece)
 {
     return PlayerCanSeePosition(piece.BoardHPos, piece.BoardVPos);
 }
Exemple #48
0
 public void PressPiece(GamePiece piece)
 {
     pressedPiece = piece;
 }
Exemple #49
0
    //---------------------------------------------------------------------------
    public void GetAvailableTargets(GamePiece startingPiece, int attackRange, bool throughWalls, bool pierce, out List<GamePiece> allCharactersInRange, out List<GamePiece> allFloorPiecesInRange)
    {
        // Default - hit everything but floor
        var hitMask =  ~(1 << LayerMask.NameToLayer("Floor"));

        // Default - characters are piercable
        var piercableMask = 1 << LayerMask.NameToLayer("Character");

        // Default - walls are impentrable
        var impenetrableMask = 1 << LayerMask.NameToLayer("Wall");

        GetAvailableTargets(startingPiece, attackRange, throughWalls, pierce, out allCharactersInRange, out allFloorPiecesInRange, hitMask, piercableMask, impenetrableMask);
    }
Exemple #50
0
 public void PressPiece(GamePiece gamePiece)
 {
     pressPiece = gamePiece;
 }
Exemple #51
0
 //---------------------------------------------------------------------------
 public GamePiece GetFloorPieceIfAvailable(int hPos, int vPos, GamePiece ignorePiece = null)
 {
     if (NonFloorPieces[hPos, vPos] == null || NonFloorPieces[hPos, vPos] == ignorePiece)
         return FloorPieces[hPos, vPos];
     return null;
 }
Exemple #52
0
    public List <GamePiece> GetMatch(GamePiece piece, int newX, int newY)
    {
        if (piece.isColored())
        {
            ColorPiece.ColorType color            = piece.ColorComponent.Color;
            List <GamePiece>     horizontalPieces = new List <GamePiece>();
            List <GamePiece>     verticalPieces   = new List <GamePiece>();
            List <GamePiece>     matchingPieces   = new List <GamePiece>();
            // 先检测水平的
            horizontalPieces.Add(piece);
            for (int dir = 0; dir <= 1; dir++)
            {
                for (int xOffset = 1; xOffset < xDim; xOffset++)
                {
                    int x;
                    if (dir == 0) // left
                    {
                        x = newX - xOffset;
                    }
                    else // right
                    {
                        x = newX + xOffset;
                    }
                    if (x < 0 || x >= xDim)
                    {
                        break;
                    }
                    if (pieces[x, newY].isColored() && pieces[x, newY].ColorComponent.Color == color)
                    {
                        horizontalPieces.Add(pieces[x, newY]);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (horizontalPieces.Count >= 3)
            {
                for (int i = 0; i < horizontalPieces.Count; i++)
                {
                    matchingPieces.Add(horizontalPieces[i]);
                }
            }
            // 对于L或者T形的我们需要再找对应的连接的
            if (horizontalPieces.Count >= 3)
            {
                for (int i = 0; i < horizontalPieces.Count; i++)
                {
                    // 每个找到的横着的去找对应的竖着的看下满足不
                    for (int dir = 0; dir <= 1; dir++)
                    {
                        for (int yOffset = 1; yOffset < yDim; yOffset++)
                        {
                            int y;
                            if (dir == 0) // up
                            {
                                y = newY - yOffset;
                            }
                            else // down
                            {
                                y = newY + yOffset;
                            }
                            if (y < 0 || y >= yDim)
                            {
                                break;
                            }
                            if (pieces[horizontalPieces[i].X, y].isColored() && pieces[horizontalPieces[i].X, y].ColorComponent.Color == color)
                            {
                                verticalPieces.Add(pieces[horizontalPieces[i].X, y]);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    if (verticalPieces.Count < 2)
                    {
                        verticalPieces.Clear();
                    }
                    else
                    {
                        for (int j = 0; j < verticalPieces.Count; j++)
                        {
                            matchingPieces.Add(verticalPieces[j]);
                        }
                        break;
                    }
                }
            }

            if (matchingPieces.Count >= 3)
            {
                return(matchingPieces);
            }

            horizontalPieces.Clear();
            verticalPieces.Clear();

            // 垂直的
            verticalPieces.Add(piece);
            for (int dir = 0; dir <= 1; dir++)
            {
                for (int yOffset = 1; yOffset < yDim; yOffset++)
                {
                    int y;
                    if (dir == 0) // up
                    {
                        y = newY - yOffset;
                    }
                    else // down
                    {
                        y = newY + yOffset;
                    }
                    if (y < 0 || y >= yDim)
                    {
                        break;
                    }
                    if (pieces[newX, y].isColored() && pieces[newX, y].ColorComponent.Color == color)
                    {
                        verticalPieces.Add(pieces[newX, y]);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (verticalPieces.Count >= 3)
            {
                for (int i = 0; i < verticalPieces.Count; i++)
                {
                    matchingPieces.Add(verticalPieces[i]);
                }
            }
            if (verticalPieces.Count >= 3)
            {
                for (int i = 0; i < verticalPieces.Count; i++)
                {
                    for (int dir = 0; dir <= 1; dir++)
                    {
                        for (int xOffset = 1; xOffset < xDim; xOffset++)
                        {
                            int x;
                            if (dir == 0) // left
                            {
                                x = newX - xOffset;
                            }
                            else // right
                            {
                                x = newX + xOffset;
                            }
                            if (x < 0 || x >= xDim)
                            {
                                break;
                            }
                            if (pieces[x, verticalPieces[i].Y].isColored() && pieces[x, verticalPieces[i].Y].ColorComponent.Color == color)
                            {
                                horizontalPieces.Add(pieces[x, verticalPieces[i].Y]);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    if (horizontalPieces.Count < 2)
                    {
                        horizontalPieces.Clear();
                    }
                    else
                    {
                        for (int j = 0; j < horizontalPieces.Count; j++)
                        {
                            matchingPieces.Add(horizontalPieces[j]);
                        }
                        break;
                    }
                }
            }
            if (matchingPieces.Count >= 3)
            {
                return(matchingPieces);
            }
        }
        return(null);
    }
Exemple #53
0
 //---------------------------------------------------------------------------
 public Vector2 GetWorldPositionForBoardPiece(GamePiece piece)
 {
     return GetWorldPositionForBoardPosition(piece.BoardHPos, piece.BoardVPos);
 }
Exemple #54
0
    public bool ClearAllValidMatches()
    {
        bool needRefill = false;

        for (int y = 0; y < yDim; y++)
        {
            for (int x = 0; x < xDim; x++)
            {
                if (pieces[x, y].isClearable())
                {
                    List <GamePiece> match = GetMatch(pieces[x, y], x, y);
                    if (match != null)
                    {
                        PieceType specialPieceType = PieceType.COUNT;
                        GamePiece randomPiece      = match[Random.Range(0, match.Count)];
                        int       specialPieceX    = randomPiece.X;
                        int       specialPieceY    = randomPiece.Y;
                        if (match.Count == 4)
                        {
                            if (pressedPiece == null || enteredPiece == null)
                            {
                                specialPieceType = (PieceType)Random.Range((int)PieceType.ROW_CLEAR, (int)PieceType.COLUMN_CLEAR);
                            }
                            else if (pressedPiece.Y == enteredPiece.Y)
                            {
                                specialPieceType = PieceType.ROW_CLEAR;
                            }
                            else
                            {
                                specialPieceType = PieceType.COLUMN_CLEAR;
                            }
                        }
                        else if (match.Count >= 5)
                        {
                            specialPieceType = PieceType.RAINBOW;
                        }
                        for (int i = 0; i < match.Count; i++)
                        {
                            if (ClearPiece(match[i].X, match[i].Y))
                            {
                                needRefill = true;
                                if (match[i] == pressedPiece || match[i] == enteredPiece)
                                {
                                    specialPieceX = match[i].X;
                                    specialPieceY = match[i].Y;
                                }
                            }
                        }
                        if (specialPieceType != PieceType.COUNT)
                        {
                            Destroy(pieces[specialPieceX, specialPieceY]);
                            GamePiece newPiece = SpanNewPiece(specialPieceX, specialPieceY, specialPieceType);
                            if ((specialPieceType == PieceType.ROW_CLEAR || specialPieceType == PieceType.COLUMN_CLEAR) &&
                                newPiece.isColored() && match[0].isColored())
                            {
                                newPiece.ColorComponent.SetColor(match[0].ColorComponent.Color);
                            }
                            else if (specialPieceType == PieceType.RAINBOW && newPiece.isColored())
                            {
                                newPiece.ColorComponent.SetColor(ColorPiece.ColorType.ANY);
                            }
                        }
                    }
                }
            }
        }
        return(needRefill);
    }
Exemple #55
0
 public void OnPieceRemoved(GameBoard board, GamePiece piece)
 {
     if (PieceRemoved != null) PieceRemoved(board, piece);
 }
 public void OnPieceCleared(GamePiece piece)
 {
     currentScore += piece.score;
     scoreDisplay.SetScore(currentScore);
 }
Exemple #57
0
 //---------------------------------------------------------------------------
 public static int ManhattenDistance(GamePiece A, GamePiece B)
 {
     return ManhattenDistance(A.BoardHPos, A.BoardVPos, B.BoardHPos, B.BoardVPos);
 }
    // Create piece object
    public GamePieceObject CreatePieceObject(GamePiece piece)
    {
        GamePieceObject newPieceObject = GamePieceObject.InitializeFromGamePiece(piece, gameMapObject.tilemap.transform, player.playerId);

        return(newPieceObject);
    }
Exemple #59
0
 public void EnterPiece(GamePiece piece)
 {
     enteredPiece = piece;
 }
Exemple #60
0
 public virtual void OnPieceCleared(GamePiece piece)
 {
     currentScore += piece.score;
     hud.SetScore(currentScore);
 }