SHARE
TWEET

hanoi backup

Mary_99 Mar 31st, 2019 112 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 5
  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.  
  21. int how_many_disks_on_the_current_tower_tab[TOWERS_NUMBER];
  22. int disks_tab[DISKS_NUMBER + 1][TOWERS_NUMBER];
  23. float number_of_towers = TOWERS_NUMBER;
  24. float nuber_of_disks = DISKS_NUMBER;
  25.  
  26.  
  27.  
  28.  
  29. void checkingBoundry();
  30. void drawingBackgraund();
  31. void drawingTowers();
  32. void drawingDisks();
  33. void initialingPositionOfDisks();
  34.  
  35.  
  36.  
  37.  
  38.  
  39. int main(int argc, char* argv[])
  40. {  
  41.  
  42.    
  43.    
  44.     if(initGraph())
  45.     {
  46.        exit(3);
  47.     }
  48.     do
  49.     {
  50.         checkingBoundry();
  51.         drawingBackgraund();
  52.         drawingTowers();
  53.         drawingDisks();
  54.         initialingPositionOfDisks();
  55.         updateScreen();
  56.  
  57.         //mowing
  58.         //moving in 3 ways
  59.         //winning
  60.    
  61.  
  62.     }while(isKeyDown(SDLK_ESCAPE) != 1);
  63.    
  64.     return 0;
  65.    
  66. }
  67.  
  68.  
  69.  
  70.  void checkingBoundry()
  71. {
  72.     if(DISKS_NUMBER < 3 || TOWERS_NUMBER > 10)
  73.     {
  74.         printf("Invalid number of Towers \n");
  75.         exit(3);
  76.     }
  77.  
  78.     if(DISKS_NUMBER < 3 || DISKS_NUMBER >15)
  79.     {
  80.         printf("Invalid number of Disks.\n");
  81.         exit(3);
  82.     }
  83.  
  84. }
  85.  
  86.  
  87.  
  88.  
  89. void drawingBackgraund(void)
  90. {
  91.     int number_of_row, number_of_column;
  92.    
  93.     filledRect(0, 0, screenWidth(), screenHeight(), BACKGROUND_COLOR);
  94.     filledRect(0, screenHeight()-FLOOR_HEIGHT, screenWidth(), screenHeight(), FLOOR_COLOR);
  95.    
  96. }
  97.  
  98.  
  99.  
  100.  
  101. typedef struct
  102. {
  103.     int x1, y1, x2, y2, width;
  104.     int priority, current_tower_number;
  105. } Disk;
  106.  
  107. typedef struct
  108. {
  109.     int x1, y1, x2, y2;
  110.     int ordinal_no, highest_disk_priority, current_disk_amount;
  111. } Tower;
  112.  
  113.  
  114. void drawingTowers(Tower tower[])
  115. {  
  116.     int i;
  117.     for(i = 0; i < TOWERS_NUMBER; i++)
  118.     {
  119.         tower[i].x1 = SPACE_BTW_TOWERS*(i + 0.5) - TOWERS_WIDTH/2;
  120.         tower[i].y1 = screenHeight() - 1 - TOWERS_HIGHT;
  121.         tower[i].x2 = SPACE_BTW_TOWERS*(i + 0.5) + TOWERS_WIDTH/2;
  122.         tower[i].y2 = screenHeight() - 1;
  123.         tower[i].ordinal_no = i + 1;
  124.         tower[i].current_disk_amount = 0;
  125.         tower[i].highest_disk_priority = -1;
  126.     }
  127.  
  128.  
  129.    // int number_of_row, number_of_column;
  130.    //int disk_haight;
  131.    //disk_haight = TOWERS_HIGHT /(DISKS_NUMBER + 1);
  132.    
  133.   //  for(number_of_column = 0; number_of_column < TOWERS_NUMBER; number_of_column ++)  
  134.     //{
  135.       // 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);
  136.     //}
  137. }
  138.  
  139.  
  140.  
  141.  
  142. void drawingDisks(void)
  143. {
  144.     int number_of_row, number_of_column;
  145.    
  146.     for(number_of_column = 0; number_of_column < TOWERS_NUMBER; number_of_column ++)
  147.     {
  148.         for(number_of_row = 0; number_of_row < DISKS_NUMBER; number_of_row++)
  149.         {
  150.             if(disks_tab[number_of_row][number_of_column]!=0)
  151.             {
  152.                 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);
  153.            
  154.                 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);
  155.             }
  156.         }
  157.     }
  158.    
  159. }
  160.  
  161. void initialingPositionOfDisks(void)
  162. {
  163.     int number_of_row, number_of_column;
  164.  
  165.     for(number_of_column = 0; number_of_column < TOWERS_NUMBER; number_of_column ++)
  166.     {  
  167.         for(number_of_row = 0; number_of_row < DISKS_NUMBER; number_of_row ++)  
  168.         {    
  169.             if(number_of_column == 0)
  170.             {
  171.                 disks_tab[number_of_row][number_of_column] = number_of_row + 1;
  172.             }
  173.             else
  174.             {
  175.             disks_tab[number_of_row][number_of_column]= 0;
  176.             }
  177.         }
  178.     }
  179.  
  180. }
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