Thread: Novice programmer looking for help with Random Numbers

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    26

    Novice programmer looking for help with Random Numbers

    I am looking to create a random number generator that can be used to calculate a 1 time use per calculation int that will determine if an attack hits or misses as well as another for the damage within a set range for turn based attacks with ACC% and atk/defense.

    If you can help please provide an example and explain how the code works as I want to learn to be able to use the code on my own. Thanks

    Here is an example of what I have come up with so far.

    do
    {
    if (PlayerRound)
    {
    Random rnd = new Random();
    int PlayerHitChance = 100 - PlayerAcc;
    int PlayerHit = rnd.Next(1, PlayerHitChance);

    if (PlayerHit >= 76)
    {
    //Player Hits
    Random rnd2 = new Random();
    int PlayerDmg = PlayerAtk - TargetMonsterDefense;
    int PlayerHitDmg = rnd2.Next(1, PlayerDmg);
    TargetMonsterHP = TargetMonsterHP - PlayerHitDmg;
    }
    else if (PlayerHit <= 75)
    {
    // Player Misses
    }

    PlayerRound = false;
    TargetMonsterRound = true;
    }
    else if (TargetMonsterRound)
    {

    TargetMonsterRound = false;
    PlayerRound = true;
    }
    else
    {

    }
    } while ((PlayerHP > 0) && (IsTargetMonsterAlive));
    Last edited by Snaef98; 07-11-2017 at 05:38 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Novice Programmer, having trouble. Netbeans/Cygwin
    By oninchowder in forum C Programming
    Replies: 7
    Last Post: 09-13-2011, 10:30 AM
  2. Novice Programmer Humbly Requests Job Seeking Advice
    By steals10304 in forum General Discussions
    Replies: 7
    Last Post: 10-20-2009, 12:12 PM
  3. Replies: 10
    Last Post: 06-17-2005, 10:00 PM
  4. [C++] Segmentation Fault {Novice C++ Programmer}
    By INFERNO2K in forum C++ Programming
    Replies: 24
    Last Post: 06-08-2005, 07:44 PM
  5. Replies: 4
    Last Post: 11-16-2004, 07:29 AM

Tags for this Thread