Leaderboard
This commit is contained in:
@@ -12,6 +12,8 @@ public class AudioManager : MonoBehaviour
|
||||
|
||||
if(PlayerPrefs.HasKey("mute")){
|
||||
isMute = PlayerPrefs.GetInt("mute") == 1;
|
||||
}else{
|
||||
isMute=false;
|
||||
}
|
||||
Refresh();
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ public static class DataManager{
|
||||
public const string API_ENDPOINT = "http://vps.playpoolstudios.com/faucet/golf/api/";
|
||||
private const string key = "#2CuV1Bit^S!sW1ZcgRv8BhrO";
|
||||
public static UserData userData{get; private set;}
|
||||
public static List<LeaderboardItemData> Leaderboard{get; private set;}
|
||||
public static bool isLogged{ get{return userData != null;}}
|
||||
|
||||
public static void Signout(){
|
||||
@@ -82,7 +83,7 @@ public static class DataManager{
|
||||
await Task.Yield();
|
||||
}
|
||||
Debug.Log("glogin response: " +request.downloadHandler.text);
|
||||
MessageBox.ShowMessage(request.downloadHandler.text);
|
||||
// MessageBox.ShowMessage(request.downloadHandler.text);
|
||||
|
||||
if(request.downloadHandler.text.Contains("{")){
|
||||
try{
|
||||
@@ -160,6 +161,47 @@ public static class DataManager{
|
||||
LoadingScreen.LoadLevel("MainMenu");
|
||||
}
|
||||
|
||||
public static async Task RefreshLeaderboard(){
|
||||
WWWForm form = new WWWForm();
|
||||
|
||||
Debug.Log(userData.ToString());
|
||||
|
||||
form.AddField("username", userData.username);
|
||||
|
||||
using (UnityWebRequest request = UnityWebRequest.Post(API_ENDPOINT + "get_leaderboard.php", form))
|
||||
{
|
||||
var operation = request.SendWebRequest();
|
||||
while (!operation.isDone)
|
||||
{
|
||||
await Task.Yield();
|
||||
}
|
||||
Debug.Log("add scores response: " +request.downloadHandler.text);
|
||||
|
||||
if(request.downloadHandler.text.Contains("{")){
|
||||
try{
|
||||
string[] items = request.downloadHandler.text.Split("<td>");
|
||||
Leaderboard = new List<LeaderboardItemData>();
|
||||
foreach(string item in items){
|
||||
LeaderboardItemData newItem = JsonConvert.DeserializeObject<LeaderboardItemData>(item);
|
||||
|
||||
Leaderboard.Add(newItem);
|
||||
}
|
||||
|
||||
Debug.Log("Success parsing userdata");
|
||||
|
||||
|
||||
}catch(Exception e){
|
||||
Debug.Log("Error parsing leaderboard");
|
||||
}
|
||||
}else{
|
||||
|
||||
MessageBox.ShowMessage("Error getting leaderboard, Server said\n" +request.downloadHandler.text);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
@@ -176,3 +218,19 @@ public class UserData{
|
||||
return JsonConvert.SerializeObject(this);
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class LeaderboardItemData{
|
||||
public int position;
|
||||
public string name;
|
||||
public int topScore;
|
||||
|
||||
public string DisplayName{get{
|
||||
string _name= name;
|
||||
if(name.Contains("#0")){
|
||||
_name = _name.Substring(0,name.IndexOf("@gmail"));
|
||||
}
|
||||
|
||||
return _name;
|
||||
}}
|
||||
}
|
||||
|
||||
36
Assets/Scripts/EncryptionTester.cs
Normal file
36
Assets/Scripts/EncryptionTester.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using UnityEngine;
|
||||
|
||||
public class EncryptionTester : MonoBehaviour
|
||||
{
|
||||
public PaddingMode paddingMode;
|
||||
public CipherMode cipherMode;
|
||||
[Header("Encryption")]
|
||||
public string textToEncrypt;
|
||||
public string encryptedText;
|
||||
|
||||
[Header("Decryption")]
|
||||
public string textToDecrypt;
|
||||
public string decryptedText;
|
||||
|
||||
[Header("Numbers")]
|
||||
[Header("Encryption")]
|
||||
public int numberToEncrypt;
|
||||
public string encryptedNumber;
|
||||
[Header("Encryption")]
|
||||
public string numTextToDecrypt;
|
||||
public int decryptedNumber;
|
||||
|
||||
void OnDrawGizmos(){
|
||||
Encryptor.cipherMode = cipherMode;
|
||||
Encryptor.paddingMode = paddingMode;
|
||||
|
||||
encryptedText = Encryptor.encrypt(textToEncrypt);
|
||||
decryptedText = Encryptor.decrypt(textToDecrypt);
|
||||
|
||||
encryptedNumber = Encryptor.intToString(numberToEncrypt);
|
||||
decryptedNumber = Encryptor.stringToInt(numTextToDecrypt);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/EncryptionTester.cs.meta
Normal file
11
Assets/Scripts/EncryptionTester.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f08b67e0ea5507a42a56c6c80c24181c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
102
Assets/Scripts/Encryptor.cs
Normal file
102
Assets/Scripts/Encryptor.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Security.Cryptography;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System;
|
||||
|
||||
public static class Encryptor
|
||||
{
|
||||
private static string hash = "@419$";
|
||||
public static PaddingMode paddingMode = PaddingMode.PKCS7;
|
||||
public static CipherMode cipherMode = CipherMode.ECB;
|
||||
|
||||
private static string charPool = "AKFLDJAHSPIWUROCNMZX";
|
||||
|
||||
public static string encrypt(string input)
|
||||
{
|
||||
byte[] data = UTF8Encoding.UTF8.GetBytes(input);
|
||||
using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider())
|
||||
{
|
||||
byte[] key = md5.ComputeHash(UTF8Encoding.UTF8.GetBytes(hash));
|
||||
using (TripleDESCryptoServiceProvider tds = new TripleDESCryptoServiceProvider() { Key=key, Mode = cipherMode, Padding = paddingMode })
|
||||
{
|
||||
ICryptoTransform ict = tds.CreateEncryptor();
|
||||
byte[] results = ict.TransformFinalBlock(data, 0, data.Length);
|
||||
return Convert.ToBase64String(results, 0, results.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string decrypt(string input)
|
||||
{
|
||||
byte[] data = Convert.FromBase64String(input);
|
||||
using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider())
|
||||
{
|
||||
byte[] key = md5.ComputeHash(UTF8Encoding.UTF8.GetBytes(hash));
|
||||
using (TripleDESCryptoServiceProvider tds = new TripleDESCryptoServiceProvider() { Key = key, Mode = cipherMode, Padding = paddingMode })
|
||||
{
|
||||
ICryptoTransform ict = tds.CreateDecryptor();
|
||||
byte[] results = ict.TransformFinalBlock(data, 0, data.Length);
|
||||
return UTF8Encoding.UTF8.GetString(results);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string intToString(int input){
|
||||
char[] inputBytes = input.ToString().ToCharArray();
|
||||
string output = "";
|
||||
foreach(char c in inputBytes){
|
||||
output += charPool[int.Parse(c.ToString())];
|
||||
}
|
||||
int luckyNumber = GetLuckyNumber(input);
|
||||
|
||||
string lastLetter = charPool.ToCharArray()[luckyNumber].ToString();
|
||||
|
||||
return output+lastLetter;
|
||||
}
|
||||
|
||||
public static int stringToInt(string input){
|
||||
char[] inputBytes = input.Remove(input.Length-1).ToCharArray();
|
||||
string output = "";
|
||||
foreach(char c in inputBytes){
|
||||
for(int i=0; i < charPool.Length; i++){
|
||||
if(charPool.ToCharArray()[i] == c){
|
||||
output += i.ToString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char lastchar = input.ToCharArray()[input.Length-1];
|
||||
|
||||
int outputInt = int.Parse(output);
|
||||
char luckyChar = charPool.ToCharArray()[GetLuckyNumber(outputInt)];
|
||||
bool validated = luckyChar == lastchar;
|
||||
|
||||
|
||||
if(validated){
|
||||
return outputInt;
|
||||
}else{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static int GetLuckyNumber(int input){
|
||||
int luckyNumber=input;
|
||||
while(luckyNumber >= 10){
|
||||
int val = 0;
|
||||
for(int i=0; i < luckyNumber.ToString().Length; i++){
|
||||
val += int.Parse(luckyNumber.ToString().ToCharArray()[i].ToString());
|
||||
}
|
||||
|
||||
luckyNumber = val;
|
||||
}
|
||||
|
||||
return luckyNumber;
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/Scripts/Encryptor.cs.meta
Normal file
11
Assets/Scripts/Encryptor.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a8ea67314c0e25f43a9834b0be9797db
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -43,11 +43,14 @@ public class GameManager : MonoBehaviour
|
||||
public Text gameOverBestScoreTxt, gameOverTotalScoreTxt;
|
||||
public GameObject GameOverUI;
|
||||
public GameObject PauseMenuUI;
|
||||
public Button muteBtn;
|
||||
public Sprite muteIcon, unmuteIcon;
|
||||
public Animator HoleInOne;
|
||||
public int curHoleIndex;
|
||||
private static int adCounter = 0;
|
||||
void Start()
|
||||
{
|
||||
muteBtn.onClick.AddListener(OnMute);
|
||||
strokesTxtDefaultSize = StrokesTxt.transform.localScale;
|
||||
scoreTxtDefaultSize = ScoreTxt.transform.localScale;
|
||||
camTargetPos = ball.transform.position;
|
||||
@@ -232,6 +235,15 @@ public class GameManager : MonoBehaviour
|
||||
}
|
||||
ScoreTxt.text = Score.ToString();
|
||||
StrokesTxt.text = CurStrokes.ToString();
|
||||
|
||||
|
||||
muteBtn.transform.GetChild(0).GetComponent<Image>().sprite = AudioManager.isMute ? muteIcon : unmuteIcon;
|
||||
}
|
||||
|
||||
void OnMute(){
|
||||
AudioManager.ToggleMute();
|
||||
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
|
||||
@@ -271,6 +283,8 @@ public class GameManager : MonoBehaviour
|
||||
}else{
|
||||
LeanTween.scale(PauseMenuUI, Vector3.zero, 0.15f).setEaseOutCirc();
|
||||
}
|
||||
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -97,12 +97,19 @@ public class LevelGenerator : MonoBehaviour
|
||||
}
|
||||
|
||||
|
||||
float checker = 0;
|
||||
void Update()
|
||||
{
|
||||
if(GameManager.instance == null){return;}
|
||||
if(checker < 30){
|
||||
checker+=Time.deltaTime;
|
||||
}else{
|
||||
checker =0;
|
||||
|
||||
if(GameManager.instance.ball.position.x > lastOffset - 100){
|
||||
GenerateBlock();
|
||||
if(GameManager.instance.ball.position.x > lastOffset - 100){
|
||||
GenerateBlock();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ public class MainMenu : MonoBehaviour
|
||||
|
||||
public GameObject MainMenuPanel;
|
||||
public GameObject SettingsPanel;
|
||||
public GameObject LeaderboarPanel;
|
||||
public Transform LeaderboardItemsParent;
|
||||
public float transitionTime;
|
||||
public LeanTweenType transitionEffect;
|
||||
|
||||
@@ -26,12 +28,16 @@ public class MainMenu : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
defaultCenter = MainMenuPanel.transform.position;
|
||||
SettingsPanel.transform.position = MainMenuPanel.transform.position - new Vector3(3000,0);
|
||||
SettingsPanel.transform.position = MainMenuPanel.transform.position - new Vector3(10000,0);
|
||||
SettingsPanel.SetActive(true);
|
||||
LeaderboarPanel.SetActive(true);
|
||||
LeaderboarPanel.transform.position = MainMenuPanel.transform.position + new Vector3(10000,0);
|
||||
|
||||
muteBtn.onClick.AddListener(ToggleMute);
|
||||
copyBtn.onClick.AddListener(CopyId);
|
||||
signoutBtn.onClick.AddListener(SignOut);
|
||||
|
||||
DataManager.RefreshLeaderboard();
|
||||
}
|
||||
public void Leave(){
|
||||
Application.Quit();
|
||||
@@ -44,7 +50,7 @@ public class MainMenu : MonoBehaviour
|
||||
|
||||
|
||||
void Refresh(){
|
||||
txtUserId.text = DataManager.userData.id.ToString();
|
||||
txtUserId.text = Encryptor.intToString(DataManager.userData.id);
|
||||
if(AudioManager.isMute){
|
||||
muteBtn.transform.GetChild(0).GetComponent<Image>().sprite = muteIcon;
|
||||
}else{
|
||||
@@ -57,13 +63,20 @@ public class MainMenu : MonoBehaviour
|
||||
LeanTween.moveX(SettingsPanel, defaultCenter.x, transitionTime).setEase(transitionEffect);
|
||||
}
|
||||
|
||||
public void LeaderboarPage(){
|
||||
LeanTween.moveX(MainMenuPanel, -10000, transitionTime).setEase(transitionEffect);
|
||||
LeanTween.moveX(LeaderboarPanel, defaultCenter.x, transitionTime).setEase(transitionEffect);
|
||||
RefreshLeaderboard();
|
||||
}
|
||||
|
||||
public void MainPage(){
|
||||
LeanTween.moveX(MainMenuPanel, defaultCenter.x, transitionTime).setEase(transitionEffect);
|
||||
LeanTween.moveX(SettingsPanel, -10000, transitionTime).setEase(transitionEffect);
|
||||
LeanTween.moveX(LeaderboarPanel, 10000, transitionTime).setEase(transitionEffect);
|
||||
}
|
||||
|
||||
public void CopyId(){
|
||||
GUIUtility.systemCopyBuffer = DataManager.userData.id.ToString();
|
||||
GUIUtility.systemCopyBuffer = txtUserId.text;
|
||||
copyBtn.transform.Find("lbl").GetComponent<Text>().text = "Copied";
|
||||
}
|
||||
|
||||
@@ -72,6 +85,29 @@ public class MainMenu : MonoBehaviour
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public void Info(){
|
||||
MessageBox.ShowMessage(@"This is a game where you can relax while playing,
|
||||
Listen to a podcast or to music while playing this to get the best out of it!
|
||||
|
||||
Any feedback or suggestion can be directed to us via this email
|
||||
sewmina7@gmail.com","About");
|
||||
}
|
||||
|
||||
async void RefreshLeaderboard(){
|
||||
UpdateLeaderboardUI();
|
||||
await DataManager.RefreshLeaderboard();
|
||||
UpdateLeaderboardUI();
|
||||
}
|
||||
|
||||
void UpdateLeaderboardUI(){
|
||||
for(int i =0; i < DataManager.Leaderboard.Count; i++){
|
||||
LeaderboardItemsParent.GetChild(i).GetChild(0).GetComponent<Text>().text = $"{i+1}." + DataManager.Leaderboard[i].DisplayName;
|
||||
// LeaderboardItemsParent.GetChild(i).GetChild(0).GetComponent<Text>().text = $"{i+1}." + DataManager.Leaderboard[i].name;
|
||||
LeaderboardItemsParent.GetChild(i).GetChild(1).GetComponent<Text>().text = DataManager.Leaderboard[i].topScore.ToString();
|
||||
|
||||
LeaderboardItemsParent.GetChild(i).GetComponent<Image>().CrossFadeAlpha((DataManager.Leaderboard[i].name == DataManager.userData.username) ? 0.9f : 0,0.5f,true);
|
||||
}
|
||||
}
|
||||
|
||||
void SignOut(){
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ public class MessageBox : MonoBehaviour
|
||||
for(int i=0; i < message.Length; i++){
|
||||
messageTxt.text += message[i];
|
||||
|
||||
yield return new WaitForSeconds(0.02f);
|
||||
yield return new WaitForSeconds(0.01f);
|
||||
}
|
||||
closeButton.gameObject.SetActive(true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user