public static int CountMonsters(Board board) { var i = 0; var j = 0; NumberOfMonsters = 0; while (i < board.Boardx) { board.ArrayLength = board.BoardChars[i].Length; while (j < board.ArrayLength) { if (board.BoardChars[i][j] == 'y') NumberOfMonsters++; j++; } j = 0; i++; } return NumberOfMonsters; }
private static void Main() { var board = new Board(); var heroInstance = new Hero("Arkhana", 100, new Position(board), new Weapon("Excalibur", 500)); //var monstersPopulateInstance = new Monster(positions, board); //var randomMonster = Monster.GetMonstersTab(); var continueToPlay = true; // Console.WriteLine(randomMonster.Name + " " + randomMonster.HitPoints + " " + randomMonster.Weapon.Name); // var monsterInstance = new Monster("Bahamut", 2000, new Position(board), new Weapon()); // board.MoveOnBoard(heroInstance.Pos, monsterInstance.Pos); // board.MoveOnBoard(heroInstance.Pos, randomMonster.Pos); while (continueToPlay) { // ReSharper disable once ObjectCreationAsStatement //var monsterInstance = new Monster(/*new Position(board), board*/); MonsterInstance = new Monster(); //var randomMonster = Monster.GetMonstersTab(); //var randomMonster = Monster.GetMonstersTab(); var flee = true; board.MoveOnBoard(heroInstance.Pos); //var monstersPos = Position.MonsterPosTab; var inventoryInstance = new Inventory(); // Console.WriteLine("You have encountered " + monsterInstance.Name + " !"); /* Pour déterminer quel Monstre correspond à quel 'y', il suffit d'établir une relation entre les indexes du tableau rand et ceux du tableau MonsterPosTab. Ainsi, lors de l'appel du combat, on obtient bien le bon monstre qui correspond au bon 'y'. */ WriteLine("You have encountered " + MonsterInstance.MonsterRand.Name + " !"); /*while ((heroInstance.HitPoints > 0) && (monsterInstance.HitPoints > 0)) { Turn(heroInstance, monsterInstance, inventoryInstance); }*/ while ((heroInstance.HitPoints > 0) && (MonsterInstance.MonsterRand.HitPoints > 0) && flee) { flee = Turn(heroInstance, MonsterInstance.MonsterRand, inventoryInstance); } if (heroInstance.HitPoints == 0) { continueToPlay = false; heroInstance.Defeated(); Clear(); } else if (heroInstance.HitPoints != 0 && flee) { MonsterInstance.MonsterRand.Defeated(); board.NumberOfSteps = 0; //monsterInstance.LstRand.RemoveAt(0); Clear(); board.DisplayBoard(); } else { board.NumberOfSteps = 0; Clear(); board.DisplayBoard(); } } }