예제 #1
0
파일: Game.cs 프로젝트: GoodSky/Sim-U
        /// <summary>
        /// Game Constructor-
        /// set the game constants
        /// NOTE: at some point the constants should probably be read from a configuration file
        /// </summary>
        public Game()
        {
            // Load the game settings
            GameConfig = new Config(@"Configs\GameSettings.ini");

            // Set up logging
            if (GameConfig.GetBoolValue("DebugLogging", false))
            {
                string logPath = GameConfig.GetStringValue("DebugLoggingPath", null);
                int logsToKeep = GameConfig.GetIntValue("DebugLoggingToKeep", 3);
                if (logPath != null)
                {
                    Logger.Initialize(logPath, logsToKeep);
                }
            }

            // Set up the graphics device
            Graphics = new GraphicsDeviceManager(this);
            Graphics.PreferredBackBufferWidth = Constants.WINDOW_WIDTH;
            Graphics.PreferredBackBufferHeight = Constants.WINDOW_HEIGHT;
            Graphics.IsFullScreen = GameConfig.GetBoolValue("FullScreen", false);
            Graphics.ApplyChanges();

            Content.RootDirectory = "Content";

            // Window Properties
            this.IsMouseVisible = true;
            this.Window.Title = "University Simulator 2014";
            this.Window.AllowUserResizing = false;
        }
예제 #2
0
        /// <summary>
        /// Load a path from Config
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        private PathData LoadPath(Config config, string key)
        {
            // Create the building data
            PathData data = new PathData();
            data.Key = key;
            data.Name = config.GetStringValue(key, "title", "");
            data.Type = DataType.Path;
            data.InToolbox = config.GetBoolValue(key, "toolbox", false);
            data.ImageName = config.GetStringValue(key, "image", "");
            data.IconImageName = config.GetStringValue(key, "icon", null);
            data.Cost = config.GetIntValue(key, "cost", 0);

            return data;
        }
예제 #3
0
        /// <summary>
        /// Load a building from Config
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        private BuildingData LoadBuilding(Config config, string key)
        {
            // Create the building data
            BuildingData data = new BuildingData();
            data.Key = key;
            data.Name = config.GetStringValue(key, "title", "");
            data.Type = DataType.Building;
            data.InToolbox = config.GetBoolValue(key, "toolbox", false);
            data.ImageName = config.GetStringValue(key, "image", "");
            data.IconImageName = config.GetStringValue(key, "icon", null);
            data.FootprintImageName = config.GetStringValue(key, "footprint", "");
            data.ImageOffsetY = config.GetIntValue(key, "imageOffsetY", 0);
            data.ImageOffsetX = config.GetIntValue(key, "imageOffsetX", 0);
            data.FootprintOffsetY = config.GetIntValue(key, "footprintOffsetY", 0);
            data.FootprintOffsetX = config.GetIntValue(key, "footprintOffsetX", 0);
            data.Cost = config.GetIntValue(key, "cost", 0);
            data.Specs = new Dictionary<BuildingStat, int>();

            // Load the specs into an enum and int pair
            var specsString = config.GetStringValue(key, "specs", "");
            if (!string.IsNullOrEmpty(specsString))
            {
                var specs = specsString.Split(';');
                foreach (var spec in specs)
                {
                    var nameValue = spec.Split(',');
                    if (nameValue.Length != 2)
                    {
                        string msg = string.Format("Invalid Catalog.ini file. Element {0} ({1}) did not have a name and value.", key, spec);
                        Logger.Log(LogLevel.Error, "LoadingCatalog", msg);
                        throw new Exception(msg);
                    }

                    try
                    {
                        BuildingStat stat = (BuildingStat)Enum.Parse(typeof(BuildingStat), nameValue[0]);
                        int value = Int32.Parse(nameValue[1]);
                        data.Specs.Add(stat, value);
                    }
                    catch (Exception e)
                    {
                        var msg = string.Format("Invalid Catalog.ini file. Element {0} ({1}) was an unrecognized BuildingStat-Int pair. ex: {2}", e.Message);
                        Logger.Log(LogLevel.Error, "LoadingCatalog", msg);
                        throw new Exception(msg);
                    }
                }
            }

            return data;
        }
예제 #4
0
        /// <summary>
        /// Create the campus catalog
        /// </summary>
        public CampusCatalog()
        {
            this.catalog = new Dictionary<string, Data>();

            Config config = new Config(@"Configs\Catalog.ini");
            foreach (var building in config.SectionNames())
            {
                try
                {
                    if (building.Equals(Constants.DEFAULT))
                    {
                        continue;
                    }

                    string typeString = config.GetStringValue(building, "type", null);
                    if (typeString == null)
                    {
                        Logger.Log(LogLevel.Error, "LoadingCatalog", string.Format("Failed to load {0} from Catalog.ini because it did not have a type defined.", building));
                    }

                    Data data = null;
                    DataType type = (DataType)Enum.Parse(typeof(DataType), typeString);

                    if (type == DataType.Building)
                    {
                        data = this.LoadBuilding(config, building);
                    }
                    else if (type == DataType.Path)
                    {
                        data = this.LoadPath(config, building);
                    }

                    if (data != null)
                    {
                        Logger.Log(LogLevel.Info, "LoadingCatalog", string.Format("Loaded Element {0}- {1}", building, data));
                        this.catalog.Add(data.Key, data);
                    }
                    else
                    {
                        Logger.Log(LogLevel.Error, "LoadingCatalog", string.Format("null data element {0}", building));
                    }
                }
                catch (Exception e)
                {
                    Logger.Log(LogLevel.Error, "LoadingCatalog", string.Format("Error loading building {0}. Exception: {1}", building, e));
                }
            }
        }
예제 #5
0
파일: GameScreen.cs 프로젝트: GoodSky/Sim-U
 /// <summary>
 /// Create an instance of a game room.
 /// Use the config file to set up information about this room.
 /// </summary>
 /// <param name="configFile"></param>
 public GameScreen(string configFile)
 {
     this.roomConfig = new Config(configFile);
 }