mirror of
				https://github.com/smyalygames/monopoly.git
				synced 2025-10-30 03:17:39 +01:00 
			
		
		
		
	Leaderboard has been added
This commit is contained in:
		
							parent
							
								
									c1d5de61a8
								
							
						
					
					
						commit
						6793b33533
					
				| @ -1,36 +0,0 @@ | ||||
| CREATE TABLE properties ( | ||||
| 	property_id int(2) AUTO_INCREMENT PRIMARY KEY NOT NULL, #Easy way to identify with code | ||||
|     property_name TINYTEXT NOT NULL, #The name of the property | ||||
|     property_group TINYTEXT NOT NULL, #The group that the property is | ||||
|     property_value int(3), #How much it costs to buy the property | ||||
|     property_cost int(3), #How much it is to buy a house/hotel | ||||
|     property_rent int(2), #How much it costs to rent | ||||
|     property_house1 int(3), #How much it costs with 1 house | ||||
|     property_house2 int(3), #How much it costs with 2 houses | ||||
|     property_house3 int(4), #How much it costs with 3 houses | ||||
|     property_house4 int(4), #How much it costs with 4 houses | ||||
|     property_hotel int(4) #How much it costs with a hotel | ||||
| ); | ||||
| 
 | ||||
| property_name,property_group,property_value,property_cost,property_rent,property_house1,property_house2,property_house3,property_house4,property_hotel | ||||
| 
 | ||||
| CREATE TABLE  users ( | ||||
| 	user_id int(11) AUTO_INCREMENT PRIMARY KEY NOT NULL, #This is a uniquie ID for the user | ||||
| 	user_uid TINYTEXT NOT NULL, #This is the username for the user | ||||
| 	user_email TINYTEXT NOT NULL, #This is the email for the user | ||||
| 	user_pwd LONGTEXT NOT NULL #This is where the hashed password would be stored | ||||
| ); | ||||
| 
 | ||||
| CREATE TABLE pwdreset ( | ||||
| 	pwd_id int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL, #This is a unique identifier | ||||
|     pwd_email TEXT NOT NULL, #The email used to change the password for | ||||
|     pwd_selector TEXT NOT NULL, #Where the selector is stored in plaintext | ||||
|     pwd_token LONGTEXT NOT NULL, #Where the hashed token is stored | ||||
|     pwd_expires TEXT NOT NULL #When the token expires | ||||
| ); | ||||
| 
 | ||||
| CREATE TABLE money_spent( | ||||
|     user_id int(11) PRIMARY KEY NOT NULL, | ||||
|     user_spent int(11) NOT NULL, | ||||
|     FOREIGN KEY (user_id) REFERENCES users(user_id) | ||||
| ); | ||||
| @ -5933,10 +5933,10 @@ RectTransform: | ||||
|   m_Father: {fileID: 1922023088} | ||||
|   m_RootOrder: 7 | ||||
|   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} | ||||
|   m_AnchorMin: {x: 0.5, y: 0.5} | ||||
|   m_AnchorMax: {x: 0.5, y: 0.5} | ||||
|   m_AnchoredPosition: {x: 0, y: 153.38} | ||||
|   m_SizeDelta: {x: 200, y: 50} | ||||
|   m_AnchorMin: {x: 0, y: 0.5} | ||||
|   m_AnchorMax: {x: 1, y: 0.5} | ||||
|   m_AnchoredPosition: {x: 227, y: 161.7} | ||||
|   m_SizeDelta: {x: -454, y: 66.54178} | ||||
|   m_Pivot: {x: 0.5, y: 0.5} | ||||
| --- !u!114 &1922298509 | ||||
| MonoBehaviour: | ||||
| @ -5960,8 +5960,8 @@ MonoBehaviour: | ||||
|       m_Calls: [] | ||||
|   m_text: 'Error:' | ||||
|   m_isRightToLeft: 0 | ||||
|   m_fontAsset: {fileID: 11400000, guid: 2e498d1c8094910479dc3e1b768306a4, type: 2} | ||||
|   m_sharedMaterial: {fileID: 2180264, guid: 2e498d1c8094910479dc3e1b768306a4, type: 2} | ||||
|   m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} | ||||
|   m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} | ||||
|   m_fontSharedMaterials: [] | ||||
|   m_fontMaterial: {fileID: 0} | ||||
|   m_fontMaterials: [] | ||||
| @ -6024,7 +6024,7 @@ MonoBehaviour: | ||||
|   m_margin: {x: 0, y: 0, z: 0, w: 0} | ||||
|   m_isUsingLegacyAnimationComponent: 0 | ||||
|   m_isVolumetricText: 0 | ||||
|   m_hasFontAssetChanged: 0 | ||||
|   m_hasFontAssetChanged: 1 | ||||
|   m_baseMaterial: {fileID: 0} | ||||
|   m_maskOffset: {x: 0, y: 0, z: 0, w: 0} | ||||
| --- !u!222 &1922298510 | ||||
|  | ||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										62
									
								
								Assets/Scripts/menu/LeaderboardHandler.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								Assets/Scripts/menu/LeaderboardHandler.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,62 @@ | ||||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using UnityEngine; | ||||
| using UnityEngine.UI; | ||||
| using UnityEngine.Networking; | ||||
| using TMPro; | ||||
| using Newtonsoft.Json; | ||||
| 
 | ||||
| class LeaderboardInformation | ||||
| { | ||||
|     public string user_username; | ||||
|     public int user_plays; | ||||
| } | ||||
| 
 | ||||
| public class LeaderboardHandler : MonoBehaviour | ||||
| { | ||||
| 
 | ||||
|     public TextMeshProUGUI Leaderboard; | ||||
|     public Button LeaderboardMenuButton; | ||||
| 
 | ||||
|     private List<LeaderboardInformation> players; | ||||
|      | ||||
|     // Start is called before the first frame update | ||||
|     void Start() | ||||
|     { | ||||
|         LeaderboardMenuButton.onClick.AddListener(delegate | ||||
|         { | ||||
|             StartCoroutine(GetLeaderboard()); | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     private void ParseLeaderboardInformation() | ||||
|     { | ||||
|         Debug.Log("running"); | ||||
|         string parsedString = ""; | ||||
|          | ||||
|         for (int i = 0; i < players.Count; i++) | ||||
|         { | ||||
|             parsedString += $"{i+1}. {players[i].user_username} played {players[i].user_plays} times\n"; | ||||
|         } | ||||
| 
 | ||||
|         Leaderboard.text = parsedString; | ||||
|     } | ||||
|      | ||||
|     IEnumerator GetLeaderboard() | ||||
|     { | ||||
|         UnityWebRequest www = UnityWebRequest.Get(Domain.subDomain("includes/get-leaderboard.inc.php")); | ||||
|         yield return www.SendWebRequest(); | ||||
| 
 | ||||
|         if (www.isNetworkError || www.isHttpError) | ||||
|         { | ||||
|             Debug.Log(www.error); | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|             // Show results as text | ||||
|             string json = www.downloadHandler.text; | ||||
|             players = JsonConvert.DeserializeObject<List<LeaderboardInformation>>(json); | ||||
|             ParseLeaderboardInformation(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										11
									
								
								Assets/Scripts/menu/LeaderboardHandler.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Assets/Scripts/menu/LeaderboardHandler.cs.meta
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,11 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: 69ea8de79eecb2641833a267c141affe | ||||
| MonoImporter: | ||||
|   externalObjects: {} | ||||
|   serializedVersion: 2 | ||||
|   defaultReferences: [] | ||||
|   executionOrder: 0 | ||||
|   icon: {instanceID: 0} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
|   assetBundleVariant:  | ||||
| @ -1,6 +1,8 @@ | ||||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using UnityEngine; | ||||
| using UnityEngine.SceneManagement; | ||||
| using UnityEngine.Networking; | ||||
| using UnityEngine.UI; | ||||
| 
 | ||||
| public class LevelLoader : MonoBehaviour | ||||
| @ -11,12 +13,33 @@ public class LevelLoader : MonoBehaviour | ||||
|      | ||||
|     public void LoadLevel (string sceneName) | ||||
| 	{ | ||||
|         StartCoroutine(LoadAsynchronously(sceneName)); //Starts the LoadAsynchronously function | ||||
| 		StartCoroutine(UpdateTable()); //Starts the LoadAsynchronously function | ||||
| 		StartCoroutine(LoadAsynchronously(sceneName)); //Starts the LoadAsynchronously function | ||||
| 	} | ||||
| 
 | ||||
|     IEnumerator UpdateTable() | ||||
|     { | ||||
| 	    List<IMultipartFormSection> formData = new List<IMultipartFormSection>(); | ||||
| 	    //POST Data | ||||
| 	    formData.Add(new MultipartFormDataSection("id", UserManager.userID.ToString())); //For the username. | ||||
| 
 | ||||
| 	    UnityWebRequest www = UnityWebRequest.Post(Domain.subDomain("includes/updateplays.inc.php"), formData); //This initiates the post request. | ||||
| 
 | ||||
| 	    yield return www.SendWebRequest(); //This sends the post request. | ||||
| 
 | ||||
| 	    if (www.isNetworkError || www.isHttpError) //This checks for an error with the server. | ||||
| 	    { | ||||
| 		    Debug.Log(www.error); //This prints the error. | ||||
| 	    } | ||||
| 	    else | ||||
| 	    { | ||||
| 		    Debug.Log(www.downloadHandler.text); //This sends the error code or if it worked on the server side. | ||||
| 	    } | ||||
|     } | ||||
|      | ||||
|     IEnumerator LoadAsynchronously (string sceneName) | ||||
| 	{ | ||||
|         AsyncOperation operation = SceneManager.LoadSceneAsync(sceneName); //Loads the monopoly board. | ||||
| 		AsyncOperation operation = SceneManager.LoadSceneAsync(sceneName); //Loads the monopoly board. | ||||
| 
 | ||||
|         loadingScreen.SetActive(true); //Shows the loading screen. | ||||
| 
 | ||||
|  | ||||
| @ -1,9 +1,6 @@ | ||||
| using Newtonsoft.Json; | ||||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using System.Collections; | ||||
| using UnityEngine; | ||||
| using UnityEngine.Networking; | ||||
| using TMPro; | ||||
| using UnityEngine.UI; | ||||
| 
 | ||||
| public class MainMenu : MonoBehaviour | ||||
| @ -54,7 +51,7 @@ public class MainMenu : MonoBehaviour | ||||
| 		Debug.Log("QUIT!"); | ||||
| 		Application.Quit(); | ||||
| 	} | ||||
| 	 | ||||
| 
 | ||||
| 	IEnumerator GetProperties() | ||||
| 	{ | ||||
| 		UnityWebRequest www = UnityWebRequest.Get(Domain.subDomain("includes/get-properties.inc.php")); | ||||
|  | ||||
| @ -1,10 +1,7 @@ | ||||
| using System; | ||||
| using System.Collections; | ||||
| using System.Collections.Generic; | ||||
| using UnityEngine; | ||||
| using Newtonsoft.Json; | ||||
| using UnityEditor; | ||||
| using UnityEngine.Networking; | ||||
| 
 | ||||
| 
 | ||||
| public class Property | ||||
| @ -780,33 +777,8 @@ public class Player | ||||
| 	public void Pay(float fee) //This function makes the user pay. | ||||
| 	{ | ||||
| 		money -= Convert.ToInt32(fee); //This deducts the money from the user's balance. | ||||
| 		if (fee > 0) | ||||
| 		{ | ||||
| 			StartCoroutine(UpdateTable); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	IEnumerable UpdateTable() | ||||
| 	{ | ||||
| 		List<IMultipartFormSection> formData = new List<IMultipartFormSection>(); | ||||
| 		//POST Data | ||||
| 		formData.Add(new MultipartFormDataSection("id", UserManager.userID.ToString())); //For the username. | ||||
| 		formData.Add(new MultipartFormDataSection("money", "200")); //For the email. | ||||
| 
 | ||||
| 		UnityWebRequest www = UnityWebRequest.Post(Domain.subDomain("includes/updatespent.inc.php"), formData); //This initiates the post request. | ||||
|          | ||||
| 		yield return www.SendWebRequest(); //This sends the post request. | ||||
| 
 | ||||
| 		if (www.isNetworkError || www.isHttpError) //This checks for an error with the server. | ||||
| 		{ | ||||
| 			Debug.Log(www.error); //This prints the error. | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			Debug.Log(www.downloadHandler.text); //This sends the error code or if it worked on the server side. | ||||
| 		} | ||||
| 	} | ||||
| 	 | ||||
| 	public bool Mortgage(int currentProperty) //This is used for mortgaging a property. | ||||
| 	{ | ||||
| 		if (currentProperty == 50) //Checks if there was an error - 50 is an error code. | ||||
|  | ||||
							
								
								
									
										45
									
								
								Assets/sql.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								Assets/sql.sql
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,45 @@ | ||||
| CREATE TABLE properties ( | ||||
| 	property_id int(2) AUTO_INCREMENT PRIMARY KEY NOT NULL, #Easy way to identify with code | ||||
| 	property_name TINYTEXT NOT NULL, #The name of the property | ||||
| 	property_group TINYTEXT NOT NULL, #The group that the property is | ||||
| 	property_value int(3), #How much it costs to buy the property | ||||
| 	property_cost int(3), #How much it is to buy a house/hotel | ||||
| 	property_rent int(2), #How much it costs to rent | ||||
| 	property_house1 int(3), #How much it costs with 1 house | ||||
| 	property_house2 int(3), #How much it costs with 2 houses | ||||
| 	property_house3 int(4), #How much it costs with 3 houses | ||||
| 	property_house4 int(4), #How much it costs with 4 houses | ||||
| 	property_hotel int(4) #How much it costs with a hotel | ||||
| ); | ||||
| 
 | ||||
| CREATE TABLE users ( | ||||
| 	user_id int(11) AUTO_INCREMENT PRIMARY KEY NOT NULL, #This is a uniquie ID for the user | ||||
| 	user_uid TINYTEXT NOT NULL, #This is the username for the user | ||||
| 	user_email TINYTEXT NOT NULL, #This is the email for the user | ||||
| 	user_pwd LONGTEXT NOT NULL #This is where the hashed password would be stored | ||||
| ); | ||||
| 
 | ||||
| CREATE TABLE password ( | ||||
| 	pwd_id int(11) PRIMARY KEY AUTO_INCREMENT NOT NULL, #This is a unique identifier | ||||
| 	user_id int(11) NOT NULL, #The email used to change the password for | ||||
| 	pwd_selector TEXT NOT NULL, #Where the selector is stored in plaintext | ||||
| 	pwd_token LONGTEXT NOT NULL, #Where the hashed token is stored | ||||
| 	pwd_expires TEXT NOT NULL #When the token expires | ||||
| 	FOREIGN KEY (user_id) REFERENCES users(user_id) #This links the user_id to the users table | ||||
| ); | ||||
| 
 | ||||
| CREATE TABLE plays( | ||||
| 	user_id int(11) PRIMARY KEY NOT NULL, #This is the unique player | ||||
| 	user_plays int(11) NOT NULL, #This is how many times the player has played the game | ||||
| 	FOREIGN KEY (user_id) REFERENCES users(user_id) #This links the user_id to the users table | ||||
| ); | ||||
| 
 | ||||
| #Not in use | ||||
| 
 | ||||
| property_name,property_group,property_value,property_cost,property_rent,property_house1,property_house2,property_house3,property_house4,property_hotel | ||||
| 
 | ||||
| CREATE TABLE money_spent( | ||||
|     user_id int(11) PRIMARY KEY NOT NULL, | ||||
|     user_spent int(11) NOT NULL, | ||||
|     FOREIGN KEY (user_id) REFERENCES users(user_id) | ||||
| ); | ||||
| @ -1,6 +1,6 @@ | ||||
| fileFormatVersion: 2 | ||||
| guid: 4e2ec0654b6aa5c4990ff0ee457f2409 | ||||
| TextScriptImporter: | ||||
| guid: 0910983ed86451f43af20cee848bb834 | ||||
| DefaultImporter: | ||||
|   externalObjects: {} | ||||
|   userData:  | ||||
|   assetBundleName:  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Anthony Berg
						Anthony Berg