Ejemplo n.º 1
0
        public async void getLobbies()
        {
            await App.Current.Dispatcher.Invoke(async delegate
            {
                bool isExistingSelectedMode = (_selectedMode == Constants.MODE_FFA || _selectedMode == Constants.MODE_SOLO || _selectedMode == Constants.MODE_COOP);
                if (isExistingSelectedMode)
                {
                    GameCards.Clear();
                    var response = await ServerService.instance.client.GetAsync(Constants.SERVER_PATH + Constants.GET_ACTIVE_LOBBY_PATH + "/" + _selectedMode);

                    StreamReader streamReader = new StreamReader(await response.Content.ReadAsStreamAsync());
                    String responseData       = streamReader.ReadToEnd();
                    var myData = JsonConvert.DeserializeObject <List <Lobby> >(responseData);
                    foreach (var item in myData)
                    {
                        GameCard gameCard = new GameCard(item);
                        GameCards.Add(gameCard);
                    }
                }
            });
        }
Ejemplo n.º 2
0
        public void CreateCardsForGame(int row, int columns)
        {
            GameCards.Clear();


            var rnd = new Random();

            for (int i = 0; i < ((row * columns) / 2); i++)
            {
                int r = rnd.Next(AllCardList.Count);
                if (GameCards.Any(x => x.Number == AllCardList[r].Number))
                {
                    i--;
                    continue;
                }

                // Clone Card object
                var pomC = (Card)AllCardList[r].Clone();
                // Load img from file for first card
                BitmapImage bmp = new BitmapImage(AllCardList[r].UriPath);
                Image       img = new Image();
                img.Source = bmp;
                img.Width  = PictureWidth;
                img.Height = PictureHeight;

                AllCardList[r].Img = img;

                GameCards.Add(AllCardList[r]);
                // Load img from file for second same card
                bmp        = new BitmapImage(pomC.UriPath);
                img        = new Image();
                img.Source = bmp;
                img.Width  = PictureWidth;
                img.Height = PictureHeight;
                pomC.Img   = img;
                GameCards.Add(pomC);
            }

            GameCards.Shuffle();
        }