Advertisement
shywolf91

TETRIS CODE UPDATED 5-17-2012

May 17th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.49 KB | None | 0 0
  1. //Dark GDK - The Game Creators - www.thegamecreators.com
  2.  
  3. //the wizard has created a very simple project that uses Dark GDK
  4. //it contains the basic code for a GDK application
  5.  
  6. //whenever using Dark GDK you must ensure you include the header file
  7. #include "DarkGDK.h"
  8.  
  9.  
  10. //Global
  11. int Block_Size=20;
  12. int grid[20][10];
  13. //colors
  14. const DWORD Red = dbRGB(255,0,0);
  15. const DWORD Green = dbRGB(0,255,0);
  16. const DWORD Blue = dbRGB(0,0,255);
  17. const DWORD Magenta = dbRGB(255,0,255);
  18. const DWORD Black = dbRGB(0,0,0);
  19. const DWORD White = dbRGB(255,255,255);
  20. const DWORD Yellow = dbRGB(255,255,0);
  21. const DWORD Cyan = dbRGB(0,255,255);
  22. const DWORD Orange = dbRGB(255,165,0);
  23. const DWORD Grey = dbRGB(177,177,177);
  24. //end colors
  25. //end global
  26.  
  27. //Classes
  28.  
  29. class Block {
  30. private:
  31.     DWORD color;
  32.     //int blocks[4];
  33. public:
  34.     int x,y;
  35.     Block();
  36.     Block(int, int, DWORD);
  37.     void draw();
  38.     void move(int, int);
  39.     void clear();
  40.     //bool col();
  41.  
  42. };
  43. Block::Block(){
  44. x = 0;
  45. y =0;
  46. color = White;
  47. }
  48. //Methods (Block)
  49.  
  50. Block::Block(int X, int Y, DWORD COLOR)
  51. {
  52.     x=X;
  53.     y=Y;
  54.     color=COLOR;
  55. }
  56.  
  57. void Block::draw()
  58. {
  59.     int x1, y1, x2, y2;
  60.     x1=x*Block_Size;
  61.     y1=y*Block_Size;
  62.     x2=x1+Block_Size;
  63.     y2=y1+Block_Size;
  64.  
  65. //  dbInk(color, Black);
  66.     dbBox(x1,y1,x2,y2);
  67. }
  68.  
  69. void Block::clear()
  70. {
  71.  
  72.     dbInk(Black, Black);
  73.     //dbBox(x1,y1,x2,y2);
  74.     draw();
  75. }
  76.  
  77. void Block::move(int dx, int dy)
  78. {
  79.     x=x+dx;
  80.     y=y+dy;
  81.     dbInk(color, Black);
  82.     draw();
  83. }
  84.  
  85. //End Method (Block)
  86.  
  87. class Shape {
  88.  
  89. private:
  90.     Block blocks[4];
  91.     //int pos[8];
  92. public:
  93.     int pos[8];
  94.     DWORD color;
  95.     Shape();
  96.     void make_ishape();
  97.     void move_shape(int,int);
  98.     void draw_shape();
  99.     bool col();
  100. };
  101. //Methods (Shape)
  102. Shape::Shape() {
  103. blocks[0] = Block(0,0, Red);
  104. blocks[1] = Block(0,0, Red);
  105. blocks[2] = Block(0,0, Red);
  106. blocks[3] = Block(0,0, Red);
  107. }
  108. bool Shape::col()
  109. {
  110.     for (int i=0; i<=4; i++)
  111.     {
  112.         if (blocks[i].y >= 19)
  113.         {
  114.             return false;
  115.         }
  116.         /*/else if (blocks[i].x >= 0 && blocks[i].x <= 9)
  117.         {
  118.             return false;
  119.         }/*/
  120.     }
  121.     return true;
  122. }
  123.  
  124. void Shape::make_ishape()
  125. {
  126.     blocks[0] = Block(pos[0],pos[1],Blue);
  127.     blocks[1] = Block(pos[2],pos[3],Blue);
  128.     blocks[2] = Block(pos[4],pos[5],Blue);
  129.     blocks[3] = Block(pos[6],pos[7],Blue);
  130.    
  131. }
  132.  
  133. void Shape::draw_shape()
  134. {
  135.     for (int i=0; i<4; i++)
  136.     {
  137.         blocks[i].draw();
  138.     }
  139. }
  140.  
  141. void Shape::move_shape(int dx, int dy)
  142. {
  143.     for (int i=0; i<4; i++)
  144.     {
  145.         blocks[i].clear();
  146.     }
  147.     for (int i=0; i<4; i++)
  148.     {
  149.         blocks[i].move(dx,dy);
  150.     }
  151. }
  152.  
  153.  
  154. class I_Shape: public Shape{
  155. public:
  156.     I_Shape(int,int);
  157.    
  158. private:
  159.     DWORD color;
  160.     //int pos[8];
  161. };
  162.  
  163. //Methods (I_Shape)
  164.  
  165.  
  166. I_Shape::I_Shape(int x, int y):Shape()
  167. {
  168. //make_shape(pos[8],color);
  169.     color=Blue;
  170.     pos[0]=x-1;
  171.     pos[1]=y;
  172.     pos[2]=x;
  173.     pos[3]=y;
  174.     pos[4]=x+1;
  175.     pos[5]=y;
  176.     pos[6]=x+2;
  177.     pos[7]=y;
  178.     //Shape();  //makes one block
  179.     make_ishape(); //makes I_Shape
  180. }
  181.  
  182. // the main entry point for the application is this function
  183. void DarkGDK ( void )
  184. {
  185.  
  186.    
  187.     I_Shape First(5,0);
  188.     // turn on sync rate and set maximum rate to 1 fps
  189.     dbSyncOn   ( );
  190.     dbSyncRate (1);
  191.     First.draw_shape();
  192.     //First.move_shape(5,4);
  193.    
  194.  
  195.  
  196.    
  197.     // our main loop
  198.     while ( LoopGDK ( ) )
  199.     {
  200.         if (First.col())
  201.         {
  202.             if (dbLeftKey())
  203.             {
  204.                 First.move_shape(-1,0);
  205.             }
  206.             else if (dbRightKey())
  207.             {
  208.                 First.move_shape(1,0);
  209.             }
  210.             else if (First.col())
  211.             {
  212.                 First.move_shape(0,1); 
  213.             }
  214.         }
  215.    
  216.    
  217.    
  218.        
  219.         // update the screen
  220.         dbSync ( );
  221.         //dbWaitKey();
  222.     }
  223.    
  224.    
  225.     // return back to windows
  226.     return;
  227. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement