示例#1
0
 public virtual void createCity(IPlayer currPlayer, String name)
 {
     City newCity = new City(currPlayer, Case);
     newCity.Name = name;
     Case.City = newCity;
     currPlayer.Cities.Add(newCity);
     Case.removeUnit(this);
 }
示例#2
0
        public CityViewModel(City c)
        {
            c.PropertyChanged += new PropertyChangedEventHandler(delegate(object sender, PropertyChangedEventArgs args)
            {
                Name = ((City)sender).Name;
                Population = populationLabel(((City)sender).Population);
                OwnedMinerals = ownedMineralsLabel(((City)sender).OwnedMinerals);
                OwnedFoods = ownedMineralsLabel(((City)sender).OwnedFoods);
            });

            Name = c.Name;
            Population = populationLabel(c.Population);
            OwnedMinerals = ownedMineralsLabel(c.OwnedMinerals);
            OwnedFoods = ownedMineralsLabel(c.OwnedFoods);
        }
示例#3
0
        static void Main()
        {
            Engine engine = InitializeEngine();

            //TODO: Create implementation running code

            string saveDir = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                @"SimuEngine");

            if (!Directory.Exists(saveDir))
            {
                Directory.CreateDirectory(saveDir);
            }

            bool readFailed = false;
            bool createNew  = false;

            if (engine.SaveExists(saveDir))
            {
                Console.WriteLine("Found save file");
                bool useSave = YesNo("Do you wish to use the save?");

                if (useSave)
                {
                    try {
                        engine.Load(saveDir, engine.player.Actions);
                        Console.WriteLine("Deserialized from save file");
                    } catch (OutOfMemoryException e) {
                        Console.WriteLine("Ran out of memory while deserializing");
                        readFailed = true;
                        throw new SystemException("Ran out of memory while deserializing", e);
                    } catch (SerializationException ex) {
                        Console.WriteLine($"Error while deserializing ({ex}), deleting file.");
                        engine.CleanDir(saveDir);
                        readFailed = true;
                    }
                }
                else
                {
                    //City c = new City(350000, 100);
                    //engine.system.graph.Add(c);
                    //// c.NodeCreation(engine.system.graph);
                    createNew = true;
                }
            }
            else
            {
                Console.WriteLine("No saved system found");
            }

            if (engine.system.graph.Count.Nodes == 0 || readFailed || createNew)
            {
                Console.WriteLine("Creating a new system");

                City c = new City(350000, 100);
                c.Name = "Irak";
                engine.system.graph.Add(c);
                // c.NodeCreation(engine.system.graph);

                bool ser = YesNo("Initialization finished, serialize?");

                if (ser)
                {
                    Console.WriteLine("Serializing...");
                    try {
                        engine.Save(saveDir);
                        Console.WriteLine("Graph initialization complete");
                    } catch (IOException) {
                        Console.WriteLine("IO error while serializing, won't keep going");
                    } catch (OutOfMemoryException) {
                        Console.WriteLine("Ran out of memory while serializing, no serialisation");
                    }
                }
            }

            ExcelExport export   = new ExcelExport();
            FileInfo    saveFile = new FileInfo(
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
                             "excel_export.xlsx"));

            using (Renderer renderer = new Renderer(engine)) {
                renderer.OnTickFinished += export.OnTick;
                renderer.Run();
                while (true)
                {
                    try {
                        export.Save(saveFile);
                        break;
                    } catch (InvalidOperationException e) {
                        Console.WriteLine("Error saving excel_export.xslx file");
                        Console.WriteLine($"Exception: {e}");
                        bool retry = YesNo("Would you like to try again?");
                        if (!retry)
                        {
                            break;
                        }
                    }
                }
            }
        }