Exemplo n.º 1
0
        public void UpdateStatus(MsgLobbyStatus status)
        {
            if (lobby_id != status.GameID)
            {
                return;
            }

            string[] dir_string = new string[]
            {
                "North",
                "East",
                "South",
                "West"
            };

            Button[] buttons = new Button[]
            {
                BtnNorth,
                BtnEast,
                BtnSouth,
                BtnWest
            };

            bool       player_is_in = false;
            GamePlayer player       = Network.GameComms.GetPlayer();

            for (int i = 0; i < Math.Min(4, status.Players.Count); ++i)
            {
                if (player.Equals(status.Players[i]))
                {
                    player_is_in = true;
                }
            }

            for (int i = 0; i < Math.Min(4, status.Players.Count); ++i)
            {
                if (status.Players[i] == null)
                {
                    buttons[i].Text    = dir_string[i];
                    buttons[i].Enabled = !player_is_in;
                }
                else
                {
                    buttons[i].Enabled = false;
                    buttons[i].Text    = string.Format(
                        "{0:} {1:}",
                        dir_string[i].Substring(0, 1),
                        status.Players[i].CapitalizedName().Substring(0, Math.Min(3, status.Players[i].CapitalizedName().Length)));
                }
            }

            BtnLeave.Enabled = player_is_in;
        }
Exemplo n.º 2
0
        private void tmrServerTick_Tick(object sender, EventArgs e)
        {
            // Read input messages
            int read_msg = 0;

            while (read_msg < 10)
            {
                MsgBase msg = Network.GameComms.ReceiveMessage();

                if (msg == null)
                {
                    break;
                }

                Console.WriteLine("Received " + msg.GetType().ToString());

                if (msg is MsgGameStatus)
                {
                    MsgGameStatus status = (MsgGameStatus)msg;

                    if (game_window != null)
                    {
                        game_window.UpdateGame(status);
                    }
                }
                else if (msg is MsgGameList)
                {
                    MsgGameList game_list = (MsgGameList)msg;

                    ListGames.Items.Clear();
                    foreach (MsgGameList.ListItem i in game_list.Games)
                    {
                        CommonEntry  gi  = new CommonEntry(id: i.GameIDValue, game_type: (GameTypes)i.GameType);
                        ListViewItem lvi = new ListViewItem(gi.ToString())
                        {
                            Tag = gi
                        };
                        ListGames.Items.Add(lvi);
                    }

                    ListLobbies.Items.Clear();
                    foreach (MsgGameList.ListItem i in game_list.Lobbies)
                    {
                        CommonEntry  li  = new CommonEntry(id: i.GameIDValue, game_type: (GameTypes)i.GameType);
                        ListViewItem lvi = new ListViewItem(li.ToString())
                        {
                            Tag = li
                        };
                        ListLobbies.Items.Add(lvi);
                    }
                }
                else if (msg is MsgLobbyStatus)
                {
                    MsgLobbyStatus status = (MsgLobbyStatus)msg;
                    if (lobby_window != null)
                    {
                        lobby_window.UpdateStatus(status);
                    }
                }

                read_msg += 1;
            }

            // Check for server failure
            if (Network.GameComms.Failed())
            {
#if DEBUG
                Application.Exit();
#else
                Application.Restart();
#endif
            }
        }