private void LoadNewGame() { try { GetSongPlayerSettings getSongPlayerNameFunction = new GetSongPlayerSettings(GetSongPlayerInfo); GetVideoPlayerSettings getMoviePlayerNameFunction = new GetVideoPlayerSettings(GetVidePlayerInfo); GameSettings settings = GameSettingsReader.GetGameSettings(chbRemovePlayedGames.Checked, getSongPlayerNameFunction, getMoviePlayerNameFunction); GenerateTabsForRounds(settings, lblTeam1Name.Text, lblTeam2Name.Text); m_Info.Team1Score = 0; m_Info.Team2Score = 0; } catch (Exception ex) { ShowErrorMessage(ex); } }
public SongRoundSettings(string songFileName, string answer, string settingsFilePath, string songsDirectory, GetSongPlayerSettings songPlayerNameGettingFunction) { if (string.IsNullOrEmpty(songFileName)) { throw new InvalidGameSettingsException("Nav norādīts dziesmas fails", settingsFilePath); } if (songPlayerNameGettingFunction == null) { throw new Exception("Song player name getting method must be specified"); } m_GetSongPlayerSettings += songPlayerNameGettingFunction; m_SongFileName = Path.Combine(songsDirectory, songFileName); if (!File.Exists(m_SongFileName)) { throw new InvalidGameSettingsException(string.Format("Dziesmas fails '{0}' neeksistē", m_SongFileName), settingsFilePath); } Answer = answer; }
public static GameSettings GetGameSettings(bool moveLoadeGame, GetSongPlayerSettings songPlayerNameGetterFunction, GetVideoPlayerSettings videoPlayerNameGetterFunction) { if (songPlayerNameGetterFunction == null) { throw new Exception("Song player name getting function must be specified"); } if (videoPlayerNameGetterFunction == null) { throw new Exception("Video player name getting function must be specified"); } string filePath; XmlDocument gameSettings = GetGameSettingsXml(out filePath); GameSettings settings = LoadAllRoundSettings(gameSettings, filePath, songPlayerNameGetterFunction, videoPlayerNameGetterFunction); if (moveLoadeGame) { string fileName = Path.GetFileName(filePath); string destFilePath = Path.Combine(DirectoryNames.PlayedGamesSettingsDirectory, fileName); File.Move(filePath, destFilePath); } return(settings); }
private static GameSettings LoadAllRoundSettings(XmlDocument settingsXml, string settingsFilePath, GetSongPlayerSettings songPlayerNameGetterFunction, GetVideoPlayerSettings videoPlayerNameGetterFunction) { GameSettings parsedSettings = new GameSettings(); XmlNodeList rounds = settingsXml.SelectNodes(c_RoundsXPath); if (rounds.Count == 0) { throw new InvalidGameSettingsException(string.Format( "Spēles konfigurācijā nav norādīts neviens raunds.{0}({1})", Environment.NewLine, c_RoundsXPath), settingsFilePath); } foreach (XmlNode round in rounds) { string roundName = null; XmlAttribute roundNameAttribute = round.Attributes[c_RoundNameAttributeName]; if (roundNameAttribute != null) { roundName = roundNameAttribute.InnerText; } if (round.SelectSingleNode(WordGuessingRoundXPaths.RoundNodeName) != null) { XmlNode roundNode = round.SelectSingleNode(WordGuessingRoundXPaths.RoundNodeName); BothTeamSettings newRoundSettings = GetWordGuessingRoundSettings(settingsFilePath, roundNode, roundName); parsedSettings.Rounds.Add(newRoundSettings); } else if (round.SelectSingleNode(ImageRoundXPaths.RoundNodeName) != null) { XmlNode roundNode = round.SelectSingleNode(ImageRoundXPaths.RoundNodeName); BothTeamSettings newRoundSettings = GetImageRoundSettings(settingsFilePath, roundNode, roundName); parsedSettings.Rounds.Add(newRoundSettings); } else if (round.SelectSingleNode(SongRoundXPaths.RoundNodeName) != null) { XmlNode roundNode = round.SelectSingleNode(SongRoundXPaths.RoundNodeName); BothTeamSettings newRoundSettings = GetSongRoundSettings(settingsFilePath, roundNode, songPlayerNameGetterFunction, roundName); parsedSettings.Rounds.Add(newRoundSettings); } else if (round.SelectSingleNode(VideoRoundXPaths.RoundNodeName) != null) { XmlNode roundNode = round.SelectSingleNode(VideoRoundXPaths.RoundNodeName); BothTeamSettings newRoundSettings = GetVideoRoundSettings(settingsFilePath, roundNode, videoPlayerNameGetterFunction, roundName); parsedSettings.Rounds.Add(newRoundSettings); } else { throw new InvalidGameSettingsException(string.Format("Nezināms spēles raunds{0}{1}", Environment.NewLine, round.InnerXml), settingsFilePath); } } return(parsedSettings); }
private static BothTeamSettings GetSongRoundSettings(string settingsFilePath, XmlNode roundSettingsNode, GetSongPlayerSettings songPlayerNameGetterFunction, string roundName) { if (string.IsNullOrEmpty(roundName)) { roundName = SongRoundSettings.DefaultRoundName; } BothTeamSettings roundSettings = new BothTeamSettings(roundName); XmlNode node = roundSettingsNode.SelectSingleNode(SongRoundXPaths.Team1SongXPath); if (node == null) { throw new InvalidGameSettingsException("Netika atrasta 1. komandas dziesma", settingsFilePath); } string songFileName = node.Value; string answer = null; node = roundSettingsNode.SelectSingleNode(SongRoundXPaths.Team1AnswerXPath); if (node != null) { answer = node.InnerText; } roundSettings.Team1Settings = new SongRoundSettings(songFileName, answer, settingsFilePath, DirectoryNames.SongsDirectory, songPlayerNameGetterFunction); node = roundSettingsNode.SelectSingleNode(SongRoundXPaths.Team2SongXPath); if (node == null) { throw new InvalidGameSettingsException("Netika atrasta 2. komandas dziesma", settingsFilePath); } songFileName = node.Value; answer = null; node = roundSettingsNode.SelectSingleNode(SongRoundXPaths.Team2AnswerXPath); if (node != null) { answer = node.InnerText; } roundSettings.Team2Settings = new SongRoundSettings(songFileName, answer, settingsFilePath, DirectoryNames.SongsDirectory, songPlayerNameGetterFunction); return(roundSettings); }