SHARE
TWEET

HANOII

Mary_99 Mar 27th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "primlib.h"
  4.  
  5. #define BACKGROUND_COLOR BLACK
  6. #define FLOOR_COLOR YELLOW
  7. #define TOWERS_COLOR RED
  8. #define DISKS_COLOR MAGENTA
  9. #define FRAME_COLOR BLACK
  10. #define TEXT_COLOR YELLOW
  11. #define TOWERS_NUMBER 9
  12. #define DISKS_NUMBER 3
  13. #define TOWERS_WIDTH 6
  14. #define FLOOR_HEIGHT 30
  15. #define TOWERS_HIGHT 10
  16. #define DISKS_WIDTH 3
  17. #define STEP_PER_ITERATION_OF_MOVING_DISC 2
  18. #define DISKS_HEIGHT 10
  19.  
  20. int how_many_disks_on_the_current_tower_tab[TOWERS_NUMBER];
  21. int disks_tab[DISKS_NUMBER + 1][TOWERS_NUMBER];
  22. float number_of_towers = TOWERS_NUMBER;
  23. float nuber_of_disks = DISKS_NUMBER;
  24.  
  25.  
  26. void initialingPositionOfDisks();
  27. void drawingBackgraund();
  28. void drawingDisks();
  29.  
  30. int main(int argc, char* argv[])
  31. {  
  32.  
  33.    
  34.    
  35.     if(initGraph())
  36.     {
  37.        exit(3);
  38.     }
  39.     do
  40.     {
  41.         drawingBackgraund();
  42.         drawingDisks();
  43.         initialingPositionOfDisks();
  44.         updateScreen();
  45.  
  46.         //mowing
  47.         //moving in 3 ways
  48.         //winning
  49.    
  50.  
  51.     }while(isKeyDown(SDLK_ESCAPE) != 1);
  52.    
  53.     return 0;
  54.    
  55. }
  56.  
  57.  
  58. void drawingBackgraund(void)
  59. {
  60.     int number_of_row, number_of_column;
  61.    
  62.     filledRect(0, 0, screenWidth(), screenHeight(), BACKGROUND_COLOR);
  63.     filledRect(0, screenHeight()-FLOOR_HEIGHT, screenWidth(), screenHeight(), FLOOR_COLOR);
  64.    
  65.    
  66.     for(number_of_column = 0; number_of_column < TOWERS_NUMBER; number_of_column ++)  
  67.     {
  68.         filledRect((number_of_column * 2 + 1)*screenWidth() / (number_of_towers * 2)-TOWERS_WIDTH / 2, screenHeight()-((nuber_of_disks + 1)*DISKS_HEIGHT+FLOOR_HEIGHT), (number_of_column * 2 + 1)*screenWidth() /(number_of_towers * 2)+TOWERS_WIDTH / 2, screenHeight()-FLOOR_HEIGHT - 1, TOWERS_COLOR);
  69.     }
  70. }
  71.  
  72.  
  73. void drawingDisks(void)
  74. {
  75.     int number_of_row, number_of_column;
  76.    
  77.     for(number_of_column = 0; number_of_column < TOWERS_NUMBER; number_of_column ++)
  78.     {
  79.         for(number_of_row = 0; number_of_row < DISKS_NUMBER; number_of_row++)
  80.         {
  81.             if(disks_tab[number_of_row][number_of_column]!=0)
  82.             {
  83.                 filledRect(screenWidth()/(number_of_towers * 2)*(1 + 2 * number_of_column) - DISKS_WIDTH * disks_tab[number_of_row][number_of_column]-TOWERS_WIDTH/2, screenHeight()-(nuber_of_disks-number_of_row)*DISKS_HEIGHT-FLOOR_HEIGHT, screenWidth()/(number_of_towers * 2) * ( 1 + 2 * number_of_column) + DISKS_WIDTH*disks_tab[number_of_row][number_of_column]+TOWERS_WIDTH / 2, screenHeight()-((nuber_of_disks-number_of_row-1)*DISKS_HEIGHT)-FLOOR_HEIGHT-1, DISKS_COLOR);
  84.            
  85.                 rect(screenWidth()/(number_of_towers*2)*(1+2*number_of_column)-DISKS_WIDTH*disks_tab[number_of_row][number_of_column]-TOWERS_WIDTH/2,screenHeight()-(nuber_of_disks-number_of_row)*DISKS_HEIGHT-FLOOR_HEIGHT, screenWidth()/(number_of_towers*2)*(1+2*number_of_column)+DISKS_WIDTH*disks_tab[number_of_row][number_of_column]+TOWERS_WIDTH/2, screenHeight()-((nuber_of_disks-number_of_row-1)*DISKS_HEIGHT)-FLOOR_HEIGHT-1, FRAME_COLOR);
  86.             }
  87.         }
  88.     }
  89.    
  90. }
  91.  
  92. void initialingPositionOfDisks(void)
  93. {
  94.     int number_of_row, number_of_column;
  95.  
  96.     for(number_of_column = 0; number_of_column < TOWERS_NUMBER; number_of_column ++)
  97.     {  
  98.         for(number_of_row = 0; number_of_row < DISKS_NUMBER; number_of_row ++)  
  99.         {    
  100.             if(number_of_column == 0)
  101.             {
  102.                 disks_tab[number_of_row][number_of_column] = number_of_row + 1;
  103.             }
  104.             else
  105.             {
  106.             disks_tab[number_of_row][number_of_column]= 0;
  107.             }
  108.         }
  109.     }
  110.  
  111. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top