I am using library of ALLEGRO:
board:
http://img407.imageshack.us/img407/2996/boardnj8.jpg
pawn:
http://img409.imageshack.us/img409/5185/pawnyi0.jpg
Could you check code of my program - game - it is run but is everything is good ??
Player throw bone and he going about some number of fields
#include<iostream>
#include<ctime>
#include <allegro.h>
using namespace std;
class boardboard
{
private:
BITMAP *board;
BITMAP *pawn;
BITMAP *buffer;
public:
boardboard (BITMAP *a, BITMAP *b, BITMAP *c) //constructor
{
board=a;
pawn=b;
buffer=c;
function (a, b, c);
}
~boardboard() //destructor
{
destroy_bitmap(board);
destroy_bitmap(pawn);
destroy_bitmap(buffer);
}
void function (BITMAP *a, BITMAP *b, BITMAP *c)
{
c=create_bitmap(SCREEN_W,SCREEN_H);
a = load_bitmap("board.bmp",NULL);
b = load_bitmap("pawn.bmp",NULL);
int tab1[2][10]= {
{100,220,370,500,700,700,500,350,220,100},
{100,100,100,100,100,340,340,340,340,340},
};
int tab2[10]={0,1,2,3,4,5,6,7,8,9};
int *index=&tab2[0];
int *zero=&tab2[0];
int *nine=&tab2[9];
int module;
int eyes;
srand (time(0));
while(!key[KEY_ESC])
{
eyes = 1+rand()%3;
clear_to_color(c,makecol(255,255,255));
blit(a,c,0,0,0,0,a->w,a->h);
blit(b,c,0,0,tab1[0][*index],tab1[1][*index],b->w,b->h);
textprintf_ex(c, font, 267, 600, makecol(0, 0, 0), -1, "You throw: %d", eyes);
textprintf_ex(c, font, 267, 620, makecol(0, 0, 0), -1, "-> - left, <- - right");
textprintf_ex(c, font, 267, 640, makecol(0, 0, 0), -1, "ESC - the end of the game");
blit(c,screen,0,0,0,0,SCREEN_W,SCREEN_H);
readkey();
direction:
if (key[KEY_LEFT])
{
if(*index==0||*index==1||*index==2||*index==3||*index==4)
{
if ((*index-eyes)>=*zero)
{
index=index-eyes;
}
else
{
index=nine-(eyes-*index-1);
}
}
else if(*index==5||*index==6||*index==7||*index==8||*index==9)
{
if ((*index+eyes)<=*nine)
{
index=index+eyes;
}
else
{
module=eyes-(*nine-*index);
if (module<0)
{
module=-module;
}
index=zero+module-1;
}
}
}
else if (key[KEY_RIGHT])
{
if(*index==0||*index==1||*index==2||*index==3||*index==4)
{
index=index+eyes;
}
else
{
index=index-eyes;
}
}
else
{
if (!key[KEY_ESC])
{
goto direction;
}
}
}
}
};
int main()
{
allegro_init();
install_keyboard();
set_color_depth(32);
set_gfx_mode(GFX_AUTODETECT,1024,768,0,0);
boardboard bb(NULL, NULL, NULL);
bb.boardboard::~boardboard();
allegro_exit();
return 0;
}
END_OF_MAIN()
#include
#include
#include
using namespace std;
int main()
{
BITMAP *plan = NULL;
BITMAP *pawn = NULL;
allegro_init();
install_keyboard();
set_color_depth(32); //32-bitowa glebia kolorow
set_gfx_mode(GFX_AUTODETECT,1280,1024,0,0);
set_palette(default_palette);
clear_to_color(screen,15); //wyczyszczenie struktury bitmap i zamalowanie jej danym kolorem
plan = load_bitmap("plan.bmp",default_palette);
pawn = load_bitmap("pawn.bmp",default_palette);
int w=550;
blit(plan,screen,0,0,0,0,plan->w,plan->h);
blit(pawn,screen,0,0,w,400,pawn->w,pawn->h);
textout_ex(screen,font,"You are starting from field number 6",10,740,2,-1);
textout_ex(screen,font,"ESC - The end of program",10,990,2,-1);
int tab[11]={1,2,3,4,5,6,7,8,9,10,11};
int *index=&tab[5];
int *start=&tab[0];
int *end=&tab[10];
int eye;
srand (time(0));
while(!key[KEY_ESC]) //program bedzie dzialac dopoki nie wcisne ESC
{
eye = 1+rand()%6;
textprintf_ex(screen, font, 10, 820, makecol(0, 0, 0), -1, "You throw number: %d", eye);
textout_ex(screen,font,"r Go on right, l Go on left",10,840,2,-1);
readkey();
if (key[KEY_L])
{
if ((index-eye)>=start)
{
index=index-eye;
textprintf_ex(screen, font, 10, 860, makecol(0, 0, 0), -1, "You are now on field number: %d", *index);
w=w-*index*130;
}
else
{
index=end-(eye-*index);
textprintf_ex(screen, font, 10, 860, makecol(0, 0, 0), -1, "You are now on field number: %d", *index);
w=w-*index*130;
}
}
else if (key[KEY_R])
{
if ((index+eye)<=end)
{
index=index+eye;
textprintf_ex(screen, font, 10, 860, makecol(0, 0, 0), -1, "You are now on field number: %d", *index);
}
else
{
index=start+(eye-(*end-*index))-1;
textprintf_ex(screen, font, 10, 860, makecol(0, 0, 0), -1, "You are now on field number: %d", *index);
}
}
clear_bitmap(screen);
blit(plan,screen,0,0,0,0,plan->w,plan->h);
blit(pawn,screen,0,0,w,400,pawn->w,pawn->h);
textout_ex(screen,font,"ESC - The end of program",10,990,2,-1);
}
destroy_bitmap(plan);
destroy_bitmap(pawn);
allegro_exit();
return 0;
}
END_OF_MAIN()
Player throw bone and he going on board about some number of fields
So,where is the problem? Is it not working?
It is working very good but is it pretty code because I am starting study C++ and library Allegro - for example is in my code destructor is good ?? :cheesy:
I gave my game in attachment
It is working very good but is it pretty code because I am starting study C++ and library Allegro - for example is in my code destructor is good ?? :cheesy:
I gave my game in attachment
Your code is provided with no documents, no documentations and with no comments, if you want a code review by a third person all these things are a must.