Example #1
0
        public void Dealt()
        {
            if (type != GameType.Client)
            {
                player1 = new Player();
                player2 = new Player();
            }
            DominoSender sender = new DominoSender();

            for (int i = 0; i < 6; i++)
            {
                Point point;
                if (i == 0)
                {
                    point = new Point(20, 486);
                }
                else
                {
                    point = new Point(Domino.Size.Width + player1PictureBox[i - 1].Location.X + 20, 486);
                }
                ImageRotator rotator = new ImageRotator();
                PictureBox   pbox1   = PictureBoxCreator(player1.List[i].Image, point);
                player1PictureBox.Add(pbox1);
                Controls.Add(pbox1);
                pbox1.Click += PictureBox_Click;
                sender.Array.Add(player1.List[i]);
            }
            for (int i = 0; i < 6; i++)
            {
                Point point;
                if (i == 0)
                {
                    point = new Point(20, 20);
                }
                else
                {
                    point = new Point(Domino.Size.Width + player2PictureBox[i - 1].Location.X + 20, 20);
                }
                //PictureBox pbox2 = PictureBoxCreator(Properties.Resources.back, point);
                PictureBox pbox2 = PictureBoxCreator(player2.List[i].Image, point);
                player2PictureBox.Add(pbox2);
                Controls.Add(pbox2);
                sender.Array.Add(player2.List[i]);
            }
            if (type == GameType.Server)
            {
                TcpSender.Send(sender.Bytes());
            }
        }
Example #2
0
        public void PictureBox_Click(object sender, EventArgs e)
        {
            Domino     domino;
            PictureBox pbox;

            if (sender is PictureBox)
            {
                pbox   = sender as PictureBox;
                domino = new Domino(pbox.Image);
            }
            else
            {
                domino     = sender as Domino;
                pbox       = new PictureBox();
                pbox.Image = domino.Image;
                Controls.Add(pbox);
            }
            if (domino.Contains(Right) || domino.Contains(Left) || Right == 7)
            {
                Blocked = true;
                table.Add(pbox);
                player1PictureBox.Remove(pbox);
                player1.List.Remove(domino);
                pbox.Click -= PictureBox_Click;
                if (Right == 7)
                {
                    firstMove(domino, pbox);
                }
                else if (domino.Contains(Right))
                {
                    rightMove(domino, pbox);
                }
                else if (domino.Contains(Left))
                {
                    leftMove(domino, pbox);
                }
                if (type != GameType.Local)
                {
                    DominoSender Sender = new DominoSender(DominoSendingState.Move, domino);
                    TcpSender.Send(Sender.Bytes());
                }
                else
                {
                    PCMove();
                }
            }
            PullTogether(player1, 486);
            (this as Form).Text = player1.List.Count + "." + player2.List.Count;
            if (Win(player1))
            {
                int sum = 0;
                for (int i = 0; i < player2.List.Count; i++)
                {
                    sum += player2.List[i].First + player2.List[i].Second;
                }
                StaticForScores.Score1 += sum;
                ScoreLabel.Text         = string.Format("{0}:{1}", StaticForScores.Score1, StaticForScores.Score2);
                if (StaticForScores.Score1 > 101)
                {
                    MessageBox.Show("Player Won the Game");
                    Application.Exit();
                }
                else
                {
                    MessageBox.Show("Player Won");
                }
                NewRound();
            }
            else if (Draw(player1, player2))
            {
                int sum1 = 0;
                for (int i = 0; i < player1.List.Count; i++)
                {
                    sum1 += player1.List[i].First + player1.List[i].Second;
                }
                StaticForScores.Score2 += sum1;
                int sum2 = 0;
                for (int i = 0; i < player2.List.Count; i++)
                {
                    sum2 += player2.List[i].First + player2.List[i].Second;
                }
                StaticForScores.Score1 += sum2;
                ScoreLabel.Text         = string.Format("{0}:{1}", StaticForScores.Score1 + sum1 > sum2 ? sum1 - sum2 : 0, StaticForScores.Score2 + sum1 < sum2 ? sum2 - sum1 : 0);
                MessageBox.Show("Draw");
                NewRound();
            }
        }