using UnityEngine;
using System.Collections;
using UnityEngine.UI;
//下注按鈕總數
static class Constants
{
public const int totalButton = 4;
}
public class buttonMsg
{
private int bettingCount;
public buttonMsg()
{
bettingCount = 0;
}
//下注
public void betting()
{
bettingCount++;
}
//回傳下注數
public int getBettingCount()
{
return bettingCount;
}
//重置
public void reSet()
{
bettingCount = 0;
}
}
public class HW : MonoBehaviour {
int one = 1;
int zero = 0;
//判斷開始或重置
bool startOrReset = true;
buttonMsg[] myBut = new buttonMsg[Constants.totalButton];
int rand;
int myMoney;
Text moneyText;
Text[] buttonJudgeText = new Text[Constants.totalButton];
Image[] img = new Image[Constants.totalButton];
Text[] button_Text = new Text[Constants.totalButton];
void Start () {
myMoney = 138;
string path;
for (int i = 0; i < Constants.totalButton; i++)
{
path = string.Format("Image{0}", i);
img[i] = GameObject.Find(path).GetComponent<Image>();
img[i].color = UnityEngine.Color.white;
path = string.Format("buttonJudge{0}", i);
buttonJudgeText[i] = GameObject.Find(path).GetComponent<Text>();
path = string.Format("button{0}/Text", i);
button_Text[i] = GameObject.Find(path).GetComponent<Text>();
buttonJudgeText[i].text = zero.ToString();
myBut[i]=new buttonMsg();
}
moneyText = GameObject.Find("money/Text").GetComponent<Text>();
moneyText.text = myMoney.ToString();
}
void Update () {
moneyText.text = myMoney.ToString();
}
public void bettingButton(int _butNum)
{
if (myMoney > 0)
{
myMoney = myMoney - 1;
myBut[_butNum].betting();
button_Text[_butNum].text = myBut[_butNum].getBettingCount().ToString();
}
}
//開始按鈕函式
public void startButton()
{
if (startOrReset == true)
{
start();
startOrReset = false;
}
else if (startOrReset == false)
{
reset();
startOrReset = true;
}
}
public void reset()
{
for (int i = 0; i < Constants.totalButton; i++)
{
myBut[i].reSet();
button_Text[i].text = zero.ToString();
buttonJudgeText[i].text = zero.ToString();
img[i].color = UnityEngine.Color.white;
}
}
public void start()
{
rand = Random.Range(0, (Constants.totalButton-1));
myMoney += myBut[rand].getBettingCount() * 2;
for (int i = 0; i < Constants.totalButton; i++)
{
if (i == rand)
{
button_Text[i].text = (myBut[rand].getBettingCount() * 2).ToString();
buttonJudgeText[i].text = one.ToString();
img[i].color = UnityEngine.Color.red;
}
//未中獎的下注按鈕
else
{
button_Text[i].text = zero.ToString();
buttonJudgeText[i].text = zero.ToString();
img[i].color = UnityEngine.Color.black;
}
}
}
public void add()
{
myMoney++;
}
}