Esempio n. 1
0
        private void WaitForPlayers()
        {
            string[]     messages;
            Deck         deck = new Deck(new List <Card>());
            string       player_name, code, currentPlayer = "";
            List <Enemy> enemies = new List <Enemy>();
            JArray       players, cards;
            dynamic      json;

            while (this.waiting)
            {
                messages = Communication.GameHandler(this.sock, "NOT MY TURN", new string[] { });
                foreach (string msg in messages)
                {
                    json = JsonConvert.DeserializeObject(msg);
                    if (json.code == null)
                    {
                        code = json.status.ToString();
                    }
                    else
                    {
                        code = json.code.ToString();
                    }
                    if (code == "player_joined")
                    {
                        dynamic args = JsonConvert.DeserializeObject(json.args.ToString());
                        player_name = args.player_name.ToString();
                        this.Invoke(new MethodInvoker(delegate() { this.players.Items.Add(player_name); }));
                        continue;
                    }

                    else if (code == "player_left")
                    {
                        dynamic args = JsonConvert.DeserializeObject(json.args.ToString());
                        player_name = args.player_name.ToString();
                        this.Invoke(new MethodInvoker(delegate() { this.players.Items.Remove(player_name); }));
                        continue;
                    }

                    else if (code == "game_starting")
                    {
                        dynamic args = JsonConvert.DeserializeObject(json.args.ToString());
                        players = args.players;
                        cards   = args.cards;
                        int index = 1;
                        foreach (string player in players)
                        {
                            if (player != "" && player != this.name)
                            {
                                enemies.Add(new Enemy(player, index));
                                index++;
                            }
                        }

                        foreach (object card in cards)
                        {
                            dynamic jsonCard = JsonConvert.DeserializeObject(card.ToString());
                            deck.AddCard(new Card((string)jsonCard.type, (string)jsonCard.color, (string)jsonCard.value));
                        }
                        this.waiting = false;
                        this.inGame  = true;
                        continue;
                    }
                    else if (code == "update_turn")
                    {
                        dynamic args = JsonConvert.DeserializeObject(json.args.ToString());
                        currentPlayer = (string)args.current_player;
                        continue;
                    }
                    else if (json.status != "success" && json.code != "success")
                    {
                        dynamic args = JsonConvert.DeserializeObject(json.args.ToString());
                        if (args.message != null)
                        {
                            MessageBox.Show(args.message.ToString(), (string)json.status, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        continue;
                    }
                }
            }
            if (this.inGame)
            {
                GamePanel panel = new GamePanel(deck, enemies, this.name);
                panel.Size = this.Size;
                GameManager gameManager = new GameManager(deck, enemies, this.name, null, this.sock, this.jwt, this.Parent, panel);
                this.Invoke(new MethodInvoker(delegate() { this.Parent.Controls.Add(panel); }));
                this.Invoke(new MethodInvoker(delegate() { this.Parent.Controls.Remove(this); }));
                gameManager.Run(currentPlayer);
            }
            else
            {
                this.Parent.Invoke(new MethodInvoker(delegate() { this.Parent.Controls.Add(this.homePanel); }));
                this.Parent.Invoke(new MethodInvoker(delegate() { this.Parent.Controls.Remove(this); }));
            }
        }
Esempio n. 2
0
 public ResizePictureBox(Size size, PictureBox image, GamePanel panel) : base(image, panel)
 {
     this.size = size;
 }
Esempio n. 3
0
 public AddPicture(PictureBox image, GamePanel panel) : base(image, panel)
 {
 }
Esempio n. 4
0
 public Rotate(double angle, Bitmap originalBitmap, PictureBox image, GamePanel panel) : base(image, panel)
 {
     this.angle          = angle;
     this.originalBitmap = originalBitmap;
 }
Esempio n. 5
0
 public Move(Point end, PictureBox image, GamePanel panel) : base(image, panel)
 {
     this.end = end;
 }
Esempio n. 6
0
 public Animation(PictureBox image, GamePanel panel)
 {
     this.image = image;
     this.panel = panel;
 }
Esempio n. 7
0
 public ReplaceTopCardPicture(PictureBox image, GamePanel panel) : base(image, panel)
 {
 }
Esempio n. 8
0
 public ChangePictureBoxImage(Bitmap newImage, PictureBox image, GamePanel panel) : base(image, panel)
 {
     this.newImage = newImage;
 }