Skip to main content
gamedev.net
🔒 Locked

Simple Textgame programming

Started by Daaark 8 replies 350+ views
Original Post
Daaark
Daaark
I''ve been trying to make some text rpg games like I used to in QBasic with Borland''s free compiler, and for windows. 1. I can''t get this code to compile , what is the right way to assign strings?
struct WEAPON
{
	char  name[20];
	int   damage;
	int   cost;
};

WEAPON w[5];

void SetWeapon(int instance,char *weaponname, int damage,int cost)
{
	w[instance].name = weaponname;
	w[instance].damage = damage;
	w[instance].cost = cost;
}

void InitWeapons(void)
{
	SetWeapon(0,"bare hands",0,0);
	SetWeapon(1,"knife",2,10);
	SetWeapon(2,"dagger",4,100);
	SetWeapon(3,"short sword",6,500);
	SetWeapon(4,"sword",8,1000);
}
 
2. How can i get the text to work in the window the same way it did in dos? in dos it used to scroll down the screen automatically as you printed more text, but with drawtext, you have to give pixel co-ordinates. I haven''t been able to find any good tutorials on this, everywhere I look, they teach you how to make a basic window, then jump to direct draw, or adavanced windows stuff and mfc.
CaptainJester
CaptainJester
Does the code just not work, or do you get a compiler error? If it is an error, post the error message.

If you are doing strictly a text based game, an easier way to do is just to do a console app. This way, your entry point is main(), not winmain() and you just have to use printf and scanf/getch for console stuff. If you want to use windows and output to a window, I don''t remember at the moment. I''ll have to look it up.

---
Make it work.
Make it fast.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
krez
krez
if you are using char arrays for strings, you have to #include < string.h> or , and then use the string functions in there. these include strcpy (to copy a string), strcat (to concatenate(sp?) - add to the end of an existing string).
some people would say use the STL strings, as they are fun and easy.

--- krez (krezisback@aol.com)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
Promit
Promit
www.geocities.com/promitr/DrugWars.zip

I wrote it myself for ppl who need stuff like this. VERY heavily commented, and uses the a little bit. It''s source and works in MSVC6, i dont know if Borlan will run it.

-----------------------------
The sad thing about artificial intelligence is that it lacks artifice and therefore intelligence.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Daaark
Daaark
I''m not making a console app, the whole point of this is to learn windows.

the error is something about needing an lvalue

i''ve tried w[instance].name = weaponname;
w[instance].name = &weaponname
w[instance].name = *weaponname;

same error.


Thanks promit, I''m looking through your file now

Daaark
Daaark
This cpp file is nothing but 1000 lines of cout :-( (it compiled fine btw) I''m looking for windows stuff.
VolkerG
VolkerG
Krez has allready told you to use the string functions from the C library.
Another option (since you''re using C++) would be using the STL string class.
BeerNutts
BeerNutts
w[instance].name = weaponname;

Does not work. It points the pointer name to the address stored in weaponname, so, when that function leaves, that address will not be vaild any more.

You have to use strcpy

ex:
strcpy(w[instance].name, weaponname);

That will solve it.
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)
Daaark
Daaark
VolkerG, I still need to find out how to write text in the window the same way i did in dos. (question number 2)
krez
krez
the console does it just like it did in DOS (ok, well not exactly, i heard someone mutter... but damn close anyways). if you feel you must do it with windows, you are going to have to work out all the details yourself, just to emulate something that you already have.

--- krez (krezisback@aol.com)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.