Jump to content

Best Way to Declare Large Data Structures

prolemur

I am trying to make a monopoly game and I have data structure for every tile and player so far, and I want to know the best way to declare them. So far I have been simply doing it right in my code. Should I make it into a text file or something? I'm not too sure.

 

I will obviously have to type out most of the things individually like the names, but not the owner as at the start of the game Mr. Monopoly owns it all! This is not my question sorry if while reading this line you got confused :P

Link to comment
Share on other sites

Link to post
Share on other sites

What data structure are you using?

Desktop: Fractel Design R5 - i5 4670K @ stock - Asrock Z97 Extreme 4 - 16GB @ 1600MHz - Asus GTX 970 - Corsair RM650 - OCZ Vector 150 240GB - WD Blue 500GB - Noctua NH-D15

Peripherals & OS: KBC Poker 2 MX Blue - Zowie FK2 - Audio-technica ATH-M50s - Audioengine D1- Windows 10 Pro Monitor: Asus PA248Q 1920x1200

Link to comment
Share on other sites

Link to post
Share on other sites

^

and what language?

What data structure are you using?

C++ and Struct that contains an array of 40 things which themselves (in the struct contain ~10 each, so around 400 variables)

Link to comment
Share on other sites

Link to post
Share on other sites

You can try linking it to an SQL table/database...

 

The table will keep track of the players' data...

 

Each turn, the structure will hold the data from the table...

After the turn, the table gets updated with new data...

 

It will add a few dozen lines to your code though...

 

I've only done this in C and PHP in my classes so I'm far from who you'd call an expert...

Link to comment
Share on other sites

Link to post
Share on other sites

the database approach is more suitable for data that is variable and flexible in size/amount imo

 

if monopoly is always going to have the same 40 places, the same cards, the same placeholders(?), then you can as well hardcode it in your program

the way i would do it is just a namespace, declared in a dedicated file, something like

but i travel on the noob train as well, so i won't say that this is the best approach

but it looks fine to me

#include <string>namespace data{    struct place{        std::string name;        int prices[5];        int upgradeCost[5];    };    extern const place places[40];};
#include "data.h"const data::place data::places[40] = {    {        "first",        {20, 40, 50, 60, 110},        {100, 200, 300, 400, 500}    },    {        "second",        {20, 40, 50, 60, 110},        {100, 200, 300, 400, 500}    }..so on so forth.};
#include <iostream>#include "data.h" int main(){    std::cout << data::places[1].name << std::endl;}
Link to comment
Share on other sites

Link to post
Share on other sites

the database approach is more suitable for data that is variable and flexible in size/amount imo

 

if monopoly is always going to have the same 40 places, the same cards, the same placeholders(?), then you can as well hardcode it in your program

the way i would do it is just a namespace, declared in a dedicated file, something like

but i travel on the noob train as well, so i won't say that this is the best approach

but it looks fine to me

Thanks, that seems like a very elegant way to do it. I haven't yet started using multiple file in my tutorial, so when I do, I'll do this :)

#include <string>namespace data{    struct place{        std::string name;        int prices[5];        int upgradeCost[5];    };    extern const place places[40];};
#include "data.h"const data::place data::places[40] = {    {        "first",        {20, 40, 50, 60, 110},        {100, 200, 300, 400, 500}    },    {        "second",        {20, 40, 50, 60, 110},        {100, 200, 300, 400, 500}    }..so on so forth.};
#include <iostream>#include "data.h" int main(){    std::cout << data::places[1].name << std::endl;}
Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×