示例#1
0
    private void Start()
    {
        //initialize board
        board = new int[size, size];
        for (int i = 0; i < size; i++)
        {
            for (int j = 0; j < size; j++)
            {
                board[i, j] = 0;
            }
        }

        //randomly assign player pieces
        int pieceIndex = Random.Range(0, pieces.Count);

        playerOnePiece = pieces[pieceIndex];
        List <GameObject> newSelection = new List <GameObject>();

        for (int i = 0; i < pieces.Count; i++)
        {
            if (i != pieceIndex)
            {
                newSelection.Add(pieces[i]);
            }
        }
        playerTwoPiece = newSelection[Random.Range(0, newSelection.Count)];

        //Functionality for buttons that appear when the game is over
        buttons = GameObject.Find("ButtonsObject");
        if (buttons == null)
        {
            Debug.Log("Unable to find reference to ButtonsObject");
        }
        else
        {
            buttons.SetActive(false);
        }

        //Setting up the move recorder
        //since board is zero indexed, { -1, -1 } is functionally the empty board move
        MoveRecord initialBoardState = new MoveRecord(new int[] { -1, -1 }, false);

        moveRecorder = new MoveRecorder();
        moveRecorder.Turn(initialBoardState, null);
    }
示例#2
0
    //place pieces on board
    public void InstantiatePiece(GameObject tile, GameObject piecePrefab, int scoreInt)
    {
        TileControl tileControl = tile.GetComponent <TileControl>();

        GameObject piece = Instantiate(piecePrefab, transform.position, Quaternion.identity)
                           as GameObject;

        piece.transform.parent        = tile.transform;
        piece.transform.localPosition = Vector2.zero;
        playerOneTurn = false;
        tileControl.SetIsPlaceable(false);
        tileControl.GetSprite().color = Color.white;
        board[tileControl.location[0], tileControl.location[1]] = scoreInt;

        MoveRecord turn = new MoveRecord(tileControl.location, playerOneTurn);

        moveRecorder.Turn(turn, previousMove);
        if (turnNumber >= (size * 2) - 1)
        {
            CheckWin(tileControl.location);
        }
    }