public Form1() { InitializeComponent(); player = AudioPlaybackEngine.Instance; keybindManager = new KeybindManager(); settings = Settings.LoadSettings(); timer1.Interval = 400; timer1.Tick += timer1_Tick; textBox2.Text = settings.fileFolder; player.PlaybackEnded += OnPlaybackEnded; player.PlaybackStarted += OnPlaybackStarted; keybindManager.KeyPressed += KeyPressed; keybindManager.KeybindAdded += KeybindAdded; keybindManager.KeybindUpdated += KeybindUpdated; keybindManager.KeybindRemoved += KeybindRemoved; keybindManager.KeybindStopButton += KeybindStopButton; keybindManager.RefreshKeybinds(); PopulateFiles(); RefreshDevices(); PopulateKeys(); }
public MainForm() { InitializeComponent(); Mapping_Btn.Enabled = false; Play_Stop_Btn.Enabled = false; SPCheckBox.Enabled = false; spComboBox.Enabled = false; foreach (var c in Dataset_tableLayoutPanel.Controls.OfType <Button>()) { c.Enabled = false; } Use_Default_CheckBox.Checked = true; DirectoryInfo dinfo = new DirectoryInfo(Directory.GetCurrentDirectory()); bool exists = System.IO.Directory.Exists($"{dinfo.ToString()}/sync_pattern"); if (!exists) { System.IO.Directory.CreateDirectory($"{dinfo.ToString()}/sync_pattern"); } FileInfo[] sp_files = dinfo.GetFiles(@"sync_pattern/*.wav"); //list sp files foreach (FileInfo file in sp_files) { spComboBox.Items.Add(file.Name); } spComboBox.SelectedIndex = Math.Min(sp_files.Length - 1, 0); playbackEngine = null; echoDotStarted = false; comboToolTip = new ToolTip(); }
public TeamViewModel(int teamIndex, ScoreboardViewModel scoreboard1, ScoreboardViewModel scoreboard2, WordGameViewModel wordGameViewModel, BingoCardSettings bingoCardSettings, Random random, AudioPlaybackEngine audioPlaybackEngine, ActiveSceneContainer activeSceneContainer) { _teamIndex = teamIndex; _bingoCardSettings = bingoCardSettings; _random = random; _audioPlaybackEngine = audioPlaybackEngine; Scoreboard1 = scoreboard1; Scoreboard2 = scoreboard2; WordGameViewModel = wordGameViewModel; ActiveSceneContainer = activeSceneContainer; if (teamIndex == 0) { this.WhenAnyValue(x => x.ActiveSceneContainer.IsTeam1Active).ToPropertyEx(this, x => x.OnAir); } else { this.WhenAnyValue(x => x.ActiveSceneContainer.IsTeam2Active).ToPropertyEx(this, x => x.OnAir); } CreateNewBingoCard(); }
public SampleChannel(OsuFile osuFile, string sourceFolder, AudioPlaybackEngine engine, ICollection <Subchannel> referencedChannels, FileCache cache = null) : base(engine, new MixSettings(), referencedChannels) { _cache = cache; _osuFile = osuFile; _sourceFolder = sourceFolder; Description = nameof(SampleChannel); }
public WordGameViewModel(GameState state, AudioPlaybackEngine audioPlaybackEngine) { _state = state; _audioPlaybackEngine = audioPlaybackEngine; _timeOutSound = new CachedSound(@"Resources\Sounds\WordGame\timeout.wav"); _winSound = new CachedSound(@"Resources\Sounds\WordGame\win.wav"); _rejectSound = new CachedSound(@"Resources\Sounds\WordGame\rejected.wav"); _newLetterAppearsSound = new CachedSound(@"Resources\Sounds\WordGame\first_letter_appears.wav"); _bonusLetterAppears = new CachedSound(@"Resources\Sounds\WordGame\bonusletter.wav"); }
public MIDIHandler(int driverSelection) { // TODO: By default, this will select the 0 index MIDI device. This should be changed so that the user can select which one they want. engine = new AudioPlaybackEngine(driverSelection); selectDevice(); if (canRead) { handleMidiMessages(); } }
public KeyValuePair <int, string> GetDevice(string name, bool primary) { IDictionary <int, string> devices = AudioPlaybackEngine.EnumerateDevices(); KeyValuePair <int, string> device = devices.Where(x => x.Value == name).FirstOrDefault(); if (primary && device.Equals(default(KeyValuePair <int, string>)) && devices.Count > 2) { return(new KeyValuePair <int, string>(-1, devices[-1])); } return(device); }
public HitsoundChannel(OsuFile osuFile, string sourceFolder, AudioPlaybackEngine engine, FileCache cache = null) : base(engine, new MixSettings { ForceMode = true }) { _cache = cache ?? new FileCache(); _osuFile = osuFile; _sourceFolder = sourceFolder; Description = nameof(HitsoundChannel); }
public BingoViewModel(BingoCardSettings settings, Random random, AudioPlaybackEngine audioEngine) { _settings = settings; _audioEngine = audioEngine; _winSound = new CachedSound(@"Resources\Sounds\Bingo\slingo_win.wav"); _fillBallShortSound = new CachedSound(@"Resources\Sounds\Bingo\ball_fill_short.wav"); _fillBallLongSound = new CachedSound(@"Resources\Sounds\Bingo\ball_fill_long.wav"); int[] numbers = Enumerable.Range(1, 50).Where(x => settings.EvenNumber ? (x % 2 == 0) : (x % 2 != 0)).ToArray(); Matrix = SetupMatrix(random, numbers, settings.FilledBalls); MatrixForAnimation = CopyMatrix(Matrix); IsAnimating = true; }
private string InstantiateDevice(string deviceName, bool primary, ref AudioPlaybackEngine soundPlayer) { KeyValuePair <int, string> device = GetDevice(deviceName, primary); if (device.Equals(default(KeyValuePair <int, string>)) || device.Value == "Disabled") { soundPlayer = null; return("Disabled"); } soundPlayer = new AudioPlaybackEngine(device.Key); return(device.Value); }
public void setDeviceName(String deviceName) { Mapping_Btn.Enabled = true; Play_Stop_Btn.Enabled = true; SPCheckBox.Enabled = true; foreach (var c in Dataset_tableLayoutPanel.Controls.OfType <Button>()) { c.Enabled = true; } this.playbackEngine = new AudioPlaybackEngine(deviceName); //set default inputChannelTypes = new List <String> { "Mic1" }; outputChannelTypes = new List <String> { "Speech1", "Speech2", "Noise1", "Noise2", "Noise3", "Noise4", "Noise5", "Noise6" }; inputMappingData = new List <int>(); outputMappingData = new List <int>(); inputChannelNames = playbackEngine.GetInputChannelNames(); outputChannelNames = playbackEngine.GetOutputChannelNames(); for (int i = 0; i < inputChannelTypes.Count; i++) { if (i < playbackEngine.inputChannelCount) { inputMappingData.Add(i); } else { inputMappingData.Add(0); } //set the first Mic manually because we plug the mic into analog9 inputMappingData[0] = 8; } for (int i = 0; i < outputChannelTypes.Count; i++) { if (i < playbackEngine.outputChannelCount) { outputMappingData.Add(i); } else { outputMappingData.Add(0); } } }
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}"); } }
private static async Task ExportOsu() { var path = "F:\\milkitic\\Songs\\" + "1346316 Nekomata Master feat. Mimi Nyami - TWINKLING\\" + "Nekomata Master feat. Mimi Nyami - TWINKLING (yf_bmp) [Another].osu"; //var path = "E:\\Games\\osu!\\Songs\\3198 Rhapsody - Emerald Sword\\" + // //"1376486 Risshuu feat. Choko - Take\\" + // "Rhapsody - Emerald Sword (Reikin) [net].osu"; var folder = Path.GetDirectoryName(path); var osuFile = await OsuFile.ReadFromFileAsync(path); if (!osuFile.ReadSuccess) { throw osuFile.ReadException; } using var engine = new AudioPlaybackEngine(); var mp3Path = Path.Combine(folder, osuFile?.General.AudioFilename ?? "."); var fileCache = new FileCache(); await using var directChannel = new DirectChannel(mp3Path, osuFile.General.AudioLeadIn, engine); await using var hitsoundChannel = new HitsoundChannel(osuFile, engine, fileCache) { ManualOffset = 50, }; await using var sampleChannel = new SampleChannel(osuFile, engine, new Subchannel[] { directChannel, hitsoundChannel }, fileCache) { ManualOffset = 50, }; var exporter = new Mp3Exporter(new MultiElementsChannel[] { directChannel, hitsoundChannel, sampleChannel }, engine); string pre = null; await exporter.ExportAsync("test.mp3", progress => { var p = $"Progress: {progress:P0}"; if (pre != p) { Console.WriteLine(p); pre = p; } }); }
public BoardViewModel(int wordsize, AudioPlaybackEngine audioPlaybackEngine) { _audioPlaybackEngine = audioPlaybackEngine; _correctSound = new CachedSound(@"Resources\Sounds\WordGame\correct.wav"); _incorrectSound = new CachedSound(@"Resources\Sounds\WordGame\incorrect.wav"); _incorrectLocationSound = new CachedSound(@"Resources\Sounds\WordGame\incorrect_location.wav"); _newRowAppears = new CachedSound(@"Resources\Sounds\WordGame\additional_row_appears.wav"); for (int i = 0; i < wordsize; i++) { _wordGameRows.Add(new WordGameRowViewModel(wordsize)); } _wordGameRows.Connect().Bind(out var rows).Subscribe(); Rows = rows; }
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); }
public SoundSet() { // Each sound has two parameters // Length (in milliseconds) // Whether the sound can interrupt the current sound _eatFruit = new Sound(Resources.pacman_eatfruit, 1000, true); _chomp1 = new Sound(Resources.pacman_chomp1, 120, false); _chomp2 = new Sound(Resources.pacman_chomp2, 120, false); _death = new Sound(Resources.pacman_death, 2000, true); _beginning = new Sound(Resources.pacman_beginning, 4000, true); _intermission = new Sound(Resources.pacman_intermission, 1000, true); _extraPac = new Sound(Resources.pacman_extrapac, 500, true); _eatGhost = new Sound(Resources.pacman_eatghost, 1000, true); _nextSound = DateTime.Now; _audioPlaybackEngine = new AudioPlaybackEngine(11025, 1); }
} // TODO move to model class public GameViewModel(Settings settings, GameState state, AudioPlaybackEngine audioPlaybackEngine, ActiveSceneContainer activeSceneContainer) { Random random = new Random(); var audioPlaybackEngine1 = audioPlaybackEngine; ScoreBoardTeam1 = new ScoreboardViewModel(state.Team1, HorizontalAlignment.Left); ScoreBoardTeam2 = new ScoreboardViewModel(state.Team2, HorizontalAlignment.Right); WordGameViewModel = new WordGameViewModel(state, audioPlaybackEngine); var bingoCardSettingsTeam1 = new BingoCardSettings(true, settings.ExcludedBallNumbersEven); var bingoCardSettingsTeam2 = new BingoCardSettings(false, settings.ExcludedBallNumbersOdd); Team1ViewModel = new TeamViewModel(0, ScoreBoardTeam1, ScoreBoardTeam2, WordGameViewModel, bingoCardSettingsTeam1, random, audioPlaybackEngine1, activeSceneContainer); Team2ViewModel = new TeamViewModel(1, ScoreBoardTeam1, ScoreBoardTeam2, WordGameViewModel, bingoCardSettingsTeam2, random, audioPlaybackEngine1, activeSceneContainer); CountDownStarted = ReactiveCommand.Create(() => new Unit()); this.WhenAnyValue(x => x.WordGameViewModel.BoardViewModel).Where(x => x != null).Subscribe(x => { WordGameStarted(); }); }
public void ClearHitsoundCache() { AudioPlaybackEngine.ClearCacheSounds(); }
public Sound() { soundEngine = new AudioPlaybackEngine(); }
#pragma warning restore 0219, 414 private void OnEnable() { this._sAudioPlaybackEngine = this.target as AudioPlaybackEngine; }
public Sound(IContentLoader contentLoader) { this.contentLoader = contentLoader ?? throw new ArgumentNullException(nameof(contentLoader)); soundEngine = new AudioPlaybackEngine(); laser = contentLoader.Load <byte[]>("laser.wav"); //content manager will cache it, but its still faster to keep a direct reference }
public HitsoundChannel(OsuMixPlayer player, OsuFile osuFile, string sourceFolder, AudioPlaybackEngine engine) : base(engine) { _player = player; _osuFile = osuFile; _sourceFolder = sourceFolder; Description = nameof(HitsoundChannel); }
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 ICollection <string> EnumerateDevices() { return(AudioPlaybackEngine.EnumerateDevices().Values); }
//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 DirectChannel(string audioPath, int delay, [NotNull] AudioPlaybackEngine engine, SampleControl control = null) : base(engine) { _audioPath = audioPath; _delay = delay; _control = control ?? new SampleControl(); }
public HitsoundChannel(LocalOsuFile osuFile, AudioPlaybackEngine engine, FileCache cache = null) : this(osuFile, Path.GetDirectoryName(osuFile.OriginPath), engine, cache) { }
public SampleChannel(LocalOsuFile osuFile, AudioPlaybackEngine engine, ICollection <Subchannel> referencedChannels, FileCache cache = null) : this(osuFile, Path.GetDirectoryName(osuFile.OriginPath), engine, referencedChannels, cache) { }
/************************************************** * 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); }
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); }