コード例 #1
0
ファイル: GameManager.cs プロジェクト: NickVanheer/MusubiGame
    //Todo: make sure the first two words don't spawn on the same line.
    void GenerateNewCell(int index = -1)
    {
        SimpleWord word = GetNextWord();

        if (EmptyCells.Count > 0 && word != null)
        {
            shownWords++;
            int newCellIndex = index;

            //if we don't specify a position, generate one randomly
            if (index == -1)
            {
                newCellIndex = UnityEngine.Random.Range(0, EmptyCells.Count);
            }

            //random
            // int randomNum = UnityEngine.Random.Range(0, 10); //0-9
            // if(randomNum == 0)
            //     EmptyCells[newNumberIndex].Number = 2;

            EmptyCells[newCellIndex].SetText(word, 2);

            //
            EmptyCells[newCellIndex].PlayAppearAnimation();
            Debug.Log("Adding " + word.Word + " on the board.");
            EmptyCells.RemoveAt(newCellIndex);
        }

        if (word == null && GetActiveCellCount() == 0)
        {
            //You won
            GameOver("You won!");
        }
    }
コード例 #2
0
ファイル: Cell.cs プロジェクト: NickVanheer/MusubiGame
    public void SetText(SimpleWord word, int style)
    {
        cellStyle = style;
        this.Word = word;

        if (cellStyle == 0)
        {
            SetHidden();
        }
        else
        {
            ApplyStyle(cellStyle);
            SetVisible();
        }
    }
コード例 #3
0
ファイル: GameManager.cs プロジェクト: NickVanheer/MusubiGame
    SimpleWord GetNextWord()
    {
        //Reset the list if we're at the end and in infinity mode
        if ((Mode == PlayMode.Infinity || Mode == PlayMode.TimeAttack) && wordIndex >= wordStream.Count)
        {
            wordIndex = 0;
            currentSet.Clear();
        }

        //Working in smaller sets makes sure that when dealing with large lists of words, a related word will be spawned soon.
        if (currentSet.Count == 0)
        {
            //Take 4 (SetCount public variable) starting at the right position
            currentSet = wordStream.Skip(wordIndex).Take(SetCount).ToList();

            wordIndex += SetCount;

            if (wordIndex >= wordStream.Count)
            {
                return(null);
            }

            //randomize
            System.Random rnd = new System.Random();
            currentSet.OrderBy((item) => rnd.Next()).ToList();

            string debugline = "New set: ";
            foreach (SimpleWord item in currentSet)
            {
                debugline += item.Word + ". ";
            }
            Debug.Log(debugline);
        }

        SimpleWord w = currentSet[0];

        currentSet.RemoveAt(0);
        return(w);
    }
コード例 #4
0
 public void Setup()
 {
     instance = CreateSimpleWord();
 }