SHARE
TWEET

Hanoi nie wyszło

Mary_99 Mar 31st, 2019 73 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 6
  12. #define DISKS_NUMBER 13
  13. #define TOWERS_WIDTH 6
  14. #define FLOOR_HEIGHT 30
  15. #define TOWERS_HIGHT 300
  16. #define DISKS_WIDTH 3
  17. #define STEP_PER_ITERATION_OF_MOVING_DISC 2
  18. #define DISKS_HEIGHT 10
  19. #define SPACE_BTW_TOWERS screenWidth()/TOWERS_NUMBER
  20. #define GROUND_HEIGHT = screenHeight() - 50
  21.  
  22. int how_many_disks_on_the_current_tower_tab[TOWERS_NUMBER];
  23. int disks_tab[DISKS_NUMBER + 1][TOWERS_NUMBER];
  24. float number_of_towers = TOWERS_NUMBER;
  25. float nuber_of_disks = DISKS_NUMBER;
  26.  
  27. void makingDistanceBetweenTowers();
  28. void checkingBoundry();
  29. void drawingBackgraund();
  30. void drawingTowers();
  31. void drawingDisks();
  32. void initialingPositionOfDisks();
  33.  
  34.  
  35. int main(int argc, char* argv[])
  36. {  
  37.  
  38.    
  39.    
  40.     if(initGraph())
  41.     {
  42.        exit(3);
  43.     }
  44.     do
  45.     {
  46.         checkingBoundry();
  47.         drawingBackgraund();
  48.         drawingTowers();
  49.         drawingDisks();
  50.         initialingPositionOfDisks();
  51.         updateScreen();
  52.  
  53.         //mowing
  54.         //moving in 3 ways
  55.         //winning
  56.    
  57.  
  58.     }while(isKeyDown(SDLK_ESCAPE) != 1);
  59.    
  60.     return 0;
  61.    
  62. }
  63.  
  64.  
  65.  
  66.  void checkingBoundry()
  67. {
  68.     if(DISKS_NUMBER < 3 || TOWERS_NUMBER > 10)
  69.     {
  70.         printf("Invalid number of Towers \n");
  71.         exit(3);
  72.     }
  73.  
  74.     if(DISKS_NUMBER < 3 || DISKS_NUMBER >15)
  75.     {
  76.         printf("Invalid number of Disks.\n");
  77.         exit(3);
  78.     }
  79.  
  80. }
  81.  
  82.  
  83.  
  84. void drawingBackgraund(void)
  85. {
  86.     int number_of_row, number_of_column;
  87.    
  88.     filledRect(0, 0, screenWidth(), screenHeight(), BACKGROUND_COLOR);
  89.     filledRect(0, screenHeight()-FLOOR_HEIGHT, screenWidth(), screenHeight(), FLOOR_COLOR);
  90.    
  91. }
  92.  
  93. double makingDistanceBetweenTowers()
  94. {
  95.     double distance_between_towers = screenWidth() / (TOWERS_NUMBER + 1);
  96.     return distance_between_towers;
  97.    
  98. }
  99.  
  100.  
  101. void drawingTowers(void)
  102. {  
  103.    
  104.     double distance_between_towers = makingDistanceBetweenTowers();
  105.     int iteration_number;
  106.  
  107.     for(iteration_number = 1; iteration_number <= TOWERS_NUMBER; iteration_number++)
  108.     {
  109.         filledRect(( distance_between_towers * iteration_number) - TOWERS_WIDTH,
  110.                    GROUND_HEIGHT - 1,
  111.         (distance_between_towers * iteration_number) + TOWERS_WIDTH,
  112.                    GROUND_HEIGHT - TOWERS_HIGHT, BLUE);
  113.     }
  114.  
  115. }
  116.  
  117.  
  118.  
  119.  
  120. void drawingDisks(void)
  121. {
  122.     int number_of_row, number_of_column;
  123.    
  124.     for(number_of_column = 0; number_of_column < TOWERS_NUMBER; number_of_column ++)
  125.     {
  126.         for(number_of_row = 0; number_of_row < DISKS_NUMBER; number_of_row++)
  127.         {
  128.             if(disks_tab[number_of_row][number_of_column]!=0)
  129.             {
  130.                 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);
  131.            
  132.                 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);
  133.             }
  134.         }
  135.     }
  136.    
  137. }
  138.  
  139. void initialingPositionOfDisks(void)
  140. {
  141.     int number_of_row, number_of_column;
  142.  
  143.     for(number_of_column = 0; number_of_column < TOWERS_NUMBER; number_of_column ++)
  144.     {  
  145.         for(number_of_row = 0; number_of_row < DISKS_NUMBER; number_of_row ++)  
  146.         {    
  147.             if(number_of_column == 0)
  148.             {
  149.                 disks_tab[number_of_row][number_of_column] = number_of_row + 1;
  150.             }
  151.             else
  152.             {
  153.             disks_tab[number_of_row][number_of_column]= 0;
  154.             }
  155.         }
  156.     }
  157.  
  158. }
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
 
Top