public async Task StartWordGame(string word) { _wordSize = word.Length; _wordGame = new WordGame(new WordPuzzle(word), _state.Team1.IsActiveTeam ? 0 : 1); BoardViewModel = new BoardViewModel(word.Length, _audioPlaybackEngine); _audioPlaybackEngine.PlaySound(_newLetterAppearsSound); await BoardViewModel.StartNextAttempt(_wordGame.KnownLetters); }
public async Task AcceptWord(WordPuzzleEntry result) { CombinedSoundSampleProvider soundProvider = SetupWordGameEntrySounds(result.LetterEntries.Select(x => x.State), 200); WordGameRowViewModel viewmodel = _wordGameRows.Items.ElementAt(attemptIndex); _audioPlaybackEngine.PlaySound(soundProvider); for (int i = 0; i < result.LetterEntries.Length; i++) { viewmodel.SetLetter(i, result.LetterEntries[i].Letter, result.LetterEntries[i].State); await Task.Delay(200); } }
public void Play(Sound sound) { if (sound.Files.Count == 0) { return; } string file = sound.Files[_random.Next(sound.Files.Count)]; try { if (_primarySoundPlayer != null) { _primarySoundPlayer.PlaySound(file, sound.Volume / 100f, sound.Loop); } if (_secondarySoundPlayer != null) { _secondarySoundPlayer.PlaySound(file, sound.Volume / 100f, sound.Loop); } } catch (Exception ex) { sound.Error = ex.ToString(); } }
private void Play(Sound sound) { if (DateTime.Now > _nextSound || sound.Interrupt) { _nextSound = DateTime.Now.Add(sound.RepeatTime); _audioPlaybackEngine.PlaySound(sound.SoundSource); } }
public async Task FillInitialBalls() { await DropBallsFromTop(); await Task.Delay(100); foreach (BingoBallViewModel[] bingoBallViewModels in Matrix) { foreach (BingoBallViewModel viewModel in bingoBallViewModels) { if (_settings.FilledBalls.Contains(viewModel.Number)) { _audioEngine.PlaySound(_fillBallShortSound); viewModel.Fill(); await Task.Delay(125); } } } }
private static void Play(String soundName) { CachedSound sound; lock (sounds) { if (!sounds.TryGetValue(soundName, out sound)) { sound = new CachedSound("Resources/Sounds/" + soundName + ".wav"); sounds.Add(soundName, sound); } } player.PlaySound(sound); }
private void SoundPlay() { try { if (lstMain.SelectedItems.Count > 0) { //parse out file extension from list view var fileName = lstMain.SelectedItems[0].SubItems[2].Text; var fileId = Convert.ToInt32(lstMain.SelectedItems[0].SubItems[1].Text); var ext = Path.GetExtension(fileName).ToLower(); //read raw sound bytes from DAT var buffer = ExtractFile(fileId); //stores sound bytes for playback var memStream = new MemoryStream(buffer, true); switch (ext) { case @".wav": var cachedWave = new WaveCachedSound(memStream); _audioEngine = new AudioPlaybackEngine(cachedWave.WaveFormat.SampleRate, cachedWave.WaveFormat.Channels); _audioEngine.PlaySound(cachedWave); break; case @".ogg": var cachedVorbis = new VorbisCachedSound(memStream); _audioEngine = new AudioPlaybackEngine(cachedVorbis.WaveFormat.SampleRate, cachedVorbis.WaveFormat.Channels); _audioEngine.PlaySound(cachedVorbis); break; case @".cbx": MessageBox.Show(@"You tried to play a LEGO *.cbx file. These are proprietary files that cannot be directly played as of now; progress is being made towards dissecting the format."); break; } memStream.Close(); } else { MessageBox.Show(@"Nothing selected!"); } } catch (Exception ex) { MessageBox.Show($"Error whilst trying to load sound content\n\n{ex}"); } }
/************************************************** * 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); }
//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); }
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(); } }
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); }