예제 #1
0
 public void Dispose()
 {
     engine.Dispose();
     if (canRead)
     {
         midiIn.Stop();
         midiIn.Dispose();
         canRead = false;
     }
 }
예제 #2
0
        private string ChangeDevice(string deviceName, float deviceVolume, ref AudioPlaybackEngine soundPlayer)
        {
            if (soundPlayer != null)
            {
                soundPlayer.Stop();
                soundPlayer.Dispose();
            }

            string selectedDeviceName = InstantiateDevice(deviceName, soundPlayer == _primarySoundPlayer, ref soundPlayer);

            if (soundPlayer != null)
            {
                soundPlayer.Overlap = Overlap;
                soundPlayer.Volume  = _volume * deviceVolume;
            }

            return(selectedDeviceName);
        }
예제 #3
0
        /**************************************************
         *          START OF MAIN INVENTORY MENU
         **************************************************
         * £££££££££££££££££££££££££££££££££££££££££££££££££££
         *  £££££££££££££££££££££££££££££££££££££££££££££
         *      £££££££££££££££££££££££££££££££££££££
         *          £££££££££££££££££££££££££££££
         *              £££££££££££££££££££££
         *                  £££££££££££££
         *                      £££££
         *                        £
         */

        public void InventoryMenu(Player player, Menu _menuObject)
        {
            bool   continueCode = false;
            string option;
            bool   error    = false;
            string errorMsg = default;

            string[] inventoryOptions = new string[3] {
                "Potions", "Items", "Weapons"
            };

            do
            {
                Print.ClearAllScreen();
                //Sets the parameters for where the frame should start printing and prints the frame.
                Print.PrintSplitMenuFrame(99, 26);
                Console.SetCursorPosition(4, 11);
                Print.RedW("---- INVENTORY ----");

                Console.SetCursorPosition(62, 11);

                /*****************************************************
                *          ADD INVENTORY STATUS TO LISTS            *
                *****************************************************/
                Print.YellowW(player.InventoryStatus());

                CreateListOfAllInventory(player);


                /****************************************************************
                *  WEAPON PRINTING ON FIRST INVENTORY PAGE (SUMMARY OVER INVENTORY)
                ****************************************************************/
                top  = 13;
                left = 28;
                Console.SetCursorPosition(left, top);
                Print.Red("Weapons");
                top++;

                if (weapons.Count < 1)
                {
                    Console.SetCursorPosition(left, top);
                    Print.DarkGrey("You have no weapons");
                }
                foreach (var item in weapons)
                {
                    Console.SetCursorPosition(left, top);
                    Console.Write($"{item.Name} ");
                    if (item.Equipped == true)
                    {
                        Print.Green($"Equipped");
                    }
                    top++;
                }

                /****************************************************************
                *  ITEM PRINTING ON FIRST INVENTORY PAGE (SUMMARY OVER INVENTORY)
                ****************************************************************/
                top  = 24;
                left = 28;

                Console.SetCursorPosition(left, top);
                Print.Red("Items");
                top++;

                if (items.Count < 1)
                {
                    Console.SetCursorPosition(left, top);
                    Print.DarkGrey("You have no items");
                }
                foreach (var item in items)
                {
                    Console.SetCursorPosition(left, top);
                    Console.Write($"{item.Name} ");
                    if (item.Equipped == true)
                    {
                        Print.Green($"Equipped");
                    }
                    top++;
                }

                /****************************************************************
                *  POTION PRINTING ON FIRST INVENTORY PAGE (SUMMARY OVER INVENTORY)
                ****************************************************************/
                top  = 13;
                left = 55;

                Console.SetCursorPosition(left, top);
                Print.Red("Potions");

                top++;

                if (potions.Count < 1)
                {
                    Console.SetCursorPosition(left, top);
                    Print.DarkGrey("You have no potions");
                }
                foreach (var item in potions)
                {
                    Console.SetCursorPosition(left, top);
                    Console.WriteLine(item.Name);
                    top++;
                }

                /***********************************************************
                *       MAIN INVENTORY MENU IS PRINTED BELOW
                ***********************************************************/
                //Sets the parameters for where the menu should start printing.
                top  = 13;
                left = 2;
                //prints the menu
                for (int i = 0; i < inventoryOptions.Length; i++)
                {
                    Console.SetCursorPosition(left, top);
                    Console.WriteLine($"{i + 1}. {inventoryOptions[i]}");
                    top++;
                }
                Console.SetCursorPosition(left, top);
                Console.WriteLine("B. Back to main menu");
                //Error message is printed out (if there are any)
                if (error)
                {
                    Console.SetCursorPosition(left, top + 3);
                    Print.Red(errorMsg);
                    errorMsg = default;
                }
                Console.SetCursorPosition(left, top + 2);
                Console.Write("Choose your option> ");
                Console.CursorVisible = true;
                option = Console.ReadLine();
                Console.CursorVisible = false;
                //Initialize clicksound
                var sounds = _menuObject.SoundList();
                AudioPlaybackEngine sound = new AudioPlaybackEngine();
                sound.PlaySound(sounds[1]);
                Thread.Sleep(700);
                sound.Dispose();
                //Removes the clicksound and dispose from use (Auto GB collector will handle it)
                switch (option.ToLower())
                {
                case "1":
                    InventoryMenuPotions(player, potions);

                    break;

                case "2":
                    InventoryMenuItemsWeapons(player, "Item");


                    break;

                case "3":
                    InventoryMenuItemsWeapons(player, "Weapon");

                    break;

                case "b":
                    continueCode = true;
                    break;

                default:
                    //If anything else is pressed, errormessage is set.
                    error    = true;
                    errorMsg = "Wrong menu choice";
                    break;
                }
            } while (!continueCode);
        }
예제 #4
0
        //Shop main
        public void GoIn(Player player)
        {
            //Create a dictionary with name of item/weapon/potion and the creationstring for creating a new object
            itemCreator.Add("Healing potion", (IInventoryable) new HealingPotion(player.MaxHealth, "Healing potion"));
            itemCreator.Add("Max healing potion", (IInventoryable) new MaxHealingPotion(player.MaxHealth));
            itemCreator.Add("Magic agility potion", (IInventoryable) new MagicAgilityPotion());
            itemCreator.Add("Fast shoes", (IInventoryable) new FastShoes());
            itemCreator.Add("Standard armor", (IInventoryable) new StandardArmor(player.Level));
            itemCreator.Add("Swift armor", (IInventoryable) new SwiftArmor(player.Level));
            itemCreator.Add("Heavy armor", (IInventoryable) new HeavyArmor(player.Level));
            itemCreator.Add("Diamond armor", (IInventoryable) new DiamondArmor(player.Level));
            itemCreator.Add("Rusty sword", (IInventoryable) new RustySword());
            itemCreator.Add("Broad sword", (IInventoryable) new BroadSword());
            itemCreator.Add("The beheader", (IInventoryable) new TheBeheader());
            itemCreator.Add("Devils blade", (IInventoryable) new DevilsBlade());
            itemCreator.Add("Dragon slayer", (IInventoryable) new DragonSlayer());
            itemCreator.Add("Agility amulett", (IInventoryable) new AgilityAmulett());
            itemCreator.Add("Strength amulett", (IInventoryable) new StrengthAmulett());



            bool   continueCode = false;
            string option;
            bool   error    = false;
            string errorMsg = default;

            string[] inventoryOptions = new string[3] {
                "Potions", "Items", "Weapons"
            };
            do
            {
                Print.ClearAllScreen();
                //Sets the parameters for where the frame should start printing and prints the frame.
                Print.PrintSplitMenuFrame(99, 26);
                Console.SetCursorPosition(4, 11);
                Print.RedW("---- THE SHOP ----");

                Print.ClearAllScreen(deleteTopHeadingsRight, 11);
                Console.SetCursorPosition(63, 11);
                Print.YellowW(player.InventoryStatus());
                weapons.Clear();
                items.Clear();
                potions.Clear();

                //loop thru and add the creation strings to specific lists
                foreach (var item in itemCreator)
                {
                    if (item.Value is IWeapon)
                    {
                        weapons.Add((Weapon)item.Value);
                    }
                    else if (item.Value is IItem)
                    {
                        items.Add((Item)item.Value);
                    }
                    else if (item.Value is Potion)
                    {
                        potions.Add((Potion)item.Value);
                    }
                }

                PrintWeapons(weapons, false);
                PrintItems(items, false);
                PrintPotions(potions, false);
                PrintCurrentInventory(player, "All");


                //Sets the parameters for where the menu should start printing.
                top  = 13;
                left = 2;
                //prints the menu
                for (int i = 0; i < inventoryOptions.Length; i++)
                {
                    Console.SetCursorPosition(left, top);
                    Console.WriteLine($"{i + 1}. {inventoryOptions[i]}");
                    top++;
                }
                Console.SetCursorPosition(left, top);
                Console.WriteLine("B. Back to main menu");
                top++;
                //Error message is printed out (if there are any)
                if (error)
                {
                    Console.SetCursorPosition(left, top + 2);
                    Print.Red(errorMsg);
                    errorMsg = default;
                }
                Console.SetCursorPosition(left, top + 1);
                Console.Write("Choose your option> ");
                Console.CursorVisible = true;
                option = Console.ReadLine();
                Console.CursorVisible = false;
                var sounds = _menuObject.SoundList();
                AudioPlaybackEngine sound = new AudioPlaybackEngine();
                sound.PlaySound(sounds[1]);
                Thread.Sleep(700);
                sound.Dispose();
                switch (option.ToLower())
                {
                case "1":
                    StoreMenuPotions();

                    break;

                case "2":
                    StoreMenuItems();

                    break;

                case "3":
                    StoreMenuWeapons();
                    break;

                case "b":
                    continueCode = true;
                    break;

                default:
                    //If anything else is pressed, errormessage is set.
                    error    = true;
                    errorMsg = "Wrong menu choice";
                    break;
                }
            } while (!continueCode);
        }
예제 #5
0
        public void GoAdventure(Player player, Menu _menuObject)
        {
            //Randomize a number 1-100, if under 10, nothing happens.
            Random rand            = new Random();
            int    adventureChoice = rand.Next(1, 101);

            if (adventureChoice <= 10)
            {
                Console.SetCursorPosition(45, 21);
                Print.Yellow("Seems to be a dead end. I´ll better go back");
                Console.SetCursorPosition(45, 22);
                Console.Write("Press enter to continue");

                var sounds = _menuObject.SoundList();
                AudioPlaybackEngine sound = new AudioPlaybackEngine();
                sound.PlaySound(sounds[4]);
                Console.ReadKey();
                sound.Dispose();
            }

            //if random number is 11-15, get bit by a snake and loose 5 hp.
            else if (adventureChoice > 10 && adventureChoice <= 15)
            {
                var sounds = _menuObject.SoundList();
                AudioPlaybackEngine sound = new AudioPlaybackEngine();
                sound.RaiseVol();
                sound.PlaySound(sounds[11]);

                player.TakeDamage(5, false);
                Console.SetCursorPosition(45, 21);
                if (!player.Alive)
                {
                    Print.Red("You got bit by a snake and died.");
                }
                else
                {
                    Print.Red("You got bit by a snake and lost 5hp. At least you survived.");
                }
                Console.SetCursorPosition(45, 22);
                Console.Write("Press enter to continue");
                Console.ReadKey();
                sound.LowerVol();
                sound.Dispose();
            }

            //Else the fight will start
            else
            {
                var sounds = _menuObject.SoundList();
                AudioPlaybackEngine fightMusic = new AudioPlaybackEngine();
                fightMusic.PlaySound(sounds[3]);

                //create new fight
                Fight fight = new Fight(player);
                //Create lists with enemy names.
                List <string> enemyList = new List <string>()
                {
                    "Devil", "Dragonpig", "Skeleton", "Axed goblin", "Little devil", "Bat", "Gummy bear"
                };
                List <string> bossList = new List <string>()
                {
                    "Winged snake", "Evil minotaur", "Long foot"
                };

                //Calculates the level of XP that next enemy can drop,
                //and if remaining XP for player to next level is below maximum XP drop,
                //the boss is created, else a miniboss or normal enemy is created. Miniboss in the end of level 3 and 6.
                if (player.Level == 3 && player.NextLevel - player.Xp <= 40 || player.Level == 6 && player.NextLevel - player.Xp <= 147)
                {
                    fight.PrintFight(new Miniboss(player, bossList[rand.Next(0, bossList.Count)]), player, fightMusic, _menuObject);
                }
                else if (player.Level == 9 && player.NextLevel - player.Xp <= 238)
                {
                    fight.PrintFight(new Dragon(player), player, fightMusic, _menuObject);
                }
                else
                {
                    fight.PrintFight(new Enemy(player, enemyList[rand.Next(0, enemyList.Count)]), player, fightMusic, _menuObject);
                }



                fightMusic.Dispose();
            }
        }
예제 #6
0
        public void PrintFight(Enemy enemy, Player player, AudioPlaybackEngine currentMusic, Menu _menuObject)
        {
            //initializing some things for the fight
            List <IConsumable> listOfPotions;
            List <string>      userInteractions = new List <string>()
            {
                "I - Inventory", "ENTER - Attack again/Continue", "ESC - Close inventory", "F - Flee"
            };
            int           top          = 11;
            int           left         = 0;
            int           leftMoveHere = default;
            int           topMoveHere  = default;
            List <string> fightText    = new List <string>();

            _fightText = fightText;
            bool fled = false;

            do
            {
                fightText.Clear();
                if (player.Alive)
                {
                    if (leftMoveHere != 0)
                    {
                        Print.ClearAllScreen(leftMoveHere, topMoveHere);
                    }
                    else
                    {
                        Print.ClearAllScreen();
                    }
                    //If the enemy is the end boss, print out a dragon as a picture.
                    if (enemy.ToString() == "Dragon")
                    {
                        Print.DragonPrint();
                    }
                    else
                    {//else print out the current enemy
                        Print.EnemyPrint(enemy.Type);
                    }
                    //else if miniboss, print out miniboss.
                    if (enemy.IsBoss && enemy.Type != "Dragon")
                    {
                        Print.EnemyPrint("Boss fight", 80, 10);
                    }
                    else if (enemy.IsBoss)
                    {
                        Print.EnemyPrint("End fight", 80, 10);
                    }
                    player.PrintCurrentPlayerStatus();
                    Print.FightConsole();
                    Print.FightConsolePrintText(fightText, player, enemy);
                    leftMoveHere = 0;
                    topMoveHere  = 40;
                    Console.SetCursorPosition(leftMoveHere, topMoveHere);
                    for (int i = 0; i < userInteractions.Count; i++)
                    {
                        Console.Write($" ║  {userInteractions[i]}  ║   ");
                    }
                    Console.SetCursorPosition(left, top);
                    leftMoveHere = 0;
                    topMoveHere  = 40;
                    Console.SetCursorPosition(leftMoveHere, topMoveHere);
                    for (int i = 0; i < userInteractions.Count; i++)
                    {
                        Console.Write($" ║  {userInteractions[i]}  ║   ");
                    }

                    //If endboss, do a weapon animation
                    if (enemy.ToString() == "Dragon")
                    {
                        Print.WeaponAnimation(false, _menuObject);
                    }

                    fightText.Add(player.Attack(enemy));
                    Print.FightConsolePrintText(fightText, player, enemy);
                    leftMoveHere = Console.CursorLeft;
                    topMoveHere  = Console.CursorTop;



                    Thread.Sleep(1000);
                    if (enemy.Alive)
                    {
                        //if the enemy is alive after the attack, counter attack (and do animation if it applies)
                        if (enemy.ToString() == "Dragon")
                        {
                            Print.ClearAllScreen();
                            player.PrintCurrentPlayerStatus();
                            Print.FightConsolePrintText(fightText, player, enemy);
                            Print.DragonAnimation(player, enemy, fightText, _menuObject);
                        }

                        fightText.Add(enemy.Attack(player));
                        Print.FightConsolePrintText(fightText, player, enemy);
                        leftMoveHere = Console.CursorLeft;
                        topMoveHere  = Console.CursorTop;
                        if (player.Alive)
                        {
                            Print.PlayerStatsPrint(player);
                        }
                        else
                        {
                            currentMusic.PauseSound();
                        }


                        Console.SetCursorPosition(leftMoveHere, topMoveHere);
                        ConsoleKey key3;
                        int        topPosition;
                        int        leftPosition;

                        //The do loop below controls the in fight inventorysystem an keylistners for that to work.
                        do
                        {
                            leftPosition = 0;
                            topPosition  = 40;
                            Console.SetCursorPosition(leftPosition, topPosition);
                            for (int i = 0; i < userInteractions.Count; i++)
                            {
                                Console.Write($" ║  {userInteractions[i]}  ║   ");
                            }
                            //Start listning for keypress after fight
                            Console.CursorVisible = false;
                            var keytest = Console.ReadKey(true);
                            key3 = keytest.Key;

                            //if pressed key is I, then print out players inventory, and if F, flee.
                            if (key3 == ConsoleKey.F)
                            {
                                fled = true;
                                break;
                            }
                            if (key3 == ConsoleKey.I)
                            {
                                listOfPotions = player.PrintAllItems(0);

                                bool   treatEscapeAsCancel = true;
                                string inputString;
                                bool   hideInput = false;

                                Console.CursorVisible = true;

                                StringBuilder inputBuilder = new StringBuilder();
                                //While player has not pressed escape
                                bool   error    = false;
                                string errorMsg = default;
                                //While player have not aborted inventory with escape
                                //Player has access to potions during fight
                                while (true)
                                {
                                    topPosition  = 18;
                                    leftPosition = 111;
                                    Console.SetCursorPosition(leftPosition, topPosition);
                                    Print.Red("Inventory (press nr to use)");
                                    topPosition++;

                                    int counter = 1;
                                    if (listOfPotions.Count < 1)
                                    {
                                        Console.SetCursorPosition(leftPosition, topPosition);
                                        Console.WriteLine("Out of potions. Press ESC");
                                        Console.CursorVisible = false;
                                    }
                                    else
                                    {
                                        foreach (var item in listOfPotions)
                                        {
                                            Console.SetCursorPosition(leftPosition, topPosition);
                                            Console.WriteLine($"{counter}. {item.Name} +{item.TheChange}");
                                            topPosition++;
                                            counter++;
                                        }
                                    }

                                    topPosition += 2;
                                    if (error)
                                    {
                                        Console.SetCursorPosition(leftPosition, topPosition);
                                        Print.Red(errorMsg);
                                        error    = false;
                                        errorMsg = default;
                                    }
                                    topPosition--;

                                    Console.SetCursorPosition(leftPosition, topPosition);
                                    if (listOfPotions.Count != 0)
                                    {
                                        Console.CursorVisible = true;
                                        Console.Write("Choose a potion: ");
                                    }
                                    Console.SetCursorPosition(leftPosition + 17 + inputBuilder.Length, topPosition);
                                    ConsoleKeyInfo inputKey = Console.ReadKey(true);
                                    if (inputKey.Key == ConsoleKey.Enter)
                                    {
                                        inputString = inputBuilder.ToString();

                                        int  number;
                                        bool converted = int.TryParse(inputString, out number);
                                        if (converted)
                                        {
                                            if (number <= listOfPotions.Count)
                                            {
                                                if (listOfPotions[number - 1].Name == "Healing potion" || listOfPotions[number - 1].Name == "Max healing potion" && player.Health != player.MaxHealth)
                                                {
                                                    player.RestoreHp(listOfPotions[number - 1].TheChange);
                                                    player.RemoveFromBackpack((IInventoryable)listOfPotions[number - 1]);
                                                    listOfPotions.Remove(listOfPotions[number - 1]);
                                                }

                                                else if (listOfPotions[number - 1].Name == "Magic agility potion")
                                                {
                                                    string beenDrinking = player.SetAgilityTempUp(listOfPotions[number - 1].Consume());
                                                    if (string.IsNullOrEmpty(beenDrinking))
                                                    {
                                                        player.RemoveFromBackpack((IInventoryable)listOfPotions[number - 1]);
                                                        listOfPotions.Remove(listOfPotions[number - 1]);
                                                    }
                                                    else
                                                    {
                                                        Console.SetCursorPosition(leftPosition, topPosition);
                                                        Console.WriteLine(beenDrinking);
                                                        Console.ReadLine();
                                                    }
                                                }
                                                topPosition = 18;
                                                Print.ClearAllScreen(leftPosition, topPosition);
                                                Print.ClearAllScreen(104, 0);
                                                inputBuilder.Clear();
                                                player.PrintCurrentPlayerStatus();
                                            }
                                            else
                                            {
                                                error    = true;
                                                errorMsg = "You don´t have that";
                                                inputBuilder.Clear();
                                            }
                                        }
                                        else
                                        {
                                            error    = true;
                                            errorMsg = "Not a valid choice.";
                                            inputBuilder.Clear();
                                            topPosition = 18;
                                            Console.SetCursorPosition(leftPosition, topPosition);
                                            Print.ClearAllScreen(leftPosition, topPosition);

                                            //Printing out everything again so it looks clean.
                                            Print.EnemyPrint(enemy.Type, 0, 10);


                                            topPosition = 18;
                                        }
                                    }
                                    //if player presses escape, then break the loop.
                                    else if (treatEscapeAsCancel && inputKey.Key == ConsoleKey.Escape)
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        inputBuilder.Append(inputKey.KeyChar);
                                    }

                                    if (!hideInput)
                                    {
                                        Console.Write(inputKey.KeyChar);
                                    }
                                }
                                //Cleaning up leftovers from inventory
                                topPosition = 18;
                                Print.ClearAllScreen(leftPosition, topPosition);
                                //Printing out everything again so it looks clean.
                            }

                            //Looping as long as the user has not pressed enter
                        } while (key3 != ConsoleKey.Enter);
                    }
                    else
                    {
                        //play victory sound and print out victory text
                        currentMusic.PauseSound();
                        currentMusic.Dispose();
                        Console.SetCursorPosition(0, 35);
                        Print.Green("VICTORY!!!");
                        player.SetAgilityTempUp(0);
                        Print.Green($"You looted the enemy and got {player.TakeGold(enemy.DropGold())} gold");
                        int currentLevel = player.Level;
                        Print.Green($"You also got {enemy.GiveXp()} XP");
                        player.TakeXp(enemy.GiveXp());
                        player.KilledCreature();
                        CachedSound         win = new CachedSound(@$ "fightwin.mp3");
                        AudioPlaybackEngine fightWin;
                        fightWin = new AudioPlaybackEngine();
                        fightWin.PlaySound(win);
                        Thread.Sleep(4000);
                        fightWin.Dispose();

                        //if level up, play sound and do an update of player stats
                        if (currentLevel < player.Level)
                        {
                            Console.Write($"LEVEL UP! You got level up bonus gold. Press enter to continue.");
                            leftMoveHere = Console.CursorLeft;
                            topMoveHere  = Console.CursorTop;
                            var sounds = _menuObject.SoundList();
                            AudioPlaybackEngine sound = new AudioPlaybackEngine();
                            sound.PlaySound(sounds[5]);
                            Print.PlayerStatsPrint(player);
                            Thread.Sleep(500);
                            sound.Dispose();
                        }
                        //update player stats
                        else
                        {
                            Console.Write("Press enter to continue.");
                            leftMoveHere = Console.CursorLeft;
                            topMoveHere  = Console.CursorTop;
                            Print.PlayerStatsPrint(player);
                        }

                        Console.ReadKey();
                        break;
                    }
                }
                else
                {
                    break;
                }
                //if the player fled or the enemy died, the fight is over.
            } while (enemy.Alive && !fled);
        }
예제 #7
0
        private void Play_Stop_Click(object sender, EventArgs e)
        {
            if (Play_Stop_Btn.Text.Equals("Play"))
            {
                if (playbackEngine == null)
                {
                    addText("You must select a device first\n\n", Color.Red);
                    return;
                }
                if (DataList.Items.Count == 0)
                {
                    addText("You must add dataset first\n\n", Color.Red);
                    return;
                }

                SPCheckBox.Enabled = false;
                foreach (var c in Dataset_splitContainer.Panel2.Controls.OfType <ComboBox>())
                {
                    c.Enabled = false;
                }
                ;
                Add_Data_Btn.Enabled   = false;
                Clear_Data_Btn.Enabled = false;
                Clear_All_Btn.Enabled  = false;
                Load_Btn.Enabled       = false;
                Save_Btn.Enabled       = false;

                // get the data sets to play
                var datasets = new List <String[]>();
                foreach (ListViewItem item in DataList.Items)
                {
                    var subItem = item.SubItems;
                    var dataset = new String[subItem.Count - 1];
                    for (int i = 0; i < subItem.Count - 1; i++)
                    {
                        if (subItem[i + 1].Text.Equals("[Silence]"))
                        {
                            dataset[i] = null;
                        }
                        else
                        {
                            var headers = DataList.Columns.OfType <ColumnHeader>().Select(header => header.Text).ToArray();
                            if (headers[i + 1].Contains("Speech"))
                            {
                                dataset[i] = String.Format($@"speech/{subItem[i + 1].Text}");
                            }
                            else if (headers[i + 1].Contains("Noise"))
                            {
                                dataset[i] = String.Format($@"noise/{subItem[i + 1].Text}");
                            }
                        }
                    }
                    datasets.Add(dataset);
                }

                DirectoryInfo dinfo  = new DirectoryInfo(Directory.GetCurrentDirectory());
                String        path   = $"{dinfo.ToString()}/auto_generated";
                bool          exists = System.IO.Directory.Exists(path);
                if (!exists)
                {
                    System.IO.Directory.CreateDirectory(path);
                }
                playbackEngine.asioWriterPath = @"auto_generated";

                //Init the playbackEngine and mwProvider
                try
                {
                    if (SPCheckBox.Checked)
                    {
                        var spFilename = $@"sync_pattern/{spComboBox.SelectedItem.ToString()}";
                        playbackEngine.Init(datasets, spFilename, inputChannelTypes, inputMappingData, outputChannelTypes, outputMappingData);
                    }
                    else
                    {
                        playbackEngine.Init(datasets, null, inputChannelTypes, inputMappingData, outputChannelTypes, outputMappingData);
                    }
                    playbackEngine.mwProvider.PlaybackChanged += new EventHandler <PlaybackChangedEventArgs>(PlaybackChangedEvent);
                    playbackEngine.asioOut.PlaybackStopped    += new EventHandler <StoppedEventArgs>(PlaybackStoppedEvent);
                    playbackEngine.Play();
                    //must raise the playbackChanged event manually at the first time
                    playbackEngine.mwProvider.RaisePlaybackChanged(0);
                    Play_Stop_Btn.Text = "Stop";
                }
                catch (Exception ex)
                {
                    if (playbackEngine != null)
                    {
                        playbackEngine.Dispose();
                    }

                    SPCheckBox.Enabled = true;
                    foreach (var c in Dataset_splitContainer.Panel2.Controls.OfType <ComboBox>())
                    {
                        c.Enabled = true;
                    }
                    ;
                    Add_Data_Btn.Enabled   = true;
                    Clear_Data_Btn.Enabled = true;
                    Clear_All_Btn.Enabled  = true;
                    Load_Btn.Enabled       = true;
                    Save_Btn.Enabled       = true;
                    SetList(-1);

                    Play_Stop_Btn.Text = "Play";

                    addText(ex.ToString() + "\n\n", Color.Red);
                    return;
                }
            }
            else if (Play_Stop_Btn.Text.Equals("Stop"))
            {
                playbackEngine.Dispose();
                SPCheckBox.Enabled = true;
                foreach (var c in Dataset_splitContainer.Panel2.Controls.OfType <ComboBox>())
                {
                    c.Enabled = true;
                }
                ;
                Add_Data_Btn.Enabled   = true;
                Clear_Data_Btn.Enabled = true;
                Clear_All_Btn.Enabled  = true;
                Load_Btn.Enabled       = true;
                Save_Btn.Enabled       = true;
                SetList(-1);

                Play_Stop_Btn.Text = "Play";
            }
        }