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 VideoRoundSettings(string videoFileName, string answer, string settingsFilePath, string videoDirectory, GetVideoPlayerSettings videoPlayerNameGettingFunction) { if (string.IsNullOrEmpty(videoFileName)) { throw new InvalidGameSettingsException("Nav norādīts video fails", settingsFilePath); } if (videoPlayerNameGettingFunction == null) { throw new Exception("Movie player name getting method must be specified"); } m_GetVideoPlayerSettings += videoPlayerNameGettingFunction; m_VideoFileName = Path.Combine(videoDirectory, videoFileName); if (!File.Exists(m_VideoFileName)) { throw new InvalidGameSettingsException(string.Format("Video fails '{0}' neeksistē", m_VideoFileName), settingsFilePath); } Answer = answer; }
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); }
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 BothTeamSettings GetVideoRoundSettings(string settingsFilePath, XmlNode roundSettingsNode, GetVideoPlayerSettings videoPlayerNameGetterFunction, string roundName) { if (string.IsNullOrEmpty(roundName)) { roundName = VideoRoundSettings.DefaultRoundName; } BothTeamSettings roundSettings = new BothTeamSettings(roundName); XmlNode node = roundSettingsNode.SelectSingleNode(VideoRoundXPaths.Team1MovieXPath); if (node == null) { throw new InvalidGameSettingsException("Netika atrasts 1. komandas video", settingsFilePath); } string videoFileName = node.Value; string answer = null; node = roundSettingsNode.SelectSingleNode(VideoRoundXPaths.Team1AnswerXPath); if (node != null) { answer = node.InnerText; } roundSettings.Team1Settings = new VideoRoundSettings(videoFileName, answer, settingsFilePath, DirectoryNames.MoviesDirectory, videoPlayerNameGetterFunction); node = roundSettingsNode.SelectSingleNode(VideoRoundXPaths.Team2MovieXPath); if (node == null) { throw new InvalidGameSettingsException("Netika atrasts 2. komandas video ", settingsFilePath); } videoFileName = node.Value; answer = null; node = roundSettingsNode.SelectSingleNode(VideoRoundXPaths.Team2AnswerXPath); if (node != null) { answer = node.InnerText; } roundSettings.Team2Settings = new VideoRoundSettings(videoFileName, answer, settingsFilePath, DirectoryNames.MoviesDirectory, videoPlayerNameGetterFunction); return(roundSettings); }