hi, ive been learning C++ from a book at home, am past the console and pretty much all the form part of the book but have a few unanswered questions.

Beware this might be quite a large post, as i have no access to the net at home so am posting everything at once, sorry :)

im using borland C++ builder. im trying to create a text rpg via forms, like i did for console, only forms allows media etc.

what im trying to create is a text adventure sorta like the game books you can get where you choose a path and go to the corrsponding page. so say there was 300 peices of text, will i need 300 forms?

how do i exit only the current form, like when i press the 'proceed' button id like the current form to close and the next to take its place.

things like equipment array or object i would just creat a equipment.h and call that?

problems/queries.

Dice part! So i have this little dice code i made, when you press the 'Roll die' button it takes a random Number between 1 & 6 and displays a dialogue box with the coresponding image, heres my code. im not sure wether rand() is okto use though? And is this a decent way to do it?

TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
	#include <cstdlib>


using namespace std;


  

{
	int result;
  
	result = rand()%6  ;    //is this part correct, i cant remember?

	ShowMessage(result); //to check result is corresponding to form shown

	if (result==1)
		{
		Form2->ShowModal();   //form showing the number 1
		 }
	else if (result==2)
		{
		 Form3->ShowModal();  //form showing the number 2
		 }
	else if (result==3)
		{
		 Form4->ShowModal();  //form showing the number 3
		 }
	else if (result==4)
		{
		 Form5->ShowModal();  //form showing the number 4
		 }
	else if (result==5)
		{
		 Form6->ShowModal();  //form showing the number 5
		 }
	else if (result==6)
		{
		 Form7->ShowModal();  //form showing the number 6
		 }


} }

2. Battle Code

For this i have just written pseudo code'ish so far but for forms i can just creat a header file and calle the function battle() ? also does that look ok, sorry its not proper pseudo.

/*Luck In Battle

WOUNDED ENEMY
1. if you wounded the ENEMY, and are lucky you Subtract and EXTRA 2 points from ENEMY STAMINA.
2. If unlucky you must restore 1 point to ENEMY STAMINA

WOUNDED PLAYER
1. If PLAYER is wounded and are Lucky restore 1 STAMINA point
2. If inlucky Subtract 1 EXTRA STAMINA point */

/*LUCK

Testing LUCK 

LUCKY - Roll 2 Dice, if number is equal to or less than your CURRENT LUCK score you have been lucky.

UNLUCKY -  If the number is higher than your CURRENT LUCK score, you are UNLUCKY.

Each Time you test luck, 1 LUCK point must be subtracted. */

/*
Read Battle ID
Call coresponding battle stats 

////Determine opponent stats\\\\\
Read INIT_ENM_SKILL  
Call ENM_`Roll2dice();
INIT_ENM_SKILL + ENM_Result = ENM_ATTCK 

////Determine Player stats\\\\\\
Read CURR_PLAY_SKILL
Call Roll2dice();
CURR_PLAY_SKILL + 2DResult = PLAY_ATTK

Do
 {    

if ENM_ATTK ==PLAY_ATTK = miss

           else if { ENM_ATTK > PLAY_ATTK} 
		    STAMINA -2 points.
	 else if { ENM_ATTK < PLAY_ATTK} 
	               ENM_STAMINA -2 points.
 } 
 WHILE STAMINA && ENM_STAMINA != 0
*/


// dice are 6 sided

3. opening an internet page

i had a look at all the internet buttons that i could see but still cant find any thing, i have a 'website' menu button, and would just like to open up a url inb the default browser.


So far im good to creat forms call the, dialogue boxes, etc. its just these niggly bits f code so in summary:

1. rand() - yay or nay?
2. closing a form as a new one opens
3. opening a web browser to a certain url from menu button.
4. Use and creation of header files for objects and battle system etc. (im pretty sure im
ok with this though, just double checking)


oh and hello everyone, very nice site wish i could take it home with me. im glad to have found and become a part of this community.

Balinor

wow nothing, cools, np.

anyways i wrote up my battle code minus luck part, here it is...

//$$---- Form CPP ----
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
//Variables
	int INIT_ENM_SKILL;
	int CURR_PLAY_SKILL;
	int ENM_Result;
	int ENM_ATTK;
	int DResult;
	int PLAY_ATTK;
	int STAMINA;
	int ENM_STAMINA;

	STAMINA=8;
	ENM_STAMINA=7;
	CURR_PLAY_SKILL=10;
	INIT_ENM_SKILL=11;

 //fight loop
do
 {

//dice code
 DResult = rand()%6 + rand()%6;   //players dice rolls
 ENM_Result = rand()%6 +rand()%6; //enemy dice rolls


//Determine opponent stats
ENM_ATTK=INIT_ENM_SKILL + ENM_Result;  //enemy's attack number

//Determine Player stats
PLAY_ATTK=CURR_PLAY_SKILL + DResult;  //players attack number




	if 	(ENM_ATTK == PLAY_ATTK)   //equal attck strength = miss
		{
		ShowMessage("Miss!");
		}

	else if (ENM_ATTK > PLAY_ATTK) // enemy attck strgth is higher
		{
		STAMINA -2;
		ShowMessage("Enemy Attacks");
		}

	else if (ENM_ATTK < PLAY_ATTK) //players is higher
		{
		ENM_STAMINA -2;
		ShowMessage("PLayer Attacks");
		}
		  }
 while (STAMINA || ENM_STAMINA != 0);   // when players stamina OR enemy's hits 0, end 

	if (STAMINA ==0)
	{
		ShowMessage("Enemy WINS!");
		exit(0);
	}
	else if (ENM_STAMINA==0)
	{
		ShowMessage("Player WINS!");
		exit(0);
	}
}
//---------------------------------------------------------------------------

but i cant seem to get stamina to 0 so get stuck in a infinite loop. do i need something like:

if 	(ENM_ATTK == PLAY_ATTK)   //equal attck strength = miss
		{
		ShowMessage("Miss!");
		}

	else if (ENM_ATTK > PLAY_ATTK) // enemy attck strgth is higher
		{
		STAMINA=STAMINA -2;   // THIS LINE
		ShowMessage("Enemy Attacks");
		}

Also some help on my oringinal post would be great. im sorrry if its been answered elsewhere, i tried searching but only have about ten mins a day of internet access.

Balinor :)

Bump ; ;

this will be my last bump, then ill guess ill need to seek help else where, its a shame i was really looking forward to being a part of what i see to be a great community. mabye im just not asking the right way, i dunno.

thanks all, hopefully its not goodbye

I'm sorry, but your code is quite big. Try posting one question at a time, event if it means opening several threads at once.

You didn't seed the random number generator, so you're getting the same result everytime.

srand(time(0));  // Initialize random number generator.

Oh and on a side note, I love your code. It's very easy to follow.

thank you chococrack, and sci@phy, ill try breaking it down

This article has been dead for over six months. Start a new discussion instead.