コード例 #1
0
ファイル: Methods.cs プロジェクト: icebeam7/nexmo-game
        private string[] GetOptions(int type, int correct, LocalContact contact)
        {
            string[] options = new string[4];

            options[correct] = (type == 1) ? contact.NexmoInfo.NexmoLookup.Carrier
                            : (type == 2) ? contact.NexmoInfo.NexmoLookup.Network
                            : (type == 3) ? contact.NexmoInfo.NexmoFormat.Prefix
                            : (type == 4) ? contact.NexmoInfo.NexmoFormat.Country
                            : contact.PhoneNumber;

            for (int i = 0; i < 4; i++)
            {
                if (i != correct)
                {
                    string option = "";

                    do
                    {
                        option = (type == 1) ? GetRandomCarrier(App.player.Country).network
                            : (type == 2) ? GetRandomNetwork().network
                            : (type == 3) ? GetRandomCarrier().country_code
                            : (type == 4) ? GetRandomCarrier().country
                            : GetRandomContactNumber();
                    } while (options.Contains(option));

                    options[i] = option;
                }
            }

            return options;
        }
コード例 #2
0
ファイル: Methods.cs プロジェクト: icebeam7/nexmo-game
        public async Task<LocalContact> GetRandomContact(int type)
        {
            int i = 0;
            LocalContact contacto;

            do
            {
                int random = Utils.GetRandomValue(App.contacts.Count);
                var contactoDB = App.contacts[random];

                if (contactoDB.PhoneNumber == "")
                {
                    i++;
                    contacto = null;
                    continue;
                }

                contacto = new LocalContact()
                {
                    Name = contactoDB.Name,
                    PhoneNumber = contactoDB.PhoneNumber,
                    Thumbnail = contactoDB.Thumbnail
                };

                contacto.NexmoInfo = (contactoDB.Carrier == "")
                    ? await GetNexmoInfo(contacto.PhoneNumber, App.player.Country, type, contactoDB.Id)
                    : GetNexmoInfoLocal(contactoDB);

                if (contacto.NexmoInfo == null)
                {
                    i++;
                    contacto = null;
                    continue;
                }
                else
                    break;
            } while (i < 5);

            return contacto;
        }