Beispiel #1
0
        public GameWindow(DirectoryInfo imagesDirectory = null)
        {
            gameState = new GameState();
            GameSetter.CreateLevel(gameState);
            gameState.UpdateState();
            ClientSize = new Size(
                ElementSize * (MapManager.Map.Wigth + 1),
                ElementSize * MapManager.Map.Height);
            FormBorderStyle = FormBorderStyle.FixedDialog;
            MaximizeBox     = false;
            if (imagesDirectory == null)
            {
                imagesDirectory = new DirectoryInfo("Images");
            }
            foreach (var e in imagesDirectory.GetFiles("*.png"))
            {
                bitmaps[e.Name] = (Bitmap)Image.FromFile(e.FullName);
            }

            var soundsDirectory = new DirectoryInfo("Sounds");

            foreach (var e in soundsDirectory.GetFiles("*.wav"))
            {
                Sounds[e.Name] = new SoundPlayer(e.FullName);
            }

            Timer = new Timer {
                Interval = TimerInterval
            };
            Timer.Tick += TimerTick;
            Timer.Start();

            //FormClosed += (sender, args) =>
            //{
            //    if (gameState.PlayerLost)
            //    {
            //        Sounds[Noises[NoiseType.Pain]].Stop();
            //        //PlayLost.EndInvoke(PlayingSound);
            //    }

            //    if (gameState.PlayerWon)
            //    {
            //        Sounds[Noises[NoiseType.Win]].Stop(); ;
            //        //PlayWon.EndInvoke(PlayingSound);
            //    }
            //};
        }