static void Main() { //1 WarriorFactory warriorFactory = new SwordFactory(); List <IElf> elves = warriorFactory.CreateElf(4); //2 elves.Add(WarELfLord.getInstance()); Printer.PrintWarrior(elves); //3 Builder builder = new ConcreteBuilder(); Director director = new Director(builder); director.Construct(); Castle castle = builder.GetResult(); Console.WriteLine(castle.ToString()); //4 Archer archer = new OgreArcher(7); Archer archerClone = archer.Clone(); Console.WriteLine(archer.Damage + " " + archerClone.Damage); archer = new ElfArcher(9); archerClone = archer.Clone(); Console.WriteLine(archer.Damage + " " + archerClone.Damage); //1 SwordElf swordElf = new SwordElf(); ImprovedSwordElf improvedSwordElf = new Adapter(swordElf); improvedSwordElf.Function(); Console.WriteLine(swordElf.HitPoints + " " + improvedSwordElf.HitPoints); //2 BuildMaterial buildMaterial = new Wood(); buildMaterial = new WithTiles(buildMaterial); Console.WriteLine(buildMaterial.Name + " price: " + buildMaterial.GetCost()); buildMaterial = new Stone(); Console.WriteLine(buildMaterial.Name + " price: " + buildMaterial.GetCost()); buildMaterial = new WithCreepers(buildMaterial); Console.WriteLine(buildMaterial.Name + " price: " + buildMaterial.GetCost()); //3 Map map = new Map("Europe"); Country country = new Country("Germany"); Map subMap = new Map("Baltic"); Country balticCountry = new Country("Lithuania"); subMap.AddComponent(balticCountry); map.AddComponent(country); map.AddComponent(subMap); Console.WriteLine(); var item = map.Find("Lithuania"); if (item != null) { item.Draw(); } else { Console.WriteLine("null"); } Console.WriteLine(); item = map.Find("Lidgdfg"); if (item != null) { item.Draw(); } else { Console.WriteLine("null"); } Console.WriteLine(); map.Draw(); //1 Invoker invoker = new Invoker(); Receiver receiver = new Receiver(); JumpCommand jumpCommand = new JumpCommand(receiver); invoker.SetCommand(jumpCommand); invoker.Run(); FireCommand fireCommand = new FireCommand(receiver); invoker.SetCommand(fireCommand); invoker.Run(); //2 var input = new Input(Console.ReadKey()); var hero = new MyObject(new Jumping()); hero.HandleRequest(input); hero.GetObjectStatus(); //3 var improvedSwordOgre = new ImprovedSwordOgre(); var history = new GameHistory(); improvedSwordOgre.Injure(); Console.WriteLine(improvedSwordOgre.HitPoints + " " + improvedSwordOgre.Damage); var improvedSwordOgreMemento = new ImprovedSwordOgreMemento(improvedSwordOgre.HitPoints, improvedSwordOgre.Damage); history.History.Push(improvedSwordOgreMemento); improvedSwordOgre.Injure(); Console.WriteLine(improvedSwordOgre.HitPoints + " " + improvedSwordOgre.Damage); //restoring improvedSwordOgre.HitPoints = improvedSwordOgreMemento.HitPoints; improvedSwordOgre.Damage = improvedSwordOgreMemento.Damage; Console.WriteLine(improvedSwordOgre.HitPoints + " " + improvedSwordOgre.Damage); //4 Attack attack = new Attack(); Defender defender1 = new Defender(22, attack); Defender defender2 = new Defender(27, attack); attack.AddObserver(defender1); attack.AddObserver(defender2); attack.UpdateStatus(); //WarriorFactory guardFactory = new GuardsFactory(); //List<IOgre> ogres = guardFactory.CreateOgre(2); var ogre = new GuardOgre(); ogre.Execute(); ogre.Damaged(30); ogre.Execute(); ogre.Damaged(50); ogre.Execute(); //ogres.FirstOrDefault().strategy = //foreach(IOgre ogre in ogres) //{ // ogre.strategy. //} Console.ReadKey(); }
public static void LoadLists(Game myGame) { enemyList = new List <IEnemy>(); itemList = new List <IItem>(); blockList = new List <IBlock>(); enemyPipeList = new List <IEnemy>(); itemPipeList = new List <IItem>(); blockPipeList = new List <IBlock>(); bgList = new List <IBg>(); StreamReader levelFile = new StreamReader( Path.Combine(Directory.GetCurrentDirectory(), "Content", "Levels", "Level1-1.txt") ); StreamReader bonusLevelFile = new StreamReader( Path.Combine(Directory.GetCurrentDirectory(), "Content", "Levels", "Level1-1BONUS.txt") ); String inComingLine; int posRow = zero; while (!levelFile.EndOfStream) { inComingLine = levelFile.ReadLine(); String[] target = inComingLine.Split(','); int posCol = zero; while (posCol < target.Length) { if (target[posCol].Equals("brick")) { IBlock block = new Brick(myGame, posCol, posRow); blockList.Add(block); } else if (target[posCol].Equals("crack")) { IBlock block = new Crack(myGame, posCol, posRow); blockList.Add(block); } else if (target[posCol].Equals("diamond")) { IBlock block = new Diamond(myGame, posCol * stdSpriteSize, posRow * stdSpriteSize); blockList.Add(block); } else if (target[posCol].Equals("question")) { IBlock block = new Question(myGame, posCol, posRow); blockList.Add(block); } else if (target[posCol].Equals("questionRedM")) { Question block = new Question(myGame, posCol, posRow); block.contain = Utility.items.redM; blockList.Add(block); } else if (target[posCol].Equals("questionFireF")) { Question block = new Question(myGame, posCol, posRow); block.contain = Utility.items.flower; blockList.Add(block); } else if (target[posCol].Equals("questionCoin")) { Question block = new Question(myGame, posCol, posRow); block.contain = Utility.items.coin; blockList.Add(block); } else if (target[posCol].Equals("questionGreenM")) { Question block = new Question(myGame, posCol, posRow); block.contain = Utility.items.greenM; blockList.Add(block); } else if (target[posCol].Equals("questionBat")) { Question block = new Question(myGame, posCol, posRow); block.contain = Utility.items.bat; blockList.Add(block); } else if (target[posCol].Equals("used")) { IBlock block = new Used(myGame, posCol, posRow); blockList.Add(block); } else if (target[posCol].Equals("invisible")) { IBlock block = new Invisible(myGame, posCol, posRow); blockList.Add(block); } else if (target[posCol].Equals("standardPipe")) { Pipe block = new Pipe(myGame, posCol, posRow); blockList.Add(block); IEnemy enemy = new PiranhaPlant(myGame, block.drawLoc.X, block.drawLoc.Y); enemyList.Add(enemy); } else if (target[posCol].Equals("standardPipeTransition")) { IBlock block = new PipeTransition(myGame, posCol, posRow); blockList.Add(block); } else if (target[posCol].Equals("popPipe")) { IBlock block = new PopPipe(myGame, posCol, posRow); blockList.Add(block); } else if (target[posCol].Equals("pipeNeck")) { IBlock block = new PipeNeck(myGame, posCol, posRow); blockList.Add(block); } else if (target[posCol].Equals("smallCastle")) { IBlock block = new Castle(myGame, posCol, posRow); blockList.Add(block); } else if (target[posCol].Equals("flagpole")) { IItem item = new Flagpole(myGame, posCol, posRow); itemList.Add(item); IBlock block = new Diamond(myGame, (posCol * stdSpriteSize) - six, (posRow * stdSpriteSize) + oneHundredTwentyEight); blockList.Add(block); } else if (target[posCol].Equals("coin")) { IItem item = new Coin(myGame, posCol * stdSpriteSize, posRow * stdSpriteSize); itemList.Add(item); } else if (target[posCol].Equals("star")) { IItem item = new Star(myGame, posCol * stdSpriteSize, posRow * stdSpriteSize); itemList.Add(item); } else if (target[posCol].Equals("flower")) { IItem item = new FireFlower(myGame, posCol * stdSpriteSize, posRow * stdSpriteSize); itemList.Add(item); } else if (target[posCol].Equals("redMushroom")) { IItem item = new RedMushroom(myGame, posCol * stdSpriteSize, posRow * stdSpriteSize); itemList.Add(item); } else if (target[posCol].Equals("greenMushroom")) { IItem item = new GreenMushroom(myGame, posCol * stdSpriteSize, posRow * stdSpriteSize); itemList.Add(item); } else if (target[posCol].Equals("smallFireBeam")) { IItem item = new SmallSpinFireBeam(myGame, posCol * stdSpriteSize, posRow * stdSpriteSize); itemList.Add(item); IBlock block = new Used(myGame, posCol, posRow); blockList.Add(block); } else if (target[posCol].Equals("mediumFireBeam")) { IItem item = new MediumSpinFireBeam(myGame, posCol * stdSpriteSize, posRow * stdSpriteSize); itemList.Add(item); } else if (target[posCol].Equals("largeFireBeam")) { IItem item = new LargeSpinFireBeam(myGame, posCol * stdSpriteSize, posRow * stdSpriteSize); itemList.Add(item); } else if (target[posCol].Equals("goomba")) { IEnemy enemy = new Goomba(myGame, posCol, posRow); enemyList.Add(enemy); } else if (target[posCol].Equals("koopa")) { IEnemy enemy = new Koopa(myGame, posCol, posRow); enemyList.Add(enemy); } else if (target[posCol].Equals("oneCloud")) { IBg bg = new Bg(myGame, myGame.oneCloudBgElement, posCol, posRow); bgList.Add(bg); } else if (target[posCol].Equals("threeClouds")) { IBg bg = new Bg(myGame, myGame.threeCloudsBgElement, posCol, posRow); bgList.Add(bg); } else if (target[posCol].Equals("oneBush")) { IBg bg = new Bg(myGame, myGame.oneBushBgElement, posCol, posRow); bgList.Add(bg); } else if (target[posCol].Equals("threeBushes")) { IBg bg = new Bg(myGame, myGame.threeBushesBgElement, posCol, posRow); bgList.Add(bg); } else if (target[posCol].Equals("smallMountain")) { IBg bg = new Bg(myGame, myGame.smallMountainBgElement, posCol, posRow); bgList.Add(bg); } else if (target[posCol].Equals("bigMountain")) { IBg bg = new Bg(myGame, myGame.bigMountainBgElement, posCol, posRow); bgList.Add(bg); } else if (target[posCol].Equals("title")) { IBg bg = new Bg(myGame, myGame.titleScreen, posCol, posRow); bgList.Add(bg); } posCol++; } posRow++; } posRow = zero; while (!bonusLevelFile.EndOfStream) { inComingLine = bonusLevelFile.ReadLine(); String[] target = inComingLine.Split(','); int posCol = zero; while (posCol < target.Length) { if (target[posCol].Equals("blueBrick")) { IBlock block = new BlueBrick(myGame, posCol, posRow); blockPipeList.Add(block); } else if (target[posCol].Equals("blueCrack")) { IBlock block = new BlueCrack(myGame, posCol, posRow); blockPipeList.Add(block); } else if (target[posCol].Equals("coin")) { IItem item = new Coin(myGame, posCol * stdSpriteSize, posRow * stdSpriteSize); itemPipeList.Add(item); } else if (target[posCol].Equals("pipeNeck")) { IBlock block = new PipeNeck(myGame, posCol, posRow); blockPipeList.Add(block); } else if (target[posCol].Equals("sidePipe")) { IBlock block = new SidePipe(myGame, posCol, posRow); blockPipeList.Add(block); } else if (target[posCol].Equals("pipeNeck")) { IBlock block = new PipeNeck(myGame, posCol, posRow); blockPipeList.Add(block); } posCol++; } posRow++; } levelFile.Close(); bonusLevelFile.Close(); IComparer <IBlock> blockComp = new BlockComparer <IBlock>(); IComparer <IItem> itemComp = new ItemComparer <IItem>(); IComparer <IEnemy> enemyComp = new EnemyComparer <IEnemy>(); blockList.Sort(blockComp); itemList.Sort(itemComp); enemyList.Sort(enemyComp); blockPipeList.Sort(blockComp); itemPipeList.Sort(itemComp); enemyPipeList.Sort(enemyComp); }