Exemple #1
0
    // Use this for initialization
    void Awake()
    {
        // elapsed is a help var for timing each second
        elapsed = 0f;

        // countries.json contains all country information
        string c = Application.streamingAssetsPath + "/countries.json";

        string countries = File.ReadAllText(c);

        Country[] countryarr = JsonHelper.FromJson <Country>(countries);

        // the json is parsed into a linked list
        LinkedList <Logic.Country> countrylist = new LinkedList <Logic.Country>();
        LinkedList <RandomEvent>   eventslist  = ReadInEvents();

        float amount = 0, production = 0;

        // Load game objects
        InfoPanel  panel = FindObjectOfType <InfoPanel>();
        Newsticker news  = FindObjectOfType <Newsticker>();

        infoBox = FindObjectOfType <ActionInfoBox>();
        change  = FindObjectOfType <SpeedChange>();

        // with random we give each country a own influence factor (between 0 and 1)
        random = new System.Random();

        // Get each country from the array, create a new Country object and save it in the linked list
        foreach (Country country in countryarr)
        {
            try
            {
                countrylist.AddLast(new Logic.Country(Int32.Parse(country.id), country.code, country.name, Int32.Parse(country.population.Replace(",", "")), country.description, float.Parse(country.waste, CultureInfo.InvariantCulture.NumberFormat), country.rate, random
                                                      ));

                // get the starting values for amount and production of plastic
                amount     += float.Parse(country.waste, CultureInfo.InvariantCulture.NumberFormat);
                production += country.rate;
            }
            catch (FormatException err)
            {
                UnityEngine.Debug.Log(err.Message.ToString());
            }
        }

        // create new play object in which most of the game logic  is
        play = new Play(countrylist, eventslist, news);
        play.SetActions(ReadInActions());

        // DateTime objects to map real time to ingame time
        last  = DateTime.Now;
        print = DateTime.Parse("2019-01-01 00:00:00");

        // add starting values to map
        panel.changeWaste(amount, production);
        panel.changeCapital(30000000, 2500000);
        news.AddNews(new News("Start", "Producing this much of plastic waste will exterminate humans til 2070.", NewsType.Emergency));

        // initialize game with first play tick
        play.Tick(print);
    }
        static void Main(string[] args)
        {
            /*Strategy Pattern*/
            Console.WriteLine("Output for strategy pattern: \n");
            Person swordsman = new Swordsman(new SwordBehaviour());

            Console.WriteLine("The swordsman is:");
            swordsman.Fight();
            Console.WriteLine();
            Person bowman = new Bowman(new BowBehaviour());

            Console.WriteLine("The bowman is:");
            bowman.Fight();
            Console.WriteLine();
            bowman.SetWeapon(new KnifeBehaviour());
            Console.WriteLine("The bowman is:");
            bowman.Fight();
            Console.WriteLine();
            Console.WriteLine("______________________________________________________________________________");

            /*Observer Pattern*/
            Console.WriteLine("Output for observer pattern: \n");
            Newsticker        newsticker        = new Newsticker();                         //Instance of subject
            SmartwatchDisplay smartwatchDisplay = new SmartwatchDisplay(newsticker);        //instance of observer

            newsticker.RegisterObserver(smartwatchDisplay);                                 //register observer to subject

            newsticker.SetNews("Breaking News! Hamburger Software does not sell burgers!"); //update news and notify observers
            Console.WriteLine("______________________________________________________________________________");

            /*Decorator Pattern*/
            Console.WriteLine("Output for decorator pattern: \n");
            DungieGame dungieGame = new Worstiny();

            Console.WriteLine(dungieGame.Description + "\nPrice: " + dungieGame.Price + "Euro");
            Console.WriteLine();
            dungieGame = new GoodDLC(dungieGame);
            Console.WriteLine(dungieGame.Description + "\nPrice: " + dungieGame.Price + "Euro");
            Console.WriteLine();
            dungieGame = new EvenBetterDLC(dungieGame);
            Console.WriteLine(dungieGame.Description + "\nPrice: " + dungieGame.Price + "Euro");
            Console.WriteLine("______________________________________________________________________________");

            /*Factory Method Pattern*/
            Console.WriteLine("Output for factory method pattern: \n");
            DeviceFactory factory = new DeviceFactory();

            Factory_Method_Pattern.IDevice device = factory.MakeDevice(Factory_Method_Pattern.DeviceType.PC);
            Console.WriteLine("Factory created device:");
            Console.WriteLine(device.Name);
            Console.WriteLine();
            Console.WriteLine("______________________________________________________________________________");

            /*Abstract Factory Pattern*/
            Console.WriteLine("Output for abstract factory pattern: \n");

            AbstractStore yStore = new YStore();
            Device        pineappleSmartphone = yStore.OrderDevice(Abstract_Factory_Pattern.DeviceType.Smartphone);

            Console.WriteLine("Peter received his " + pineappleSmartphone.Name + "!");
            Console.WriteLine();

            AbstractStore jupiterStore = new JupiterStore();

            Device macroComputer = jupiterStore.OrderDevice(Abstract_Factory_Pattern.DeviceType.Computer);

            Console.WriteLine("Chris received his " + macroComputer.Name + "!");
            Console.WriteLine("______________________________________________________________________________");

            /*Singleton Pattern*/
            Console.WriteLine("Output for singleton pattern: \n");
            BasicSingleton basicSingleton = BasicSingleton.CreateInstance;

            Console.WriteLine(basicSingleton.Text);


            Console.ReadLine();
        }