_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/Battle_Royale/BettingBtn.cs
2024-11-13 21:45:48 +08:00

210 lines
6.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class BettingBtn : MonoBehaviour
{
public static BettingBtn instance;
public GameObject BetList;
public Button NumBtn;
public Text BetText;
public float BetValue;//投注的值
public float AllBetValue;//投注总值
public Button BetButton;//投注的按钮
public GameObject text1;
public GameObject text2;
public GameObject text3;
public GameObject text4;
public GameObject text5;
public GameObject text6;
public List<GameObject> list=new List<GameObject>();
// Start is called before the first frame update
void Start()
{
instance = this;
BetList.SetActive(false);
NumBtn.onClick.AddListener(OnClickNumBtn);
BetButton.onClick.AddListener(OnClickBetBtn);
BetValue = 50;//默认50
SetBet();
}
void OnClickNumBtn()
{
BetList.SetActive(true);
}
void OnClickBetBtn()
{
if (HegemonTime.instance.timeNum>20)
{
switch (PlayerMovePos.instance.HouseId)
{
case 1:
if (PlayerInfo.instance.SetMoney(-BetValue))
{
text1.GetComponent<TextBox>().SetText(BetValue);
AllBetValue += BetValue;
}
break;
case 2:
if (PlayerInfo.instance.SetMoney(-BetValue))
{
text2.GetComponent<TextBox>().SetText(BetValue);
AllBetValue += BetValue;
}
break;
case 3:
if (PlayerInfo.instance.SetMoney(-BetValue))
{
text3.GetComponent<TextBox>().SetText(BetValue);
AllBetValue += BetValue;
}
break;
case 4:
if (PlayerInfo.instance.SetMoney(-BetValue))
{
text4.GetComponent<TextBox>().SetText(BetValue);
AllBetValue += BetValue;
}
break;
case 5:
if (PlayerInfo.instance.SetMoney(-BetValue))
{
text5.GetComponent<TextBox>().SetText(BetValue);
AllBetValue += BetValue;
}
break;
case 6:
if (PlayerInfo.instance.SetMoney(-BetValue))
{
text6.GetComponent<TextBox>().SetText(BetValue);
AllBetValue += BetValue;
}
break;
default:
Debug.Log("请选择房间");
break;
}
}
else
{
Debug.Log("现在无法投注");
}
}
void SetBet()
{
// 获取所有的Button组件
Button[] buttons = BetList.GetComponentsInChildren<Button>();
// 遍历每一个Button添加点击事件
foreach (Button button in buttons)
{
button.onClick.AddListener(() => {
BetText.text = button.transform.GetComponentInChildren<Text>().text;
BetValue = float.Parse(BetText.text);
BetList.SetActive(false);
});
}
}
public void GiveMoney()
{
float AllMoney = text1.GetComponent<TextBox>().ReturnText() + text2.GetComponent<TextBox>().ReturnText() + text3.GetComponent<TextBox>().ReturnText()
+ text4.GetComponent<TextBox>().ReturnText() + text5.GetComponent<TextBox>().ReturnText() + text6.GetComponent<TextBox>().ReturnText();
switch (BossContro.instance.HouseId)
{
case 1:
text1.GetComponent<TextBox>().PlayAni();
ControMoney(text1);
break;
case 2:
text2.GetComponent<TextBox>().PlayAni();
ControMoney(text2);
break;
case 3:
text3.GetComponent<TextBox>().PlayAni();
ControMoney(text3);
break;
case 4:
text4.GetComponent<TextBox>().PlayAni();
ControMoney(text4);
break;
case 5:
text5.GetComponent<TextBox>().PlayAni();
ControMoney(text5);
break;
case 6:
text6.GetComponent<TextBox>().PlayAni();
ControMoney(text6);
break;
}
}
public void ControMoney(GameObject text)
{
float giveMoney= text.GetComponent<TextBox>().ReturnText();
text.GetComponent<TextBox>().SetText(-giveMoney);
float AllMoney = text1.GetComponent<TextBox>().ReturnText() + text2.GetComponent<TextBox>().ReturnText() + text3.GetComponent<TextBox>().ReturnText()
+ text4.GetComponent<TextBox>().ReturnText() + text5.GetComponent<TextBox>().ReturnText() + text6.GetComponent<TextBox>().ReturnText();
for (int i=0;i<list.Count;i++)
{
if (list[i]==text)
{
continue;
}
list[i].GetComponent<TextBox>().SetText(giveMoney*(list[i].GetComponent<TextBox>().ReturnText()/AllMoney));
}
}
public void GiveMoneyToPlayer()
{
switch (PlayerMovePos.instance.HouseId)
{
case 1:
PlayerInfo.instance.SetMoney(text1.GetComponent<TextBox>().ReturnText()/2);
break;
case 2:
PlayerInfo.instance.SetMoney(text2.GetComponent<TextBox>().ReturnText()/2);
break;
case 3:
PlayerInfo.instance.SetMoney(text3.GetComponent<TextBox>().ReturnText() / 2);
break;
case 4:
PlayerInfo.instance.SetMoney(text4.GetComponent<TextBox>().ReturnText()/2);
break;
case 5:
PlayerInfo.instance.SetMoney(text5.GetComponent<TextBox>().ReturnText() / 2);
break;
case 6:
PlayerInfo.instance.SetMoney(text6.GetComponent<TextBox>().ReturnText() / 2);
break;
default:
Debug.Log("未选择房间");
break;
}
}
}