Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            GameContainer container = new GameContainer("window", 650, 400); //constructor, creates new instance of the game
            Gravity       gravity   = new Gravity();

            container.GetWorld().SetPhysics(gravity);

            Kettle kettle = new Kettle();

            container.GetWorld().AddActor(kettle);
            kettle.SetPosition(100, 100);

            Stove stove = new Stove();

            container.GetWorld().AddActor(stove);
            stove.SetPosition(170, 170);
            stove.AddKettle(kettle);

            PowerSource source = new PowerSource();

            container.GetWorld().AddActor(source);
            source.SetPosition(200, 200);

            Crystal crystal = new Crystal(source);

            container.GetWorld().AddActor(crystal);
            crystal.SetPosition(200, 250);

            CrackedCrystal crackedCrystal = new CrackedCrystal(source, 3);

            container.GetWorld().AddActor(crackedCrystal);
            crackedCrystal.SetPosition(200, 350);

            Player player = new Player();

            container.GetWorld().AddActor(player);
            player.SetPhysics(true);
            player.SetPosition(220, 100);

            Enemy enemy = new Enemy(player, 5, 20, 20);

            container.GetWorld().AddActor(enemy);
            enemy.SetPhysics(true);
            enemy.SetPosition(300, 100);

            container.SetMap("resources/maps/map01.tmx");

            stove.AddKettle(kettle);



            container.Run(); //start the game, infinite loop, no change is accepted after this until the game ends
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            GameContainer container = new GameContainer("Remorseless winter", 1024, 768);

            //code here

            container.SetMap("resources/maps/map01.tmx");

            Gravity gravity = new Gravity(container.GetWorld());

            container.GetWorld().SetPhysics(gravity);

            Kettle kettle = new Kettle();

            kettle.SetPosition(200, 240);
            Stove stove = new Stove();

            stove.SetPosition(200, 285);
            IActor player = new Player();

            player.SetPosition(250, 200);
            ((Stove)stove).AddKettle((Kettle)kettle);
            stove.AddWood();
            stove.AddWood();
            stove.AddWood();
            stove.RemoveWood();

            container.GetWorld().AddActor(kettle);
            container.GetWorld().AddActor(stove);
            container.GetWorld().AddActor(player);

            /*Actor actor = kettle;
             *
             * if(powerSource is IObservable && Actor is IObserver)
             * {
             *  (IObservable)powerSource.Subscribe((IObserver)actor);
             * }*/

            PowerSource source = new PowerSource();

            source.SetPosition(100, 150);
            Crystal crystal = new Crystal((PowerSource)source);

            crystal.SetPosition(100, 100);

            CrackedCrystal crackedCrystal = new CrackedCrystal((PowerSource)source, 100);

            crackedCrystal.SetPosition(150, 100);

            IActor enemy = new Enemy(player);

            enemy.SetPosition(250, 500);
            player.SetPhysics(true);
            enemy.SetPhysics(true);

            container.GetWorld().AddActor(crackedCrystal);
            container.GetWorld().AddActor(source);
            container.GetWorld().AddActor(crystal);
            container.GetWorld().AddActor(enemy);

            //((IObservable)source).Subscribe((IObserver)crystal); - pre pridavani dalsieho observera na kontrolu

            List <IActor> actors = new List <IActor>();

            actors.Add(source);
            actors.Add(crystal);
            actors.Add(kettle);
            actors.Add(stove);
            //actor = actors.Find(a => a.GetName()); //select single entry
            //Console.WriteLine(actor);

            foreach (IActor actor in actors)
            {
                Console.WriteLine(actor.GetType());
            }


            //run game with current settings
            container.Run();
        }