示例#1
0
        private void attack(UserFighter attacking, BodyPart attackPart, UserFighter deffender, BodyPart defPart)
        {
            logEvent($"Round {round}: ");
            logEvent($"User {attacking.Name} attacks");
            logEvent($"User {deffender.Name} deffends");
            deffender.SetBlock(defPart);
            deffender.GetHit(attackPart);

            round++;
            if (round % 2 == 0)
            {
                command.Image = Image.FromFile("defence.png");
            }
            else
            {
                command.Image = Image.FromFile("attack.png");
            }
        }
示例#2
0
        private void StartGame()
        {
            this.Controls.Clear();
            user         = new UserFighter(username);
            enemy        = new UserFighter("Enemy");
            user.Block  += Blocked;
            user.Death  += Dead;
            user.Wound  += Wouned;
            enemy.Block += Blocked;
            enemy.Death += Dead;
            enemy.Wound += Wouned;
            round        = 1;

            head             = new PictureBox();
            head.Image       = Image.FromFile("head1.png");
            head.Size        = new Size(100, 100);
            head.Location    = new Point(this.Width / 2 - head.Size.Width / 2, this.Height / 6 + 30);
            head.MouseEnter += Head_MouseEnter;
            head.MouseLeave += Head_MouseLeave;
            head.Click      += Head_Click;
            this.Controls.Add(head);

            body             = new PictureBox();
            body.Image       = Image.FromFile("body1.png");
            body.Size        = new Size(100, 100);
            body.Location    = new Point(this.Width / 2 - head.Size.Width / 2, this.Height / 3);
            body.MouseEnter += Body_MouseEnter;
            body.MouseLeave += Body_MouseLeave;
            body.Click      += Body_Click;
            this.Controls.Add(body);

            legs             = new PictureBox();
            legs.Image       = Image.FromFile("legs1.png");
            legs.Size        = new Size(100, 100);
            legs.Location    = new Point(this.Width / 2 - head.Size.Width / 2, this.Height / 2 + 5);
            legs.MouseEnter += Legs_MouseEnter;
            legs.MouseLeave += Legs_MouseLeave;
            legs.Click      += Legs_Click;
            this.Controls.Add(legs);

            userHeart          = new PictureBox();
            userHeart.Image    = Image.FromFile("heart.png");
            userHeart.Size     = new Size(100, 100);
            userHeart.Location = new Point((head.Location.X - 50) / 2, 30);
            this.Controls.Add(userHeart);

            enemyHeart          = new PictureBox();
            enemyHeart.Image    = Image.FromFile("heart.png");
            enemyHeart.Size     = new Size(100, 100);
            enemyHeart.Location = new Point(head.Location.X + (head.Location.X - userHeart.Location.X) + 55, 30);
            this.Controls.Add(enemyHeart);

            userHealth           = new Label();
            userHealth.Text      = "100%";
            userHealth.ForeColor = Color.Red;
            userHealth.AutoSize  = true;
            userHealth.Font      = new Font("Times New Roman", 15, FontStyle.Bold);
            userHealth.Location  = new Point((head.Location.X - 50) / 2 - 55, 60);
            this.Controls.Add(userHealth);

            enemyHealth           = new Label();
            enemyHealth.Text      = "100%";
            enemyHealth.ForeColor = Color.Red;
            enemyHealth.AutoSize  = true;
            enemyHealth.Font      = new Font("Times New Roman", 15, FontStyle.Bold);
            enemyHealth.Location  = new Point(enemyHeart.Location.X - 55, 60);
            this.Controls.Add(enemyHealth);

            nameOfUser           = new Label();
            nameOfUser.Text      = username;
            nameOfUser.AutoSize  = true;
            nameOfUser.Font      = new Font("Times New Roman", 15, FontStyle.Bold);
            nameOfUser.ForeColor = Color.DarkBlue;
            nameOfUser.Location  = new Point(userHeart.Location.X - nameOfUser.Text.Length / 2, 0);
            this.Controls.Add(nameOfUser);

            enemyName           = new Label();
            enemyName.Text      = "Enemy";
            enemyName.AutoSize  = true;
            enemyName.Font      = new Font("Times New Roman", 15, FontStyle.Bold);
            enemyName.ForeColor = Color.DarkBlue;
            enemyName.Location  = new Point(enemyHeart.Location.X - enemyName.Text.Length / 2, 0);
            this.Controls.Add(enemyName);

            eventRecords             = new TextBox();
            eventRecords.Size        = new Size(300, 200);
            eventRecords.BackColor   = Color.Aqua;
            eventRecords.ReadOnly    = true;
            eventRecords.ScrollBars  = ScrollBars.Vertical;
            eventRecords.MaximumSize = new Size(300, 20);
            eventRecords.Location    = new Point((head.Location.X + 50) - 150, this.Height - 150);
            eventRecords.Text        = "";
            eventRecords.Multiline   = true;
            eventRecords.MinimumSize = new Size(300, 100);

            this.Controls.Add(eventRecords);

            command          = new PictureBox();
            command.Image    = Image.FromFile("attack.png");
            command.Size     = new Size(100, 100);
            command.Location = new Point(head.Location.X, 0);
            this.Controls.Add(command);
        }