/// <summary> /// Gets a collection of games matched up with loose search terms. /// </summary> /// <param name="Name">The game title to search for</param> /// <param name="Platform">Filters results by platform</param> /// <param name="Genre">Filters results by genre</param> /// <returns>A collection of games that matched the search terms</returns> public static ICollection<GameSearchResult> GetGames(String Name, String Platform = "", String Genre = "") { XmlDocument doc = new XmlDocument(); doc.Load(@"http://thegamesdb.net/api/GetGamesList.php?name=" + Name + @"&platform=" + Platform + @"&genre=" + Genre); XmlNode root = doc.DocumentElement; IEnumerator ienum = root.GetEnumerator(); List<GameSearchResult> games = new List<GameSearchResult>(); // Iterate through all games XmlNode gameNode; while (ienum.MoveNext()) { GameSearchResult game = new GameSearchResult(); gameNode = (XmlNode)ienum.Current; IEnumerator ienumGame = gameNode.GetEnumerator(); XmlNode attributeNode; while (ienumGame.MoveNext()) { attributeNode = (XmlNode)ienumGame.Current; // Iterate through all game attributes switch (attributeNode.Name) { case "id": int.TryParse(attributeNode.InnerText, out game.ID); break; case "GameTitle": game.Title = attributeNode.InnerText; break; case "ReleaseDate": game.ReleaseDate = attributeNode.InnerText; break; case "Platform": game.Platform = attributeNode.InnerText; break; } } games.Add(game); } return games; }
/// <summary> /// Gets the data for a specific game. /// </summary> /// <param name="game">The game to return data for</param> /// <returns>A Game-object containing all the data about the game, or null if no game was found</returns> public static Game GetGame(GameSearchResult game) { return GetGame(game.ID); }