void Start()
    {
        p1 = (Piece1)FindObjectOfType(typeof(Piece1));
        p2 = (Piece2)FindObjectOfType(typeof(Piece2));
        p3 = (Piece3)FindObjectOfType(typeof(Piece3));
        p4 = (Piece4)FindObjectOfType(typeof(Piece4));

        button.SetActive(false);
    }
    void Update()
    {
        if (fail == true)
        {
            Piece1.GetComponent <SpriteRenderer>().sprite = CrumbleWall;
            Piece2.GetComponent <SpriteRenderer>().sprite = CrumbleWall;
            Piece3.GetComponent <SpriteRenderer>().sprite = CrumbleWall;
            Piece4.GetComponent <SpriteRenderer>().sprite = CrumbleWall;
            Win = 0;
        }

        else if (p1 == true && p2 == true && p3 == true && p4 == true)
        {
            Piece1.GetComponent <SpriteRenderer>().sprite = FixWall;
            Piece2.GetComponent <SpriteRenderer>().sprite = FixWall;
            Piece3.GetComponent <SpriteRenderer>().sprite = FixWall;
            Piece4.GetComponent <SpriteRenderer>().sprite = FixWall;
            Win = 1;
        }

        else
        {
            if (p1 == true)
            {
                Piece1.GetComponent <SpriteRenderer>().sprite = FixWall;
            }
            if (p2 == true)
            {
                Piece2.GetComponent <SpriteRenderer>().sprite = FixWall;
            }
            if (p3 == true)
            {
                Piece3.GetComponent <SpriteRenderer>().sprite = FixWall;
            }
            if (p4 == true)
            {
                Piece4.GetComponent <SpriteRenderer>().sprite = FixWall;
            }
            p1   = Piece1.GetComponent <ClickItem>().Clicked;
            p2   = Piece2.GetComponent <ClickItem>().Clicked;
            p3   = Piece3.GetComponent <ClickItem>().Clicked;
            p4   = Piece4.GetComponent <ClickItem>().Clicked;
            fail = Back.GetComponent <ClickItem>().Clicked;
        }

        if (T < 0)
        {
            PlayerPrefs.SetInt("Result", Win);
            Back.GetComponent <PresentResults>().enabled = true;
            Back.GetComponent <GameWall>().enabled       = false;
        }
        else
        {
            T = T - Time.deltaTime;
        }
    }
Example #3
0
        void DragPiece(Piece2 selected)
        {
            Ray        camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            // Detects mouse ray hit point
            if (Physics.Raycast(camRay, out hit))
            {
                // Updates position of selected piece to hit point + offset
                selected.transform.position = hit.point + Vector3.up;
            }
        }
Example #4
0
        void GeneratePiece(GameObject prefab, Vector2Int desiredCell)
        {
            // Generate Instance of prefab
            GameObject clone = Instantiate(prefab, transform);
            // Get the Piece component
            Piece2 piece = clone.GetComponent <Piece2>();

            // Set the cell data for the first time
            piece.oldCell = desiredCell;
            piece.cell    = desiredCell;
            // reposition clone
            MovePiece(piece, desiredCell);
        }
Example #5
0
        void MovePiece(Piece2 piece, Vector2Int newCell)
        {
            Vector2Int oldCell = piece.cell;

            // Update array
            pieces[oldCell.x, oldCell.y] = null;
            pieces[newCell.x, newCell.y] = piece;
            // Update data on piece
            piece.oldCell = oldCell;
            piece.cell    = newCell;
            // Translate the piece to another location
            piece.transform.localPosition = GetWorldPosition(newCell);
        }
 void Start()
 {
     ScoreText.enabled = false;
     LivesText.enabled = false;
     RuleText.enabled  = false;
     Progress          = 1;
     Win  = 0;
     T    = PlayerPrefs.GetFloat("PTime");
     tt   = T;
     p1   = Piece1.GetComponent <ClickItem>().Clicked;
     p2   = Piece2.GetComponent <ClickItem>().Clicked;
     p3   = Piece3.GetComponent <ClickItem>().Clicked;
     p4   = Piece4.GetComponent <ClickItem>().Clicked;
     fail = Back.GetComponent <ClickItem>().Clicked;
 }
Example #7
0
        bool TryMove(Piece2 selected, Vector2Int desiredCell)
        {
            // Get the selected piece's cell
            Vector2Int startCell = selected.cell;

            // is it not a valid move?
            if (!ValidMove(selected, desiredCell))
            {
                // move back to start Pos
                MovePiece(selected, startCell);
                return(false);
            }

            // Replace end coordinates with selectedPiece
            MovePiece(selected, desiredCell);
            // Valid move detected!
            return(true);
        }
Example #8
0
        Piece2 SelectPiece(Vector2Int cell)
        {
            // Check is X and Y is out of bounds
            if (IsOutOfBounds(cell))
            {
                // return result early
                return(null);
            }

            // get the piece at X and Y location
            Piece2 piece = GetPiece(cell);

            // Check that it isn't null
            if (piece)
            {
                return(piece);
            }

            return(null);
        }
Example #9
0
        public List <Vector2Int> IsForcedMove(Piece2 piece) // check if forced Capture for a given piece
        {
            List <Vector2Int> forcedMoves = new List <Vector2Int>();
            int yCheck = -1;

            if (piece.isWhite || (!piece.isWhite && piece.isKing))
            {
                yCheck *= -1;
            }

            for (int xCheck = -1; xCheck <= 1; xCheck += 2)
            {
                int x1 = piece.cell.x + xCheck;
                int y1 = piece.cell.y + yCheck;

                if (IsOutOfBounds(piece.cell))
                {
                    continue;
                }

                Piece2 detectedPiece = pieces[x1, y1];
                if (detectedPiece != null && detectedPiece.isWhite != piece.isWhite)
                {
                    int x2 = x1 + xCheck;
                    int y2 = y1 + yCheck;
                    if (IsOutOfBounds(piece.cell))
                    {
                        continue;
                    }
                    Piece2 destinationCell = pieces[x2, y2];
                    if (destinationCell == null)
                    {
                        forcedMoves.Add(destinationCell.cell);
                    }
                }
            }
            return(forcedMoves);
        }
Example #10
0
 void Update()
 {
     // Update mouse over info
     MouseOver();
     if (Input.GetMouseButtonDown(0))
     {
         // Try selecteidng piece
         selectedPiece = SelectPiece(mouseOver);
     }
     // If there is a selected piece
     if (selectedPiece)
     {
         // Move the piece with mouse
         DragPiece(selectedPiece);
         // If button is released
         if (Input.GetMouseButtonUp(0))
         {
             // Move piece to end position
             TryMove(selectedPiece, mouseOver);
             // release piece
             selectedPiece = null;
         }
     }
 }
Example #11
0
        /// <summary>
        /// set up module for pieces and location
        /// </summary>
        private void setUp()
        {
            try
            {
                tangrampuzzle[0] = new Piece1(color[0]);
                tangrampuzzle[1] = new Piece2(color[1]);
                tangrampuzzle[2] = new Piece3(color[2]);
                tangrampuzzle[3] = new Piece4(color[3]);
                tangrampuzzle[4] = new Piece5(color[4]);
                tangrampuzzle[5] = new Piece6(color[5]);
                tangrampuzzle[6] = new Piece7(color[6]);

                for (int i = 0; i < tangrampuzzle.Length; i++)
                {

                    this.region[i] = tangrampuzzle[i].getRegion();
                    this.color[i] = tangrampuzzle[i].getColor();
                }
            }
            catch (Exception ex)
            {

                System.Windows.MessageBox.Show(ex.Message, "Can not create the pieces.");
                throw;
            }
        }
Example #12
0
    private void CreateAllPieces()
    {
        var player = PlayerType.Player1;

        Pieces1 = new PieceBase[15];
        for (int i = 0; i < 5; i++)
        {
            Pieces1[i]       = new Piece1(player, i);
            PiecesObject1[i] = ObjectCreator.CreateInObject(PlayerGameObject[0], piecePrefabs[0]).GetComponent <PieceProvider>();
            PiecesObject1[i].SetPieceUIInfo(player, i, PieceType.Piece1);
        }
        for (int i = 5; i < 9; i++)
        {
            Pieces1[i]       = new Piece2(player, i);
            PiecesObject1[i] = ObjectCreator.CreateInObject(PlayerGameObject[0], piecePrefabs[1]).GetComponent <PieceProvider>();
            PiecesObject1[i].SetPieceUIInfo(player, i, PieceType.Piece2);
        }
        for (int i = 9; i < 12; i++)
        {
            Pieces1[i]       = new Piece3(player, i);
            PiecesObject1[i] = ObjectCreator.CreateInObject(PlayerGameObject[0], piecePrefabs[2]).GetComponent <PieceProvider>();
            PiecesObject1[i].SetPieceUIInfo(player, i, PieceType.Piece3);
        }
        for (int i = 12; i < 14; i++)
        {
            Pieces1[i]       = new Piece4(player, i);
            PiecesObject1[i] = ObjectCreator.CreateInObject(PlayerGameObject[0], piecePrefabs[3]).GetComponent <PieceProvider>();
            PiecesObject1[i].SetPieceUIInfo(player, i, PieceType.Piece4);
        }
        Pieces1[14]       = new Piece5(player, 14);
        PiecesObject1[14] = ObjectCreator.CreateInObject(PlayerGameObject[0], piecePrefabs[4]).GetComponent <PieceProvider>();
        PiecesObject1[14].SetPieceUIInfo(player, 14, PieceType.Piece5);

        player  = PlayerType.Player2;
        Pieces2 = new PieceBase[15];
        for (int i = 0; i < 5; i++)
        {
            Pieces2[i]       = new Piece1(player, i);
            PiecesObject2[i] = ObjectCreator.CreateInObject(PlayerGameObject[1], piecePrefabs[5]).GetComponent <PieceProvider>();
            PiecesObject2[i].SetPieceUIInfo(player, i, PieceType.Piece1);
        }
        for (int i = 5; i < 9; i++)
        {
            Pieces2[i]       = new Piece2(player, i);
            PiecesObject2[i] = ObjectCreator.CreateInObject(PlayerGameObject[1], piecePrefabs[6]).GetComponent <PieceProvider>();
            PiecesObject2[i].SetPieceUIInfo(player, i, PieceType.Piece2);
        }
        for (int i = 9; i < 12; i++)
        {
            Pieces2[i]       = new Piece3(player, i);
            PiecesObject2[i] = ObjectCreator.CreateInObject(PlayerGameObject[1], piecePrefabs[7]).GetComponent <PieceProvider>();
            PiecesObject2[i].SetPieceUIInfo(player, i, PieceType.Piece3);
        }
        for (int i = 12; i < 14; i++)
        {
            Pieces2[i]       = new Piece4(player, i);
            PiecesObject2[i] = ObjectCreator.CreateInObject(PlayerGameObject[1], piecePrefabs[8]).GetComponent <PieceProvider>();
            PiecesObject2[i].SetPieceUIInfo(player, i, PieceType.Piece4);
        }
        Pieces2[14]       = new Piece5(player, 14);
        PiecesObject2[14] = ObjectCreator.CreateInObject(PlayerGameObject[1], piecePrefabs[9]).GetComponent <PieceProvider>();
        PiecesObject2[14].SetPieceUIInfo(player, 14, PieceType.Piece5);

        PutKings();
    }
Example #13
0
        public override string ToString()
        {
            string piece2Desc = PieceCount == 2 ? Piece2.ToString() : "nothing";

            return($"Move {Piece} {piece2Desc} from {FromFloor} to {ToFloor}");
        }
Example #14
0
        // checks if start and end drag positions are valid game moves
        bool ValidMove(Piece2 selected, Vector2Int desiredCell)
        {
            bool doingForced = false;
            // get direction of movement
            Vector2Int direction = selected.cell - desiredCell;

            #region Rule 1 - out of bounds?
            // out of bounds?
            if (IsOutOfBounds(desiredCell))
            {
                Debug.Log("<color=red>Invalid - You cannot move outside the board</color>");
                return(false);
            }
            #endregion

            #region Rule 2 - selected cell same as desired cell (drop piece where it started)
            if (SameCell(selected.cell, desiredCell))
            {
                Debug.Log("<color=red>Invalid - You cannot move to where you started</color>");
                return(false);
            }

            #endregion

            #region Rule 3 - is there a piece at the desired cell?
            if (OccupiedCell(desiredCell))
            {
                Debug.Log("<color=red>Invalid - You cannot move on top of another piece</color>");
                return(false);
            }

            #endregion

            #region Rule 4 - forced moves?
            // are there any forced moves?
            if (IsForcedMove(selected).Count > 0)
            {
                foreach (Vector2Int move in IsForcedMove(selected))
                {
                    // is the desired move not one of the forced moves
                    if (move == desiredCell)
                    {
                        return(true);
                        //doingForced = true;
                        //break;
                    }
                }
                if (!doingForced)
                {
                    Debug.Log("<color=red>Invalid - There is a forced move you have to make</color>");
                    return(false);
                }
            }

            #endregion

            #region Rule 5 - is the drag a 2 square drag?
            // Is the drag more than 1 cell?
            if (Mathf.Abs(selected.cell.y - desiredCell.y) > 1 || Mathf.Abs(selected.cell.x - desiredCell.x) > 1)
            {
                return(false);
            }

            #endregion

            #region Rule 6 - is the piece moving diagonally?
            if (NotDiagonalMove(selected.cell, desiredCell))
            {
                return(false);
            }

            #endregion

            #region Rule 7 - is the piece moving the right direction (forward/back)

            #endregion
            // If all the above rules dont return false, move is valid!
            Debug.Log("<color=green>Success - Valid move detected!</color>");
            return(true);
        }