could you check my code ?

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2006
Posts: 3
Reputation: kosmitek is an unknown quantity at this point 
Solved Threads: 0
kosmitek kosmitek is offline Offline
Newbie Poster

could you check my code ?

 
0
  #1
Dec 25th, 2006
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

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












#include<iostream>
#include<ctime>
#include <allegro.h>
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()
Last edited by kosmitek; Dec 25th, 2006 at 3:07 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: could you check my code ?

 
0
  #2
Dec 25th, 2006
What is your code supposed to do?
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 3
Reputation: kosmitek is an unknown quantity at this point 
Solved Threads: 0
kosmitek kosmitek is offline Offline
Newbie Poster

Re: could you check my code ?

 
0
  #3
Dec 26th, 2006
Player throw bone and he going on board about some number of fields
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 176
Reputation: dubeyprateek is an unknown quantity at this point 
Solved Threads: 22
dubeyprateek's Avatar
dubeyprateek dubeyprateek is offline Offline
Junior Poster

Re: could you check my code ?

 
0
  #4
Dec 26th, 2006
Originally Posted by kosmitek View Post
Player throw bone and he going on board about some number of fields
So,where is the problem? Is it not working?
I know I am. Therefore I am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 3
Reputation: kosmitek is an unknown quantity at this point 
Solved Threads: 0
kosmitek kosmitek is offline Offline
Newbie Poster

Re: could you check my code ?

 
0
  #5
Dec 26th, 2006
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
Last edited by kosmitek; Dec 26th, 2006 at 8:53 am.
Attached Files
File Type: zip game.zip (519.8 KB, 4 views)
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 176
Reputation: dubeyprateek is an unknown quantity at this point 
Solved Threads: 22
dubeyprateek's Avatar
dubeyprateek dubeyprateek is offline Offline
Junior Poster

Re: could you check my code ?

 
0
  #6
Dec 27th, 2006
Originally Posted by kosmitek View Post
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.
I know I am. Therefore I am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC