Hi Thomas,
As we are only working with variables here, my question would be: is there
an advantage to using a class versus a data structure?

Best Regards,
Hayden


-----Original Message-----
From: gamers-boun...@audyssey.org [mailto:gamers-boun...@audyssey.org] On
Behalf Of Thomas Ward
Sent: Friday, April 22, 2011 1:17 AM
To: Gamers Discussion list
Subject: Re: [Audyssey] jim kitchen's nfl football

Hi Jim,

Right. I see your point. Well, one of the reasons I use classes is
that it simplifies that reading and writing game files quite a lot. I
don't know how much you know about object oriented programming/design
but a class is a fansy name for a collection of related variables. For
instance, a wrestler class might be something like this.

class Wrestler
{

public:

    string name;
    float height;
    int weight;
};

Right there we have created a collection of variables that all relate
to a wrestler. In this case a generic one since we haven't actually
asigned them to a specific wrestler, I.E. an object, just yet. So
we'll do that now.

Wrestler steve_austin;
Wrestler shawn_michaels;
Wrestler the_undertaker;

Ah, now we have three wrestlers and the moment I declared them above
it registered copies of the name, height, and weight variables and
asign them to each wrestler. NO problem. This is where it gets easy
for saving and loading files. Since we can reference any variable or
variables  through its object all we have to do is open a file like
this
ofstream file ("wrestlers.sav", ios::binary);
and then write the objects to it as is. For example,
file.write ((char *) &steve_austin, sizeof (steve_austin));
file.write ((char *) &shawn_michaels, sizeof (shawn_michaels));
file.write ((char *) &the_undertaker, sizeof (the_undertaker));
saves the status of every single variable inside the class weather you
have one or one hundred at one time. It is very fast and easy.
Finally, doing
file.close ();
closes our data file.

The reason this is easier for me than reading from a text file is I
can read or write hundreds of variables simply by passing the name of
the class object to the file.write() function or file.read() function
and instantly save or load the state of all variables in that class at
once rather than loading them one by one. This method of streaming
class data to a file is called serialization. In particular binary
serialization since I created a binary file in this case.

Cheers!


On 4/21/11, Jim Kitchen <j...@kitchensinc.net> wrote:
> Hi Thomas,
>
> As I do not create classes or anything like that, a simple text file is
the
> easiest way to write and retrieve data, it is just
>
> Open "homer.cfg" For Output As #1
> Print #1, nv(1)
> Close #1
>
> Open "homer.cfg" For Input As #1
> Input #1, nv(1)
> Close #1
>
> or like
>
> Open "homerrec.txt" For Output As #1
> Print #1, " Homer on a Harley  record file  By Jim Kitchen "
> tp$ = " Record number of buses jumped successfully"
> tp$ = tp$ + Str$(sbj)
> Print #1, tp$
> tp$ = " on " + Date$
> Print #1, tp$
> tp$ = " By " + r$
> Print #1, tp$
> Close #1
>
> But for binary files there is more to it, like building strings etc
because
> you can not just write a string to or in a binary file.
>
> Open "homer.rec" For Binary Access Read As #1
> Get #1, , rnb
> Get #1, , lorn
> For x = 1 To lorn
> Get #1, , ln
> rn$ = rn$ + Chr$(ln)
> Next x
> Get #1, , RecMonth
> Get #1, , RecDay
> Get #1, , RecYear
> Close #1
>
> Open "homer.rec" For Binary Access Write As #1
> Put #1, , sbj
> lorn = Len(r$)
> Put #1, , lorn
> For x = 1 To lorn
> ln = Asc(Mid$(r$, x, 1))
> Put #1, , ln
> Next x
> dt$ = Date$
> RecMonth = Val(Mid$(dt$, 1, 2))
> RecDay = Val(Mid$(dt$, 4, 2))
> RecYear = Val(Mid$(dt$, 7, 4))
> Put #1, , RecMonth
>  Put #1, , RecDay
> Put #1, , RecYear
> Close #1
>
> But I go through the hassle of binary files so that one can not as easily
> edit the record files etc.
>
> BFN
>
>      Jim
>
> Binary Choir = 1"1"1"1"1"1"1"1"1
>
> j...@kitchensinc.net
> http://www.kitchensinc.net
> (440) 286-6920
> Chardon Ohio USA
> ---
> Gamers mailing list __ Gamers@audyssey.org
> If you want to leave the list, send E-mail to
> gamers-unsubscr...@audyssey.org.
> You can make changes or update your subscription via the web, at
> http://audyssey.org/mailman/listinfo/gamers_audyssey.org.
> All messages are archived and can be searched and read at
> http://www.mail-archive.com/gamers@audyssey.org.
> If you have any questions or concerns regarding the management of the
list,
> please send E-mail to gamers-ow...@audyssey.org.
>

---
Gamers mailing list __ Gamers@audyssey.org
If you want to leave the list, send E-mail to
gamers-unsubscr...@audyssey.org.
You can make changes or update your subscription via the web, at
http://audyssey.org/mailman/listinfo/gamers_audyssey.org.
All messages are archived and can be searched and read at
http://www.mail-archive.com/gamers@audyssey.org.
If you have any questions or concerns regarding the management of the list,
please send E-mail to gamers-ow...@audyssey.org.


---
Gamers mailing list __ Gamers@audyssey.org
If you want to leave the list, send E-mail to gamers-unsubscr...@audyssey.org.
You can make changes or update your subscription via the web, at
http://audyssey.org/mailman/listinfo/gamers_audyssey.org.
All messages are archived and can be searched and read at
http://www.mail-archive.com/gamers@audyssey.org.
If you have any questions or concerns regarding the management of the list,
please send E-mail to gamers-ow...@audyssey.org.

Reply via email to