Advertisement
Carlotronics

Untitled

Mar 14th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.83 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using UnityEngine.SceneManagement;
  4. using Random = System.Random;
  5.  
  6. public class Game : MonoBehaviour
  7. {
  8.     public RequestToServer rts;
  9.     public MapGenerator mg;
  10.     public string mapUID;
  11.  
  12.     public int seed;
  13.     public Vector3[] vector3;
  14.     public int gameEnd;
  15.  
  16.     public static Game g;
  17.  
  18.     public MapGenMode mapGenMode;
  19.  
  20.     void Start()
  21.     {
  22.         rts = gameObject.AddComponent<RequestToServer>();
  23.     }
  24.  
  25.     void Update()
  26.     {
  27.         if (rts.response != null)
  28.         {
  29.             rts.response = null;
  30.             // GET MAP_UID
  31.             Dictionary<string, string> mapInfo = new Dictionary<string, string>();
  32.             mapInfo = Json.DeserializeIntoString(rts.response);
  33.             MapGenerator.uid = mapInfo["map_uid"];
  34.         }
  35.     }
  36.    
  37.     /*WARNING: THE FOLLOWING FUNCTIONS ARE ONLY TO BE CALLED BY MAPGENERATOR,
  38.       IF YOU WANT TO USE THEM, SET MAPGENMODE TO THE CORRESPONDING VALUE AND SWITCH TO THE MAP SCENE*/
  39.     public void StartGame()
  40.     {      
  41.         rts = gameObject.AddComponent<RequestToServer>();
  42.         mg = FindObjectOfType<MapGenerator>();
  43.         mg.seed = new Random().Next(1,100);
  44.         mg.GenerateMap();
  45.         mg.GetSpawnablePoints();
  46.         mg.AddFlagCoords(100);
  47.        
  48.         Dictionary<string,string> shitToSend = new Dictionary<string, string>();
  49.         shitToSend.Add("token", Login.token);
  50.         shitToSend.Add("seed", mg.seed.ToString());
  51.         shitToSend.Add("Vector3", Json.SerializeVector3(mg.flagCoords.ToArray()));
  52.         Debug.Log("ready to send:" + Json.SerializeVector3(mg.flagCoords.ToArray()));
  53.        
  54.         StartCoroutine(rts.PostRequest("https://doe:doe@game.strategydivision.fr/map/create_map.php", shitToSend));
  55.     }
  56. }
  57.  
  58. public enum MapGenMode
  59. {
  60.     Create, Join
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement