/// <summary> /// Prevents a default instance of the <see cref="Game"/> class from being created. /// </summary> /// <param name="filename">The filename of game configuration</param> /// <param name="graphicObject"> IGraphic object</param> private Game(string filename, IGraphic graphicObject) { //Must be initialized in the first place LevelStarted = false; _paused = false; object[] gameSettings; //Getting main configuration using (BinaryReader loader = new BinaryReader(new FileStream(Environment.CurrentDirectory + "\\Data\\GameConfigs\\" + filename + ".tdgc", FileMode.Open, FileAccess.Read))) { _pathToLevelConfigurations = Environment.CurrentDirectory + "\\Data\\GameConfigs\\" + filename + ".tdlc"; SaveNLoad.LoadMainGameConf(loader, out _numberOfMonstersAtLevel, out _goldForSuccessfulLevelFinish, out _goldForKillMonster, out gameSettings); loader.Close(); } //Lists initialization _monsters = new List<Monster>(); _towers = new List<Tower>(); _towerParamsForBuilding = new List<TowerParam>(); _missels = new List<Missle>(); //Additional initialization Lose = false; _levelsNumber = (int)gameSettings[2]; Gold = (int)gameSettings[4]; NumberOfLives = (int)gameSettings[5]; //Map loading _map = new Map(Environment.CurrentDirectory + "\\Data\\Maps\\" + Convert.ToString(gameSettings[0]).Substring(Convert.ToString(gameSettings[0]).LastIndexOf('\\')), true); #region Loading of tower configurations DirectoryInfo diForLoad = new DirectoryInfo(Environment.CurrentDirectory + "\\Data\\Towers\\" + Convert.ToString(gameSettings[1])); FileInfo[] towerConfigs = diForLoad.GetFiles(); _towerConfigsHashes = new List<string>(); var iconsForShop = new List<Bitmap>(); foreach (FileInfo i in towerConfigs.Where(i => i.Extension == ".tdtc")) { if (_towerParamsForBuilding.Count == 90)//if number of towers>90. Hmm. Bad news for designer break; using (FileStream towerConfLoadStream = new FileStream(i.FullName, FileMode.Open, FileAccess.Read)) { IFormatter formatter = new BinaryFormatter(); _towerParamsForBuilding.Add((TowerParam)formatter.Deserialize(towerConfLoadStream)); iconsForShop.Add(_towerParamsForBuilding.Last().Icon); } _towerConfigsHashes.Add(Helpers.GetMD5ForFile(i.FullName)); } /*_pageCount = (_towerParamsForBuilding.Count % Settings.ElemSize == 0) ? _towerParamsForBuilding.Count / Settings.ElemSize : (_towerParamsForBuilding.Count / Settings.ElemSize) + 1;*/ _towerShop = new TowerShop(iconsForShop.AsReadOnly(), Settings.TowerShopPageSelectorPos, Settings.TowerShopPagePos); /*var lol = new List<Bitmap>(IconsForShop.AsReadOnly()); lol.Clear();*/ #endregion Loading of tower configurations #if Debug Gold = 1000; #endif _graphicEngine = new GraphicEngine(graphicObject); _uiMenu = new GameUIMenu(graphicObject); _pauseMenu = null; Scaling = 1F; }
/// <summary> /// Shows the map from map configuration file /// </summary> /// <param name="fileName">Name of the file.</param> /// <exception cref="ArgumentNullException"></exception> /// <returns>true if map loaded successfully</returns> private bool ShowMapByFileName(string fileName) { try { if (fileName == string.Empty) throw new ArgumentNullException("fileName"); PBMap.Image = null; PBMap.Size = new Size(0, 0); string mapNameGetting = fileName.Substring(fileName.LastIndexOf('\\') + 1); LMapName.Text = string.Format("Map name: {0}", mapNameGetting.Substring(0, mapNameGetting.IndexOf('.'))); Map map = new Map(fileName); Bitmap tmpImg = new Bitmap(Convert.ToInt32(map.Width * Settings.ElemSize * map.Scaling), Convert.ToInt32(map.Height * Settings.ElemSize * map.Scaling)); Graphics canva = Graphics.FromImage(tmpImg);//canva map.ShowOnGraphics(canva); PBMap.Width = Convert.ToInt32(map.Width * Settings.ElemSize * map.Scaling);//sizes setting PBMap.Height = Convert.ToInt32(map.Height * Settings.ElemSize * map.Scaling); PBMap.Image = tmpImg; PBMap.Tag = fileName; BNewGameConfig.Tag = 1; } catch (Exception e) { MessageBox.Show("Map loading error" + e.Message); return false; } MessageBox.Show("Map loaded Successful"); return true; }