Advertisement
Guest User

Random Code

a guest
Feb 5th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. /* idk what half this stuff does, but it works. */
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <ctime>
  6. #include <cstdlib>
  7. #include <math.h>
  8. #include <stdio.h> /* printf, scanf, puts, NULL */
  9. #include <stdlib.h> /* srand, rand */
  10. #include <time.h> /* time */
  11.  
  12. using namespace std;
  13.  
  14.  
  15.  
  16. // This is the 3 randomizers needed for the code: Attack damage randomizer, Hit chance randomizer, Move selection randomizer
  17.  
  18. int main(){
  19.  
  20. //Attack damage randomizer start.
  21.  
  22.  
  23. double ATTM; //Attack multiplier.
  24. double ATTD; //Attack default.
  25. double ATTB; //Attack buffer.
  26. srand(time(0)); //Randomzies the code by making up a random string of numbers.
  27.  
  28. ATTB = 0.5; //Attack modifer to grant +-50%. Changes to 1 if using ATT up to make to 0~100% damage scaling.
  29. ATTD = 20; //Default damage if there was no multiplier, changes for each attack, set to 20 for testing.
  30.  
  31. //Yes, I know the line is repeated twice. No, I dont know why I need to do it. Yes, it is nesesary. No, there is no other way.
  32. ATTM =(double)rand()/(RAND_MAX+1)+(ATTB); //The attack multiplier. Default is 0.5-1.5, AKA 50% less damage to 50% more.
  33. ATTM =(double)rand()/(RAND_MAX+1)+(ATTB); //Taking an attack potion should change to to 1-2, AKA default to double damage.
  34. //If you dont have BOTH of them, then it does not generate an actual random number. Try it yourself.
  35.  
  36. cout << "Attack multiplier is: "; //Words
  37. cout << ATTM; //Final multiplier
  38. cout << "\nThe final damage done is: "; //Move stuff to another line
  39. cout << floor ((ATTD * ATTM) + 0.5 ); //Final damage caulcuation. Multiplies base damage by the multiplier, then rounds it to a whole number.
  40.  
  41.  
  42. //Attack damage randomizer end.
  43.  
  44.  
  45.  
  46.  
  47. //Move hit randomzier start.
  48.  
  49.  
  50. int r; //Randomizer for a number from 0-100, used for hit chance and move selection.
  51. int HitC; //Hit chance, the number needed for the attack to hit.
  52.  
  53. r = rand() % 100; //Random number from 0-100
  54. HitC = 75; //Default chance for the attack to hit, set to 75 for testing.
  55.  
  56. cout << "\nRandom number is: "; //Move stuff to another line
  57. cout << r; //prints the number
  58. if (r<=HitC) puts ("\nThe attack hit!"); //If the number rolled is smaller then chance to hit, the attack is sucsesful.
  59. else if (r>HitC) puts ("\nThe attack missed!"); //If the number rolled is greater then chance to hit, the attack missed.
  60.  
  61.  
  62. //Move hit randomzier end.
  63.  
  64.  
  65.  
  66. //Move selection start
  67.  
  68.  
  69. r = rand() % 100; //Random number from 0-100
  70.  
  71. cout << "\nNew random number: "; //Prints the new random number. Also, it seems to have an extra space when printed, idk why, its like a second \n was typed.
  72. cout << r;
  73. if (r<=20) puts ("\nMove one selected!"); //If the number is 0-20, move one (20% chance to select)
  74. if (r<=50&&r>20) puts ("\nMove two selected!"); //If the number is 21-50, move two (30% chance to select)
  75. if (r<=75&&r>50) puts ("\nMove three selected!"); //if the number is 51-75, move three (25% chance to select)
  76. if (r<=100&&r>75) puts ("\nMove four selected!"); //if the number is 76-100, move four (25% chance to select)
  77.  
  78.  
  79. //Move selection end
  80.  
  81. std::cout << "\n\nPress ENTER to end program..."; //Tells user how to end the program.
  82. std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' ); //Will stop the program from ending prematuerly, requiers user to push ENTER.
  83.  
  84. return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement