private Night parse(string[] lines) { Night night = new Night(); Game game = null; int contPartidas = 0; foreach (string line in lines) { if (line.Contains("InitGame")) { string[] words = line.Split('\\'); int gameNameIndex = Array.IndexOf(words, "mapname") + 1; int gameModeIndex = Array.IndexOf(words, "g_gametype") + 1; game = new Game() { Id = (++contPartidas).ToString(), GameMap = new Map() { Name = words[gameNameIndex], Mode = words[gameModeIndex] } }; continue; } else if (line.Contains("ShutdownGame")) { night.AddGame(game); game = null; } if (game != null) { string[] words = line.Split(';'); if (words[0] != string.Empty) { switch (words[0][words[0].Length - 1]) { case 'J': joinEvent(game, words); break; case 'D': damageEvent(game, words); break; case 'K': killEvent(game, words); break; } } } } return night; }
public Parser(string filePath) { string[] lines = File.ReadAllLines(filePath); night = parse(lines); }