예제 #1
0
 public GameDetail(GameDetailedData gameData)
 {
     Data = gameData;
     InitializeComponent();
     BackgroundColor = Color.FromHex("#EEEEEE");
     BindingContext  = Data;
 }
예제 #2
0
        private GameDetailedData get_a_game()
        {
            // 获得game列表
            string              url      = "http://real.eastasia.cloudapp.azure.com/game";
            HttpClient          client   = new HttpClient();
            HttpResponseMessage response = client.GetAsync(url).Result;
            var             content      = response.Content.ReadAsStringAsync().Result;
            List <GameData> GamesList    = JsonConvert.DeserializeObject <List <GameData> >(content);
            int             i            = new Random().Next(0, GamesList.Count);
            GameData        game_temp    = GamesList[i];


            url      = "http://real.eastasia.cloudapp.azure.com/user";
            client   = new HttpClient();
            response = client.GetAsync(url).Result;
            content  = response.Content.ReadAsStringAsync().Result;
            GameDetailedData gameData = new GameDetailedData();

            gameData.Type         = game_temp.type;
            gameData.GameName     = game_temp.name;
            gameData.GameID       = game_temp.id;
            gameData.InitiatorID  = game_temp.initiator;
            gameData.Participants = game_temp.participants;
            gameData.GameIntro    = game_temp.introduction;
            gameData.Is_private   = game_temp.is_private;
            gameData.StartTime    = game_temp.start_time;
            Images imgs = new Images();

            gameData.GameImage = imgs.GetImage(game_temp.name);
            List <FriendData> playersList = new List <FriendData>();

            if (response.IsSuccessStatusCode)
            {
                List <UserObject> userObjects = JsonConvert.DeserializeObject <List <UserObject> >(content);
                foreach (var user in userObjects)
                {
                    if (user.id == gameData.InitiatorID)
                    {
                        gameData.InitiatorAvatar = user.avatar;
                        gameData.InitiatorName   = user.username;
                    }
                    if (gameData.Participants.Contains(user.id))
                    {
                        FriendData data = new FriendData
                        {
                            Avatar   = user.avatar,
                            UserName = user.username,
                            UserID   = user.id
                        };
                        playersList.Add(data);
                    }
                }
            }
            gameData.PlayersList = playersList;
            return(gameData);
        }
예제 #3
0
        public GameMessageListView()
        {
            InitializeComponent();
            gameMessageListView.ItemsSource = LoadMessageData();
            GameDetailedData random_game = get_a_game();

            gameMessageListView.ItemTapped += async(sender, args) => {
                await Navigation.PushModalAsync(new GameDetail(random_game));
            };
        }
예제 #4
0
        async void OnSelection(object sender, SelectedItemChangedEventArgs e)
        {
            if (e.SelectedItem == null)
            {
                return;
            }
            ListView listView = (ListView)sender;

            listView.SelectedItem = null;
            GameDetailedData gameData = (GameDetailedData)e.SelectedItem;

            List <FriendData> playersList = new List <FriendData>();

            // 获得user列表
            string              url      = "http://real.eastasia.cloudapp.azure.com/user";
            HttpClient          client   = new HttpClient();
            HttpResponseMessage response = await client.GetAsync(new Uri(url));

            var content = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                List <UserObject> userObjects = JsonConvert.DeserializeObject <List <UserObject> >(content);
                foreach (var user in userObjects)
                {
                    if (user.id == gameData.InitiatorID)
                    {
                        gameData.InitiatorAvatar = user.avatar;
                        gameData.InitiatorName   = user.username;
                    }
                    if (gameData.Participants.Contains(user.id))
                    {
                        FriendData data = new FriendData
                        {
                            Avatar   = user.avatar,
                            UserName = user.username,
                            UserID   = user.id
                        };
                        playersList.Add(data);
                    }
                }
            }
            else
            {
                Console.Out.WriteLine("请求失败~~~~~~~");
                // await DisplayAlert("提示", "StatusCode:" + content + " ", "确定");
            }
            client.Dispose();
            gameData.PlayersList = playersList;

            NavigationPage gameDetail = new NavigationPage(new GameDetail(gameData));
            // gameDetail.BindingContext = gameData;
            await Navigation.PushModalAsync(gameDetail);
        }
예제 #5
0
        async void LoadData()
        {
            // 获得game列表
            string              url      = "http://real.eastasia.cloudapp.azure.com/game";
            HttpClient          client   = new HttpClient();
            HttpResponseMessage response = await client.GetAsync(new Uri(url));

            var content = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                // Console.Out.WriteLine("请求成功~~~~~~~" + content);
                GameSource = new List <GameDetailedData>();
                List <GameData> GamesList = JsonConvert.DeserializeObject <List <GameData> >(content);
                foreach (var game in GamesList)
                {
                    GameDetailedData gameItem = new GameDetailedData
                    {
                        GameID       = game.id,
                        GameName     = game.name,
                        GameIntro    = String.IsNullOrEmpty(game.introduction) ? "一起来玩" + game.name + "吧~~~" : game.introduction,
                        StartTime    = game.start_time,
                        InitiatorID  = game.initiator,
                        Participants = game.participants
                    };
                    string[] labels = gameItem.StartTime.Split('T');
                    string   time   = labels[0] + " ";
                    time += labels[1].Split(':')[0] + ":" + labels[1].Split(':')[1];
                    gameItem.GameDetailLabel = gameItem.GameName + "(开始时间:" + time + ")";

                    // gameImage
                    Images imgs = new Images();
                    gameItem.GameImage = imgs.GetImage(gameItem.GameName);
                    GameSource.Add(gameItem);
                }
            }
            else
            {
                Console.Out.WriteLine("请求失败~~~~~~~");
                // await DisplayAlert("提示", "StatusCode:" + content + " ", "确定");
            }
            gameListView.ItemsSource = GameSource;
        }