public void Begin() { InitializeDecks(players.Count); InitializeWonders(players.Count); current_age = Age.I; foreach (Player player in players) { player.current_booster = GenerateBooster(Age.I); player.board = new List <Card>(); GameCommand command = new GameCommand("Wonder", player.wonder.Id.ToString()); gameinterface.Send(player, command); } foreach (Player player in players) { player.Gold = 3; // можно доложить игроку, что у него три голды // а можно не докладывать, сам додумается string booster = String.Join(",", player.current_booster.Select(card => card.Id)); GameCommand command = new GameCommand("Booster", booster); IssueCommand(command, player); } }
public void Execute(ApplicationCommand command) { GameCommand game_command = (GameCommand)command; switch (game_command.type) { case "Message": { gui.ShowStringMessage(command.body); break; } case "Booster": { string[] ids = game_command.body.Split(','); List <Card> tmp = new List <Card>(); foreach (string id in ids) { Card card = allcards.Find(crd => crd.Id.ToString() == id); if (card == null) { throw new Exception("CARD NOT FOUND: " + id.ToString()); } tmp.Add(card); } gui.ShowBooster(tmp); break; } case "PlayCard": { if (current_playmode != null) { // !!! // тоже костыль, надо сразу научить игру просить то, что надо GameCommand response = new GameCommand("PlayMode", current_playmode); Send(response); } else { throw new Exception("Empty card play mode"); } break; } case "CurrentGold": { gui.DisplayGold(command.body); break; } case "Board": { string[] ids = game_command.body.Split(','); List <Card> tmp = new List <Card>(); foreach (string id in ids) { tmp.Add(allcards.Find(card => card.Id.ToString() == id)); } gui.DisplayBoard(tmp); break; } case "Wonder": { Wonder wonder = allwonders.Find(wnd => wnd.Id == Convert.ToInt32(command.body)); gui.DisplayWonder(wonder); break; } case "NewTier": { gui.DisplayNewTier(); break; } case "GameState": { int gold = (int)game_command.Data["Gold"]; gui.DisplayGameState(gold); break; } } }
public void Execute(Player player, GameCommand command) { switch (command.type) { case "CardPick": { // !!! // скипнули валидацию player.picked_card = player.current_booster.Find(card => card.Id.ToString() == command.body); if (!players.Where(plr => plr.picked_card == null).Any()) { GameCommand response = new GameCommand("PlayCard", ""); foreach (Player plr in players) { IssueCommand(response, plr); } } break; } case "PlayMode": { // !!! // и тут скипнули валидацию switch (command.body) { // Похоже, тут свитч уже не нужен case "Play": { // validate costs // pay costs player.play_mode = "Play"; if (!players.Where(plr => plr.play_mode == null).Any()) { ProcessCardPlays(); ResetPlayerStates(); NextTurn(); } break; } case "Wonder": { // validate costs // pay costs // play wonder player.play_mode = "Wonder"; if (!players.Where(plr => plr.play_mode == null).Any()) { ProcessCardPlays(); ResetPlayerStates(); NextTurn(); } break; } case "Sell": { player.play_mode = "Sell"; if (!players.Where(plr => plr.play_mode == null).Any()) { // валидация здесь? ProcessCardPlays(); ResetPlayerStates(); NextTurn(); } break; } } break; } } }
public void IssueCommand(GameCommand command, Player player) { gameinterface.Send(player, command); }