Exemplo n.º 1
0
 void SetSymbol(SlotColumn col, SlotRow row, E_SlotMachineSymbol symbol)
 {
     if ((int)symbol < (int)E_SlotMachineSymbol.First)
     {
         symbol = (E_SlotMachineSymbol)((int)symbol + (int)E_SlotMachineSymbol.Last);
     }
     if ((int)symbol > (int)E_SlotMachineSymbol.Last)
     {
         symbol = (E_SlotMachineSymbol)((int)symbol - (int)E_SlotMachineSymbol.Last);
     }
     m_Slots[(int)col][(int)row].SetSymbol(symbol);
 }
Exemplo n.º 2
0
 bool IsWinningCombination(E_SlotMachineSymbol left, E_SlotMachineSymbol right)
 {
     if (left == right)
     {
         return(true);
     }
     if (left == E_SlotMachineSymbol.Jackpot)
     {
         return(true);
     }
     if (right == E_SlotMachineSymbol.Jackpot)
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 3
0
        public void SetSymbol(E_SlotMachineSymbol symbol)
        {
            int idx = (int)symbol;

            // compute size of cell
            Vector2 size = new Vector2(1.0f / m_Columns, 1.0f / m_Rows);

            // split into coords
            int uIndex = idx / m_Rows;
            int vIndex = idx % m_Rows;

            // set new texture coords
            Material mat    = m_Mesh.material;
            Vector2  offset = mat.mainTextureOffset;

            offset.x = (-1.0f + size.x) + uIndex * size.x;
            offset.y = (+1.0f - size.y) - vIndex * size.y;
            mat.mainTextureOffset = offset;
        }
Exemplo n.º 4
0
    void CheckSymbols(E_SlotMachineSymbol[] matrix, int aIdx, int bIdx, int cIdx, ref List <int> indexes)
    {
        E_SlotMachineSymbol a = matrix[aIdx];
        E_SlotMachineSymbol b = matrix[bIdx];
        E_SlotMachineSymbol c = matrix[cIdx];

        if (IsWinningCombination(a, b) && IsWinningCombination(a, c) && IsWinningCombination(b, c))
        {
            if (indexes.Contains(aIdx) == false)
            {
                indexes.Add(aIdx);
            }
            if (indexes.Contains(bIdx) == false)
            {
                indexes.Add(bIdx);
            }
            if (indexes.Contains(cIdx) == false)
            {
                indexes.Add(cIdx);
            }
        }
    }
Exemplo n.º 5
0
    void SetMachineState(E_SlotMachineSymbol symbol, bool shouldWin)
    {
        E_SlotMachineSymbol symbolA;
        E_SlotMachineSymbol symbolB;
        E_SlotMachineSymbol symbolC;

        if (shouldWin == true)
        {
            symbolA = symbol;
            symbolB = symbol;
            symbolC = symbol;
        }
        else
        {
            symbolA = (E_SlotMachineSymbol)Random.Range((int)E_SlotMachineSymbol.First, (int)E_SlotMachineSymbol.Last + 1);
            do
            {
                symbolB = (E_SlotMachineSymbol)Random.Range((int)E_SlotMachineSymbol.First, (int)E_SlotMachineSymbol.Last + 1);
                symbolC = (E_SlotMachineSymbol)Random.Range((int)E_SlotMachineSymbol.First, (int)E_SlotMachineSymbol.Last + 1);
            } while ((symbolA == symbolB) && (symbolB == symbolC));
        }

        // column A
        SetSymbol(SlotColumn.A, SlotRow.Top, (E_SlotMachineSymbol)((int)symbolA - 1));
        SetSymbol(SlotColumn.A, SlotRow.Middle, symbolA);
        SetSymbol(SlotColumn.A, SlotRow.Bottom, (E_SlotMachineSymbol)((int)symbolA + 1));

        // collumn B
        SetSymbol(SlotColumn.B, SlotRow.Top, (E_SlotMachineSymbol)((int)symbolB - 4));
        SetSymbol(SlotColumn.B, SlotRow.Middle, symbolB);
        SetSymbol(SlotColumn.B, SlotRow.Bottom, (E_SlotMachineSymbol)((int)symbolB + 2));

        // collumn C
        SetSymbol(SlotColumn.C, SlotRow.Top, (E_SlotMachineSymbol)((int)symbolC + 3));
        SetSymbol(SlotColumn.C, SlotRow.Middle, symbolC);
        SetSymbol(SlotColumn.C, SlotRow.Bottom, (E_SlotMachineSymbol)((int)symbolC - 3));
    }
Exemplo n.º 6
0
    IEnumerator Spin_Coroutine()
    {
        IsBusy = true;
        Reward = 0;

        int reward;

        E_SlotMachineSymbol[] matrix;

        // create cloud action
        SlotMachineSpin action = new SlotMachineSpin(CloudUser.instance.authenticatedUserID);

        GameCloudManager.AddAction(action);

        // spin symbols
        {
            m_WinAnim.Stop();
            m_SpinAnim.Stop();

            ShowSpinAnimation(true);

            // play spin sound
            GetComponent <AudioSource>().loop = true;
            GetComponent <AudioSource>().clip = m_SpinSound;
            GetComponent <AudioSource>().Play();

            // play start sound
            GetComponent <AudioSource>().PlayOneShot(m_StartSound, AudioListener.volume);            //Added volume, otherwise in webplayer it was always playing on max

            // start slot machine
            m_SpinAnim.Play(START_ANIM);
            while (m_SpinAnim.isPlaying == true)
            {
                yield return(new WaitForEndOfFrame());
            }

            m_SpinAnim.Play(SPIN_ANIM);
        }

        // wait for cloud action to finish
        {
            float delay = 0.5f;
            do
            {
                yield return(new WaitForSeconds(delay));

                delay = 0.1f;
            } while (action.isDone == false);

            // get result from cloud
            if (action.isSucceeded == true)
            {
                reward = action.Reward;
                matrix = action.Matrix;

                SetMachineState(action.Matrix);
            }
            else
            {
                reward = 0;
                matrix = new E_SlotMachineSymbol[9];

                // update slot machine slots
                SetMachineState(E_SlotMachineSymbol.First, false);
            }
        }

        // stop slot machine
        {
            // stop slots
            m_SpinAnim.Play(STOP_ANIM);

            float oneStopDeuration = m_SpinAnim.GetClip(STOP_ANIM).length / 3.0f;
            for (int idx = 0; idx < 3; ++idx)
            {
                GetComponent <AudioSource>().PlayOneShot(m_StopSound, AudioListener.volume);                //Added volume, otherwise in webplayer it was always playing on max

                yield return(new WaitForSeconds(oneStopDeuration));
            }

            // stop symbol spinning
            ShowSpinAnimation(false);

            // stop spin sound
            GetComponent <AudioSource>().Stop();

            // play win anim if needed
            if (reward > 0)
            {
                int[] indexes = GetWinningSymbols(matrix);

                m_WinAnim.Play();

                GetComponent <AudioSource>().loop = false;

                float step = reward * 0.1f > 4.0f ? 4.0f / reward : 0.1f;
                float temp = (float)Reward;
                do
                {
                    temp  += reward * step;
                    Reward = Mathf.Min(reward, (int)temp);

                    GetComponent <AudioSource>().clip = m_WinSound;
                    GetComponent <AudioSource>().Play();

                    if (m_WinAnim.isPlaying == false)
                    {
                        m_WinAnim.Play();
                    }

                    foreach (var index in indexes)
                    {
                        Slot slot = GetSlot(index);
                        slot.Shine = !slot.Shine;
                    }

                    yield return(new WaitForSeconds(0.075f));

                    foreach (var index in indexes)
                    {
                        Slot slot = GetSlot(index);
                        slot.Shine = !slot.Shine;
                    }

                    yield return(new WaitForSeconds(0.025f));
                } while (Reward < reward);

                m_WinAnim.Stop();

                foreach (var index in indexes)
                {
                    Slot slot = GetSlot(index);
                    slot.Shine = false;
                }

                Reward = reward;
            }
        }

        // done
        IsBusy = false;
    }