Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » board, pawn and classes

This thread is locked; no one can reply to it. rss feed Print
 1   2   3 
board, pawn and classes
kosmitek
Member #8,151
December 2006

Please help me - I want change my code that in code were classes, constructors and destructors but I don't know where must be for example: BITMAP *board = NULL; set_color_depth(32) and other things in my code - could you change my code that it includes classes, constructors and destructors ?? Please help :(

It is my board:
http://img407.imageshack.us/img407/2996/boardnj8.jpg
It is my pawn:
http://img409.imageshack.us/img409/5185/pawnyi0.jpg

It is my code:

1 
2 
3#include<iostream>
4#include<ctime>
5#include <allegro.h>
6 
7using namespace std;
8 
9 
10int main()
11{
12BITMAP *board = NULL;
13BITMAP *pawn = NULL;
14BITMAP *buffer = NULL;
15allegro_init();
16install_keyboard();
17set_color_depth(32);
18set_gfx_mode(GFX_AUTODETECT,1024,768,0,0);
19buffer=create_bitmap(SCREEN_W,SCREEN_H);
20 
21 
22board = load_bitmap("board.bmp",NULL);
23pawn = load_bitmap("pawn.bmp",NULL);
24 
25 
26int tab1[2][10]={
27 {100,220,370,500,700,700,500,350,220,100},
28 {100,100,100,100,100,340,340,340,340,340},
29 };
30 
31int tab2[10]={0,1,2,3,4,5,6,7,8,9};
32 
33int *index=&tab2[0];
34int *zero=&tab2[0];
35int *nine=&tab2[9];
36int module;
37int eyes;
38srand (time(0));
39 
40 
41while(!key[KEY_ESC])
42{
43eyes = 1+rand()%3;
44clear_to_color(buffer,makecol(255,255,255));
45blit(board,buffer,0,0,0,0,board->w,board->h);
46blit(pawn,buffer,0,0,tab1[0][*index],tab1[1][*index],pawn->w,pawn->h);
47textprintf_ex(buffer, font, 267, 600, makecol(0, 0, 0), -1, "You throw: %d", eyes);
48textprintf_ex(buffer, font, 267, 620, makecol(0, 0, 0), -1, "-> - left, <- - right");
49textprintf_ex(buffer, font, 267, 640, makecol(0, 0, 0), -1, "ESC - the end of the game");
50blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
51readkey();
52 
53 
54 
55direction:
56if (key[KEY_LEFT])
57{
58if(*index==0||*index==1||*index==2||*index==3||*index==4)
59 {
60 if ((*index-eyes)>=*zero)
61 {
62 index=index-eyes;
63 }
64 else
65 {
66
67 index=nine-(eyes-*index-1);
68 }
69
70 }
71else if(*index==5||*index==6||*index==7||*index==8||*index==9)
72 
73 {
74 if ((*index+eyes)<=*nine)
75 {
76 index=index+eyes;
77 }
78 else
79 {
80 module=eyes-(*nine-*index);
81 if (module<0)
82 {
83 module=-module;
84 }
85 index=zero+module-1;
86 }
87
88 }
89}
90 
91 
92 
93
94else if (key[KEY_RIGHT])
95{
96 if(*index==0||*index==1||*index==2||*index==3||*index==4)
97 {
98 index=index+eyes;
99
100 }
101 else
102 {
103 index=index-eyes;
104 }
105
106
107}
108
109
110
111else
112{
113 if (!key[KEY_ESC])
114 {
115 goto direction;
116 }
117
118}
119 
120 
121 
122}
123 
124destroy_bitmap(board);
125destroy_bitmap(pawn);
126destroy_bitmap(buffer);
127allegro_exit();
128return 0;
129}
130END_OF_MAIN()

Albin Engström
Member #8,110
December 2006
avatar

MERRY CHRISTMAS!!!. HO! HO! HO!.

kosmitek
Member #8,151
December 2006

marry christmas hehehe :) But is this answer for my problem ? :)

HardTranceFan
Member #7,317
June 2006
avatar

Quote:

But is this answer for my problem ?

No. I'm guessing that Albin Engström is hinting that this may be Christmas time, but we're not feeling benevolent enough to do all the coding for you. We can help, but firstly you really need to pick up a C++ book, or check out the on-line tutorials, and try to work it out for yourself. If you get stuck, then maybe we can help you.

--
"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)

kosmitek
Member #8,151
December 2006

But in c++ books don't write where should be:
allegro_init();
install_keyboard();
set_color_depth(32);
set_gfx_mode(GFX_AUTODETECT,1024,768,0,0);
buffer=create_bitmap(SCREEN_W,SCREEN_H);
BITMAP *board = NULL;
BITMAP *pawn = NULL;
BITMAP *buffer = NULL;

in classes or in main ??
:( :( :(

1#include<iostream>
2#include<ctime>
3#include <allegro.h>
4using namespace std;
5 
6 
7class boardboard
8{
9public:
10allegro_init();
11install_keyboard();
12set_color_depth(32);
13set_gfx_mode(GFX_AUTODETECT,1024,768,0,0);
14buffer=create_bitmap(SCREEN_W,SCREEN_H);
15BITMAP *board = NULL;
16BITMAP *pawn = NULL;
17BITMAP *buffer = NULL;
18board = load_bitmap("board.bmp",NULL);
19pawn = load_bitmap("pawn.bmp",NULL);
20 
21int tab1[2][10]={
22 {100,220,370,500,700,700,500,350,220,100},
23 {100,100,100,100,100,340,340,340,340,340},
24 };
25int tab2[10]={0,1,2,3,4,5,6,7,8,9};
26 
27int *index=&tab2[0];
28int *zero=&tab2[0];
29int *nine=&tab2[9];
30int module;
31int eyes;
32srand (time(0));
33 
34 
35while(!key[KEY_ESC])
36{
37eyes = 1+rand()%3;
38clear_to_color(buffer,makecol(255,255,255));
39blit(board,buffer,0,0,0,0,board->w,board->h);
40blit(pawn,buffer,0,0,tab1[0][*index],tab1[1][*index],pawn->w,pawn->h);
41textprintf_ex(buffer, font, 267, 600, makecol(0, 0, 0), -1, "You throw: %d", eyes);
42textprintf_ex(buffer, font, 267, 620, makecol(0, 0, 0), -1, "-> - left, <- - right");
43textprintf_ex(buffer, font, 267, 640, makecol(0, 0, 0), -1, "ESC - the end of the game");
44blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
45readkey();
46 
47 
48 
49direction:
50if (key[KEY_LEFT])
51{
52if(*index==0||*index==1||*index==2||*index==3||*index==4)
53 {
54 if ((*index-eyes)>=*zero)
55 {
56 index=index-eyes;
57 }
58 else
59 {
60
61 index=nine-(eyes-*index-1);
62 }
63
64 }
65else if(*index==5||*index==6||*index==7||*index==8||*index==9)
66 
67 {
68 if ((*index+eyes)<=*nine)
69 {
70 index=index+eyes;
71 }
72 else
73 {
74 module=eyes-(*nine-*index);
75 if (module<0)
76 {
77 module=-module;
78 }
79 index=zero+module-1;
80 }
81
82 }
83}
84 
85 
86 
87
88else if (key[KEY_RIGHT])
89{
90 if(*index==0||*index==1||*index==2||*index==3||*index==4)
91 {
92 index=index+eyes;
93
94 }
95 else
96 {
97 index=index-eyes;
98 }
99
100
101}
102
103
104
105else
106{
107 if (!key[KEY_ESC])
108 {
109 goto direction;
110 }
111
112}
113 
114 
115 
116}
117 
118destroy_bitmap(board);
119destroy_bitmap(pawn);
120destroy_bitmap(buffer);
121allegro_exit();
122};
123 
124 
125 
126 
127 
128 
129int main()
130{
131boardboard.something;
132 
133 
134return 0;
135}
136END_OF_MAIN()

Durnus
Member #7,997
November 2006
avatar

For the initialization (allegro_init(), etc.), that should be in the main function.

Classes (in my opinion) should just give the main function bitmaps to draw, or even just their position. Although after you initialize allegro in the main function, classes can use allegro functions.

I hope this answers your question. (And I hope that my answer is valid. :P )

kosmitek
Member #8,151
December 2006

I change my code but something is wrong - what is wrong :( :( ??

1 
2#include<iostream>
3#include<ctime>
4#include <allegro.h>
5using namespace std;
6 
7 
8class boardboard
9{
10private:
11BITMAP *board;
12BITMAP *pawn;
13BITMAP *buffer;
14
15public:
16 
17int tab1[2][10]={
18 {100,220,370,500,700,700,500,350,220,100},
19 {100,100,100,100,100,340,340,340,340,340},
20 };
21int tab2[10]={0,1,2,3,4,5,6,7,8,9};
22 
23boardboard (BITMAP a, BITMAP b, BITMAP c) //constructor
24{
25 *board=a;
26 *board=b;
27 *board=c;
28
29}
30 
31 
32int *index=&tab2[0];
33int *zero=&tab2[0];
34int *nine=&tab2[9];
35int module;
36int eyes;
37srand (time(0));
38 
39while(!key[KEY_ESC])
40{
41eyes = 1+rand()%3;
42clear_to_color(buffer,makecol(255,255,255));
43blit(board,buffer,0,0,0,0,board->w,board->h);
44blit(pawn,buffer,0,0,tab1[0][*index],tab1[1][*index],pawn->w,pawn->h);
45textprintf_ex(buffer, font, 267, 600, makecol(0, 0, 0), -1, "You throw: %d", eyes);
46textprintf_ex(buffer, font, 267, 620, makecol(0, 0, 0), -1, "-> - left, <- - right");
47textprintf_ex(buffer, font, 267, 640, makecol(0, 0, 0), -1, "ESC - the end of the game");
48blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
49readkey();
50 
51 
52 
53direction:
54if (key[KEY_LEFT])
55{
56if(*index==0||*index==1||*index==2||*index==3||*index==4)
57 {
58 if ((*index-eyes)>=*zero)
59 {
60 index=index-eyes;
61 }
62 else
63 {
64
65 index=nine-(eyes-*index-1);
66 }
67
68 }
69else if(*index==5||*index==6||*index==7||*index==8||*index==9)
70 
71 {
72 if ((*index+eyes)<=*nine)
73 {
74 index=index+eyes;
75 }
76 else
77 {
78 module=eyes-(*nine-*index);
79 if (module<0)
80 {
81 module=-module;
82 }
83 index=zero+module-1;
84 }
85
86 }
87}
88 
89 
90 
91
92else if (key[KEY_RIGHT])
93{
94 if(*index==0||*index==1||*index==2||*index==3||*index==4)
95 {
96 index=index+eyes;
97
98 }
99 else
100 {
101 index=index-eyes;
102 }
103
104
105}
106
107
108
109else
110{
111 if (!key[KEY_ESC])
112 {
113 goto direction;
114 }
115
116}
117 
118}
119 
120 
121~boardboard(a, b, c) //destructor
122{
123destroy_bitmap(board);
124destroy_bitmap(pawn);
125destroy_bitmap(buffer);
126
127}
128 
129};
130 
131 
132 
133 
134 
135 
136int main()
137{
138
139allegro_init();
140install_keyboard();
141set_color_depth(32);
142set_gfx_mode(GFX_AUTODETECT,1024,768,0,0);
143buffer=create_bitmap(SCREEN_W,SCREEN_H);
144 
145 
146boardboard something ("board.bmp","pawn.bmp",NULL); //constructor
147something.boardboard::~boardboard(BITMAP a, BITMAP b, BITMAP c); //destructor
148 
149allegro_exit();
150return 0;
151}
152END_OF_MAIN()

raccoon
Member #7,478
July 2006

are you kidding?

[EDIT]
but to name one thing which is totally wrong:
don't use goto

also, you can't just write code into a class without putting it into a method. I think you should inform yourself about the concept of object-orientation before trying to use classes.

LennyLen
Member #5,313
December 2004
avatar

Quote:

I change my code but something is wrong

Sorry, I left my psychic powers behind somewhere. Please explain what you mean by "something is wrong."

X-G
Member #856
December 2000
avatar

We will not do your homework for you, either.

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

LennyLen
Member #5,313
December 2004
avatar

Quote:

but to name one thing which is totally wrong:
don't use goto

There are a few things like that in the code that are bad, and he was told about them last time he posted about his programs not working.

kosmitek
Member #8,151
December 2006

so I have questions:

1. in the class is this must be private ??? or maybe something else ??:

BITMAP *board;  
BITMAP *pawn; 
BITMAP *buffer;

?????

2.

constructor in the class should be ?????:
boardboard (BITMAP a, BITMAP b, BITMAP c)  //constructor
{
           *board=a;
           *board=b;
           *board=c;
           
}

3.

constructor in the main ????- what is wrong ??:
boardboard something ("board.bmp","pawn.bmp",NULL);  //constructor

???

4. destructor in the class - what is wrong ???:

~boardboard(a, b, c)   //destructor
{
destroy_bitmap(board); 
destroy_bitmap(pawn); 
destroy_bitmap(buffer); 
}

5. destructor in main - what is wrong ???:
something.boardboard::~boardboard(BITMAP a, BITMAP b, BITMAP c); //destructor

LennyLen
Member #5,313
December 2004
avatar

Quote:

in the class is this must be private or maybe something else ??

No, they don't have to be private, but they should be.

Quote:

constructor in the class should be ?????:

Well for one thing, you're assingning the board pointer three different values consecutively, so the first two lines do nothing. Secondly, it should be:
board=&a;

Quote:

4. destructor in the class - what is wrong

Well, you haven't given any type information about the arguments that the function takes. I don't know what C++ defults too if you omit this information. ints? Your destructor doesn't need to take any arguments anyway (I don't even think destructors can take arguments).

Quote:

5. destructor in main - what is wrong

You do not call the destructor yourself. These are called automatically when you delete the object.

edit: had accidentally put "*board=&a"

X-G
Member #856
December 2000
avatar

Okay, I'm just going to be blunt as hell.

You have no idea what the hell you are talking about. You don't know what classes or objects are, what they represent, or how to use them. And you're trying to shoehorn a paradigm that you don't understand onto existing code that you probably don't understand either.

GET A C++ BOOK. FOLLOW IT. START FROM THE BOTTOM.

Then come back when you have questions that make sense.

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

Durnus
Member #7,997
November 2006
avatar

May I suggest this C++ book?

I learned from it, it has stuff about about classes and basic programming practices, such as the standard library. I highly suggest it. :)

Steve Terry
Member #1,989
March 2002
avatar

Steve head hurt >_<

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

Matthew Dalrymple
Member #7,922
October 2006
avatar

Steve smash steve go boom boom steve no likey

=-----===-----===-----=
I like signatures that only the signer would understand. Inside jokes are always the best, because they exclude everyone else.

kosmitek
Member #8,151
December 2006

LennyLen thank you - you are very helpful - Can I give you some points for help ?

I read c++ books and now I want use my knowledge but it is now the most complicated programm which I want write so I want that you help me - do some of you have really to be such boorish ?
Your advices very help me understand classes, constructors, destructors and ALLEGRO - really :).

I change my code - could you now what in this code is wrong ??

1#include<iostream>
2#include<ctime>
3#include <allegro.h>
4using namespace std;
5 
6 
7class boardboard
8{
9private:
10BITMAP *board;
11BITMAP *pawn;
12BITMAP *buffer;
13
14public:
15 
16boardboard (BITMAP a, BITMAP b, BITMAP c) //constructor
17{
18 *board=&a;
19 *board=&b;
20 *board=&c;
21
22}
23 
24 
25~boardboard() //destructor
26{
27destroy_bitmap(board);
28destroy_bitmap(pawn);
29destroy_bitmap(buffer);
30
31}
32 
33 
34 
35 
36void function ()
37{
38int tab1[2][10]= {
39 {100,220,370,500,700,700,500,350,220,100},
40 {100,100,100,100,100,340,340,340,340,340},
41 };
42int tab2[10]={0,1,2,3,4,5,6,7,8,9};
43 
44 
45 
46 
47int *index=&tab2[0];
48int *zero=&tab2[0];
49int *nine=&tab2[9];
50int module;
51int eyes;
52srand (time(0));
53 
54while(!key[KEY_ESC])
55{
56eyes = 1+rand()%3;
57clear_to_color(buffer,makecol(255,255,255));
58blit(board,buffer,0,0,0,0,board->w,board->h);
59blit(pawn,buffer,0,0,tab1[0][*index],tab1[1][*index],pawn->w,pawn->h);
60textprintf_ex(buffer, font, 267, 600, makecol(0, 0, 0), -1, "You throw: %d", eyes);
61textprintf_ex(buffer, font, 267, 620, makecol(0, 0, 0), -1, "-> - left, <- - right");
62textprintf_ex(buffer, font, 267, 640, makecol(0, 0, 0), -1, "ESC - the end of the game");
63blit(buffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
64readkey();
65 
66 
67 
68direction:
69if (key[KEY_LEFT])
70{
71if(*index==0||*index==1||*index==2||*index==3||*index==4)
72 {
73 if ((*index-eyes)>=*zero)
74 {
75 index=index-eyes;
76 }
77 else
78 {
79
80 index=nine-(eyes-*index-1);
81 }
82
83 }
84else if(*index==5||*index==6||*index==7||*index==8||*index==9)
85 
86 {
87 if ((*index+eyes)<=*nine)
88 {
89 index=index+eyes;
90 }
91 else
92 {
93 module=eyes-(*nine-*index);
94 if (module<0)
95 {
96 module=-module;
97 }
98 index=zero+module-1;
99 }
100
101 }
102}
103 
104 
105 
106
107else if (key[KEY_RIGHT])
108{
109 if(*index==0||*index==1||*index==2||*index==3||*index==4)
110 {
111 index=index+eyes;
112
113 }
114 else
115 {
116 index=index-eyes;
117 }
118
119
120}
121
122
123
124else
125{
126 if (!key[KEY_ESC])
127 {
128 goto direction;
129 }
130
131}
132 
133}
134 
135 
136 
137}
138};
139 
140 
141 
142 
143 
144 
145int main()
146{
147
148allegro_init();
149install_keyboard();
150set_color_depth(32);
151set_gfx_mode(GFX_AUTODETECT,1024,768,0,0);
152buffer=create_bitmap(SCREEN_W,SCREEN_H);
153 
154 
155boardboard something ("board.bmp","pawn.bmp",NULL); //constructor
156something.boardboard::~boardboard(); //destructor
157 
158allegro_exit();
159return 0;
160}
161END_OF_MAIN()

Durnus
Member #7,997
November 2006
avatar

If you could please post the errors, that would be good. I, for one, do not like to take the time to compile your code. I did with yours though, just for the heck of it. [Edit:] Yes, I did just contradict myself.

I spotted one problem: You did not declare your "buffer" bitmap before trying to set it to a value.

The other problems I cannot figure out, because I have no clue what boardboard is, and what the point of most of the functions are.

[EDIT2:]

I just noticed something... you are trying to use strings as bitmaps when creating a "boardboard". This cannot be done. If you want to load a bitmap, you would want to use this.

[EDIT3:] After more attempts to fix your code, I gave up.

Personally, I would re-write my code and use comments more often. It seems your code is very disorganized, and you don't even use the game loop function in your main function. (At least I don't think so.)

BAF
Member #2,981
December 2002
avatar

boardboard (BITMAP a, BITMAP b, BITMAP c)  //constructor
{
           *board=&a;
           *board=&b;
           *board=&c;
           
}

WTF is that?

Jonatan Hedborg
Member #4,886
July 2004
avatar

It's slightly amusing but probably more depressing, thats what it is!

TeamTerradactyl
Member #7,733
September 2006
avatar

kosmitek:

1) You should probably put the class declaration in its own header (.H) file and the implementation in a .CPP file:

something.h:

class boardboard
{
   public:

      boardboard (BITMAP a, BITMAP b, BITMAP c);   // Constructor
      ~boardboard(); // Destructor

      void function();

   private:
      BITMAP *board;
      BITMAP *pawn;
      BITMAP *buffer;
};

something.cpp:

1#include <iostream>
2#include <ctime>
3#include <allegro.h>
4 
5using namespace std;
6 
7 
8boardboard::boardboard(BITMAP a, BITMAP b, BITMAP c)
9{
10 *board = &a;
11 *board = &b;
12 *board = &c;
13}
14 
15 
16boardboard::~boardboard()
17{
18 destroy_bitmap(board);
19 destroy_bitmap(pawn);
20 destroy_bitmap(buffer);
21}
22 
23 
24void boardboard::function(void)
25{
26 int tab1[2][10] =
27 {
28 {100, 220, 370, 500, 700, 700, 500, 350, 220, 100},
29 {100, 100, 100, 100, 100, 340, 340, 340, 340, 340},
30 };
31 
32 int tab2[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
33 
34 int *index = &tab2[0];
35 int *zero = &tab2[0];
36 int *nine = &tab2[9];
37 int module;
38 int eyes;
39 
40 srand (time(0));
41 
42 while (!key[KEY_ESC])
43 {
44 eyes = 1 + rand() % 3;
45 clear_to_color(buffer, makecol(255, 255, 255));
46 
47 blit(board, buffer, 0, 0, 0, 0, board->w, board->h);
48 blit(pawn, buffer, 0, 0, tab1[0][*index], tab1[1][*index], pawn->w, pawn->h);
49 
50 textprintf_ex(buffer, font, 267, 600, makecol(0, 0, 0), -1, "You throw: %d", eyes);
51 textprintf_ex(buffer, font, 267, 620, makecol(0, 0, 0), -1, "-> - left, <- - right");
52 textprintf_ex(buffer, font, 267, 640, makecol(0, 0, 0), -1, "ESC - the end of the game");
53 
54 blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
55 readkey();
56 }
57 
58:direction // for GOTO statement
59 
60 if (key[KEY_LEFT])
61 {
62 if (*index >= 0 && *index <= 4)
63 {
64 if ((*index - eyes) >= *zero)
65 {
66 index -= eyes;
67 }
68 else
69 {
70 index = nine - (eyes - *index - 1);
71 }
72 }
73 else if (*index >= 5 && *index <= 9)
74 {
75 if ((*index + eyes) <= *nine)
76 {
77 index += eyes;
78 }
79 else
80 {
81 module = eyes - (*nine - *index);
82 
83 if (module < 0)
84 {
85 module = -module;
86 }
87 
88 index = zero + module - 1;
89 }
90 }
91 }
92 else if (key[KEY_RIGHT])
93 {
94 if (*index >= 0 && *index <= 4)
95 {
96 index += eyes;
97 }
98 else
99 {
100 index -= eyes;
101 }
102 }
103 else
104 {
105 if (!key[KEY_ESC])
106 {
107 goto direction;
108 }
109 }
110}
111 
112 
113int main()
114{
115 allegro_init();
116 install_keyboard();
117 set_color_depth(32);
118 set_gfx_mode(GFX_AUTODETECT, 1024, 768, 0, 0);
119 buffer = create_bitmap(SCREEN_W, SCREEN_H);
120 
121 boardboard something ("board.bmp", "pawn.bmp", NULL); //constructor
122 something.boardboard::~boardboard(); //destructor
123 
124 allegro_exit();
125 return 0;
126}
127 
128END_OF_MAIN()

2) You should put your movement TEST routines in a regular function, not a class. You should keep your movement LOGIC routines in the class:

1int main()
2{
3 ...
4 process_movement();
5 ...
6}
7 
8void process_movement(void)
9{
10 if (key[KEY_LEFT])
11 something.move_left();
12 ...
13 else if (key[KEY_RIGHT])
14 something.move_right();
15 ...
16}

That would also take care of the need for the GOTO statement in there: it would be processed fine without ever needing that.

3) As Durnus said, you are trying to pass strings: boardboard something ("board.bmp", "pawn.bmp", NULL); into a function that is expecting a BITMAP pointer: boardboard(BITMAP a, BITMAP b, BITMAP c) (which should be <b>boardboard(BITMAP *a, BITMAP *b, BITMAP c), by the way.

You would want to change either:

1// Example 1:
2 
3PALETTE pal; // Global
4 
5int main()
6{
7 ...
8 BITMAP *board;
9 BITMAP *pawn;
10 BITMAP *other;
11 
12 boardboard something(board, pawn, NULL);
13 ...
14}
15 
16boardboard::boardboard(BITMAP *a, BITMAP *b, BITMAP *c)
17{
18 load_bitmap(a, pal);
19 load_bitmap(b, pal);
20 load_bitmap(c, pal);
21}

...or...

1// Example 2:
2int main()
3{
4 ...
5 boardboard something ("board.bmp", "pawn.bmp", "");
6}
7 
8boardboard::boardboard(char *a, char *b, char *c)
9{
10 if (a != NULL)
11 load_bitmap(a, pal);
12 if (b != NULL)
13 load_bitmap(b, pal);
14 if (c != NULL)
15 load_bitmap(c, pal);
16 
17 ...
18}

4) I'm not entirely certain what you're doing with all those pointers (tab1 and tab2), but you could DEFINITELY be able to simplify those, or get rid of them entirely (why have an array with the VALUES 0..9, instead of just using "0..9" as numbers?).

Steve Terry
Member #1,989
March 2002
avatar

We went through this last thread... I don't have any idea what C++ book you read but you gotta find something better. I hope it's not a Sams Teach Yourself C++ in 24hr books either.

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

X-G
Member #856
December 2000
avatar

Look, the very fact that you're trying to impose an object-oriented design approach onto something that isn't designed that way in the first place is the clearest indicator we could possibly get that you just don't understand object-oriented programming. Get a different book, read it slowly, and follow the exercises if there are any.

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

Durnus
Member #7,997
November 2006
avatar

May I suggest my previously suggested C++ book?

Durnus said:

May I suggest this C++ book?

I learned from it, it has stuff about about classes and basic programming practices, such as the standard library. I highly suggest it.

As I have said, it doesn't include just classes, but basic C++ programming. (No offence intended with the basic stuff, but it is a very good book to learn classes from.

And as X-G said, you are trying to make classes for something that doesn't need them.

 1   2   3 


Go to: