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()); }
private void CreatingFruits() { creatorCounterPoints++; // this is around 4 seconds. if (creatorCounterPoints == creatorCounterMax) { creatorCounterPoints = 0; // we need to think where to put Tom and the state of bombing. I guess with a boolean bombing and every 30 seconds or so to make it true and if it is not bombing to do this below if it is bombing we are going to run another code. if (random.Next(10) > 8) { Bonus timeBonus = bonusFactory.CreateBonus("TimeBonus"); timeBonus.LoadContent(); gameObjects.Add(timeBonus); } else { // fruit switch (random.Next(6)) { case 0: Consumable fruitStrawberry = fruitFactory.CreateFruit("Strawberry"); fruitStrawberry.LoadContent(); gameObjects.Add(fruitStrawberry); break; case 1: Consumable fruitCherry = fruitFactory.CreateFruit("Cherry"); fruitCherry.LoadContent(); gameObjects.Add(fruitCherry); break; case 2: Consumable fruitCheese = fruitFactory.CreateFruit("Cheese"); fruitCheese.LoadContent(); gameObjects.Add(fruitCheese); break; case 3: Consumable fruitCake = fruitFactory.CreateFruit("Cake"); fruitCake.LoadContent(); gameObjects.Add(fruitCake); break; case 4: Consumable fruitMuffin = fruitFactory.CreateFruit("Muffin"); fruitMuffin.LoadContent(); gameObjects.Add(fruitMuffin); break; case 5: Consumable fruitSalami = fruitFactory.CreateFruit("Salami"); fruitSalami.LoadContent(); gameObjects.Add(fruitSalami); break; default: break; } } } }
/// <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); }
static void Main(string[] args) { var apple = FruitFactory.CreateFruit(FruitType.Apple);
/// <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 }