Beispiel #1
0
//*********************************************************************************************************************
//*********************************************************************************************************************

    #region GamePlayMethods ************************************
    //this will execute the click method if any alphabet  is selected from the grid to create the answer string
    public void OnClick(int row, int col)
    {
        Button       temp = myQuestionArry [row, col];                      // get button of corresponding row and col
        AlphaBetInfo info = temp.gameObject.GetComponent <AlphaBetInfo> (); // get its info from AlphabetInfo class

        if (info.IsAnswerChar())
        {
            // if it is already a part of answer then user must have clicked this to remove from answer array
            // so remove it and put it back to its original position
            temp.GetComponent <RectTransform> ().position = info.GetOriginalPosition();
            currentAnsweGridNo = info.GetAnswerIndex();
            info.SetAnswerChar(false);
            noOfLetterClicked--;
            destructionArry.Remove(temp);
        }
        else
        {
            // if its a fresh selection then mark it as a part of answer string and put it in current answer array
            info.SetAnswerChar(true);
            temp.GetComponent <RectTransform> ().position = answerGridArry[currentAnsweGridNo];
            info.SetAnswerIndex(currentAnsweGridNo);
            answerArray[currentAnsweGridNo] = info.GetButtonId();
            noOfLetterClicked++;
            currentAnsweGridNo = noOfLetterClicked;
            destructionArry.Add(temp);
        }
    }
Beispiel #2
0
//************************************************************************************************************
// this is rough UI part not paid much attention as it was not the part of problem defination
    // it is made to visualize the game
    // this method is to create the grid
    void calculateGridDimensionsAndCreateEMptyGrid(int row, int col)
    {
        int minRowVal;
        int minColVal;

        if (row <= noOfRow && col <= noOfCol)
        {
            minRowVal      = Mathf.FloorToInt((noOfRow - row) / 2);
            minColVal      = Mathf.FloorToInt((noOfCol - col) / 2);
            myQuestionArry = new Button[row, col];
        }
        else
        {
            return;
        }
        GridWidth  = Screen.width * (ScrenPercentage / 100);
        GridHeight = GridWidth;          // as i want square alphabates
        int index = 0;

        tileWidth  = Screen.width / noOfCol;
        tileHeight = tileWidth;         // to keep It Square
        startX     = Screen.width / 2 - ((tileWidth * noOfCol) / 2 - tileWidth / 2);
        startY     = Screen.height - (tileHeight * noOfRow) + tileHeight / 3;
        int counter   = 0;
        int wordIndex = 0;

        for (int i = 0; i < noOfRow; i++)
        {
            for (int j = 0; j < noOfCol; j++)
            {
                Image img = Instantiate(blankImgPrefab) as Image;
                img.rectTransform.SetParent(this.transform);
                img.rectTransform.sizeDelta  = (new Vector2(tileWidth, tileHeight));
                img.rectTransform.localScale = new Vector3(1, 1, 1);
                img.rectTransform.position   = new Vector3(startX + (j * tileWidth), startY + (i * tileHeight), 1);
                // this is to create answer grid
                if ((i >= minRowVal && i < (minRowVal + row)) && (j >= minColVal && j < (col + minColVal)))
                {
                    Button        alphabetTab = Instantiate(bprefab) as Button;
                    RectTransform rt          = alphabetTab.GetComponent <RectTransform>();
                    rt.SetParent(container.transform);
                    rt.sizeDelta  = (new Vector2(tileWidth, tileHeight));
                    rt.localScale = new Vector3(1, 1, 1);
                    rt.position   = new Vector3(startX + (j * tileWidth), startY + (i * tileHeight), 0);
                    //int id=Random.Range(0,26); this was for random generation
                    int id = GetWordIndex(tempQuestionArray[wordIndex]);
                    alphabetTab.image.sprite = alphabetManager.GetAlphabateImg(id);
                    int          r    = i - minRowVal;
                    int          c    = j - minColVal;
                    AlphaBetInfo info = alphabetTab.gameObject.AddComponent <AlphaBetInfo>();
                    info.setInfo(id, rt.position, alphabateArry[id]);
                    alphabetTab.onClick.AddListener(delegate { OnClick(r, c); });
                    myQuestionArry[r, c] = alphabetTab;
                    wordIndex++;
                }
                if (counter < 2)
                {
                    Image tempImg = Instantiate(AnswerPrefab) as Image;
                    tempImg.rectTransform.SetParent(this.transform);
                    tempImg.rectTransform.sizeDelta  = (new Vector2(tileWidth, tileHeight));
                    tempImg.rectTransform.localScale = new Vector3(1, 1, 1);
                    answerGridArry[index]            = new Vector3(startX + (j * tileWidth), (startY - (tileHeight * 1.1f)) - (counter * tileHeight), 1);
                    tempImg.rectTransform.position   = answerGridArry[index];
                    index++;
                }
            }
            counter++;
        }
        Button        done   = Instantiate(donePrefab) as Button;
        RectTransform donert = done.GetComponent <RectTransform>();

        donert.SetParent(container.transform);
        donert.sizeDelta  = (new Vector2(tileWidth * 2, tileHeight));
        donert.localScale = new Vector3(1, 1, 1);
        donert.position   = new Vector3(Screen.width / 2, (startY - (tileHeight * 3.2f)), 0);
        done.onClick.AddListener(delegate { OnDOneClick(); });

        wrong = Instantiate(wrongPrefab) as Image;
        wrong.rectTransform.SetParent(container.transform);
        wrong.rectTransform.sizeDelta  = (new Vector2(tileWidth * 2, tileHeight));
        wrong.rectTransform.localScale = new Vector3(0, 0, 0);
        wrong.rectTransform.position   = new Vector3(Screen.width / 4, (startY - (tileHeight * 3.2f)), 0);

        right = Instantiate(correctPrefab) as Image;
        right.rectTransform.SetParent(container.transform);
        right.rectTransform.sizeDelta  = (new Vector2(tileWidth * 2, tileHeight));
        right.rectTransform.localScale = new Vector3(0, 0, 0);
        right.rectTransform.position   = new Vector3(Screen.width / 1.2f, (startY - (tileHeight * 3.2f)), 0);
    }