private void TexLoadButton_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.Filter = "(*.bmp)|*.bmp";
            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                if (PlayerRadio.IsChecked == true)
                {
                    gameTextures.PlayerIcon = CLevelParser.LockFreeBmpLoad(dlg.FileName);
                    PlayerImage.Source      = gameTextures.PlayerIcon;
                }
                else if (EnemyRadio.IsChecked == true)
                {
                    gameTextures.EnemyIcon = CLevelParser.LockFreeBmpLoad(dlg.FileName);
                    EnemyImage.Source      = gameTextures.EnemyIcon;
                }
                else if (GoalRadio.IsChecked == true)
                {
                    gameTextures.GoalIcon = CLevelParser.LockFreeBmpLoad(dlg.FileName);
                    GoalImage.Source      = gameTextures.GoalIcon;
                }
                else if (WallRadio.IsChecked == true)
                {
                    gameTextures.WallTexture = CLevelParser.LockFreeBmpLoad(dlg.FileName);
                    WallImage.Source         = gameTextures.WallTexture;
                }
                else if (FloorRadio.IsChecked == true)
                {
                    gameTextures.FloorTexture = CLevelParser.LockFreeBmpLoad(dlg.FileName);
                    FloorImage.Source         = gameTextures.FloorTexture;
                }
                else if (FireRadio.IsChecked == true)
                {
                    gameTextures.FireIcon = CLevelParser.LockFreeBmpLoad(dlg.FileName);
                    FireImage.Source      = gameTextures.FireIcon;
                }

                cvsMainScreen.Children.Clear();
                reRender();
            }
        }
        //****************************************************************//
        // This function is used as an event handler for the load click  *//
        // event. This is used to load a new level. In addition to       *//
        // the data required for the level it also ensures the board is  *//
        // displayed.                                                    *//
        //****************************************************************//
        private void btnLoad_Click(object sender, RoutedEventArgs e)
        {
            ////////////////////////////////////////////////////////////
            // clear any existing children from the canvas.

            cvsMainScreen.Children.Clear();

            ///////////////////////////////////////////////////////////
            // Get the directory where the level data is stored and
            // load the data in.

            string fileDir = txtLevelDir.Text;

            currentLevel = CLevelParser.ImportLevel(fileDir);
            gameTextures = CLevelParser.ImportTextures(fileDir);


            ///////////////////////////////////////////////////////////
            // Draw the set of wall and floor tiles for the current
            // level and the goal icon. This is part of the game
            // we do not expect to change as it cannot move.

            DrawLevel();


            //////////////////////////////////////////////////////////
            // Add a game state, this represents the position and velocity
            // of all the enemies and the player. Basically, anything
            // that is dynamic that we expect to move around.

            gameState = new CGameState(currentLevel.EnemyPositions.Count());


            ///////////////////////////////////////////////////////////
            // Set up the player to have the correct .bmp and set it to
            // its initial starting point. The player's position is stored
            // as a tile index on the Clevel class, this must be converted
            // to a pixel position on the game state.

            playerIcon        = new Image();
            playerIcon.Width  = CGameTextures.TILE_SIZE;
            playerIcon.Height = CGameTextures.TILE_SIZE;

            playerIcon.Source = gameTextures.PlayerIcon;

            cvsMainScreen.Children.Add(playerIcon);


            //////////////////////////////////////////////////////////
            // Create instances of the enemies and fires for display. We must do
            // this as each child on a canvas must be a distinct object,
            // we could not simply add the same image multiple times.

            enemyIcons = new Image[currentLevel.EnemyPositions.Count()];

            for (int i = 0; i < currentLevel.EnemyPositions.Count(); i++)
            {
                enemyIcons[i] = new Image();

                enemyIcons[i].Width  = CGameTextures.TILE_SIZE;
                enemyIcons[i].Height = CGameTextures.TILE_SIZE;

                enemyIcons[i].Source = gameTextures.EnemyIcon;

                cvsMainScreen.Children.Add(enemyIcons[i]);
            }


            fireIcons = new Image[currentLevel.FirePositions.Count()];

            for (int i = 0; i < currentLevel.FirePositions.Count(); i++)
            {
                fireIcons[i] = new Image();

                fireIcons[i].Width  = CGameTextures.TILE_SIZE;
                fireIcons[i].Height = CGameTextures.TILE_SIZE;

                fireIcons[i].Source = gameTextures.FireIcon;

                cvsMainScreen.Children.Add(fireIcons[i]);

                CPoint2i tilePosition = CLevelUtils.GetPixelFromTileCoordinates(new CPoint2i(currentLevel.FirePositions[i].X, currentLevel.FirePositions[i].Y));


                Canvas.SetLeft(fireIcons[i], tilePosition.X);
                Canvas.SetTop(fireIcons[i], tilePosition.Y);
            }

            loadTextures();
            ////////////////////////////////////////////////////////////
            // Set each instance of a dynamic object to its initial position
            // as defined by the current level object.

            InitialiseGameState();


            ////////////////////////////////////////////////////////////
            // Render the current game state, this will render the player
            // and the enemies in their initial position.

            RenderGameState();
        }
 private void LevelSaveBtn_Click(object sender, RoutedEventArgs e)
 {
     CLevelParser.ExportLevel(currentLevel, txtLevelDir.Text);
     CLevelParser.ExportTextures(gameTextures, txtLevelDir.Text);
 }