Beispiel #1
0
        public void SetOnlineGame(string viewerId, BGA.TableData table, JSONObject bgaData)
        {
            Logger.Instance.Log("LOG", "NWInterface: SetOnlineGame()");
            try
            {
                Clear();

                BGA.BoardData board = new BGA.BoardData(viewerId, table);

                string bgaDataDebugString = JSONTools.FormatJsonDisplay(bgaData);
                foreach (string chunk in splitInLineChunks(bgaDataDebugString, 500))
                {
                    Logger.Instance.Log("DETAIL", chunk);
                }

                GameStateReader gameStateReader = new GameStateReader(bgaData, board);
                if (!gameStateReader.IsValid)
                {
                    Logger.Instance.Log("ERROR", "invalid gamestate received from server");
                }
                gamestate = gameStateReader.convertToGameState();

                gameData.SetOnlineGame(board, gameStateReader.initMoveId, gameStateReader.initPacketId);
            }
            catch (System.Exception e)
            {
                Logger.Instance.Log("ERROR", e.ToString());
                BGA.BoardData board = new BGA.BoardData(viewerId, table);
                gamestate = null;
                gameData.SetOnlineGame(board, 0, 0);
            }
        }
Beispiel #2
0
            private ActionType EvaluateAction(int action)
            {
                Debug.Assert(IsActive);
                if (action < 0 || action > 1)
                {
                    return(ActionType.NONE);
                }

                ActionType[] actions = { ActionType.NONE, ActionType.NONE };

                if (_selectedTable == "") // no table selected
                {
                    actions[1] = ActionType.CREATE;
                }
                else
                {
                    BGA.TableData table = _tableList[_selectedTable];
                    switch (table.playerCount)
                    {
                    case 2:
                        if (table.HasPlayer(Http.Instance.BgaUserId))
                        {
                            actions[0] = ActionType.PLAY;
                            actions[1] = ActionType.QUIT;
                        }
                        else
                        {
                            actions[1] = ActionType.WATCH;
                        }
                        break;

                    case 1:
                        if (table.HasPlayer(Http.Instance.BgaUserId))
                        {
                            actions[1] = ActionType.QUIT;
                        }
                        else
                        {
                            actions[1] = ActionType.JOIN;
                        }
                        break;

                    case 0:
                    default:
                        break;
                    }
                }

                return(actions[action]);
            }
Beispiel #3
0
        private void Reload()
        {
            string selectedId = GetSelectedGameId();

            Logger.Instance.Log("DETAIL", "previously selected id: " + selectedId);
            OnGameSelected(-1);

            for (int i = 0; i < _buttonList.Count; ++i)
            {
                GameObject.Destroy(_buttonList[i]);
            }
            _buttonList.Clear();
            _change     = false;
            _nextChange = DateTime.Now + _refreshTimeSpan;

            BGA.TableListData tables = Http.Instance.Lobby.Tables;
            _keys = tables.GetSortedKeys();

            GenerateDefaultLines(tables.Count);

            for (int i = 0; i < tables.Count; ++i)
            {
                string        id   = _keys[i];
                BGA.TableData data = tables[id];

                string players = "";
                if (data.player1 != null)
                {
                    players += data.player1.fullname + "(" + data.player1.rank + ")";
                }
                if (data.player2 != null)
                {
                    players += " - " + data.player2.fullname + "(" + data.player2.rank + ")";
                }

                string status = "";
                if (data.isOpen && data.playerCount == 1)
                {
                    if (data.HasPlayer(Http.Instance.BgaUserId))
                    {
                        status = "En attente";
                    }
                    else
                    {
                        status = "Rejoindre";
                    }
                }
                else if (data.playerCount == 2)
                {
                    if (data.HasPlayer(Http.Instance.BgaUserId))
                    {
                        status = "Reprendre";
                    }
                    else
                    {
                        status = "Observer";
                    }
                }
                else
                {
                    status = "Invalide";
                }

                GameObject line = _buttonList[i];
                line.transform.FindChild("Joueurs").gameObject.GetComponent <Text>().text = players;
                line.transform.FindChild("Etat").gameObject.GetComponent <Text>().text    = status;

                Logger.Instance.Log("DETAIL", "compare ids " + id + " and " + selectedId);
                if (id == selectedId)
                {
                    Logger.Instance.Log("DETAIL", "newly selected id: " + selectedId);
                    OnGameSelected(i);
                }
            }
        }