// Generates a turnlist by grabbing all monsters and characters in the grid then arranging them by speed. public List <BattleTile> ComputeTurnList() { // Visit every tile in the Grid to identify all potential fighters List <BattleTile> turnList = new List <BattleTile>(); for (int i = 0; i < Grid.Count; i++) { for (int j = 0; j < Grid[i].Count; j++) { // If this tile is a fighter BattleTile tempTile = Grid[i][j]; if (tempTile.Type != "Tile") { // Identify where in the turnlist this fighter will be inserted. bool insterted = false; for (var k = 0; k < turnList.Count && !insterted; k++) { // If the fighter from the grid is faster than the current fighter in the turnlist, insert the fighter if (tempTile.GetSpeed() > turnList[k].GetSpeed()) { insterted = true; turnList.Insert(k, tempTile); } // If the fighter from the grid is of equal speed as the fighter in the turnlist, compare levels else if (tempTile.GetSpeed() == turnList[k].GetSpeed()) { // If the fighter from the grid is of a higher level than the current fighter in the turnlist, insert the fighter if (tempTile.GetLevel() > turnList[k].GetLevel()) { insterted = true; turnList.Insert(k, tempTile); } // If the fighter from the grid is of equal speed as the fighter in the turnlist, compare experience else if (tempTile.GetLevel() == turnList[k].GetLevel()) { // If the fighter from the grid is of a higher experience than the current fighter in the turnlist, insert the fighter // Experience for characters is their current XP and the experience for monsters is their current ExpToGive. if (tempTile.GetExperience() > turnList[k].GetExperience()) { insterted = true; turnList.Insert(k, tempTile); } // If the fighter from the grid is of equal speed as the fighter in the turnlist, compare type else if (tempTile.GetExperience() == turnList[k].GetExperience()) { // If the fighter from the grid is a Character and the current fighter in the turnlist is a Monster, insert the fighter if (tempTile.Type == "Character" && turnList[k].Type == "Monster") { insterted = true; turnList.Insert(k, tempTile); } // If the fighter from the grid is of equal type as the fighter in the turnlist, compare name else if (tempTile.Type == turnList[k].Type) { // If the fighter from the grid does not have the same name as the current fighter in the turnlist, check alphabetical order if (tempTile.Name != turnList[k].Name) { List <string> judge = new List <string> { tempTile.Name, turnList[k].Name }; judge.Sort(); // If the fighter from the grid is first based on alphabetical order for both names, insert the fighter if (tempTile.Name == judge[0]) { insterted = true; turnList.Insert(k, tempTile); } // If the fighter from the grid is second based on alphabetical order for both names, check the next fighter. } // If they are equal then check the next fighter because this fighter came first in the list order. } } } } } // If the fighter is the slowest among the fighters in the turnlist if (!insterted) { // Insert the fighter to the end of the list. turnList.Add(tempTile); } } } } return(turnList); }