944,118 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1957
  • C RSS
Dec 25th, 2006
0

could you check my code ?

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kosmitek is offline Offline
3 posts
since Dec 2006
Dec 25th, 2006
0

Re: could you check my code ?

What is your code supposed to do?
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Dec 26th, 2006
0

Re: could you check my code ?

Player throw bone and he going on board about some number of fields
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kosmitek is offline Offline
3 posts
since Dec 2006
Dec 26th, 2006
0

Re: could you check my code ?

Click to Expand / Collapse  Quote originally posted by kosmitek ...
Player throw bone and he going on board about some number of fields
So,where is the problem? Is it not working?
Reputation Points: 39
Solved Threads: 24
Junior Poster
dubeyprateek is offline Offline
176 posts
since Mar 2006
Dec 26th, 2006
0

Re: could you check my code ?

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
Attached Files
File Type: zip game.zip (519.8 KB, 23 views)
Last edited by kosmitek; Dec 26th, 2006 at 8:53 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kosmitek is offline Offline
3 posts
since Dec 2006
Dec 27th, 2006
0

Re: could you check my code ?

Click to Expand / Collapse  Quote originally posted by kosmitek ...
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.
Reputation Points: 39
Solved Threads: 24
Junior Poster
dubeyprateek is offline Offline
176 posts
since Mar 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Export Class in DLl
Next Thread in C Forum Timeline: Data rate of a serial port





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC