commit1e4ffae4f6Author: bance <90307762+bance23@users.noreply.github.com> Date: Sat May 13 14:23:47 2023 +0200 proba athozas veszelyes commit0297a2cb78Merge:604088e31b9214Author: bance <90307762+bance23@users.noreply.github.com> Date: Sat May 13 14:09:48 2023 +0200 Merge branch 'master' of https://github.com/playmaker1210/PuzzleColorBall commit31b9214f35Merge:184d2e889976bbAuthor: Playmaker1210 <hatvanitamas09@gmail.com> Date: Mon May 8 14:42:34 2023 +0200 Merge https://github.com/playmaker1210/PuzzleColorBall commit184d2e84daAuthor: Playmaker1210 <hatvanitamas09@gmail.com> Date: Mon May 8 14:41:59 2023 +0200 server mukodik commit89976bbcf8Author: playmaker1210 <75033623+playmaker1210@users.noreply.github.com> Date: Fri May 5 12:49:28 2023 +0200 Update README.md commit250cc0ffeeAuthor: playmaker1210 <75033623+playmaker1210@users.noreply.github.com> Date: Fri May 5 12:49:01 2023 +0200 Create README.md commit2f0ae77e35Author: playmaker1210 <hatvanitamas09@gmail.com> Date: Thu May 4 12:56:56 2023 +0200 update commitb94c80b293Author: Playmaker1210 <hatvanitamas09@gmail.com> Date: Tue May 2 13:46:38 2023 +0200 coin db working commit25d792e0fdAuthor: playmaker1210 <hatvanitamas09@gmail.com> Date: Sat Apr 29 17:07:23 2023 +0200 update
214 lines
5.5 KiB
C#
214 lines
5.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Net.Sockets;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
public class jatekmanager : MonoBehaviour
|
|
{
|
|
//gamestate-s cuccok
|
|
public static jatekmanager Instance;
|
|
public GameState State;
|
|
public static event Action<GameState> OnGameStateChanged;
|
|
|
|
//gameobjectek,gombok,scriptek
|
|
public GameObject playButton;
|
|
public GameObject garazs;
|
|
public GameObject homeGomb;
|
|
public GameObject settingsGomb;
|
|
public GameObject shopGomb;
|
|
|
|
public GameObject goLeftButton;
|
|
public GameObject jumpButton;
|
|
public GameObject goRightButton;
|
|
|
|
public TMP_Text scoreText;
|
|
public TMP_Text timerText;
|
|
|
|
|
|
private DatabaseData db;
|
|
private UsernameHandler usernameHandler;
|
|
private Score score;
|
|
private Timer timer;
|
|
private CoinCounter cc;
|
|
|
|
private void Awake()
|
|
{
|
|
Application.targetFrameRate = 60;
|
|
|
|
Instance = this;
|
|
db = FindObjectOfType<DatabaseData>();
|
|
usernameHandler = FindObjectOfType<UsernameHandler>();
|
|
score = FindObjectOfType<Score>();
|
|
timer = FindObjectOfType<Timer>();
|
|
cc = FindObjectOfType<CoinCounter>();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
UpdateGameState(GameState.Home);
|
|
}
|
|
|
|
public void UpdateGameState(GameState newState)
|
|
{
|
|
State = newState;
|
|
|
|
switch (newState)
|
|
{
|
|
case GameState.Home:
|
|
HandleHome();
|
|
break;
|
|
case GameState.Settings:
|
|
HandleSettings();
|
|
break;
|
|
case GameState.Shop:
|
|
HandleShop();
|
|
break;
|
|
case GameState.Game:
|
|
HandleGame();
|
|
break;
|
|
case GameState.Meghaltal:
|
|
HandleMeghaltal();
|
|
break;
|
|
default:
|
|
throw new ArgumentOutOfRangeException(nameof(newState), newState, null);
|
|
}
|
|
|
|
OnGameStateChanged?.Invoke(newState);
|
|
}
|
|
|
|
public enum GameState
|
|
{
|
|
Home,
|
|
Settings,
|
|
Shop,
|
|
Game,
|
|
Meghaltal
|
|
}
|
|
|
|
public void ChangeToHome()
|
|
{
|
|
UpdateGameState(GameState.Home);
|
|
homeGomb.SetActive(true);
|
|
settingsGomb.SetActive(true);
|
|
shopGomb.SetActive(true);
|
|
goLeftButton.SetActive(false);
|
|
jumpButton.SetActive(false);
|
|
goRightButton.SetActive(false);
|
|
scoreText.gameObject.SetActive(false);
|
|
timerText.gameObject.SetActive(false);
|
|
}
|
|
|
|
private async void HandleHome()
|
|
{
|
|
//deactivate buttons
|
|
StartCoroutine(TimerHome());
|
|
GetComponent<GroundController>().enabled = false;
|
|
GetComponent<PlayerController>().enabled = false;
|
|
goLeftButton.SetActive(false);
|
|
jumpButton.SetActive(false);
|
|
goRightButton.SetActive(false);
|
|
scoreText.gameObject.SetActive(false);
|
|
timerText.gameObject.SetActive(false);
|
|
garazs.SetActive(true);
|
|
}
|
|
|
|
IEnumerator TimerHome()
|
|
{
|
|
yield return new WaitForSecondsRealtime(2);
|
|
playButton.SetActive(true);
|
|
}
|
|
|
|
public void ChangeToSettings()
|
|
{
|
|
UpdateGameState(GameState.Settings);
|
|
}
|
|
|
|
private async void HandleSettings()
|
|
{
|
|
playButton.SetActive(false);
|
|
goLeftButton.SetActive(false);
|
|
jumpButton.SetActive(false);
|
|
goRightButton.SetActive(false);
|
|
scoreText.gameObject.SetActive(false);
|
|
timerText.gameObject.SetActive(false);
|
|
}
|
|
|
|
public void ChangeToShop()
|
|
{
|
|
UpdateGameState(GameState.Shop);
|
|
}
|
|
|
|
private async void HandleShop()
|
|
{
|
|
playButton.SetActive(false);
|
|
goLeftButton.SetActive(false);
|
|
jumpButton.SetActive(false);
|
|
goRightButton.SetActive(false);
|
|
scoreText.gameObject.SetActive(false);
|
|
timerText.gameObject.SetActive(false);
|
|
}
|
|
|
|
public void ChangeToGame()
|
|
{
|
|
homeGomb.SetActive(false);
|
|
settingsGomb.SetActive(false);
|
|
shopGomb.SetActive(false);
|
|
playButton.SetActive(false);
|
|
UpdateGameState(GameState.Game);
|
|
}
|
|
|
|
IEnumerator TimerGame()
|
|
{
|
|
yield return new WaitForSecondsRealtime(1);
|
|
garazs.SetActive(false);
|
|
}
|
|
|
|
private async void HandleGame()
|
|
{
|
|
StartCoroutine(TimerGame());
|
|
|
|
GetComponent <GroundController> ().enabled = true;
|
|
GetComponent <PlayerController>().enabled = true;
|
|
|
|
goLeftButton.SetActive(true);
|
|
jumpButton.SetActive(true);
|
|
goRightButton.SetActive(true);
|
|
scoreText.gameObject.SetActive(true);
|
|
timerText.gameObject.SetActive(true);
|
|
playButton.SetActive(false);
|
|
|
|
timer.playTime.Start();
|
|
}
|
|
|
|
public void ChangeToMeghaltal()
|
|
{
|
|
UpdateGameState(GameState.Meghaltal);
|
|
}
|
|
|
|
private async void HandleMeghaltal()
|
|
{
|
|
//ora leallitasa
|
|
timer.playTime.Stop();
|
|
|
|
//Valtson at high score tabla scenebe utana ha megnyomott egy gombot ugy menjen vissza a menube
|
|
//toltse fel az adatokat a run-rol
|
|
db.PostNewScoreData(usernameHandler.userid, score.score, timer.convertTimeToString());
|
|
|
|
//coin feltoltes
|
|
db.PostNewCoinData(cc.coin, usernameHandler.userid);
|
|
|
|
SceneUIManager.LoadScene(1); //HighScore scene
|
|
|
|
|
|
/*playButton.SetActive(false);
|
|
homeGomb.SetActive(true);
|
|
GetComponent<GroundController>().enabled = false;
|
|
GetComponent<PlayerController>().enabled = false;
|
|
garazs.SetActive(true);*/
|
|
}
|
|
} |