Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Small Battle Simulator Problem

$
0
0
Hi there, it's difficult to explain the problem. I am VERY new to C# as it is my first language. I tried writing a little one sided battle simulator but the problem occurs that sometimes when clicking attack it does not deduct from the enemies health if they are hit, but instead adds to it. Here is the code:

 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Battle_Simulator
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
           Random attackChance = new Random();

           int health = 1000; 
           int critStrike = 200;  
           int strike = 100; 
              
           int hit = attackChance.Next(1, 100); 
            //hit can either be 1 to 100.
           if(hit >= 60) 
           {
               MessageBox.Show("You Hit the Monster for: 100");
               label6.Text = (health - strike).ToString(); 

           } 
           else if((hit > 40) && (hit < 60))
           {
               MessageBox.Show("You Critically Hit the Monster for: 200 Damage!" );
               label6.Text = (health - critStrike).ToString(); 
           } 

           else{  
               MessageBox.Show("Your Attack Missed"); 
           } 

            if(health <50) 
            {
                MessageBox.Show(" YOU HAVE SLAIN THE MONSTER!");
            }






        }
    }
} 




I hope you can help.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>