# D&D C++ Style!!



## dradcliffe09 (Sep 4, 2009)

I'm getting back into my C++ programming hobby to brush up my skills for a new engineering career. 

Anyway, when I put the hobby down last christmas, I was working on a text rpg not unlike Dracula 1980 on PC, but with a random nuber generator to roll dice for the combat. I had a working source code that could run a combat encounter in the IDE until the player lost or the monster died.

Has anyone else tried to do this? MAy I borrow some source code?

Either way, I'll get back to work on this project and I would be happy to share my work with a community of interested gamers.

I deleted all the old work when I partitioned my HD, so I'm starting from scratch again. I'll be sure to post the progress as it goes, but to give you an idea, it ran a DOWHILE loop that terminated when the INT monterhp or charhp fell below zero.

I look forward to comments on this and sharing my work with you guys. Cheers!:victory:


----------



## dradcliffe09 (Sep 4, 2009)

Geez, somehow I get the feeling this thread won't last very long. I'm gonna post ojn this baby until I DIE!!!! ;D


----------



## dradcliffe09 (Sep 4, 2009)

Still refreshing my C++ skills. Man, you put this stuff down too long and you just lose it! As soon as I canget a working random number generator going, we should be on our way...


----------



## NerdyOgre254 (Jul 16, 2008)

I can't believe i'm coming to this thread so late.
I'm a first year Bachelor of Computer Science (Games Technology) student.
the function you're looking for to get a random number generator is the 'rand' function.
i'll whip up a quick random number C++ program right now (just here, you can do debugging on your own )
(note // means a comment)
#include <iostream> //input output stream library
#include <cstdlib> //C standard Library, for C++. if you're using C, then its <stdlib.h>
using namespace std;

int randomnumber()
(
int result; //declares the variable 'result' where we store the final result
int range; //declares the range of random variables
range = 20;
result = (rand() % range) + 1;
cout << result;
return 0;
)

that should give you what you need to begin with. without a compiler I can't tell you whether that will compile without errors but I think you should be right.
note that the % symbol after rand() means that it has a range of possible values from 0 to whatever you declare 'range' to be. 
I added a +1 to factor in that you can't have a 0 on your to hit roll.

That should be a good start.
If you can afford it, I would suggest investing in the book 'Problem Solving with C++', by Walter Savitch. it's a bit expensive (it is a university textbook after all) but it's well worth it.


----------



## dradcliffe09 (Sep 4, 2009)

HELL YEAH! Thanks, Nerdy. I'll have to take it home to give it a try. I'm using Dev.cpp from bloodshed. I'll let you know how it goes ASAP.


----------



## Jezlad (Oct 14, 2006)

Would you be able to turn your programming skills towards an online dice roller for warhammer 40k?

I'm looking for a coder now.


----------



## dradcliffe09 (Sep 4, 2009)

You bet! I'm still working on the program now. Of course NerdyOgre may be more help to you at this point with his education. I'm sure he can get the job done much faster than I!


----------



## NerdyOgre254 (Jul 16, 2008)

if you want me to write something up I can give it a shot, but as for making it look pretty and integrating it with the website I'm not experienced enough to do that at the moment
Give me a PM and we can talk about what you need/want.


----------



## WoRLoKKeD (Apr 1, 2008)

Is it bad that while I like the idea, my knowledge of physics and maths makes me cringe at the term 'random' number generator?


----------



## NerdyOgre254 (Jul 16, 2008)

WoRLoKKeD said:


> Is it bad that while I like the idea, my knowledge of physics and maths makes me cringe at the term 'random' number generator?


semantics.
while rand() doesn't do it perfectly, you can seed the variables from the system clock as many times as you want ie rand(time(time(time))) if I remember correctly, so it does randomise pretty well.
there's another way to do it but it was pretty damn long and I don't remember it particularly well, because it was pretty damn confusing too.


----------



## dradcliffe09 (Sep 4, 2009)

Well, I'm having to put this project on hold for the moment. I've got my hands full doing pixel art for two big projects. I'll check in here once in a while to see houw it's going. I still want to go through with this project, because my goal is to have a DnD game that will run turn based play on the pc, with the ability to upload maps, items, characters, campaigns, etc.. The only limit would be our imaginations. This may have been atempted or there may be one in progress, but I want to get my hands in it and really see how it works, plus, maybe we can actually get a 3D engine based game going at some point! L8R! If you want to see what I'm up to:

http://www.heresy-online.net/forums/showthread.php?t=48287

http://www.heresy-online.net/forums/showthread.php?p=500684#post500684

check it out! :biggrin:


----------



## NerdyOgre254 (Jul 16, 2008)

Ooh, this I like...
I would follow through, but I am *incredibly* busy at the moment - I have 1 Win32 assignment, 1 Data Communications assignment, 1 Database Management Systems Assignment, and 1 Discrete Mathematics Assignment.
Shouldn't be on here, to be honest


----------



## dradcliffe09 (Sep 4, 2009)

WHOA! :shok: Good luck with that, Nerdy!! Just one semester with Algebra I keeps me busy enough! I'll be checkin' in here and there!


----------



## ghazghkull-killyork (Jun 15, 2008)

hey one of my good friends has written a complete program where you can have any numbered dice and roll a chosen amount, show which die are over a chosen number, and total the dice over them limit. he has also added a dnd portion, where with one press of a button you get 6 sets for 4 randomly rolled d6's and gives the total of the 3 highest. not sure if i get it be be able to be down loaded but ill try figure it out. ill get it up if/when i can


----------



## dradcliffe09 (Sep 4, 2009)

I like the dice roller. It would make a good subroutine for a game program when you have to have AI or randomized outcomes.

I've started a course in C++ at college this spring, hopefully I'll know enough by May to write a decent program for D&D. We shall have to see...


----------



## dradcliffe09 (Sep 4, 2009)

UPDATE: I'm in the third week of Intro to C++ at college, and I'm learning a few things. 

// Dan Radcliffe
// First Random Number Generator 

#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

int main()
{
// declare variables
int firstRandomNumber;

// generate a random number and assign the number to
// a variable
firstRandomNumber = rand() % 10 + 1; // +1 so the number won't be zero

// output the number
cout << “Your random number between 1 and 10 is: “ << endl;

// wait for user input before ending program
char myLine[100];
cin.getline(myLine,100);

// end program
return 0;
}

The dice roller should be ready soon!


----------

