Go Back   Forums > Community Chatterbox > Tech Corner > Programming
Memberlist Forum Rules Today's Posts
Search Forums:
Click here to use Advanced Search

Reply
 
Thread Tools Display Modes
Old 11-09-2005, 01:11 AM   #31
punch999
The true Shadow President
 
punch999's Avatar

 
Join Date: Sep 2004
Location: Celebration, United States
Posts: 1,195
Default

Then why did you promise you could do it?
punch999 is offline                         Send a private message to punch999
Reply With Quote
Old 11-09-2005, 10:36 AM   #32
Reup
10 GOSUB Abandonia
20 GOTO 10
 
Reup's Avatar

 
Join Date: Dec 2004
Location: Eindhoven, Netherlands
Posts: 1,508
Default

Quote:
Originally posted by chickenman@Aug 27 2005, 04:23 PM
@Reup
To play the game you will have to give your player commands like,

go north
eat cow
kill sheep

This will be a mix of adventure and RPG
That part was clear to me. Still I'm curious how your game is designed (NOT how it's coded). What classes are you using, how do they relate? And surely you're not planning to hardcode all the rooms? Your code gives no clue about this (there's not much there anyway).

You should look into XML! You could specify your rooms in a rather simple way:
Code:
<room type="normal" id="123">
 * <name>The Ultradark and dank Dungeon</name>
 * <exit>
 * * * <dir>North</dir>
 * * * <desc>The sturdy wooden door</desc>
 * </exit>
 * * *<exit>
 * * * <dir>West</dir>
 * * * <desc>A chain hanging from the ceiling</desc>
 * </exit>
 * <desc>The walls in this dark and dank dungeon are covered in what seem to be
 * * * * * * *troll excrements. Some are still warm and extremely smelly. Bit of toilet
 * * * * * * *paper can be seen between the goo. </desc>
</room> *
Something like this. Off course, i'd give some more thought to a reallly decent DTD You can use any XML-lib for C++ (I'm into Java myself, so I don't know any...).
Reup is offline                         Send a private message to Reup
Reply With Quote
Old 12-09-2005, 07:06 PM   #33
chickenman
Hero Gamer

 
Join Date: Mar 2005
Location: Shella, Kenya
Posts: 417
Default

@ Punch
I thought i could do it LOL

@ Reup
Wait and see i've only just got to work on the game it's self.

A question for any one who can program C++

How will i save the players stats like, attack = 1, defence = 5
as fwrite and fread only accept char and strings ?
chickenman is offline                         Send a private message to chickenman
Reply With Quote
Old 12-09-2005, 08:37 PM   #34
NrmMyth
Hero Gamer

 
Join Date: Jan 2005
Location: ,
Posts: 454
Default

For anything.

Syntax:
Code:
 #include <stdio.h>
 *int fwrite( const void *buffer, size_t size, size_t count, FILE *stream );
The fwrite() function writes, from the array buffer, count objects of size size to stream. The return value is the number of objects written.
__________________
Never mess with me when I have a cougar, Never!
NrmMyth is offline                         Send a private message to NrmMyth
Reply With Quote
Old 13-09-2005, 11:13 AM   #35
chickenman
Hero Gamer

 
Join Date: Mar 2005
Location: Shella, Kenya
Posts: 417
Default

hmmmm i have tryed a number of things but i still can't get it to work.

28 C:\SYS\Desktop\cpp\int-save-test\main.cpp invalid conversion from `int' to `const void*'

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
int age = 15;
int number = 22;
char Fname[12]; //for filename
cout<<"Enter file to save to: ";

cin.getline(Fname,12); //get data
cout<< endl;

//Open file
FILE *file;
file = fopen (Fname,"w");

fwrite (age,1,sizeof(age),file);
fwrite (number,2,sizeof(number),file);

cin.get();
return 0;
}

chickenman is offline                         Send a private message to chickenman
Reply With Quote
Old 13-09-2005, 11:38 AM   #36
Data
retired
 
Data's Avatar


 
Join Date: Jun 2004
Location: Jan Mayen, Svalbard and Jan Mayen
Posts: 2,167
Default

uhm try &age instead of age
and &number instead of number
__________________
Flowing with the stream of life
Data is offline                         Send a private message to Data
Reply With Quote
Old 13-09-2005, 12:06 PM   #37
mik
Newbie

 
Join Date: Jan 2005
Location: ,
Posts: 7
Send a message via MSN to mik
Default

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
int age = 15;
int number = 22;
char Fname[12]; //for filename
cout<<"Enter file to save to: ";

cin.getline(Fname,12); //get data
cout<< endl;

//Open file
FILE *file;
file = fopen (Fname,"w");

char buffer[2];
_itoa(age, buffer, 10); //convert int to char
fwrite (buffer,sizeof(buffer), 1, file);
_itoa(number, buffer, 10);
fwrite (buffer,sizeof(buffer), 1, file);

cin.get();
fclose(file);
return 0;
}

It is work.
mik is offline                         Send a private message to mik
Reply With Quote
Old 15-09-2005, 08:50 AM   #38
chickenman
Hero Gamer

 
Join Date: Mar 2005
Location: Shella, Kenya
Posts: 417
Default

Well it works but I don't understand the
_itoa(number, buffer, 10);

also how do I load the saved data into the correct integers?

:eeeeeh:
chickenman is offline                         Send a private message to chickenman
Reply With Quote
Old 15-09-2005, 10:19 AM   #39
mik
Newbie

 
Join Date: Jan 2005
Location: ,
Posts: 7
Send a message via MSN to mik
Default

So, I don't think that it's a good idea to use "fwrite" here but if you want...

_itoa - convert an integer to a string (see MSDN).
Code for save and load:
Code:
#include <iostream>
#include <fstream>
using namespace std;

int main()
{ 
int age = 15;
int number = 22;
char Fname[12]; //for filename 
cout<<"Enter file to save to: ";

cin.getline(Fname,12); //get data
cout<< endl;

//Open file
FILE *file;
if ((file = fopen (Fname,"w")) != NULL)
{
	char buffer[2];
	_itoa(age, buffer, 10); //convert int to char
	fwrite (buffer,sizeof(char), 2, file);
	_itoa(number, buffer, 10);
	fwrite (buffer,sizeof(char), 2, file);
	fclose(file);
}
else cout<<"Error opening the file";

if ((file = fopen (Fname,"r+t")) != NULL)
{
	char ch_age[2], ch_number[2];
	fread(ch_age, sizeof(char), 2, file);
	fread(ch_number, sizeof(char), 2, file);
	fclose(file);

	age = atoi(ch_age); //convert char to int
	number = atoi(ch_number);
	cout<<"Age = "<<age<<" Number = "<<number;
}
else cout<<"Error opening the file";

cin.get();
return 0;
}
mik is offline                         Send a private message to mik
Reply With Quote
Old 15-09-2005, 03:51 PM   #40
Data
retired
 
Data's Avatar


 
Join Date: Jun 2004
Location: Jan Mayen, Svalbard and Jan Mayen
Posts: 2,167
Default

Or as you really seem to wanting to learn C++
use ifstream and ofstream class.
then you can just output and load stuff like you do with cin/cout
__________________
Flowing with the stream of life
Data is offline                         Send a private message to Data
Reply With Quote
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump
 


The current time is 03:06 PM (GMT)

 
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.