SemiMetalAlchemist

SlotMachine_GameControl

May 15th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.41 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using System;
  6.  
  7. public class GameControl : MonoBehaviour
  8. {
  9.     public static event Action HandlePulled = delegate { };
  10.  
  11.     [SerializeField]
  12.     private Text prizeText;
  13.  
  14.     [SerializeField]
  15.     private Row[] rows;
  16.  
  17.     [SerializeField]
  18.     private Transform handle;
  19.  
  20.     private int prizeValue;
  21.  
  22.     private bool resultsChecked = false;
  23.  
  24.     //Update is called once per frame
  25.     private void Update()
  26.     {
  27.         if (!rows[0].rowStopped || !rows[1].rowStopped || !rows[2].rowStopped)
  28.  
  29.  
  30.         {
  31.             prizeValue = 0;
  32.             prizeText.enabled = false;
  33.             resultsChecked = false;
  34.  
  35.         }
  36.  
  37.         if (rows[0].rowStopped && rows[1].rowStopped && rows[2].rowStopped)
  38.  
  39.  
  40.         {
  41.             CheckResults();
  42.             prizeText.enabled = true;
  43.             prizeText.text = "Prize: " + prizeValue;
  44.         }
  45.     }
  46.  
  47.     private void OnMouseDown()
  48.     {
  49.         if (rows[0].rowStopped && rows[1].rowStopped && rows[2].rowStopped)
  50.             StartCoroutine("PullHandle");
  51.     }
  52.  
  53.     private IEnumerator PullHandle()
  54.     {
  55.         for (int i = 0; i <15; i += 5)
  56.         {
  57.             handle.Rotate(0f, 0f, i);
  58.             yield return new WaitForSeconds(0.1f);
  59.         }
  60.  
  61.         HandlePulled();
  62.  
  63.         for (int i = 0; i < 15; i += 5)
  64.         {
  65.             handle.Rotate(0f, 0f, -i);
  66.             yield return new WaitForSeconds(0.1f);
  67.         }
  68.     }
  69.  
  70.     private void CheckResults()
  71.     {
  72.         if (rows[0].stoppedSlot == "Diamond"
  73.             && rows[1].stoppedSlot == "Diamond"
  74.             && rows[2].stoppedSlot == "Diamond")
  75.  
  76.             prizeValue = 200;
  77.  
  78.         else if (rows[0].stoppedSlot == "Crown"
  79.             && rows[1].stoppedSlot == "Crown"
  80.             && rows[2].stoppedSlot == "Crown")
  81.  
  82.             prizeValue = 400;
  83.  
  84.         else if (rows[0].stoppedSlot == "Melon"
  85.             && rows[1].stoppedSlot == "Melon"
  86.             && rows[2].stoppedSlot == "Melon")
  87.  
  88.             prizeValue = 600;
  89.  
  90.         else if (rows[0].stoppedSlot == "Bar"
  91.             && rows[1].stoppedSlot == "Bar"
  92.             && rows[2].stoppedSlot == "Bar")
  93.  
  94.             prizeValue = 800;
  95.  
  96.         else if (rows[0].stoppedSlot == "Seven"
  97.             && rows[1].stoppedSlot == "Seven"
  98.             && rows[2].stoppedSlot == "Seven")
  99.  
  100.             prizeValue = 1500;
  101.  
  102.         else if (rows[0].stoppedSlot == "Cherry"
  103.             && rows[1].stoppedSlot == "Cherry"
  104.             && rows[2].stoppedSlot == "Cherry")
  105.  
  106.             prizeValue = 3000;
  107.  
  108.         else if (rows[0].stoppedSlot == "Lemon"
  109.             && rows[1].stoppedSlot == "Lemon"
  110.             && rows[2].stoppedSlot == "Lemon")
  111.  
  112.             prizeValue = 5000;
  113.  
  114.         else if (((rows[0].stoppedSlot == rows[1].stoppedSlot)
  115.             && (rows[0].stoppedSlot == "Diamond"))
  116.  
  117.             || ((rows[0].stoppedSlot == rows[2].stoppedSlot)
  118.             && (rows[0].stoppedSlot == "Diamond"))
  119.  
  120.             || ((rows[1].stoppedSlot == rows[2].stoppedSlot)
  121.             && (rows[1].stoppedSlot == "Diamond")))
  122.  
  123.             prizeValue = 100;
  124.  
  125.         else if (((rows[0].stoppedSlot == rows[1].stoppedSlot)
  126.             && (rows[0].stoppedSlot == "Crown"))
  127.  
  128.             || ((rows[0].stoppedSlot == rows[2].stoppedSlot)
  129.             && (rows[0].stoppedSlot == "Crown"))
  130.  
  131.             || ((rows[1].stoppedSlot == rows[2].stoppedSlot)
  132.             && (rows[1].stoppedSlot == "Crown")))
  133.  
  134.             prizeValue = 200;
  135.  
  136.         else if (((rows[0].stoppedSlot == rows[1].stoppedSlot)
  137.             && (rows[0].stoppedSlot == "Melon"))
  138.  
  139.             || ((rows[0].stoppedSlot == rows[2].stoppedSlot)
  140.             && (rows[0].stoppedSlot == "Melon"))
  141.  
  142.             || ((rows[1].stoppedSlot == rows[2].stoppedSlot)
  143.             && (rows[1].stoppedSlot == "Melon")))
  144.  
  145.             prizeValue = 300;
  146.  
  147.         else if (((rows[0].stoppedSlot == rows[1].stoppedSlot)
  148.             && (rows[0].stoppedSlot == "Bar"))
  149.  
  150.             || ((rows[0].stoppedSlot == rows[2].stoppedSlot)
  151.             && (rows[0].stoppedSlot == "Bar"))
  152.  
  153.             || ((rows[1].stoppedSlot == rows[2].stoppedSlot)
  154.             && (rows[1].stoppedSlot == "Bar")))
  155.  
  156.             prizeValue = 400;
  157.  
  158.         else if (((rows[0].stoppedSlot == rows[1].stoppedSlot)
  159.             && (rows[0].stoppedSlot == "Seven"))
  160.  
  161.             || ((rows[0].stoppedSlot == rows[2].stoppedSlot)
  162.             && (rows[0].stoppedSlot == "Seven"))
  163.  
  164.             || ((rows[1].stoppedSlot == rows[2].stoppedSlot)
  165.             && (rows[1].stoppedSlot == "Seven")))
  166.  
  167.             prizeValue = 1000;
  168.  
  169.         else if (((rows[0].stoppedSlot == rows[1].stoppedSlot)
  170.             && (rows[0].stoppedSlot == "Cherry"))
  171.  
  172.             || ((rows[0].stoppedSlot == rows[2].stoppedSlot)
  173.             && (rows[0].stoppedSlot == "Cherry"))
  174.  
  175.             || ((rows[1].stoppedSlot == rows[2].stoppedSlot)
  176.             && (rows[1].stoppedSlot == "Cherry")))
  177.  
  178.             prizeValue = 2000;
  179.  
  180.         else if (((rows[0].stoppedSlot == rows[1].stoppedSlot)
  181.             && (rows[0].stoppedSlot == "Lemon"))
  182.  
  183.             || ((rows[0].stoppedSlot == rows[2].stoppedSlot)
  184.             && (rows[0].stoppedSlot == "Lemon"))
  185.  
  186.             || ((rows[1].stoppedSlot == rows[2].stoppedSlot)
  187.             && (rows[1].stoppedSlot == "Lemon")))
  188.  
  189.             prizeValue = 4000;
  190.  
  191.         resultsChecked = true;
  192.  
  193.  
  194.     }
  195.  
  196. }
Add Comment
Please, Sign In to add comment