private void Ok() { if (lbGames.SelectedItem == null) MessageBox.Show("You must select a game"); else { LoadedGame = Game.Load((string)lbGames.SelectedItem); this.DialogResult = DialogResult.OK; this.Close(); } }
private void btnLoadGame_Click(object sender, EventArgs e) { LoadGame loadGameForm = new LoadGame(); if (_game != null && _game.Settings != null) loadGameForm.LoadedGame = _game; DialogResult result = loadGameForm.ShowDialog(); if (result == DialogResult.OK) { _game = loadGameForm.LoadedGame; UpdateForm(); } }
private void btnCreateGame_Click(object sender, EventArgs e) { if (_game != null) _game.Save(); CreateGame createGameForm = new CreateGame(); DialogResult result = createGameForm.ShowDialog(); if (result == DialogResult.OK) { _game = createGameForm.NewGame; UpdateForm(); } }
private void btnOk_Click(object sender, EventArgs e) { if (_existingGames.Contains(tbGameName.Text)) { MessageBox.Show("A game with this name already exists."); } else { NewGame = new Game(); NewGame.Init(tbGameName.Text); NewGame.Save(); this.DialogResult = DialogResult.OK; this.Close(); } }
/// <summary> /// Saves the players. /// </summary> /// <param name="game">The game.</param> public static void SavePlayers(Game game) { if (game == null || game.Players == null || game.Players.Count == 0) return; foreach (Player p in game.Players.Values) p.Save(game); }
/// <summary> /// Loads the players. /// </summary> /// <param name="game">The game.</param> public static void LoadPlayers(Game game) { game.Players = new Dictionary<string, Player>(); List<string> pemails = Directory.GetDirectories("Games\\" + game.Settings.GameName + "\\Players").Select(d => d.Substring(d.LastIndexOf('\\') + 1)).ToList(); foreach (string email in pemails) { Player p = new Player(); p.ReadFromFile(game.Settings.GameName, email); game.Players.Add(p.Identifier, p); } }
/// <summary> /// Creates a new player for the specified game, using the specified name and email. /// </summary> /// <param name="game">The game.</param> /// <param name="name">The name.</param> /// <param name="email">The email.</param> /// <param name="turnJoined">The turn joined.</param> /// <returns></returns> public static Player CreatePlayer(Game game, string name, string email, int turnJoined) { Player p = new Player(); p.Identifier = game.Pool.ConsumeIdentifier(); p.Name = name; p.Email = email; p.TurnJoined = turnJoined; Hero h = new Hero(); h.Identifier = game.Pool.ConsumeIdentifier(); h.Name = "New Hero"; p.Heroes.Add(h.Identifier, h); game.Players.Add(p.Identifier, p); return p; }
/// <summary> /// Starts the order for the specified game and hero. /// </summary> /// <param name="game">The game.</param> /// <param name="who">The who.</param> /// <returns></returns> public string Start(Game game, IOrderTaker who) { return string.Empty; }
/// <summary> /// Determines whether this order can start. /// </summary> /// <param name="game">The game.</param> /// <param name="who">The who.</param> /// <param name="logline">The logline.</param> /// <returns></returns> public bool CanStart(Game game, IOrderTaker who, out string logline) { logline = string.Empty; return true; }
/// <summary> /// Ends the order for the specified game and hero. /// </summary> /// <param name="game">The game.</param> /// <param name="who">The who.</param> /// <returns></returns> public string End(Game game, IOrderTaker who) { if (!Parameters.ContainsKey("name")) throw new InvalidOperationException("This cannot happen, parsed Name order should have parameter name"); string newname = (string)Parameters["name"]; if (who is Player) { Player p = who as Player; string oldname = p.Name; p.Name = newname; return "Player renamed from " + oldname + "to " + newname + "." + Environment.NewLine; } if (who is Hero) { Hero h = who as Hero; string oldname = h.Name; h.Name = newname; return "Hero renamed from " + oldname + "to " + newname + "." + Environment.NewLine; } return "An error occurred while trying to use the order Name." + Environment.NewLine; }
void AddGame(string[] args) { if (args.Count() != 2) { Console.WriteLine("Invalid number of parameters."); Console.WriteLine("Syntax: <executable> addgame <name>"); return; } List<string> existingGames = Game.GameNames().ToList(); string name = args[1]; if (existingGames.Contains(name)) { Console.WriteLine("Cannot add game."); Console.WriteLine("A game with that name already exists."); return; } Game g = new Game(args[1]); g.Save(); Console.Write("Game " + args[1] + " added successfully."); }
/// <summary> /// Ends the order for the specified game and hero. /// </summary> /// <param name="game">The game.</param> /// <param name="who">The who.</param> /// <returns></returns> string IOrder.End(Game game, IOrderTaker who) { return string.Empty; }
/// <summary> /// Starts the order for the specified game and hero. /// </summary> /// <param name="game">The game.</param> /// <param name="who">The who.</param> /// <returns></returns> public string Start(Game game, IOrderTaker who) { // Our start condition checked and who is a Hero Hero h = who as Hero; if (h == null) throw new InvalidOperationException("This cannot happen since the cast was checked at start condition"); return h.Name + " starts negotiations to hire a new hero." + Environment.NewLine; }
/// <summary> /// Ends the order for the specified game and hero. /// </summary> /// <param name="game">The game.</param> /// <param name="who">The who.</param> /// <returns></returns> public string End(Game game, IOrderTaker who) { // Our start condition checked and who is a Hero Hero h = who as Hero; if (h == null) throw new InvalidOperationException("This cannot happen since the cast was checked at start condition"); string newheroname = (string)this.Parameters["name"]; Hero newhero = new Hero(); newhero.Identifier = game.Pool.ConsumeIdentifier(); newhero.Name = newheroname; h.Owner.Heroes.Add(newhero.Identifier, newhero); return h.Name + " hires " + newheroname + "." + Environment.NewLine; }
/// <summary> /// Determines whether this order can start. /// </summary> /// <param name="game">The game.</param> /// <param name="who">The who.</param> /// <param name="logline">The logline.</param> /// <returns></returns> public bool CanStart(Game game, IOrderTaker who, out string logline) { // check if the hero is in a city // check if the player has hero points left // should we also check on the length of the name being given? if (who is Hero) { logline = string.Empty; return true; } logline = "Only heroes can hire other heroes." + Environment.NewLine; return false; }
/// <summary> /// Saves this player. /// </summary> public void Save(Game game) { if (game.Settings != null) { string gamedir = game.Settings.GameName; string playeremail = this.Email; CreatePlayersDir(gamedir, playeremail); this.WriteToFile(gamedir); } }
/// <summary> /// Initializes a new instance of the <see cref="Engine"/> class. /// </summary> /// <param name="game">The game.</param> public Engine(Game game) { _game = game; }
/// <summary> /// Initializes a new instance of the <see cref="GameData"/> class. /// </summary> public GameData(Game game) { this.CurrentTurn = 0; this.Owner = game; }
/// <summary> /// Loads the specified game with the given name. /// </summary> /// <param name="gameName">Name of the game.</param> /// <returns></returns> /// <exception cref="System.Exception">Cannot load game</exception> public static Game Load(string gameName) { if (Directory.Exists("Games\\" + gameName)) { Game game = new Game(); game.Settings = new Settings(); game.Settings.ReadFromFile(gameName); game.GameData = new GameData(game); game.GameData.ReadFromFile(gameName); game.Pool = new Pool(); game.Pool.ReadFromFile(gameName); // As opposed to saving the game, we're not loading the players through // the Player.ReadFromFile method since the players are already loaded // through the GameData. return game; } else { throw new Exception("Cannot load game"); } }
/// <summary> /// Determines whether this order can start. /// </summary> /// <param name="game">The game.</param> /// <param name="who">The who.</param> /// <param name="logline">The logline.</param> /// <returns></returns> public bool CanStart(Game game, IOrderTaker who, out string logline) { // no requirements on naming players or heroes logline = string.Empty; return true; }