示例#1
0
文件: Form1.cs 项目: 74805/Whist
        public void Createcards()
        {
            Card[] cards = myICommon.GetCards(clientid);
            int    spa = 0, dia = 0, hea = 0;

            List <Card> spad = new List <Card>();
            List <Card> hear = new List <Card>();
            List <Card> diam = new List <Card>();
            List <Card> clu  = new List <Card>();

            Card[] cards1 = new Card[13];

            for (int i = 0; i < 13; i++)
            {
                if (cards[i].GetShape() == "spades")
                {
                    spad.Add(cards[i]);
                    spa++;
                }
                if (cards[i].GetShape() == "hearts")
                {
                    hear.Add(cards[i]);
                    hea++;
                }
                if (cards[i].GetShape() == "diamonds")
                {
                    diam.Add(cards[i]);
                    dia++;
                }
                if (cards[i].GetShape() == "clubs")
                {
                    clu.Add(cards[i]);
                }
            }
            for (int i = 0; i < spa; i++)
            {
                for (int j = i + 1; j < spa; j++)
                {
                    if (spad[i].GetNum() < spad[j].GetNum())
                    {
                        Card card = new Card(spad[j]);
                        spad[j] = new Card(spad[i]);
                        spad[i] = card;
                    }
                }
                cards1[i] = spad[i];
            }

            for (int i = 0; i < hea; i++)
            {
                for (int j = i + 1; j < hea; j++)
                {
                    if (hear[i].GetNum() < hear[j].GetNum())
                    {
                        Card card = new Card(hear[j]);
                        hear[j] = new Card(hear[i]);
                        hear[i] = card;
                    }
                }
                cards1[i + spa] = hear[i];
            }
            for (int i = 0; i < dia; i++)
            {
                for (int j = i + 1; j < dia; j++)
                {
                    if (diam[i].GetNum() < diam[j].GetNum())
                    {
                        Card card = new Card(diam[j]);
                        diam[j] = new Card(diam[i]);
                        diam[i] = card;
                    }
                }
                cards1[i + 13 - dia] = diam[i];
            }

            for (int i = 0; i < 13 - spa - hea - dia; i++)
            {
                for (int j = i + 1; j < 13 - spa - hea - dia; j++)
                {
                    if (clu[i].GetNum() < clu[j].GetNum())
                    {
                        Card card = new Card(clu[j]);
                        clu[j] = new Card(clu[i]);
                        clu[i] = card;
                    }
                }
                cards1[i + spa + hea] = clu[i];
            }

            for (int i = 0; i < 13; i++)
            {
                Card   card  = cards1[i];
                Label  label = new Label();
                string str   = card.GetNum().ToString() + card.GetShape().ToUpper()[0];
                Image  img   = Image.FromFile("..\\..\\..\\PNG\\" + str + ".png");
                img            = Resize(img, 54, 83);
                label.Image    = img;
                label.Location = new Point(335 + i * 56, 550);
                label.Size     = img.Size;
                label.Tag      = card;
                this.cards.Add(label);
                Controls.Add(label);

                Label label1 = new Label();
                Image img1   = Image.FromFile("..\\..\\..\\PNG\\gray_back.png");
                img1            = Resize(img1, 83, 54);
                label1.Image    = img1;
                label1.Size     = img1.Size;
                label1.Location = new Point(1100, 150 + i * 30);
                Controls.Add(label1);
                othercards1.Add(label1);

                Label label2 = new Label();
                Image img2   = Image.FromFile("..\\..\\..\\PNG\\green_back.png");
                img2            = Resize(img2, 83, 54);
                label2.Image    = img2;
                label2.Size     = img2.Size;
                label2.Location = new Point(190, 150 + i * 30);
                Controls.Add(label2);
                othercards2.Add(label2);

                Label label3 = new Label();
                Image img3   = Image.FromFile("..\\..\\..\\PNG\\blue_back.png");
                img3            = Resize(img3, 54, 83);
                label3.Image    = img3;
                label3.Size     = img3.Size;
                label3.Location = new Point(480 + i * 30, 60);
                Controls.Add(label3);
                othercards3.Add(label3);
            }
        }
示例#2
0
        public JoinCreateForm(Connector c, string action)
        {
            this.StartPosition = FormStartPosition.Manual;
            this.Location      = MainForm.StartPos;

            Size = new Size(290, 105);

            PleaseCloseForm     = false;
            CloseTimer.Interval = 10;
            CloseTimer.Enabled  = true;
            CloseTimer.Tick    += delegate
            {
                if (PleaseCloseForm)
                {
                    PleaseCloseForm           = false;
                    c.Socket.MessageReceived -= Connection_Socket_MessageReceived;
                    Close();
                }
            };

            Connection = c;
            Connection.Socket.MessageReceived += new EventHandler <MessageReceivedEventArgs>(Connection_Socket_MessageReceived);

            Controls.AddRange(new Control[2] {
                StatLabel, AddPlayerButton
            });

            StatLabel.Text     = "Waiting for registration";
            StatLabel.Location = new Point(10, 10);
            StatLabel.Size     = new Size(250, 20);

            AddPlayerButton.Text     = "Add Player";
            AddPlayerButton.Location = new Point(10, 35);
            AddPlayerButton.Click   += delegate(object sender, EventArgs e)
            {
                SubInitForm = new AddPlayerForm();
                SubInitForm.ShowDialog();
                PlayerName = (SubInitForm as AddPlayerForm).Playername;

                JsonObject Message = new JsonObject();

                Message.Add("type", "join");
                Message.Add("name", PlayerName);
                Connection.Send(Message);
            };

            JsonObject message = new JsonObject();

            if (action == "join")
            {
                AddPlayerButton.Width = 250;
            }
            if (action == "create_new")
            {
                message.Add("type", "request_pack_list");
                Connection.Send(message);

                AddPlayerButton.Width = 120;

                Controls.Add(StartButton);
                StartButton.Width    = 120;
                StartButton.Location = new Point(140, 35);
                StartButton.Text     = "Start";
                StartButton.Enabled  = false;

                StartButton.Click += delegate(object button, EventArgs e)
                {
                    if (Connection.Socket.State == WebSocketState.Open)
                    {
                        JsonObject Message = new JsonObject();
                        Message.Add("type", "start");
                        Connection.Send(Message);
                    }
                };
            }
        }
示例#3
0
文件: Form1.cs 项目: 74805/Whist
        public void ShowNames()
        {//לאחר שכל השחקנים התחברו, הפעולה מראה את השם של כל שחקן על המסך ואת מספר הסיבובים שבהן ניצח
            for (int i = 0; i < 4; i++)
            {
                names[i]      = new Label();
                names[i].Text = pnames[i];

                take[i]      = new Label();
                take[i].Text = 0.ToString();
            }
            names[clientid].Location = new Point(660, 640);
            take[clientid].Location  = new Point(550, 640);
            if (clientid != 3)
            {
                names[clientid + 1].Location = new Point(1200, 350);
                take[clientid + 1].Location  = new Point(1200, 450);
            }
            else
            {
                names[0].Location = new Point(1200, 350);
                take[0].Location  = new Point(1200, 450);
            }
            if (clientid == 0 || clientid == 1)
            {
                names[clientid + 2].Location = new Point(660, 10);
                take[clientid + 2].Location  = new Point(550, 10);
            }
            else
            {
                if (clientid == 2)
                {
                    names[0].Location = new Point(660, 10);
                    take[0].Location  = new Point(550, 10);
                }
                else
                {
                    names[1].Location = new Point(660, 10);
                    take[1].Location  = new Point(550, 10);
                }
            }
            if (clientid == 0)
            {
                names[3].Location = new Point(80, 350);
                take[3].Location  = new Point(80, 450);
            }
            else
            {
                if (clientid == 1)
                {
                    names[0].Location = new Point(80, 350);
                    take[0].Location  = new Point(80, 450);
                }
                else
                {
                    if (clientid == 2)
                    {
                        names[1].Location = new Point(80, 350);
                        take[1].Location  = new Point(80, 450);
                    }
                    else
                    {
                        names[2].Location = new Point(80, 350);
                        take[2].Location  = new Point(80, 450);
                    }
                }
            }
            for (int i = 0; i < 4; i++)
            {
                Controls.Add(take[i]);
                Controls.Add(names[i]);
            }
        }