Пример #1
0
        private void HandleFileNames()
        {
            _clickSound = null;
            if (File.Exists(settings.ClickSoundFilename))
            {
                try
                {
                    _clickSound = new CachedSound(settings.ClickSoundFilename);
                }
                catch (Exception ex)
                {
                    Logger.Instance.LogMessage(TracingLevel.FATAL, $"CachedSound: {settings.ClickSoundFilename} {ex}");

                    _clickSound = null;
                    settings.ClickSoundFilename = null;
                }
            }

            _primaryFile   = Tools.FileToBase64(settings.PrimaryImageFilename, true);
            _secondaryFile = Tools.FileToBase64(settings.SecondaryImageFilename, true);



            Connection.SetSettingsAsync(JObject.FromObject(settings)).Wait();
        }
Пример #2
0
        // extra data 1: file path
        // extra data 2: device name
        // extra data 3: second device name
        public override void HotkeyTriggered()
        {
            if (audioDevice == null)
            {
                audioDevice = MainAudio.Instance.GetDevice(ExtraData2);
            }

            MainLogic.Instance.InputCallbacks.TextResultRequestOnTopCallback("Text",
                                                                             (bool speakCanceled, string speakInput) =>
            {
                if (!speakCanceled)
                {
                    try
                    {
                        string fileName = "tts_" + Guid.NewGuid() + ".wav";
                        if (speechSynthesizer == null)
                        {
                            speechSynthesizer = new SpeechSynthesizer();
                        }
                        speechSynthesizer.SetOutputToWaveFile(fileName);
                        speechSynthesizer.Speak(speakInput);
                        try
                        {
                            speechSynthesizer?.Dispose();
                        }
                        catch (Exception) { }
                        speechSynthesizer = null;
                        //var voices = speechSynthesizer.GetInstalledVoices();

                        files.Add(fileName);

                        CachedSound sound = new CachedSound(fileName);
                        provider          = audioDevice.AssociatedEngine.PlaySound(sound);

                        if (!String.IsNullOrWhiteSpace(ExtraData3))
                        {
                            if (audioDeviceTwo == null)
                            {
                                audioDeviceTwo = MainAudio.Instance.GetDevice(ExtraData3);
                            }

                            providerTwo = audioDeviceTwo.AssociatedEngine.PlaySound(sound);
                        }

                        if (AdditionalExtraData != null && AdditionalExtraData.ContainsKey((int)HotkeyAdditionalDataType.DeviceThree) && !String.IsNullOrWhiteSpace(AdditionalExtraData[(int)HotkeyAdditionalDataType.DeviceThree]))
                        {
                            if (audioDeviceThree == null)
                            {
                                audioDeviceThree = MainAudio.Instance.GetDevice(AdditionalExtraData[(int)HotkeyAdditionalDataType.DeviceThree]);
                            }

                            providerThree = audioDeviceThree.AssociatedEngine.PlaySound(sound);
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
            });
        }
Пример #3
0
        public static async Task <ISampleProvider> PlaySound(this MixingSampleProvider mixer, string path,
                                                             float volume, float balance)
        {
            var sound = await CachedSound.GetOrCreateCacheSound(path).ConfigureAwait(false);

            PlaySound(mixer, sound, volume, balance, out var rootSample);
            return(rootSample);
        }
Пример #4
0
        public static async Task <ISampleProvider> PlaySound(this MixingSampleProvider mixer, string path,
                                                             SampleControl sampleControl)
        {
            var sound = await CachedSound.GetOrCreateCacheSound(path).ConfigureAwait(false);

            PlaySound(mixer, sound, sampleControl, out var rootSample);
            return(rootSample);
        }
Пример #5
0
 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");
 }
Пример #6
0
        private static void PlaySound(MixingSampleProvider mixer, CachedSound sound, float volume, float balance,
                                      out ISampleProvider rootSample)
        {
            if (sound == null)
            {
                rootSample = default;
                return;
            }

            mixer.AddMixerInput(new CachedSoundSampleProvider(sound), volume, balance, out rootSample);
        }
Пример #7
0
        private static void PlaySound(MixingSampleProvider mixer, CachedSound sound, SampleControl sampleControl,
                                      out ISampleProvider rootSample)
        {
            if (sound == null)
            {
                rootSample = default;
                return;
            }

            mixer.AddMixerInput(new CachedSoundSampleProvider(sound), sampleControl, out rootSample);
        }
Пример #8
0
        internal async Task <CachedSound> GetCachedSoundAsync()
        {
            if (_cachedSound != null)
            {
                return(_cachedSound);
            }

            var result = await CachedSound.GetOrCreateCacheSound(FilePath).ConfigureAwait(false);

            _cachedSound = result;
            return(result);
        }
Пример #9
0
        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;
        }
Пример #10
0
        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);
        }
Пример #11
0
        void test_play_file_cache(string url, TYPE_SOURCE type = TYPE_SOURCE.FILE_LOCAL)
        {
            // on startup:
            var zap = new CachedSound(url, type);

            //var boom = new CachedSound("boom.wav");

            // later in the app...
            AudioPlaybackEngine.Instance.PlaySound(zap);
            //AudioPlaybackEngine.Instance.PlaySound(boom);
            //AudioPlaybackEngine.Instance.PlaySound("crash.wav");

            // on shutdown
            //AudioPlaybackEngine.Instance.Dispose();
        }
Пример #12
0
        public MainMenuState(MainGame g) : base(g)
        {
            game       = g;
            graphics   = game.graphics;
            resumeAble = (game.gameData.world != null);
            mState     = MenuState.main;
            oldState   = Keyboard.GetState();
            if (!resumeAble)
            {
                selection = 1;
            }
            click = new CachedSound("Content/Assets/Sound/ClickEffect.mp3");

            audioVol = game.gameData.audioVolume;
        }
Пример #13
0
        internal void CheckBulletCollision()
        {
            // Check Bullet collision with GameObjects
            int     isBlood;//0 = false 1 = true;
            var     fragmentSize      = 0.002f;
            var     fragmentSpeed     = 0.5f;
            var     fragmentHitpoints = 2f;
            var     weaponIsRocket    = 4;
            Vector2 fragmentDirection;

            foreach (GameObject gameObject in model.GameObjects)
            {
                for (int j = 0; j < this.model.Bullets.Count; j++)
                {
                    if (this.Intersection.IsIntersectingCircle(this.model.Bullets[j], gameObject) && gameObject.Id != -1)
                    {
                        if (gameObject.Id > 50)
                        {
                            isBlood = 0;;
                        }
                        else
                        {
                            isBlood = 1;
                            var Bloodsound = new CachedSound("../../Content/Sounds/Bloodsound.mp3");
                            sManager.PlaySound(Bloodsound);
                        }
                        if (this.player.SelectedWeapon == weaponIsRocket)
                        {
                            for (int i = 0; i < rng.Next(10, 20); i++)
                            {
                                fragmentDirection = new Vector2((float)rng.NextDouble() * 2 - 1, (float)rng.NextDouble() * 2 - 1);
                                this.model.RPGFragments.Add(new Particle(gameObject.Position, fragmentSize, fragmentSize, fragmentSpeed, fragmentHitpoints, isBlood, fragmentDirection, gameObject));
                            }
                        }
                        for (int i = 0; i < rng.Next(10, 20); i++)
                        {
                            fragmentDirection = new Vector2((float)rng.NextDouble() * 2 - 1, (float)rng.NextDouble() * 2 - 1);
                            fragmentSize      = 0.0015f;
                            fragmentSpeed     = (float)rng.NextDouble() - 0.2f;
                            fragmentHitpoints = 5f;
                            this.model.Particles.Add(new Particle(gameObject.Position + (this.model.Bullets[j].Position - gameObject.Position), fragmentSize, fragmentSize, fragmentSpeed, fragmentHitpoints, isBlood, fragmentDirection, gameObject));
                        }
                        this.model.Bullets.RemoveAt(j);
                        gameObject.Hitpoints -= this.weapon.Damage;
                    }
                }
            }
        }
Пример #14
0
        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;
        }
Пример #15
0
        public VolumeSampleProvider PlaySound(CachedSound sound, float volume = 1f, bool loop = false)
        {
            if (isDisposed)
            {
                return(null);
            }

            if (sound == null)
            {
                return(null);
            }

            var mixInput = new CachedSoundSampleProvider(sound);
            var ss       = new VolumeSampleProvider(mixInput);

            ss.Volume = volume * volume;
            AddMixerInput(ss);
            return(ss);
        }
Пример #16
0
        public static CachedSound TryGetSetSoundFile(string soundFile, int volume = 100)
        {
            var fileName = Regex.Replace(soundFile, @"[\\/]+", "\\", SharedRegEx.DefaultOptions);

            lock (SoundFiles) {
                try {
                    CachedSound value;
                    if (SoundFiles.TryGetValue(fileName, out value))
                    {
                        return(value);
                    }

                    value = new CachedSound(Path.Combine(Constants.SoundsPath, fileName));
                    SoundFiles.Add(fileName, value);
                    return(value);
                }
                catch (Exception) {
                    return(null);
                }
            }
        }
Пример #17
0
        private static int Main(string[] args)
        {
            _startupSound             = Sound.TryLoadCached("Audio/Startup.mp3");
            _messageNotificationSound = Sound.TryLoadCached("Audio/MessageNotification.mp3");
            _connectionSound          = Sound.TryLoadCached("Audio/Connection.mp3");

            Console.OutputEncoding = Encoding.Unicode;
            _network = new NetworkManager(Notification);

            var name  = "";
            var color = "";

            var port = 0;
            var host = "";

            var startServer = false;
            var startClient = false;


            _startupSound?.TryPlay();

            if (args.Length > 0)                //Check for console options
            {
                for (var i = 0; i < args.Length - 1; i++)
                {
                    var arg = args[i];

                    switch (arg)
                    {
                    case { } s when(s == "-N" || s == "--name"):
                    {
                        if (i + 1 < args.Length)                //If after option we have argument
                        {
                            name = args[i + 1];                 //Set up it
                            i++;
                        }
                        break;
                    }

                    case { } s when(s == "-c" || s == "--color"):
                    {
                        if (i + 1 < args.Length)
                        {
                            color = args[i + 1];
                            i++;
                        }
                        break;
                    }

                    case { } s when(s == "-S" || s == "--server"):
                    {
                        if (i + 1 < args.Length)
                        {
                            int.TryParse(args[i + 1], out port);
                            i++;

                            startServer = true;
                        }
                        break;
                    }

                    case { } s when(s == "-C" || s == "--client"):
                    {
                        if (i + 1 < args.Length)
                        {
                            if (args[i + 1].Contains(':'))                     //If host and port in format [host:port]
                            {
                                var hostArgs = args[i + 1].Split(':');         //Split it

                                host = hostArgs[0];
                                int.TryParse(hostArgs[1], out port);              //And convert

                                i++;

                                startServer = false;
                                startClient = true;
                            }
                            else if (i + 2 < args.Length)                           //If there is 2 arguments and format [host] [port]
                            {
                                host = args[i + 1];
                                int.TryParse(args[i + 2], out port);              //Convert it
                                i += 2;
                            }
                        }
                        break;
                    }
                    }
                }

                if (color.Length > 0 && name.Length > 0)                                   //If color and name are specified then
                {
                    _network.User = new User(name, ColorParser.GetColorFromString(color)); //Set up user

                    _network.Cmd.Clear();

                    if (host.Length > 0 && port > 0 && startClient && !startServer)     //If host and port are specified and this is client
                    {
                        _network.Connector.Host = host;
                        _network.Connector.Port = port;

                        if (_network.StartClient())                      //then start client
                        {
                            _connectionSound.TryPlay();
                        }
                        _network.Cmd.SwitchToPrompt();
                    }

                    if (port > 0 && startServer && !startClient)    //If port specified and this is server
                    {
                        _network.Connector.Port = port;

                        if (_network.StartServer())                    //Start server
                        {
                            _connectionSound.TryPlay();
                        }

                        _network.Cmd.SwitchToPrompt();
                    }
                }
                else
                {
                    _network.RegisterUser();                                         //Or register him
                }
            }

            else
            {
                _network.RegisterUser();                 //If there are no commands, register user
            }
            while (true)
            {
                ParseCommand(_network.Process());                      //Starts manager
            }
            // ReSharper disable once FunctionNeverReturns
        }
Пример #18
0
 internal static ISampleProvider PlaySound(this MixingSampleProvider mixer, CachedSound sound,
                                           float volume, float balance)
 {
     PlaySound(mixer, sound, volume, balance, out var rootSample);
     return(rootSample);
 }
Пример #19
0
 public void OnSoundChanged(CachedSound newSound)
 {
     Configuration.CustomSound = newSound;
 }
Пример #20
0
 public CustomSoundChangedEvent(CachedSound prevSound, CachedSound newSound)
 {
     PrevSound = prevSound;
     NewSound  = newSound;
 }
Пример #21
0
 public CachedSoundSampleProvider(CachedSound cachedSound)
 {
     this.cachedSound = cachedSound;
 }
Пример #22
0
 public void OnSoundChanged(CachedSound newSound)
 {
 }
Пример #23
0
 public void PlaySound(CachedSound sound)
 {
     AddMixerInput(new CachedSoundSampleProvider(sound));
 }
Пример #24
0
        internal void Shoot(List <Bullet> bullets, float deltaTime, Weapon weapon_)
        {
            var mouse = Mouse.GetState();

            this.Rpm -= deltaTime;
            Vector2 bulletOffset   = new Vector2(this.RadiusDraw, this.RadiusDraw);
            double  angleRadOffset = Math.Atan2(bulletOffset.Y, -bulletOffset.X);

            if (mouse.IsButtonDown(MouseButton.Left) && this.Rpm < 0)
            {
                switch (weapon_.Type)
                {
                case 1:
                    if (this.AmmoPistol > 0)
                    {
                        var AmmoSound = new CachedSound("../../Content/Sounds/PistolSound.mp3");
                        this.sManager.PlaySound(AmmoSound);
                        bullets.Add(new Bullet(this.Position, weapon_.Size, weapon_.Size, deltaTime * weapon_.Velocity, 5f, bullets.Count + 1, this.direction));
                        this.AmmoPistol--;
                        this.Rpm       = weapon_.RPM;
                        SelectedWeapon = weapon_.Type;
                    }

                    break;

                case 2:
                    if (this.AmmoUZI > 0)
                    {
                        var AmmoSound = new CachedSound("../../Content/Sounds/UZISound.mp3");
                        this.sManager.PlaySound(AmmoSound);
                        bullets.Add(new Bullet(this.Position, weapon_.Size, weapon_.Size, deltaTime * weapon_.Velocity, 5f, bullets.Count + 1, this.direction));
                        this.AmmoUZI--;
                        this.Rpm       = weapon_.RPM;
                        SelectedWeapon = weapon_.Type;
                    }

                    break;

                case 3:
                    if (this.AmmoShotgun > 0)
                    {
                        var AmmoSound = new CachedSound("../../Content/Sounds/ShotgunSound.mp3");
                        this.sManager.PlaySound(AmmoSound);
                        bullets.Add(new Bullet(this.Position, weapon_.Size, weapon_.Size, deltaTime * weapon_.Velocity, 5f, bullets.Count + 1, this.direction + (this.direction.PerpendicularLeft * 0.1f)));
                        bullets.Add(new Bullet(this.Position, weapon_.Size, weapon_.Size, deltaTime * weapon_.Velocity, 5f, bullets.Count + 1, this.direction + (this.direction.PerpendicularLeft * 0.2f)));
                        bullets.Add(new Bullet(this.Position, weapon_.Size, weapon_.Size, deltaTime * weapon_.Velocity, 5f, bullets.Count + 1, this.direction + (this.direction.PerpendicularLeft * 0.3f)));
                        bullets.Add(new Bullet(this.Position, weapon_.Size, weapon_.Size, deltaTime * weapon_.Velocity, 5f, bullets.Count + 1, this.direction));
                        bullets.Add(new Bullet(this.Position, weapon_.Size, weapon_.Size, deltaTime * weapon_.Velocity, 5f, bullets.Count + 1, this.direction + (this.direction.PerpendicularRight * 0.1f)));
                        bullets.Add(new Bullet(this.Position, weapon_.Size, weapon_.Size, deltaTime * weapon_.Velocity, 5f, bullets.Count + 1, this.direction + (this.direction.PerpendicularRight * 0.2f)));
                        bullets.Add(new Bullet(this.Position, weapon_.Size, weapon_.Size, deltaTime * weapon_.Velocity, 5f, bullets.Count + 1, this.direction + (this.direction.PerpendicularRight * 0.3f)));
                        this.AmmoShotgun--;
                        this.Rpm       = weapon_.RPM;
                        SelectedWeapon = weapon_.Type;
                    }

                    break;

                case 4:
                    if (this.AmmoRPG > 0)
                    {
                        var AmmoSound = new CachedSound("../../Content/Sounds/RPGSound.mp3");
                        this.sManager.PlaySound(AmmoSound);
                        bullets.Add(new Bullet(this.Position, weapon_.Size, weapon_.Size, deltaTime * weapon_.Velocity, 5f, bullets.Count + 1, this.direction));
                        this.AmmoRPG--;
                        this.Rpm       = weapon_.RPM;
                        SelectedWeapon = weapon_.Type;
                    }

                    break;

                default:
                    break;
                }
            }
            foreach (Bullet bullet in bullets)
            {
                bullet.MoveBullet(bullet);
                bullet.Hitpoints -= deltaTime;
                if (bullet.Hitpoints < 0)
                {
                    bullets.Remove(bullet);
                }
            }
        }
Пример #25
0
 static public void PlayNoteSound(CachedSound snd, int skipMs = 0, int takeMs = 0)
 {
     PlayNoteSound(new CachedSoundSampleProvider(snd), skipMs, takeMs);
 }
Пример #26
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);
        }
Пример #27
0
        /// <summary>
        ///     Create a notification object linked to the enum value
        /// </summary>
        /// <param name="eEnum"></param>
        /// <param name="icon"></param>
        /// <param name="sound"></param>
        /// <returns></returns>
        public static INotification CreateNotification(NotificationTypeEnum eEnum, NotifyIcon icon, CachedSound sound)
        {
            switch (eEnum)
            {
            case NotificationTypeEnum.DefaultWindowsNotification:
                return(new NotificationWindows(icon));

            case NotificationTypeEnum.SoundNotification:
                return(new NotificationSound());

            case NotificationTypeEnum.NoNotification:
                return(new NotificationNone());

            default:
                throw new ArgumentOutOfRangeException(nameof(eEnum), eEnum, null);
            }
        }
Пример #28
0
 internal static ISampleProvider PlaySound(this MixingSampleProvider mixer, CachedSound sound,
                                           SampleControl sampleControl)
 {
     PlaySound(mixer, sound, sampleControl, out var rootSample);
     return(rootSample);
 }
Пример #29
0
        private void InitializeSettings()
        {
            _clickSound = null;
            if (File.Exists(settings.ClickSoundFilename))
            {
                try
                {
                    _clickSound = new CachedSound(settings.ClickSoundFilename);
                }
                catch (Exception ex)
                {
                    Logger.Instance.LogMessage(TracingLevel.FATAL, $"CachedSound: {settings.ClickSoundFilename} {ex}");

                    _clickSound = null;
                    settings.ClickSoundFilename = null;
                }
            }

            _errorSound = null;
            if (File.Exists(settings.ErrorSoundFilename))
            {
                try
                {
                    _errorSound = new CachedSound(settings.ErrorSoundFilename);
                }
                catch (Exception ex)
                {
                    Logger.Instance.LogMessage(TracingLevel.FATAL, $"CachedSound: {settings.ErrorSoundFilename} {ex}");

                    _errorSound = null;
                    settings.ErrorSoundFilename = null;
                }
            }

            if (string.IsNullOrEmpty(settings.PrimaryColor))
            {
                settings.PrimaryColor = "#ffffff";
            }

            if (string.IsNullOrEmpty(settings.SecondaryColor))
            {
                settings.SecondaryColor = "#ffffff";
            }

            if (string.IsNullOrEmpty(settings.TertiaryColor))
            {
                settings.TertiaryColor = "#ffffff";
            }

            try
            {
                var converter = new ColorConverter();

                _primaryBrush   = new SolidBrush((Color)converter.ConvertFromString(settings.PrimaryColor));
                _secondaryBrush = new SolidBrush((Color)converter.ConvertFromString(settings.SecondaryColor));
                _tertiaryBrush  = new SolidBrush((Color)converter.ConvertFromString(settings.TertiaryColor));

                if (_primaryImage != null)
                {
                    _primaryImage.Dispose();
                    _primaryImage      = null;
                    _primaryFile       = null;
                    _primaryImageIsGif = false;
                }

                if (_secondaryImage != null)
                {
                    _secondaryImage.Dispose();
                    _secondaryImage      = null;
                    _secondaryFile       = null;
                    _secondaryImageIsGif = false;
                }

                if (_tertiaryImage != null)
                {
                    _tertiaryImage.Dispose();
                    _tertiaryImage      = null;
                    _tertiaryFile       = null;
                    _tertiaryImageIsGif = false;
                }

                if (File.Exists(settings.PrimaryImageFilename))
                {
                    _primaryImage = (Bitmap)Image.FromFile(settings.PrimaryImageFilename);

                    _primaryFile = Tools.FileToBase64(settings.PrimaryImageFilename, true);

                    _primaryImageIsGif = CheckForGif(settings.PrimaryImageFilename);
                }

                if (File.Exists(settings.SecondaryImageFilename))
                {
                    _secondaryImage = (Bitmap)Image.FromFile(settings.SecondaryImageFilename);

                    _secondaryFile = Tools.FileToBase64(settings.SecondaryImageFilename, true);

                    _secondaryImageIsGif = CheckForGif(settings.SecondaryImageFilename);
                }
                else
                {
                    _secondaryImage = _primaryImage;

                    _secondaryFile = _primaryFile;

                    _secondaryImageIsGif = CheckForGif(settings.PrimaryImageFilename);
                }

                if (File.Exists(settings.TertiaryImageFilename))
                {
                    _tertiaryImage = (Bitmap)Image.FromFile(settings.TertiaryImageFilename);

                    _tertiaryFile = Tools.FileToBase64(settings.TertiaryImageFilename, true);

                    _tertiaryImageIsGif = CheckForGif(settings.TertiaryImageFilename);
                }
                else
                {
                    _tertiaryImage = _primaryImage;

                    _tertiaryFile = _primaryFile;

                    _tertiaryImageIsGif = CheckForGif(settings.PrimaryImageFilename);
                }

                if (_primaryImage == null)
                {
                    _primaryImage = _secondaryImage;

                    _primaryFile = _secondaryFile;

                    _primaryImageIsGif = CheckForGif(settings.SecondaryImageFilename);
                }

                if (_primaryImage == null)
                {
                    _primaryImage = _tertiaryImage;

                    _primaryFile = _tertiaryFile;

                    _primaryImageIsGif = CheckForGif(settings.TertiaryImageFilename);
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.LogMessage(TracingLevel.FATAL, "Hyperspace InitializeSettings " + ex);
            }

            Connection.SetSettingsAsync(JObject.FromObject(settings)).Wait();
        }
Пример #30
0
        internal void CheckPlayerCollisions()
        {
            // Check Enemy and Player collision
            foreach (Enemy enemy in model.Enemies)
            {
                if (this.Intersection.IsIntersectingCircle(this.model.Player, enemy))
                {
                    var     minSplatter       = 10;
                    var     maxSplatter       = 20;
                    var     particleSize      = 0.0015f;
                    var     particleId        = 1;
                    var     particleHitpoints = 5f;
                    float   particleSpeed;
                    Vector2 particleDirection;
                    var     powerOfschubs = 0.001f;
                    Console.WriteLine("Player Collision mit Enemy: " + enemy.Id);
                    this.model.Player.Hitpoints -= enemy.Damage;
                    this.model.Player.Position  += enemy.playerDirection.Normalized() * powerOfschubs;
                    for (int j = 0; j < rng.Next(minSplatter, maxSplatter); j++)
                    {
                        particleSpeed     = (float)rng.NextDouble() - 0.2f;
                        particleDirection = new Vector2((float)rng.NextDouble() * 2 - 1, (float)rng.NextDouble() * 2 - 1);
                        this.model.Particles.Add(new Particle(player.Position, particleSize, particleSize, particleSpeed, particleHitpoints, particleId, particleDirection, player));
                    }
                    var Grunt = new CachedSound("../../Content/Sounds/Grunt.mp3");
                    sManager.PlaySound(Grunt);
                }
            }

            // Check Obstacle with Player collision
            foreach (Obstacle obstacle in model.Obstacles)
            {
                if (this.Intersection.IsIntersectingCircle(this.player, obstacle))
                {
                    float   radiusSum = (player.RadiusCollision + obstacle.RadiusCollision);
                    Vector2 diff      = player.Position - obstacle.Position;
                    diff /= diff.Length;
                    diff *= (radiusSum);
                    this.player.Position = obstacle.Position + diff;
                    Console.WriteLine("Player Collision mit Obstacle: " + obstacle.Id);
                }
            }
            // Check Pickup with Player collision
            for (int i = 0; i < this.model.PickUps.Count; i++)
            {
                if (this.Intersection.IsIntersectingCircle(this.model.Player, this.model.PickUps[i]))
                {
                    Console.WriteLine("Player Collision mit Pickup: " + this.model.PickUps[i].Id);
                    if (this.model.PickUps[i].Type > 0)
                    {
                        var ReloadSound = new CachedSound("../../Content/Sounds/Reload.mp3");
                        sManager.PlaySound(ReloadSound);
                    }
                    else
                    {
                        var Lifeup = new CachedSound("../../Content/Sounds/Lifeup.mp3");
                        sManager.PlaySound(Lifeup);
                    }
                    switch (this.model.PickUps[i].Type)
                    {
                    case 0:
                        this.player.Hitpoints += 0.1f;
                        Console.WriteLine("Leben: +100");
                        this.model.PickUps.RemoveAt(i);
                        break;

                    case 1:
                        this.player.AmmoPistol += 25;
                        Console.WriteLine("Pistol Ammo: +25");
                        this.model.PickUps.RemoveAt(i);
                        break;

                    case 2:
                        this.player.AmmoUZI += 100;
                        Console.WriteLine("UZI Ammo: +100");
                        this.model.PickUps.RemoveAt(i);
                        break;

                    case 3:
                        this.player.AmmoShotgun += 20;
                        Console.WriteLine("Shotgun Ammo: +20");
                        this.model.PickUps.RemoveAt(i);
                        break;

                    case 4:
                        this.player.AmmoRPG += 3;
                        Console.WriteLine("RPG Ammo: +3");
                        this.model.PickUps.RemoveAt(i);
                        break;

                    default:
                        break;
                    }
                }
            }
        }