Exemple #1
0
        public static void Start()
        {
            Console.Title = "Fantasy RPG";
            List <Merchant> equipment = Armor.StarterArmor();
            List <Merchant> weapon    = Weapons.AddWeapon();
            List <Merchant> armor     = Armor.AddArmor();
            List <Merchant> items     = Items.AddItems();
            List <Merchant> food      = Inn.AddFood();
            Hero            hero      = CreateHero(equipment, armor);

            bool activeGame = false;

            do
            {
                Console.WriteLine("\n**************************************\n" +
                                  "* 1. Go Adventuring\n" +
                                  "* 2. Show details about your character\n" +
                                  "* 3. Rest at the Inn\n" +
                                  "* 4. Visit shop\n" +
                                  "* 5. Exit\n" +
                                  "**************************************\n");
                Console.Write(">> ");
                Console.ForegroundColor = ConsoleColor.Cyan;
                string menuChoice = Console.ReadLine();
                Console.ResetColor();

                switch (menuChoice)
                {
                case "1":     // hero enters battle phase , returns boolean which if player dies ends game
                    activeGame = HeroMethods.Battle(hero);
                    break;

                case "2":     //prints Hero stats and current equipment from ToString in Hero
                    Console.WriteLine(hero);
                    break;

                case "3":     //Allows hero to rest at in exchange for gold, this heals the player to full health
                    Inn.VisitInn(hero, food);
                    break;

                case "4":     //Enters shop, where all equipment is located, when purchased items are auto equipped.
                    Merchant.ItemShop(hero, items, armor, weapon, equipment);
                    break;

                case "5":     // quits game
                    activeGame = true;
                    break;
                }
                if (hero.lvl >= 10)
                {
                    Console.WriteLine("You are a true hero! You win!");
                    activeGame = true;
                }
            } while (!activeGame);
        }
Exemple #2
0
        public void Reset(IEnumerable <T> newContents)
        {
            if (newContents == null)
            {
                throw new ArgumentNullException(nameof(newContents));
            }

            Items.Clear();
            Items.AddItems(newContents);
            OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
        }
Exemple #3
0
 protected override void SetItemsCore(IList value)
 {
     BeginUpdate();
     try {
         Items.Clear();
         Items.AddItems(value);
         _dataSource          = new ListboxDataSource(this, value);
         tableView.DataSource = _dataSource;
         tableView.SizeToFit();
     } finally {
         EndUpdate();
     }
 }
        public void Handle(MsgDownloadStateChanged message)
        {
            var item = message.Item as SongViewModel;

            if (item == null || !item.HasMp3)
            {
                return;
            }
            item.Song.DownloadState = "complete";
            SongViewModel.RequestSave(item);
            Items.AddItems(new List <IMusic> {
                item.Song
            }, true);
        }
Exemple #5
0
        /// <summary>
        /// 添加OPCItems
        /// </summary>
        /// <param name="itemNames">待添加的OPCItems名</param>
        /// <param name="itemClientHandles">客户端句柄</param>
        /// <param name="removeFormer">是否移除当前已存在的Items</param>
        protected void AddItems(string[] itemNames, int[] itemClientHandles, bool removeFormer)
        {
            try
            {
                if (removeFormer)
                {
                    RemoveAllItems();
                }
                Array ar_itemNames = Array.CreateInstance(typeof(string), itemNames.Length + 1);
                ((Array)itemNames).CopyTo(ar_itemNames, 1);
                Array ar_itemClientHandles = Array.CreateInstance(typeof(int), itemNames.Length + 1);
                ((Array)itemClientHandles).CopyTo(ar_itemClientHandles, 1);
                Array ar_Errors;

                Items.AddItems(ar_itemClientHandles.Length - 1, ref ar_itemNames, ref ar_itemClientHandles, out itemServerHandles, out ar_Errors);
            }
            catch
            {
                //没有任何权限的项,都是OPC服务器保留的系统项,此处可不做处理。
            }
        }
        private void AddItems()
        {
            var actions = new List <(Category Header, CommandAction Item)>
            {
                (Category.Navigation, new CommandAction(
                     new RelayCommand(() =>
                {
                    _pageNavigationService
                    .For <DetailsPageViewModel>()
                    .Navigate();
                }),
                     "Without parameters")),
                (Category.Navigation, new CommandAction(
                     new RelayCommand(() =>
                {
                    _pageNavigationService
                    .For <DetailsPageViewModel>()
                    .WithParam(x => x.Person, new Person {
                        FirstName = "Ivan", LastName = "Ivanov"
                    })
                    .Navigate();
                }),
                     "With parameters")),
                (Category.Navigation, new CommandAction(
                     new RelayCommand(() =>
                {
                    _pageNavigationService
                    .For <BottomTabsPageViewModel>()
                    .Navigate();
                }),
                     "Bottom Tabs")),
                (Category.Navigation, new CommandAction(
                     new RelayCommand(() =>
                {
                    _pageNavigationService
                    .For <DialogsPageViewModel>()
                    .Navigate();
                }),
                     "Dialogs")),
                (Category.Navigation, new CommandAction(
                     new RelayCommand(() =>
                {
                    _pageNavigationService
                    .For <FramesViewModel>()
                    .Navigate();
                }),
                     "Frames")),
                (Category.Collections, new CommandAction(
                     new RelayCommand(() =>
                {
                    _pageNavigationService
                    .For <TablePageViewModel>()
                    .Navigate();
                }),
                     "Observable list")),
                (Category.Collections, new CommandAction(
                     new RelayCommand(() =>
                {
                    _pageNavigationService
                    .For <CollectionPageViewModel>()
                    .Navigate();
                }),
                     "Observable collection")),
                (Category.Collections, new CommandAction(
                     new RelayCommand(() =>
                {
                    _pageNavigationService
                    .For <GroupedTablePageViewModel>()
                    .Navigate();
                }),
                     "Observable grouped list")),
                (Category.Collections, new CommandAction(
                     new RelayCommand(() =>
                {
                    _pageNavigationService
                    .For <GroupedCollectionPageViewModel>()
                    .Navigate();
                }),
                     "Observable grouped collection")),
                (Category.Collections, new CommandAction(
                     new RelayCommand(() =>
                {
                    if (_appInfoService.Platform == Platform.iOS)
                    {
                        _pageNavigationService
                        .For <CompositionalLayoutPageViewModel>()
                        .Navigate();
                    }
                }),
                     "Compositional Layout (iOS 13+)")),
                (Category.Controls, new CommandAction(
                     new RelayCommand(() =>
                {
                    _pageNavigationService
                    .For <PhotoBrowserViewModel>()
                    .Navigate();
                }),
                     "Photo browser")),
                (Category.Controls, new CommandAction(
                     new RelayCommand(() =>
                {
                    _pageNavigationService
                    .For <PhotoViewerViewModel>()
                    .Navigate();
                }),
                     "Photo viewer")),

                // (Category.Components, new CommandAction(
                //   new RelayCommand(() =>
                //   {
                //       _pageNavigationService.NavigateToViewModel<FilesViewModel>();
                //   }),
                //   "Files")),
                (Category.Components, new CommandAction(
                     new RelayCommand(() =>
                {
                    _pageNavigationService
                    .For <PermissionsPageViewModel>()
                    .Navigate();
                }),
                     "Permissions")),
                (Category.Components, new CommandAction(
                     new RelayCommand(() =>
                {
                    _pageNavigationService
                    .For <ConnectivityPageViewModel>()
                    .Navigate();
                }),
                     "Connectivity")),
                (Category.Components, new CommandAction(
                     new RelayCommand(() =>
                {
                    if (_appInfoService.Platform == Platform.iOS)
                    {
                        _pageNavigationService
                        .For <GesturesPageViewModel>()
                        .Navigate();
                    }
                }),
                     "Gestures (iOS)"))
            };

            Items.AddItems(actions, x => x.Header.ToString(), x => x.Item);
        }
        void btn_import_click(object sender, RoutedEventArgs e)
        {
            var dir = Global.AppSettings["DownloadFolder"];

            Task.Run(async() =>
            {
                var buffer       = new List <IMusic>();
                int bufferLength = 10;
                var mp3s         = Directory.EnumerateFiles(dir, "*.mp3").ToArray();
                foreach (var item in mp3s)
                {
                    try
                    {
                        var mp3  = TagLib.File.Create(item);
                        var tags = mp3.Tag;
                        if (tags.Comment == null)
                        {
                            continue;
                        }
                        var id       = "";
                        var artistid = "";
                        var albumid  = "";
                        var logo     = "";
                        var m        = reg_ids.Match(tags.Comment);
                        if (!m.Success)
                        {
                            m = reg.Match(tags.Comment);
                            if (!m.Success)
                            {
                                continue;
                            }
                            id           = m.Groups[1].Value;
                            var obj      = await NetAccess.Json(XiamiUrl.url_song, "id", id);
                            artistid     = MusicHelper.Get(obj["song"], "artist_id");
                            albumid      = MusicHelper.Get(obj["song"], "album_id");
                            logo         = StringHelper.EscapeUrl(MusicHelper.Get(obj["song"], "logo"));
                            tags.Comment = string.Join(" ", new[] { id, artistid, albumid });
                            mp3.Save();
                        }
                        else
                        {
                            id       = m.Groups[1].Value;
                            artistid = m.Groups[2].Value;
                            albumid  = m.Groups[3].Value;
                        }
                        var art = System.IO.Path.Combine(Global.BasePath, "cache", albumid + ".art");
                        if (!File.Exists(art))
                        {
                            if (string.IsNullOrEmpty(logo))
                            {
                                var obj = await NetAccess.Json(XiamiUrl.url_song, "id", id);
                                logo    = StringHelper.EscapeUrl(MusicHelper.Get(obj["song"], "logo"));
                            }
                            await new System.Net.WebClient().DownloadFileTaskAsync(logo, art);
                        }
                        var song = new Song
                        {
                            Id         = id,
                            ArtistId   = artistid,
                            AlbumId    = albumid,
                            Name       = tags.Title,
                            ArtistName = tags.FirstPerformer,
                            AlbumName  = tags.Album,
                            FilePath   = item,
                            Logo       = logo,
                        };
                        buffer.Add(song);
                    }
                    catch
                    {
                    }
                    if (buffer.Count == bufferLength)
                    {
                        var songs = new List <IMusic>();
                        foreach (var s in buffer.OfType <Song>())
                        {
                            SongViewModel.Get(s).HasMp3 = true;
                        }
                        songs.AddRange(buffer);
                        Items.AddItems(songs);
                        buffer.Clear();
                    }
                }
                if (buffer.Count > 0)
                {
                    foreach (var s in buffer.OfType <Song>())
                    {
                        SongViewModel.Get(s).HasMp3 = true;
                    }
                    Items.AddItems(buffer);
                }
            });
        }