コード例 #1
0
ファイル: GameController.cs プロジェクト: Szyximus/Stars
    // start game

    /*
     *  Server only
     *  Called from ServerNetworkManager
     *  Starts new game or loads game from file
     */
    public void ServerStartNewGame(bool isNewGame)
    {
        Debug.Log("ServerStartNewGame");
        if (!isServer)
        {
            throw new Exception("ServerStartNewGame not a server, return");
        }

        string path = null;

        if (isNewGame)
        {
            path = gameApp.startMapsPath + gameApp.GetInputField("MapToLoad");
        }
        else
        {
            path = gameApp.savedGamesPath + gameApp.GetInputField("GameToLoad");
        }
        JObject newGameJson = gameApp.ReadJsonFile(path);

        List <GameApp.PlayerMenu> PlayerMenuList = gameApp.GetAllPlayersFromMenu();

        PlayersFromJsonAndMenu(newGameJson, PlayerMenuList, isNewGame);
        MapFromJson((JObject)newGameJson["map"], isNewGame);
        InfoFromJson((JObject)newGameJson["info"], isNewGame);

        // because "NextTurn" will increment
        currentPlayerIndex -= 1;
        NextTurn();
    }
コード例 #2
0
ファイル: ServerNetworkManager.cs プロジェクト: mmielus/Stars
    /*
     *  After "Create" button in "NewGameScene"
     *  Setup bind address and port, start server, change scene
     */
    public void SetupNewGame()
    {
        Debug.Log("SetupNewGame");
        isNewGame  = true;
        isLoadGame = false;

        try
        {
            this.serverBindAddress = gameApp.GetInputField("ServerAddress");
            this.serverBindToIP    = true;
            this.networkPort       = int.Parse(gameApp.GetInputField("ServerPort"));

            // uncomment for testing
            //this.serverBindAddress = "127.0.0.1";
            //this.networkPort = 7777;
            if (!this.StartServer())
            {
                throw new Exception("Starting server error!");
            }
            this.ServerChangeScene("GameScene");
        } catch (Exception e)
        {
            Debug.Log("SetupNewGame error: " + e.Message);
            errorInfoPanel.Show("SetupNewGame error: " + e.Message);
            return;
        }
    }
コード例 #3
0
    void Start()
    {
        Debug.Log("NewGameSceneInit");

        gameApp     = GameObject.Find("GameApp").GetComponent <GameApp>();
        levelLoader = GameObject.Find("LevelLoader").GetComponent <LevelLoader>();
        dynamicGrid = GameObject.Find("ListCanvas/ListPanel/ListGrid").GetComponent <RectTransform>();

        playersToAddToGame = new List <GameObject>();

        // get and parse map to load
        string  path       = gameApp.startMapsPath + gameApp.GetInputField("MapToLoad");
        JObject gameParsed = null;

        try
        {
            gameParsed = gameApp.ReadJsonFile(path);
        }
        catch (Exception e)
        {
            Debug.Log("NewGameSceneInit error: " + e.Message);
            Back();
        }

        if (gameParsed == null)
        {
            Debug.Log("NewGameSceneInit gameParsed is null");
            Back();
        }

        try
        {
            maxPlayers = (int)gameParsed["info"]["maxPlayers"];
        } catch (Exception e)
        {
            Debug.Log("NewGameSceneInit error: " + e.Message);
            Back();
        }
    }
コード例 #4
0
ファイル: LoadGameSceneInit.cs プロジェクト: mmielus/Stars
    void Start()
    {
        Debug.Log("LoadGameSceneInit");

        gameApp     = GameObject.Find("GameApp").GetComponent <GameApp>();
        levelLoader = GameObject.Find("LevelLoader").GetComponent <LevelLoader>();
        dynamicGrid = GameObject.Find("ListCanvas/ListPanel/ListGrid").GetComponent <RectTransform>();

        playersToAddToGame = new List <GameObject>();

        // gat and parse saved json file
        string  path       = gameApp.savedGamesPath + gameApp.GetInputField("GameToLoad");
        JObject gameParsed = null;

        try
        {
            gameParsed = gameApp.ReadJsonFile(path);
        }
        catch (Exception e)
        {
            Debug.Log("LoadGameSceneInit error: " + e.Message);
            Debug.Log(e.StackTrace);
            Back();
        }

        if (gameParsed == null)
        {
            Debug.Log("LoadGameSceneInit gameParsed is null");
            Back();
        }

        JArray playersJson;
        int    maxPlayers;

        try
        {
            playersJson = (JArray)gameParsed["players"];
            maxPlayers  = (int)gameParsed["info"]["maxPlayers"];
        }
        catch (Exception e)
        {
            Debug.Log("LoadGameSceneInit error: " + e.Message);
            Back();
            return;
        }

        if (maxPlayers != playersJson.Count)
        {
            Debug.Log("LoadGameSceneInit error: maxPlayers != playersJson.Count");
            Back();
            return;
        }

        // players' names and races shouldn't change between sessions
        foreach (JObject playerJson in playersJson)
        {
            GameObject newPlayer = Instantiate(gameApp.PlayerMenuPrefab, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
            newPlayer.transform.SetParent(dynamicGrid.transform, false);
            EventTrigger       trigger = newPlayer.GetComponentInChildren <Toggle>().gameObject.AddComponent <EventTrigger>();
            EventTrigger.Entry entry   = new EventTrigger.Entry();
            entry.eventID = EventTriggerType.PointerExit;
            entry.callback.AddListener((eventData) => {
                GameObject.Find("EventSystem").GetComponent <EventSystem>().SetSelectedGameObject(GameObject.Find("EventSystem"));
            });
            trigger.triggers.Add(entry);
            newPlayer.transform.Find("PlayerNameInput").GetComponent <InputField>().text    = (string)playerJson["name"];
            newPlayer.transform.Find("PlayerNameInput").GetComponent <InputField>().enabled = false;

            //newPlayer.transform.Find("PlayerRaceInput").GetComponent<InputField>().text = (string)playerJson["playerMain"]["race"];
            //newPlayer.transform.Find("PlayerRaceInput").GetComponent<InputField>().enabled = false;
            playersToAddToGame.Add(newPlayer);
        }
    }