Files
findthesource/Assets/Scripts/Dice.cs

189 lines
7.4 KiB
C#
Raw Normal View History

2022-10-30 15:02:17 +01:00
using System.Collections;
2023-02-10 14:06:30 +01:00
using System.Collections.Generic;
2022-10-30 15:02:17 +01:00
using UnityEngine;
2023-02-08 16:03:08 +01:00
using UnityEngine.UI;
2022-10-30 15:02:17 +01:00
public class Dice : MonoBehaviour {
public Sprite[] diceSides = new Sprite[6];
2022-11-02 11:15:11 +01:00
public SpriteRenderer hely1;
public SpriteRenderer hely2;
2023-02-12 16:53:09 +01:00
public Button dice1btnBtn;
public Button dice2btnBtn;
2022-11-04 13:05:20 +01:00
private Upgrade upgrade;
private Akciopont ap;
2022-11-07 17:56:31 +01:00
private Energia energiasav;
2023-01-26 21:25:20 +01:00
private Targyak targyak;
2023-02-08 16:03:08 +01:00
public int[] diceResult = { 0, 0 };
2023-02-10 14:06:30 +01:00
public List<int> ujertek = new List<int>();
2022-11-02 12:52:21 +01:00
public int valasztottErtek; //a jatekos altal valasztott dobott ertek helye
2023-02-12 16:53:09 +01:00
private bool locked = false; //ne lehessen ujra kivalasztani a masikat ha mar tortent egy valasztas
2023-02-08 16:03:08 +01:00
public bool adrenalinMegerosites = false;
2023-01-26 21:25:20 +01:00
public GameObject adrenalinHasznalat;
2023-02-08 16:03:08 +01:00
public Button confirm;
public Button cancel;
2023-02-09 13:38:54 +01:00
public bool mehet = false;
2023-02-08 16:03:08 +01:00
public BoxCollider2D[] colliders;
2022-10-30 15:02:17 +01:00
//getters setters
public int[] getDices() { return diceResult; }
public int getValasztottErtek() { return valasztottErtek; }
public void setValasztottErtek(int ujErtek) { valasztottErtek = ujErtek; }
2022-11-07 17:25:24 +01:00
public bool getLocked() { return locked; }
public void setLocked(bool locked) { this.locked = locked; }
2023-01-24 18:39:30 +01:00
public int dobott = 0;
2023-02-12 16:53:09 +01:00
public bool dobottEgyszer = false; //tudjon ujra dobni vagy nem
2023-01-24 18:39:30 +01:00
2023-02-10 14:06:30 +01:00
private void Awake() {
2022-11-04 13:05:20 +01:00
upgrade = FindObjectOfType<Upgrade>();
ap = FindObjectOfType<Akciopont>();
2022-11-07 17:56:31 +01:00
energiasav = FindObjectOfType<Energia>();
2023-01-26 21:25:20 +01:00
targyak = FindObjectOfType<Targyak>();
2022-11-04 13:05:20 +01:00
}
public void ertekValasztas(GameObject gomb) {
2022-11-02 12:52:21 +01:00
if (diceResult[0] != 0 && diceResult[1] != 0 && !locked) { //megnezzuk hogy lett e mar dobva es nem valasztott meg a jatekos
if (gomb.name == "dice1btn") {
2022-11-02 12:52:21 +01:00
valasztottErtek = diceResult[0];
2022-11-04 13:05:20 +01:00
if (diceResult[0] < diceResult[1]) {
2022-11-07 17:56:31 +01:00
upgrade.canUpgrade = true; //kisebb szam valasztasa eseten fejlesztes egyszer
} else {
2022-11-15 14:42:09 +01:00
energiasav.csokkenEnergia(1); //nagyobb szam valasztasa eseten -1 energia
2022-11-04 13:05:20 +01:00
}
2022-11-02 12:52:21 +01:00
locked = true;
} else if (gomb.name == "dice2btn") {
2022-11-02 12:52:21 +01:00
valasztottErtek = diceResult[1];
2022-11-04 13:05:20 +01:00
if (diceResult[1] < diceResult[0]) {
upgrade.canUpgrade = true;
2022-11-07 17:56:31 +01:00
} else {
2022-11-15 14:42:09 +01:00
energiasav.csokkenEnergia(1);
2022-11-04 13:05:20 +01:00
}
2022-11-02 12:52:21 +01:00
locked = true;
}
2022-11-04 13:05:20 +01:00
ap.UpdateAkciopont(getValasztottErtek() + upgrade.akcio[upgrade.getAkcioIndex()]);
2022-10-30 15:02:17 +01:00
}
2022-12-07 18:52:40 +01:00
Debug.Log("valasztott ertek: " + valasztottErtek + " locked status: " + locked);
2022-11-02 12:52:21 +01:00
}
2022-11-02 11:15:11 +01:00
2022-11-18 10:12:04 +01:00
public int RollDice() {
2022-12-14 10:32:38 +01:00
int randomDiceSide = Random.Range(0, 6);
2022-11-02 12:52:21 +01:00
int finalSide = randomDiceSide + 1;
2022-11-02 11:15:11 +01:00
Debug.Log(finalSide);
return finalSide;
}
2023-02-08 16:03:08 +01:00
public void CallRenderDice() => StartCoroutine(renderDice());
public IEnumerator renderDice() {
2023-02-12 16:53:09 +01:00
//ha zarolva van akkor ne tudjon ujra dobni / csak egyszer dobhasson (amig nincs feloldva a kovetkezo dobashoz)
if(dobottEgyszer) yield break;
//dice gombok kikapcsolasa hogy amig nem vegez ne tudjon erteket valasztani
dice1btnBtn.enabled = false;
dice2btnBtn.enabled = false;
2022-11-02 11:15:11 +01:00
do {
2022-11-18 10:12:04 +01:00
diceResult[0] = RollDice();
diceResult[1] = RollDice();
2022-11-02 11:15:11 +01:00
} while (diceResult[0] == diceResult[1]);
2023-02-12 16:53:09 +01:00
2023-02-08 16:03:08 +01:00
//lassa a jatekos mit dobott
hely1.sprite = diceSides[diceResult[0]-1];
hely1.size = new Vector2(38, 38);
hely2.sprite = diceSides[diceResult[1]-1];
hely2.size = new Vector2(38, 38);
2023-02-12 16:53:09 +01:00
dobottEgyszer = true;
2023-02-09 13:38:54 +01:00
//ha megvan a targy
2023-02-08 11:47:47 +01:00
if(targyak.adrenalinloket > 0) {
2023-02-08 16:03:08 +01:00
//helyszin collider kikapcsolas a gomb miatt
HelyszinKiBekapcs(true);
2023-02-08 11:47:47 +01:00
//text aktivalasa kerdesre hogy akarja e hasznalni a targyat
2023-02-08 16:03:08 +01:00
adrenalinHasznalat.gameObject.SetActive(true);
2023-02-08 11:47:47 +01:00
//ha igen gomb -> valtozo igaz, targy fv meghivas, deaktivalas
//VARNIA KELL A GOMBRA
2023-02-08 16:03:08 +01:00
var waitForButton = new WaitForUIButtons(confirm, cancel);
yield return waitForButton.Reset();
if(waitForButton.PressedButton == confirm){
adrenalinMegerosites = true;
}else{
adrenalinMegerosites = false;
}
adrenalinHasznalat.gameObject.SetActive(false);
2023-02-08 11:47:47 +01:00
if (adrenalinMegerosites) {
2023-02-08 16:03:08 +01:00
targyak.CallAdrenalinLoket();
2023-02-10 14:06:30 +01:00
yield return new WaitUntil(() => ujertek.Count > 0);
2023-02-09 13:38:54 +01:00
if(mehet){
Debug.Log("belep mehet");
2023-02-10 14:06:30 +01:00
Debug.Log("List: 0: " + ujertek[0] + " 1: " + ujertek[1]);
2023-02-12 16:53:09 +01:00
//EGYENLO ERTEKEK VIZSGALATA
2023-02-10 16:13:26 +01:00
//ha tul nagy vagy tul kicsi erteket ad meg az elso kockanak valtsa at az erteket
if(targyak.ujertek1 > 6 && diceResult[1] != 6 && targyak.ujertek2 != 6){ //ha tul nagy szamot adott meg legyen 6 az ertek
targyak.ujertek1 = 6;
}else if(targyak.ujertek1 > 6 && (diceResult[1] == 6 || targyak.ujertek2 == 6)){ //ha a masik ertek 6 akkor legyen az ertek 5
targyak.ujertek1 = 5;
}else if(targyak.ujertek1 < 1 && diceResult[1] != 1 && targyak.ujertek2 != 1){
targyak.ujertek1 = 1;
}else if(targyak.ujertek1 < 1 && (diceResult[1] == 1 || targyak.ujertek2 == 1)){
targyak.ujertek1 = 2;
}
//
//ha tul nagy vagy tul kicsi erteket ad meg az masodik kockanak valtsa at az erteket
if(targyak.ujertek2 > 6 && diceResult[0] != 6 && targyak.ujertek1 != 6){ //ha tul nagy szamot adott meg legyen 6 az ertek
targyak.ujertek2 = 6;
}else if(targyak.ujertek2 > 6 && (diceResult[0] == 6 || targyak.ujertek1 == 6)){ //ha a masik ertek 6 akkor legyen az ertek 5
targyak.ujertek2 = 5;
}else if(targyak.ujertek2 < 1 && diceResult[0] != 1 && targyak.ujertek1 != 1){
targyak.ujertek2 = 1;
}else if(targyak.ujertek2 < 1 && (diceResult[0] == 1 || targyak.ujertek1 == 1)){
targyak.ujertek2 = 2;
2023-02-12 16:53:09 +01:00
}
2023-02-10 16:13:26 +01:00
2023-02-09 13:38:54 +01:00
diceResult[0] = targyak.ujertek1;
diceResult[1] = targyak.ujertek2;
2023-02-12 16:53:09 +01:00
dobottEgyszer = true;
2023-02-10 14:06:30 +01:00
}
2023-02-08 11:47:47 +01:00
}
//deaktivalas
adrenalinMegerosites = false;
}
2022-11-02 12:52:21 +01:00
hely1.sprite = diceSides[diceResult[0]-1];
2022-11-02 11:15:11 +01:00
hely1.size = new Vector2(38, 38);
2022-11-02 12:52:21 +01:00
hely2.sprite = diceSides[diceResult[1]-1];
2022-11-02 11:15:11 +01:00
hely2.size = new Vector2(38, 38);
2023-01-24 18:39:30 +01:00
dobott++;
2023-02-12 16:53:09 +01:00
//ha vegzett mindennel kapcsolja vissza az ertekvalasztast
dice1btnBtn.enabled = true;
dice2btnBtn.enabled = true;
2022-10-30 15:02:17 +01:00
}
2023-01-26 21:25:20 +01:00
2023-02-08 16:03:08 +01:00
public void HelyszinKiBekapcs(bool kikapcsolas){
if(kikapcsolas)
foreach(var item in colliders)
item.gameObject.SetActive(false);
else
foreach(var item in colliders)
item.gameObject.SetActive(true);
}
2023-01-26 21:25:20 +01:00
public void setAdrenalinMegerosites(bool adrenalinMegerosites) {
this.adrenalinMegerosites = adrenalinMegerosites;
}
2022-10-30 15:02:17 +01:00
}