SHARE
TWEET

hanoi working not yet

Mary_99 Mar 27th, 2019 12 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 5
  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. void drawingBackgraund();
  26. void drawingTowers();
  27. void drawingDisks();
  28. void initialingPositionOfDisks();
  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.         drawingTowers();
  43.         drawingDisks();
  44.         initialingPositionOfDisks();
  45.         updateScreen();
  46.  
  47.         //mowing
  48.         //moving in 3 ways
  49.         //winning
  50.    
  51.  
  52.     }while(isKeyDown(SDLK_ESCAPE) != 1);
  53.    
  54.     return 0;
  55.    
  56. }
  57.  
  58.  
  59. void drawingBackgraund(void)
  60. {
  61.     int number_of_row, number_of_column;
  62.    
  63.     filledRect(0, 0, screenWidth(), screenHeight(), BACKGROUND_COLOR);
  64.     filledRect(0, screenHeight()-FLOOR_HEIGHT, screenWidth(), screenHeight(), FLOOR_COLOR);
  65.    
  66. }
  67.  
  68. void drawingTowers(void)
  69. {
  70.     int number_of_row, number_of_column;
  71.    //int disk_haight;
  72.    //disk_haight = TOWERS_HIGHT /(DISKS_NUMBER + 1);
  73.    
  74.     for(number_of_column = 0; number_of_column < TOWERS_NUMBER; number_of_column ++)  
  75.     {
  76.        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, TOWERS_HIGHT + FLOOR_HEIGHT - 1, TOWERS_COLOR);
  77.     }
  78. }
  79.  
  80.  
  81. void drawingDisks(void)
  82. {
  83.     int number_of_row, number_of_column;
  84.    
  85.     for(number_of_column = 0; number_of_column < TOWERS_NUMBER; number_of_column ++)
  86.     {
  87.         for(number_of_row = 0; number_of_row < DISKS_NUMBER; number_of_row++)
  88.         {
  89.             if(disks_tab[number_of_row][number_of_column]!=0)
  90.             {
  91.                 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);
  92.            
  93.                 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);
  94.             }
  95.         }
  96.     }
  97.    
  98. }
  99.  
  100. void initialingPositionOfDisks(void)
  101. {
  102.     int number_of_row, number_of_column;
  103.  
  104.     for(number_of_column = 0; number_of_column < TOWERS_NUMBER; number_of_column ++)
  105.     {  
  106.         for(number_of_row = 0; number_of_row < DISKS_NUMBER; number_of_row ++)  
  107.         {    
  108.             if(number_of_column == 0)
  109.             {
  110.                 disks_tab[number_of_row][number_of_column] = number_of_row + 1;
  111.             }
  112.             else
  113.             {
  114.             disks_tab[number_of_row][number_of_column]= 0;
  115.             }
  116.         }
  117.     }
  118.  
  119. }
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