Exemple #1
0
 void OnMouseDown()
 {
     if (gameObject.tag == "Field")
     {
         Field     fieldToMove = gameObject.GetComponent <Field>();
         MoveTobit currentMove = (MoveTobit)fieldToMove.MoveOn;
         currentMove.figure.MovePlayer(currentMove, ref GameController.Instance.CurrentBoard.board);
         EventManager.Instance.PostNotification(EVENT_TYPE.DEFAULT);
         if (currentMove.haveKill && currentFigure.figure.GetMoves(ref GameController.Instance.CurrentBoard.board).ToList().Exists(x => (x as MoveTobit).haveKill))
         {
             Move[] moves = currentFigure.figure.GetMoves(ref GameController.Instance.CurrentBoard.board);
             GameController.Instance.HighLightMoves(moves);
         }
         else
         {
             GameController.Instance.ChangePlayer();
         }
     }
     if (gameObject.tag == "Figure")
     {
         ViewFigure selectedFigure = gameObject.GetComponent <ViewFigure>();
         if (selectedFigure.figure.Color == GameController.Instance.playerColor)
         {
             if (currentFigure != selectedFigure)
             {
                 EventManager.Instance.PostNotification(EVENT_TYPE.DEFAULT);
             }
             currentFigure = selectedFigure;
             Move[] moves = selectedFigure.figure.GetMoves(ref GameController.Instance.CurrentBoard.board);
             GameController.Instance.HighLightMoves(moves);
         }
     }
 }
Exemple #2
0
    private void PlaceFigures(int x, int y, FigureColor color)
    {
        Vector3    pos     = deskView[y, x].transform.position;
        GameObject gameObj = Instantiate(figurePrefab);

        gameObj.transform.position = new Vector3(pos.x, pos.y, pos.z - 1);
        ViewFigure gameFigure = gameObj.GetComponent <ViewFigure>();
        Figure     figure     = new Figure(x, y, color);

        gameFigure.SetStartProperties(figure);
        CurrentBoard.board[y, x] = figure;
    }
Exemple #3
0
    void Start()
    {
        playerColor = FigureColor.WHITE;
        AIColor     = FigureColor.BLACK;
        ViewFigure figure = figurePrefab.GetComponent <ViewFigure>();

        if (figure == null)
        {
            Debug.LogError("No figure component detected");
            return;
        }
        int r;
        int c;
        int figuresLeft = CurrentBoard.numFigures;

        for (r = 0; r < CurrentBoard.rowsOfBoard; r++)
        {
            if (figuresLeft == 0)
            {
                break;
            }
            int init = 0;
            int max  = CurrentBoard.columnsOfBoard;
            if (r == 0)
            {
                init = 1;
                max  = CurrentBoard.columnsOfBoard - 1;
            }
            for (c = init; c < max; c++)
            {
                if (figuresLeft == 0)
                {
                    break;
                }
                PlaceFigures(c, r, FigureColor.WHITE);
                figuresLeft--;
            }
        }

        figuresLeft = CurrentBoard.numFigures;
        for (r = CurrentBoard.rowsOfBoard - 1; r >= 0; r--)
        {
            if (figuresLeft == 0)
            {
                break;
            }
            int init = 0;
            int max  = CurrentBoard.columnsOfBoard;
            if (r == CurrentBoard.rowsOfBoard - 1)
            {
                init = 1;
                max  = CurrentBoard.columnsOfBoard - 1;
            }
            for (c = init; c < max; c++)
            {
                if (figuresLeft == 0)
                {
                    break;
                }
                PlaceFigures(c, r, FigureColor.BLACK);
                figuresLeft--;
            }
        }
    }