/// <summary>
        /// Generates the source code in C# for the game defined by the project.
        /// </summary>
        /// <param name="textWriter">The <see cref="TextWriter"/> for writing the source code of the game.</param>
        /// <param name="buildType">Type of the build.</param>
        public void Generate(TextWriter textWriter, BuildType buildType)
        {
            writer = textWriter;

            // header
            GenerateUsingNamespaces();

            // namespace of the game
            writer.WriteLine("namespace GameUsingPlatformGameCreatorEditor");
            writer.WriteLine("{");

            // class with main method
            GenerateProgram();

            // game class
            writer.WriteLine(@"    class GameUsingPlatformGameCreator : PhysicsGame
    {
        public GameUsingPlatformGameCreator()
            : base()
        {");

            // size of the game window
            writer.WriteLine("graphics.PreferredBackBufferWidth = {0};", Project.Singleton.Settings.GameWindowWidth);
            writer.WriteLine("graphics.PreferredBackBufferHeight = {0};", Project.Singleton.Settings.GameWindowHeight);

            // fullscreen
            if (Project.Singleton.Settings.GameIsFullScreen)
            {
                writer.WriteLine("graphics.IsFullScreen = true;");
            }

            // content directory of the game
            writer.WriteLine(@"Content.RootDirectory = @""{0}"";", buildType == BuildType.Release ? "Content" : Project.Singleton.ContentDirectory);
            writer.WriteLine(@"        }

        protected override void Initialize()
        {
            base.Initialize();
");

            // start with the game with the current scene
            writer.WriteLine(@"            screenManager.AddScreen(new {0}());", SceneGenerator.GetSceneFullClassName(Project.Singleton.Scenes.SelectedScene));
            writer.WriteLine(@"        }
    }");

            SceneGenerator sceneGenerator = new SceneGenerator();

            // content for all scenes
            sceneGenerator.GenerateGlobalContent(textWriter, buildType);

            // scenes
            foreach (Scene scene in Project.Singleton.Scenes)
            {
                sceneGenerator.Generate(scene, textWriter, buildType);
            }

            // end of namespace of the game
            writer.WriteLine("}");
        }
        /// <summary>
        /// Gets the specified variable value in string.
        /// </summary>
        /// <param name="variable">The variable to get value from.</param>
        /// <returns>Value of the specified variable.</returns>
        private string GetVariableValue(IVariable variable)
        {
            switch (variable.VariableType)
            {
            case VariableType.Actor:
                Debug.Assert(variable is ActorVar, "Invalid actor variable class.");
                ActorVar actorVar = variable as ActorVar;

                if (actorVar.Value != null)
                {
                    return(GetActorValue(actorVar.Value));
                }
                else
                {
                    return(actorVar.Owner ? "this" : "null");
                }

            case VariableType.ActorType:
                Debug.Assert(variable is ActorTypeVar, "Invalid actor type variable class.");

                return(((ActorTypeVar)variable).Value.Value.ToString());

            case VariableType.Bool:
                Debug.Assert(variable is BoolVar, "Invalid bool variable class.");

                return(((BoolVar)variable).Value ? "true" : "false");

            case VariableType.Float:
                Debug.Assert(variable is FloatVar, "Invalid float variable class.");

                return(String.Format("{0}f", ((FloatVar)variable).Value));

            case VariableType.Int:
                Debug.Assert(variable is IntVar, "Invalid int variable class.");

                return(((IntVar)variable).Value.ToString());

            case VariableType.String:
                Debug.Assert(variable is StringVar, "Invalid string variable class.");

                return(String.Format(@"""{0}""", ((StringVar)variable).Value));

            case VariableType.Vector2:
                Debug.Assert(variable is Vector2Var, "Invalid Vector2 variable class.");

                return(String.Format("new Vector2({0}f, {1}f)", ((Vector2Var)variable).Value.X, ((Vector2Var)variable).Value.Y));

            case VariableType.Sound:
                Debug.Assert(variable is SoundVar, "Invalid Sound variable class.");

                if (((SoundVar)variable).Value == null)
                {
                    return("null");
                }
                else
                {
                    return(String.Format(@"Screen.Content.Load<SoundEffect>(""{0}"")", ((SoundVar)variable).Value.Id));
                }

            case VariableType.Song:
                Debug.Assert(variable is SoundVar, "Invalid Song variable class.");

                if (((SoundVar)variable).Value == null)
                {
                    return("null");
                }
                else
                {
                    return(String.Format(@"Screen.Content.Load<Song>(""{0}S"")", ((SoundVar)variable).Value.Id));
                }

            case VariableType.Path:
                Debug.Assert(variable is PathVar, "Invalid Path variable class.");

                if (((PathVar)variable).Value == null)
                {
                    return("null");
                }
                else
                {
                    return(String.Format("Screen.Paths.Get({0})", ((PathVar)variable).Value.Id));
                }

            case VariableType.Texture:
                Debug.Assert(variable is TextureVar, "Invalid Texture variable class.");

                if (((TextureVar)variable).Value == null)
                {
                    return("null");
                }
                else
                {
                    return(String.Format("(TextureData)Screen.GraphicsAssets.Get({0})", ((TextureVar)variable).Value.Id));
                }

            case VariableType.Animation:
                Debug.Assert(variable is AnimationVar, "Invalid Animation variable class.");

                if (((AnimationVar)variable).Value == null)
                {
                    return("null");
                }
                else
                {
                    return(String.Format("(AnimationData)Screen.GraphicsAssets.Get({0})", ((AnimationVar)variable).Value.Id));
                }

            case VariableType.Scene:
                Debug.Assert(variable is SceneVar, "Invalid scene variable class.");

                if (((SceneVar)variable).Value == null)
                {
                    return("null");
                }
                else
                {
                    return(String.Format("new {0}()", SceneGenerator.GetSceneFullClassName(((SceneVar)variable).Value)));
                }

            case VariableType.Key:
                Debug.Assert(variable is KeyVar, "Invalid key variable class.");

                return(String.Format("Keys.{0}", ((KeyVar)variable).Value.ToString()));

            default:
                Debug.Assert(true, "Not supported variable type.");
                return(null);
            }
        }