Beispiel #1
0
 public GameState()
 {
     gameObjects  = new List <GameObject>();
     random       = new Random();
     fruitFactory = new FruitFactory();
     bonusFactory = new BonusFactory();
 }
Beispiel #2
0
    static void Main(string[] args)
    {
        var apple  = FruitFactory.CreateFruit(FruitType.Apple);
        var banana = FruitFactory.CreateFruit(FruitType.Banana);

        Console.WriteLine(apple.GetWeight());
        Console.WriteLine(banana.GetWeight());
    }
Beispiel #3
0
 public Classic() :
     base(new Position(ClassicMapConstants.MapWidth / 2, (ClassicMapConstants.MapHeight / 2) + (ClassicMapConstants.DistanceFromTheTop - ClassicMapConstants.DistanceFromTheLeft)), new Size(ClassicMapConstants.MapWidth, ClassicMapConstants.MapHeight))
 {
     this.InitBoard();
     this.playerFactory = new EnemyFactory();
     this.fruitFactory  = new FruitFactory();
     this.image         = ImageParser.Parse(GlobalConstants.ClassicMapImagePath);
 }
Beispiel #4
0
        /// <summary>
        /// 简单工厂模式
        /// </summary>
        public static void SimpleFactoryPatternMethods()
        {
            var apple  = FruitFactory.CreateInstance("Apple");
            var banana = FruitFactory.CreateInstance("Banana");

            Console.WriteLine($"苹果单价是:{apple.GetPrice()}");
            Console.WriteLine($"香蕉单价是:{banana.GetPrice()}");
        }
    static void Main(string[] args)
    {
        var       fruitFactory = new FruitFactory();
        FruitType fruitType    = AcquireFruit();
        IFruit    fruit        = fruitFactory.GetInstance(fruitType);

        fruit.Prepare();
        fruit.Eat();
    }
    public static AbstractFactory GetFactory(FactoryType factoryType)
    {
        switch (factoryType)
        {
        case FactoryType.Fruit:
            AbstractFactory fruitFactory = new FruitFactory();
            return(fruitFactory);

        case FactoryType.Veggie:
            AbstractFactory veggieFactory = new VeggieFactory();
            return(veggieFactory);
        }

        return(null);
    }
Beispiel #7
0
        static void Main(string[] args)
        {
            string   fullTypeName = typeof(Strawberry).AssemblyQualifiedName;
            AbsFruit absFruit2    = FruitFactory.CreateInstance <AbsFruit>(fullTypeName);

            absFruit2.Show();
            //C: \Users\Administrator\Documents\Visual Studio 2015\Projects\WebApplication3\ConsoleApplication2\DAL.dll

            System.Reflection.Assembly ass = Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory + "DAL.dll"); //加载DLL


            System.Type t = ass.GetType("lgk.DAL.tb_user");//获得类型
            Console.WriteLine("类型名:{0}", t.Name);
            Console.WriteLine("类全名:{0}", t.FullName);
            Console.WriteLine("命名空间:{0}", t.Namespace);
            Console.WriteLine("程序集名:{0}", t.Assembly);
            Console.WriteLine("模块名:{0}", t.Module);
            Console.WriteLine("基类名:{0}", t.BaseType);
            Console.WriteLine("是否类:{0}", t.IsClass);
            Console.WriteLine("类的公共成员:");
            Console.ReadKey();
            //MemberInfo[] members = t.GetMembers();
            //foreach (MemberInfo memberInfo in members)
            //{
            //    Console.WriteLine("{0}:{1}", memberInfo.MemberType, memberInfo);
            //}


            //string name = typeof(tt).AssemblyQualifiedName;
            //System.Type t1 = Type.GetType(name);
            ////System.Type t2 = typeof(MyClass);

            //object o = System.Activator.CreateInstance(t1);//创建实例
            //System.Reflection.MethodInfo mi = t1.GetMethod("gg1");//获得方法
            //mi.Invoke(o,new string[] {"test" });//调用方法


            // //System.Reflection.MethodInfo mi1 = t.GetMethod("Fun_2");
            // //mi1.Invoke(t, new object[] { , "alert('测试反射机制1')" });//调用方法



            // Type type = typeof(xx);

            //var a = type.GetMethods();
            //var b = type.GetProperties();
            //var c = type.GetCustomAttributes(true);
        }
        public static void Main()
        {
            var caisse       = new Caisse();
            var fruitfactory = new FruitFactory();

            try
            {
                var input = Console.ReadLine();
                while (input != "exit")
                {
                    caisse.Enregistrer(fruitfactory.Create(input));
                    Console.WriteLine("-> " + caisse.GetPrix());
                    input = Console.ReadLine();
                }
            }
            catch (InvalidDataException ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }
        }
Beispiel #9
0
        /// <summary>
        /// Met à jour le fruit, en gardant l'ancien fruit ou en créant un autre
        /// </summary>
        /// <param name="fruit">fruit à Mettre à jour</param>
        /// <param name="isFruitEat">Indique si le fruit a été mangé</param>
        /// <param name="fruitFactory">Objet servant à rectéer un nouveau fruit si nécessaire</param>
        /// <param name="gameArea">La zone de jeu</param>
        /// <param name="score">le score à mettre à jour</param>
        /// <returns>Le fruit mis à jour</returns>
        public Fruit UpdateFruit(Fruit fruit, bool isFruitEat, FruitFactory fruitFactory, GameArea gameArea, Score score, Snake snake)

        {
            if (Game.isFruitEat)
            {
                fruit             = fruitFactory.CreateFruit(gameArea, snake);
                score.ScoreValue += fruit.earnedPoints;
                EattingFood.StartSound();
            }
            else
            {
                if (fruit.existingTicksLeft == 0)
                {
                    FruitView.ClearFruit(fruit);
                    fruit = fruitFactory.CreateFruit(gameArea, snake);
                }
                else
                {
                    fruit.existingTicksLeft--;
                }
            }
            return(fruit);
        }
 public FruitEater()
 {
     this.myFruit      = new Arraylist();
     this.myFruitMaker = new FruitFactory();
 }
 static void Main(string[] args)
 {
     var apple = FruitFactory.CreateFruit(FruitType.Apple);
Beispiel #12
0
        /// <summary>
        /// exécute le contrôleur principal
        /// </summary>
        public static void Execute()
        {
            //*************************SETUP*************************
            //Model
            GameArea     gameAreaModel = new GameArea(Game.widthArea, Game.heightArea);
            Snake        snakeModel    = new Snake();
            Score        scoreModel    = new Score();
            FruitFactory fruitFactory  = new FruitFactory();
            Fruit        fruitModel    = fruitFactory.CreateFruit(gameAreaModel, snakeModel);

            //Controllers
            ControlKey          KeyController       = new ControlKey();
            SnakeControler      snakeControler      = new SnakeControler();
            FruitControler      fruitControler      = new FruitControler();
            CollisionController collisionController = new CollisionController();
            Clock clock = new Clock(Game.durationTick);

            Direction newDirection;

            //Views
            Console.Title = "BananaSnake game";
            TetrisMusic.StartMusic();
            GameAreaView.GameAera = gameAreaModel;
            GameAreaView.Draw();
            SnakeView.DrawAllSnake(snakeModel);

            //*************************READY*************************
            Console.ReadKey(true);

            //*************************START*************************
            clock.StartClock();
            while (Game.isGameOn)
            {
                //Récupère nouvelle direction serpent
                newDirection = KeyController.GetLastKey(snakeModel);

                if (!Game.isGamePaused)
                {
                    //Controler collisions
                    Game.isWallHit         = collisionController.IsHitWall(snakeModel, gameAreaModel, newDirection);//Mintenant inutile
                    Game.isFruitEat        = collisionController.IsHitFruit(snakeModel, fruitModel, newDirection, gameAreaModel);
                    Game.isSnakeHitHimself = collisionController.IsHitSnake(snakeModel);

                    //Act selon collisions

                    //Controller AvancerSerpent
                    fruitModel = fruitControler.UpdateFruit(fruitModel, Game.isFruitEat, fruitFactory, gameAreaModel, scoreModel, snakeModel);


                    //Controler serpent
                    snakeControler.MoveSnake(snakeModel,
                                             newDirection,
                                             Game.isFruitEat,
                                             gameAreaModel);

                    //Game Over
                    if (Game.isSnakeHitHimself)
                    {
                        Game.isGameOn = false;
                    }
                }
                //Dessiner jeu
                ViewStratege.DrawView(scoreModel, gameAreaModel, snakeModel, fruitModel);
                if (!Game.isGameOn)
                {
                    Console.ReadKey();
                }

                //Attendre prochain tick
                clock.WaitNextTick();
                //System.Threading.Thread.Sleep(Game.speed);
            }


            //Fin du jeu
        }