Пример #1
0
    private void AddOnePossibleMatch(int x, int y)
    {
        //all checks are to the right and down and both are valid when they get here
        var index = BoardConfig.Instance.GetIndex(x, y);

        //int baseGem = PuzzleBoard.GetGemAtIndex(index);

        //only check to the right if we're not at the right edge
        if (x < BoardConfig.Instance.Width - 1)
        {
            var indexr = BoardConfig.Instance.GetIndex(x + 1, y);

            PuzzlePresentation.Instance.SwapTwoGridCellsStraight(index, indexr);
            //PuzzleBoard.SwapTwoGems(index, indexr);
            var match1x = GetOneIndexMatchData(x, y);
            var match2x = GetOneIndexMatchData(x + 1, y);
            if (match1x != null || match2x != null)
            {
                var possible = new PossibleMoveData();
                possible.SetMove(index, indexr);
                if (match1x != null)
                {
                    possible.AddMatch(match1x);
                }
                if (match2x != null)
                {
                    possible.AddMatch(match2x);
                }
                PossibleMoves.Add(possible);
            }
            PuzzlePresentation.Instance.SwapTwoGridCellsStraight(index, indexr);
        }

        //only check down if we're not at the bottom edge
        if (y < BoardConfig.Instance.Height - 1)
        {
            var indexd = BoardConfig.Instance.GetIndex(x, y + 1);
            //int baseGemd = PuzzleBoard.GetGemAtIndex(indexd);

            PuzzlePresentation.Instance.SwapTwoGridCellsStraight(index, indexd);
            var match1y = GetOneIndexMatchData(x, y);
            var match2y = GetOneIndexMatchData(x, y + 1);
            if (match1y != null || match2y != null)
            {
                var possible = new PossibleMoveData();
                possible.SetMove(index, indexd);
                if (match1y != null)
                {
                    possible.AddMatch(match1y);
                }
                if (match2y != null)
                {
                    possible.AddMatch(match2y);
                }
                PossibleMoves.Add(possible);
            }
            PuzzlePresentation.Instance.SwapTwoGridCellsStraight(index, indexd);
        }
    }
Пример #2
0
    public PossibleMoveData ShowStraightForwardMoves(PossibleMoveData possibleMoveData)
    {
        int rank = occupiedPawn.rankForMoveAndTake;

        possibleMoveData = CheckPossibleMoveForOneSide(leftSquares, rank, possibleMoveData);
        possibleMoveData = CheckPossibleMoveForOneSide(rightSquares, rank, possibleMoveData);
        possibleMoveData = CheckPossibleMoveForOneSide(upSquares, rank, possibleMoveData);
        possibleMoveData = CheckPossibleMoveForOneSide(downSquares, rank, possibleMoveData);


        possibleMoveData = CheckPossibleMoveForOneSideTaking(leftUpDiagonalSquares, rank, possibleMoveData, true);
        possibleMoveData = CheckPossibleMoveForOneSideTaking(rightUpDiagonalSquares, rank, possibleMoveData, true);
        possibleMoveData = CheckPossibleMoveForOneSideTaking(leftDownDiagonalSquares, rank, possibleMoveData, true);
        possibleMoveData = CheckPossibleMoveForOneSideTaking(rightDownDiagonalSquares, rank, possibleMoveData, true);

        return(possibleMoveData);
    }
Пример #3
0
    public PossibleMoveData ShowDiagonalMoves(PossibleMoveData possibleMoveData)
    {
        if (occupiedPawn == null)
        {
            Debug.Log("Null found" + gameObject.name);
            return(possibleMoveData);
        }
        int rank = occupiedPawn.rankForMoveAndTake;

        possibleMoveData = CheckPossibleMoveForOneSide(leftUpDiagonalSquares, rank, possibleMoveData);
        possibleMoveData = CheckPossibleMoveForOneSide(rightUpDiagonalSquares, rank, possibleMoveData);
        possibleMoveData = CheckPossibleMoveForOneSide(leftDownDiagonalSquares, rank, possibleMoveData);
        possibleMoveData = CheckPossibleMoveForOneSide(rightDownDiagonalSquares, rank, possibleMoveData);

        possibleMoveData = CheckPossibleMoveForOneSideTaking(leftSquares, rank, possibleMoveData, true);
        possibleMoveData = CheckPossibleMoveForOneSideTaking(rightSquares, rank, possibleMoveData, true);
        possibleMoveData = CheckPossibleMoveForOneSideTaking(upSquares, rank, possibleMoveData, true);
        possibleMoveData = CheckPossibleMoveForOneSideTaking(downSquares, rank, possibleMoveData, true);

        return(possibleMoveData);
    }
Пример #4
0
 public virtual void ShowPossibleMoves()
 {
     possibleMoveData = new PossibleMoveData();
     if (Rank > 1 && Rank < 5)
     {
         for (int i = 1; i < transform.childCount - 1; i++)
         {
             if (transform.GetChild(i).GetComponent <Pawn>().currentPawnType == PawnType.PLUS)
             {
                 possibleMoveData = occupiedSquare.ShowStraightForwardMoves(possibleMoveData);
             }
             else if (transform.GetChild(i).GetComponent <Pawn>().currentPawnType == PawnType.CROSS)
             {
                 possibleMoveData = occupiedSquare.ShowDiagonalMoves(possibleMoveData);
             }
             else if (transform.GetChild(i).GetComponent <Pawn>().currentPawnType == PawnType.STAR)
             {
                 possibleMoveData = occupiedSquare.ShowStraightForwardMoves(possibleMoveData);
                 possibleMoveData = occupiedSquare.ShowDiagonalMoves(possibleMoveData);
             }
         }
     }
 }
Пример #5
0
    private PossibleMoveData CheckPossibleMoveForOneSideTaking(List <Square> squareList, int rank, PossibleMoveData possibleMoveData, bool canTake = false)
    {
        canCheckForward = true;
        for (int i = 0; i < squareList.Count; i++)
        {
            if (canCheckForward)
            {
                if (CheckPossibleMoveForTaking(rank, i, squareList, canTake))
                {
                    //squareList[i].SetHighlightStatus(true);
                    int distance = (SquareId - squareList[i].SquareId) / Constants.noOfSquarePerRow;
                    possibleMoveData.possibleTakes.Add(new SquareWithDistance(this, squareList[i], Mathf.Abs(distance)));
                    // possibleMoveData.possibleTakes.Add(squareList[i]);
                }
            }
            else
            {
                break;
            }
        }

        return(possibleMoveData);
    }
Пример #6
0
 private PossibleMoveData CheckPossibleMoveForOneSide(List <Square> squareList, int rank, PossibleMoveData possibleMoveData)
 {
     for (int i = 0; i < squareList.Count; i++)
     {
         if (CheckPossibleMove(rank, i, squareList))
         {
             // squareList[i].SetHighlightStatus(true);
             int distance = (SquareId - squareList[i].SquareId) / Constants.noOfSquarePerRow;
             possibleMoveData.possibleMoves.Add(new SquareWithDistance(this, squareList[i], Mathf.Abs(distance)));
         }
         else
         {
             break;
         }
     }
     return(possibleMoveData);
 }
Пример #7
0
	private void AddOnePossibleMatch(int x, int y)
	{
		//all checks are to the right and down and both are valid when they get here
		var index = BoardConfig.GetIndex(x, y);

		//only check to the right if we're not at the right edge
		if (x < BoardConfig.Width - 1)
		{

			var indexr = BoardConfig.GetIndex(x + 1, y);
			//int baseGemr = PuzzleBoard.GetGemAtIndex(indexr);

			PuzzleBoard.SwapTwoGems(index, indexr);
			var match1x = GetOneIndexMatchData(x, y);
			var match2x = GetOneIndexMatchData(x + 1, y);
			if (match1x != null || match2x != null)
			{
				var possible = new PossibleMoveData();
				possible.SetMove(index, indexr);
				if (match1x != null)
					possible.AddMatch(match1x);
				if (match2x != null)
					possible.AddMatch(match2x);
				PossibleMoves.Add(possible);
			}
			PuzzleBoard.SwapTwoGems(index, indexr);
		}

		//only check down if we're not at the bottom edge
		if (y < BoardConfig.Height - 1)
		{
			var indexd = BoardConfig.GetIndex(x, y + 1);
			//int baseGemd = PuzzleBoard.GetGemAtIndex(indexd);

			PuzzleBoard.SwapTwoGems(index, indexd);
			var match1y = GetOneIndexMatchData(x, y);
			var match2y = GetOneIndexMatchData(x, y + 1);
			if (match1y != null || match2y != null)
			{
				var possible = new PossibleMoveData();
				possible.SetMove(index, indexd);
				if (match1y != null)
					possible.AddMatch(match1y);
				if (match2y != null)
					possible.AddMatch(match2y);
				PossibleMoves.Add(possible);
			}
			PuzzleBoard.SwapTwoGems(index, indexd);
		}
	}