Card AddJSONCard(JSONCard jsonCard) { Card c = ConvertJsonCardToCard(jsonCard); hand.Add(c); return(c); }
private void HandleConnection() { try { while (this.execThread) { SetLabelText("Members: " + this.playerNum.ToString() + "/4"); dynamic json = client.RecvJSON(true); if (json.code == "player_joined") { this.playerNum++; AddListBoxItem(json.args.player_name.ToString()); } else if (json.code == "player_left") { this.playerNum--; RemoveListBoxItem(json.args.player_name.ToString()); } else if (json.code == "game_ended") { MessageBox.Show("The game was ended by the host", "Error"); Application.Exit(); } else if (json.code == "game_starting") { this.execThread = false; List <JSONCard> activePlayerCards = new List <JSONCard>(); foreach (dynamic jcard in json.args.cards) { JSONCard temp = JsonConvert.DeserializeObject <JSONCard>(jcard.ToString()); activePlayerCards.Add(temp); } string[] players = new string[4]; for (int i = 0; i < 4; i++) { players[i] = json.args.players[i]; } MethodInvoker showGameFormInvoker = delegate() { Game game = new Game(players, activePlayerCards); Form form = new GameWindow(game, this.client); form.FormClosing += delegate { Environment.Exit(0); }; form.Show(); this.Hide(); }; this.Invoke(showGameFormInvoker); } } } catch (Exception ee) { MessageBox.Show(ee.ToString()); } }
public void PlayCard(List <Card> cardsToPlay, Client client, Color specialColor) { JSONCard[] jsonCards = new JSONCard[cardsToPlay.Count]; for (int i = 0; i < jsonCards.Length; i++) { JSONCard jsonCard = (cardsToPlay[i] is ISpecialCard card) ? card.SerializeColor(specialColor) : cardsToPlay[i].Serialize(); jsonCards[i] = jsonCard; hand.Remove(cardsToPlay[i]); } PlayCardJSON doMoveJson = new PlayCardJSON(client.jwt, jsonCards); client.SendJSON(doMoveJson); }
public Card ConvertJsonCardToCard(JSONCard jsonCard) { Card c = null; dynamic cardValue = jsonCard.value; Color cardColor = Color.UNDEFINED; if (jsonCard.color != "") { cardColor = (Color)Enum.Parse(typeof(Color), jsonCard.color, true); } switch (jsonCard.type) { case "number_card": c = new NumberCard(Convert.ToInt32(cardValue), cardColor); break; case "plus": c = new PlusCard(cardColor); break; case "plus_2": c = new TwoPlusCard(cardColor); break; case "stop": c = new StopCard(cardColor); break; case "change_direction": c = new ChangeDirectionCard(cardColor); break; case "change_color": c = new ChangeColorCard(); break; case "taki": c = new TakiCard(cardColor); break; case "super_taki": c = new SuperTakiCard(); break; } return(c); }
private void StartButton_Click(object sender, EventArgs e) { this.execThread = false; handleNewMemebersThread.Join(); StartGameJSON startGameJSON = new StartGameJSON(client.jwt); this.client.SendJSON(startGameJSON); dynamic statusJson = this.client.RecvJSON(true); if (statusJson.code == "game_starting") { List <JSONCard> activePlayerCards = new List <JSONCard>(); foreach (dynamic jcard in statusJson.args.cards) { Console.WriteLine(jcard.ToString()); JSONCard temp = JsonConvert.DeserializeObject <JSONCard>(jcard.ToString()); activePlayerCards.Add(temp); } string[] players = new string[4]; for (int i = 0; i < 4; i++) { players[i] = statusJson.args.players[i]; } MethodInvoker methodInvokerDelegate = delegate() { Game game = new Game(players, activePlayerCards); Form form = new GameWindow(game, this.client); form.FormClosing += delegate { Environment.Exit(0); }; form.Show(); this.Hide(); }; this.Invoke(methodInvokerDelegate); } else if (statusJson.status == "denied") { MessageBox.Show(statusJson.args.message.ToString(), "Error"); handleNewMemebersThread = new Thread(HandleNewMembers); this.execThread = true; handleNewMemebersThread.Start(); } }