Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9167965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:31:07+00:00 2026-06-17T15:31:07+00:00

In my C# game TextQuest, The fighting system is in progress now and I

  • 0

In my C# game TextQuest, The fighting system is in progress now and I ran into a problem.
If the player misses the Monster misses too (always at the same time). Here is the used code:

private void button1_Click(object sender, EventArgs e)
    {
        Monster_Class mc = new Monster_Class();
        Account_Class ac = new Account_Class();
        if (hitOrMiss())
        {
            int hit = -1;
            hit = mc.hitAmount(ac.getAtk(Properties.Settings.Default.CurrentUser), mc.getDef(monster));
            mhealth -= hit;
            if (hit == -1)
            {
                setText("You missed.");
            }
            else
            {
                setText("You hit " + hit + ".");
            }
            monsterHit();
            update();
        }
        else
        {
            setText("You missed.");
            monsterHit();
        }
    }

private void monsterHit()
{
    Monster_Class mc = new Monster_Class();
    Account_Class ac = new Account_Class();
    if (hitOrMiss())
    {
        int hit = -1;
        hit = mc.hitAmount(mc.getAtk(monster), ac.getDef(Properties.Settings.Default.CurrentUser));
        phealth -= hit;
        if (hit == -1)
        {
            addText(monster + " missed.");
        }
        else
        {
            addText(monster + " hit " + hit + ".");
        }
    }
    else
    {
        addText(monster + " missed.");
    }
}

private bool hitOrMiss()
{
    bool hit = true;
    Random rand = new Random();
    if (rand.Next(101) < 15)
    {
        hit = false;
    }
    return hit;
}

public int hitAmount(int Atk, int Def)
{
    int hit = -1;
    Random rand = new Random();
    int deturm = rand.Next(6);
    try
    {
        hit = ((Atk + deturm * 3) / Def + 1) / 2;
        if (hit == 0)
        {
            hit = 1;
        }
    }
    catch { }
    return hit;
}

Also if you have a better Idea for the amount of damage done please let me know. since I just kinda threw numbers and symbols together

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:31:08+00:00Added an answer on June 17, 2026 at 3:31 pm

    You don’t want to create a new Random object every time you need a random number. Otherwise I suspect you will get always the same number! Define a global Random object once and use it in every request for random numbers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does Game Center offer any support for player avatars, e.g in a multiplayer game?
game.h file @interface ViewController : UIViewController { UIImageView * player; } @end game.m -(void)InitPlayer
I have an online game currently using MySQL. I have a Player table looking
My game is divided into a grid of regions. Each region has an List
A game I wrote some time ago has a problem with ANRs, and debugging
I'm a web-game developer and I got a problem with random numbers. Let's say
game.h needs: - packet.h - socket.h socket.h needs: - game.h The problem comes when
My game units have an angle variable, and a targetAngle variable. These variables range
My game is a small shooting game in cocos2d. The enemy generates the bullets
The game I'm developing renders perfectly on the Java backend and on IE 10.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.