Ejemplo n.º 1
0
        private string GetVal()
        {
            string val = PREFS.getPrefString(_input.name);

            Debug.Log("Read Value of [" + _input.name + "] as:" + val);
            return(val);
        }
Ejemplo n.º 2
0
        // Use this for initialization
        private void Start()
        {
            //needed to make this a singleton
            Instance = this;

            //needed to preserve game objects between scenes
            DontDestroyOnLoad(gameObject);
            GameManager.Instance.goDontDestroyList.Add(gameObject);
            Debug.Log("Added PREFS at position:" + GameManager.Instance.goDontDestroyList.Count +
                      " to donotdestroylist");
        }
Ejemplo n.º 3
0
        //Reading messages from the Server
        private void OnIncomingData(string data)
        {
            var x = 0;
            var z = 0;

            Debug.Log("Client Receiving: " + data);
            int howManyPlaying = 0;
            int howManyTeams   = 0;
            int howManyCallers = 0;

            int sizeOfXDim = 0;
            int sizeOfYDim = 0;
            var cardID     = "";

            //Use these for temporary messages
            Game        gEventGame     = new Game();
            GameMessage gMessagePlayer = new GameMessage();

            //TODO - remove this when all messaging is done via XML
            if (!data[0].Equals('<'))
            {
                var aData = data.Split('|');
                switch (aData[0])
                {
                case "SMOV":
//                        x = int.Parse(aData[2]);
//                        z = int.Parse(aData[3]);
                    cardID = aData[2];
                    if (aData[4] == "1")
                    {
//                          GameBoard.Instance.TryGameboardMove(x, z, cardID);
                        GameBoard.Instance.TryGameboardMove(cardID);
                    }
                    else
                    {
                        Debug.Log("Invalid Move attempted by " + aData[1]);
                    }
                    break;

                case "SHAN":
                    cardID = aData[2];
                    if (aData[4] == "1")
                    {
                        GameBoard.Instance.TryHandMove(cardID);
                    }
                    else
                    {
                        Debug.Log("Invalid Move attempted by " + aData[1]);
                    }
                    break;

                case "SDIC":
                    GameBoard.Instance.isRedTurn  = aData[1] == "0" ? false: true;
                    GameBoard.Instance.isRedStart = aData[1] == "0" ? false: true;

                    var wData = aData[2].Split(',');
                    GameBoard.Instance.words = wData;

                    var pData = aData[3].Split(',');
                    GameBoard.Instance.populate = pData;

                    var iData = aData[4].Split(',');
                    GameBoard.Instance.cardids = iData;

                    GameBoard.Instance.GeneratePlayerGameboard();

                    GetGameCardDeck(CS.CREATE);
                    break;

                case "SKEY":
                {
                    switch (aData[1])
                    {
                    case "R":
                        //need to get rid of the local gameCard copy if we receive a restart. When the scene loads we need to make sure we load a new set of cards
                        gcd.gameCards.RemoveAll(gameCards => gameCards.cardID != "");
                        GameBoard.Instance.ResartGame();
                        break;

                    case "P":
                        GameBoard.Instance.SetCamera(aData[1]);
                        break;
                        ;

                    case "C":
                        GameBoard.Instance.SetCamera(aData[1]);
                        break;
                    }
                }
                break;

                case "SGFU":
                    //Forced client update of Gameboard from server
                    GameBoard.Instance.isRedTurn = aData[1] == "False" ? false: true;

                    wData = aData[2].Split(',');
                    GameBoard.Instance.words = wData;

                    pData = aData[3].Split(',');
                    GameBoard.Instance.populate = pData;

                    var xData = aData[4].Split(',').Select(s => Int32.Parse(s)).ToArray();
                    GameBoard.Instance.xPos = xData;

                    var zData = aData[5].Split(',').Select(s => Int32.Parse(s)).ToArray();;
                    GameBoard.Instance.zPos = zData;

                    var rData = aData[6].Split(',');
                    GameBoard.Instance.reveal = rData;

                    GameBoard.Instance.UpdatePlayerGameboard();
                    break;
                }
            }
            //Must be XML
            //This section is harccoded for only dealing with decks, it is the first use of XML messaging and eventually must be removed
            else if (1 == 0)
            {
                //TODO - Assumes that the xml message is one to populate a game card deck
                gcdTemp = GameHandDeck.LoadFromText(data);
                if (!gcdTemp.SaveToText().Equals(gcd.SaveToText()))
                {
                    gcd = GameHandDeck.LoadFromText(data);
                    //TODO - Assumes only a red and blue deck
                    gcdRed  = new GameHandDeck();
                    gcdBlue = new GameHandDeck();
                    for (var cnt = 0; cnt < gcd.gameCards.Count; cnt++)
                    {
                        var gc = gcd.gameCards[cnt];
                        if (gc.cardSuit == CS.RED_TEAM)
                        {
                            gcdRed.gameCards.Add(gc);
                        }
                        else if (gc.cardSuit == CS.BLUE_TEAM)
                        {
                            gcdBlue.gameCards.Add(gc);
                        }
                    }

                    // If there are differences render the deck
                    GameBoard.Instance.GeneratePlayerHand();
                }
            }
            else if (1 == 1)
            {
                GameMessage gIncomingMessage = new GameMessage();
                GameMessage gOutgoingMessage = new GameMessage();
                gIncomingMessage = GameMessage.LoadFromText(data);
                switch (gIncomingMessage.name)
                {
                case CS.MESSAGE_SWHO:
                    //This message sets the ClientID from the server
                    gClientPlayer.id = gIncomingMessage.receiver.id;

                    foreach (var cntT in gIncomingMessage.gameTeams)
                    {
                        var fPlayer = cntT.teamPlayers.Where(player => player.id == gClientPlayer.id);
                        if (fPlayer.FirstOrDefault() == null)
                        {
                            gClientTeam.id = cntT.id;
                        }
                        gClientTeam.name = cntT.name;
                    }

                    //Hosts will use their preferences in order to determine the game parameters e.g. number of players, board dimentions
                    //Note that cannot write the number of participants that is used to decide to start the game
                    //this must be initiated from the server sending a message to the client

                    if (gClientPlayer.isHost)
                    {
                        howManyPlaying = PREFS.getPrefInt("MinPlayers");
                        howManyTeams   = PREFS.getPrefInt("NumTeams");
                        howManyCallers = PREFS.getPrefInt("NumCallers");
                        sizeOfXDim     = PREFS.getPrefInt("GridXDim");
                        sizeOfYDim     = PREFS.getPrefInt("GridZDim");
                    }
                    else
                    {
                        howManyPlaying = 0;
                        howManyTeams   = 0;
                        howManyCallers = 0;
                        sizeOfXDim     = 0;
                        sizeOfYDim     = 0;
                    }
                    //Respond the ask for more details about the player
                    //Build the message
                    //Message Header
                    gOutgoingMessage.id   = CS.MESSAGE_CWHO;
                    gOutgoingMessage.name = gOutgoingMessage.id;
                    gOutgoingMessage.type = CS.MESSAGE_REPLY;

                    //Message Sender
                    gOutgoingMessage.sender.id   = gClientPlayer.id;
                    gOutgoingMessage.sender.name = gClientPlayer.name;

                    //Message Details
                    gOutgoingMessage.gameParameters.howManyPlaying = howManyPlaying;
                    gOutgoingMessage.gameParameters.howManyTeams   = howManyTeams;
                    gOutgoingMessage.gameParameters.howManyCallers = howManyCallers;

                    gOutgoingMessage.gameParameters.sizeOfXDim = sizeOfXDim;
                    gOutgoingMessage.gameParameters.sizeOfYDim = sizeOfYDim;

                    gOutgoingMessage.gameTeams.Clear();
                    gOutgoingMessage.gameTeams.Add(gClientTeam);

                    Send(gOutgoingMessage);
                    break;

                case CS.MESSAGE_SCNN:
                    gClientGame.gameParameters = gIncomingMessage.gameParameters;
                    gClientGame.gameTeams      = gIncomingMessage.gameTeams;

                    int cntIncomingPlayers = 0;
                    foreach (var t in gIncomingMessage.gameTeams)
                    {
                        foreach (var p in t.teamPlayers)
                        {
                            cntIncomingPlayers++;
                        }
                    }

                    if ((gClientGame.gameParameters.howManyPlaying == cntIncomingPlayers) && (cntIncomingPlayers != 0))
                    {
                        GameManager.Instance.gridXDim.text = gClientGame.gameParameters.sizeOfXDim.ToString();
                        GameManager.Instance.gridZDim.text = gClientGame.gameParameters.sizeOfYDim.ToString();
                        GameManager.Instance.OpenLobby();
                    }
                    break;

                case CS.MESSAGE_SBEG:
                    //Update Game Data
                    gClientGame.gameParameters = gIncomingMessage.gameParameters;
                    gClientGame.gameTeams      = gIncomingMessage.gameTeams;

                    //Update Client Player Data
                    gClientGame.FindPlayer(gClientPlayer.id, ref gClientPlayer);

                    //Update Client Team Data
                    gClientGame.FindPlayerTeam(gClientPlayer.id, ref gClientTeam);

                    //Start the Game
                    GameManager.Instance.StartGame();
                    break;
                }
            }
        }
Ejemplo n.º 4
0
 private void SetVal(string arg0)
 {
     Debug.Log("Captured Value of [" + _input.name + "] as:" + arg0);
     PREFS.SetPref(_input.name, arg0);
 }