Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › How would I make something like a rolling dice for a TEXT BASED game?
New Posts  All Forums:Forum Nav:

How would I make something like a rolling dice for a TEXT BASED game?

post #1 of 3
Thread Starter 
I am wanting to make a little text based RPG type thing in C++. I am a beginner, and I feel like making something like this would be a good way for me to practice this. I understand the if statements and what not, but I am just not sure how I would make a random number generate, damage health and what. Any kind of help would be appreciated. Thanks!
Go Skate
(19 items)
 
  
CPUMotherboardGraphicsRAM
intel i5 7600k Asus TUF Z270 Mark 2 NVIDIA GTX 1060 16 GB 2400 DDR4  
Hard DriveHard DriveHard DriveCooling
Samsung 2.5-inch SSD 840 Seagate 2 TB 7200 RPM 32MB Cache 4 500GB HDDs in RAID 10  DeepCool PWM Fan GAMMAXX 300 
OSMonitorKeyboardPower
Windows 10 Pro HP LA2405wg Corsair K90 Mechanical Red Switch 910 watt PC Power and Cooling 
CaseMouseMouse PadAudio
Coolermaster Elite Razer Naga Steel Series SC2 Edition Senheisser 
AudioAudio
Razer Kraken Steelseries Siberia v3 
  hide details  
Reply
Go Skate
(19 items)
 
  
CPUMotherboardGraphicsRAM
intel i5 7600k Asus TUF Z270 Mark 2 NVIDIA GTX 1060 16 GB 2400 DDR4  
Hard DriveHard DriveHard DriveCooling
Samsung 2.5-inch SSD 840 Seagate 2 TB 7200 RPM 32MB Cache 4 500GB HDDs in RAID 10  DeepCool PWM Fan GAMMAXX 300 
OSMonitorKeyboardPower
Windows 10 Pro HP LA2405wg Corsair K90 Mechanical Red Switch 910 watt PC Power and Cooling 
CaseMouseMouse PadAudio
Coolermaster Elite Razer Naga Steel Series SC2 Edition Senheisser 
AudioAudio
Razer Kraken Steelseries Siberia v3 
  hide details  
Reply
post #2 of 3
Generating random numbers is actually impossible for a computer to do since it can't do random, so we have to do pseudo-random. To get a random number dice roll try something like this:
Code:
    #include <cstdlib>
    #include <iostream>
    using namespace std;
    int main()
    {
    int RAND_MAX == 6;
    int random_integer = rand();
    cout << random_integer << endl;
    }

I'm rusty on C++ but I think that should be the right direction wink.gif

Edit:

Some reading: http://www.daniweb.com/software-development/cpp/threads/1769/c-random-numbers
The Riginator
(20 items)
 
 
Wife's Rig
(5 items)
 
CPUGraphicsRAMHard Drive
Qualcomm Snapdragon S600 Adreno 330 2GB LPDDR3 NAND Storage 
Hard DriveOSMonitorKeyboard
Samsung 32GB MicroSD Android 4.4.2 KitKat 5 inch (441ppi) 1080x1920 Super AMOLED SwiftKey 
Power
2600mAh Battery 
  hide details  
Reply
The Riginator
(20 items)
 
 
Wife's Rig
(5 items)
 
CPUGraphicsRAMHard Drive
Qualcomm Snapdragon S600 Adreno 330 2GB LPDDR3 NAND Storage 
Hard DriveOSMonitorKeyboard
Samsung 32GB MicroSD Android 4.4.2 KitKat 5 inch (441ppi) 1080x1920 Super AMOLED SwiftKey 
Power
2600mAh Battery 
  hide details  
Reply
post #3 of 3
Quote:
Originally Posted by Rubers View Post

Generating random numbers is actually impossible for a computer to do since it can't do random, so we have to do pseudo-random. To get a random number dice roll try something like this:
Code:
    #include <cstdlib>
    #include <iostream>
    using namespace std;
    int main()
    {
    int RAND_MAX == 6;
    int random_integer = rand();
    cout << random_integer << endl;
    }
I'm rusty on C++ but I think that should be the right direction wink.gif
Edit:
Some reading: http://www.daniweb.com/software-development/cpp/threads/1769/c-random-numbers

RAND_MAX is a constant defined in and can not be modified. the correct way to specify a range of random numbers is to use the modulus operation. this code generates 10 random numbers between 1 and 6.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main ()
{
  int rand_num, i;

  /* initialize random seed: */
  srand ( time(NULL) );

  /* generate 10 random numbers  */
  for(i=0; i<10; i++){
    rand_num = rand() % 6 + 1;
    printf("random number = %d\n", rand_num);
  }

  return 0;
}
Fractal Design
(15 items)
 
775 4 life
(15 items)
 
 
CPUMotherboardGraphicsRAM
Intel i7 2600K Biostar TP67XE NVidia GTX 570 Crucial Ballistix 
Hard DriveHard DriveCoolingOS
Crucial C300 RealSSD SDD Samsung F4 2TB Noctua NH-D14 Windows 7 Professional x64 
MonitorMonitorKeyboardPower
Asus VH202T 20'' 1600x900 Acer P244W 24" 1920 x 1080 Apple Keyboard with Numeric Keypad SeaSonic M12II 620W 
CaseMouseAudio
Fractal Design Define XL Titanium Grey Razor Abyssus Creative Sound Blaster X-FI Xtreme Gamer 
CPUMotherboardGraphicsRAM
Intel X3350 3.2Ghz @ 1.25v Gigabyte-GA-P35-DS3L (rev 2) XFX 4870 1GB 4GB OCZ Reaper PC2-6400 
RAMHard DriveHard DriveOptical Drive
2GB Corsair XMS2 PC2-6400 Crucial C300 64GB SSD 2TB Samsung Spinpoint F4 Sony Super Multi 
OSMonitorPowerCase
Windows 7 Professional x64 SP1 Asus VH202T 20'' 1600x900 SeaSonic M12II 620W Cooler Master Centurion 5 
Mouse
Razor Abyssus 
CPUMotherboardGraphicsRAM
Core i5-520M Lenovo 2522BF3 NVIDIA® Quadro® NVS3100M  Ramaxel Technology 4Gb DDR3 
Hard DriveOptical DriveOSMonitor
Samsung SSD 128GB 1.8" Micro SATA  hl-dt-st dvdram gu10n Windows 7 Enterprise (64-bit) 14.1" WXGA (1280x800) display, anti-glare, LED ... 
Power
9-cell plus Slice battery 
  hide details  
Reply
Fractal Design
(15 items)
 
775 4 life
(15 items)
 
 
CPUMotherboardGraphicsRAM
Intel i7 2600K Biostar TP67XE NVidia GTX 570 Crucial Ballistix 
Hard DriveHard DriveCoolingOS
Crucial C300 RealSSD SDD Samsung F4 2TB Noctua NH-D14 Windows 7 Professional x64 
MonitorMonitorKeyboardPower
Asus VH202T 20'' 1600x900 Acer P244W 24" 1920 x 1080 Apple Keyboard with Numeric Keypad SeaSonic M12II 620W 
CaseMouseAudio
Fractal Design Define XL Titanium Grey Razor Abyssus Creative Sound Blaster X-FI Xtreme Gamer 
CPUMotherboardGraphicsRAM
Intel X3350 3.2Ghz @ 1.25v Gigabyte-GA-P35-DS3L (rev 2) XFX 4870 1GB 4GB OCZ Reaper PC2-6400 
RAMHard DriveHard DriveOptical Drive
2GB Corsair XMS2 PC2-6400 Crucial C300 64GB SSD 2TB Samsung Spinpoint F4 Sony Super Multi 
OSMonitorPowerCase
Windows 7 Professional x64 SP1 Asus VH202T 20'' 1600x900 SeaSonic M12II 620W Cooler Master Centurion 5 
Mouse
Razor Abyssus 
CPUMotherboardGraphicsRAM
Core i5-520M Lenovo 2522BF3 NVIDIA® Quadro® NVS3100M  Ramaxel Technology 4Gb DDR3 
Hard DriveOptical DriveOSMonitor
Samsung SSD 128GB 1.8" Micro SATA  hl-dt-st dvdram gu10n Windows 7 Enterprise (64-bit) 14.1" WXGA (1280x800) display, anti-glare, LED ... 
Power
9-cell plus Slice battery 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › How would I make something like a rolling dice for a TEXT BASED game?