SHARE
TWEET

hanoi part1

Mary_99 Mar 26th, 2019 63 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 BLUE
  10. #define TEXT_COLOR YELLOW
  11. #define TOWERS_NUMBER 3
  12. #define DISKS_NUMBER 6
  13. #define TOWERS_WIDTH 6
  14. #define FLOOR_HEIGHT 30
  15. #define DISKS_WIDTH 3
  16. /*This variable represents the width of the smallest disk minus tower's width and divided by two*/
  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]; /*In this tab we store the sizes of individual disks which occupy current position on towers */
  22. float nr_towers = TOWERS_NUMBER;
  23. float nr_disks = DISKS_NUMBER;
  24.  
  25.  
  26. void initial_position_of_disks();
  27. void drawing();
  28.  
  29. int main(int argc, char* argv[])
  30. {  
  31.  
  32.     initial_position_of_disks();
  33.     if(initGraph())
  34.        exit(3);
  35.    
  36.     do
  37.         {
  38.         drawing();
  39.         updateScreen();
  40.    
  41.         //winning();
  42.         //if(winning()==1)
  43.         //  break;
  44.  
  45.     //  array_transport();
  46.         //updateScreen();
  47.  
  48.         }while(isKeyDown(SDLK_ESCAPE) != 1);
  49.    
  50.     return 0;
  51.    
  52. }
  53.  
  54. void initial_position_of_disks(void)
  55. {
  56.     int nr_row, nr_column;
  57.  
  58.     for(nr_column = 0; nr_column < TOWERS_NUMBER; nr_column ++)
  59.         {  
  60.         for(nr_row = 0; nr_row < DISKS_NUMBER; nr_row ++)  
  61.                 {    
  62.                 if(nr_column == 0)
  63.                 disks_tab[nr_row][nr_column] = nr_row + 1;
  64.             else
  65.                 disks_tab[nr_row][nr_column]= 0;
  66.             }
  67.         }
  68.  
  69. }
  70.  
  71.  
  72.  
  73. void drawing(void)
  74. {
  75.     int nr_row, nr_column;
  76.    
  77.     filledRect(0, 0, screenWidth(), screenHeight(), BACKGROUND_COLOR);
  78.    
  79.     filledRect(0, screenHeight()-FLOOR_HEIGHT, screenWidth(), screenHeight(), FLOOR_COLOR);
  80.    
  81.    
  82.     for(nr_column = 0; nr_column < TOWERS_NUMBER; nr_column ++)  
  83.         {
  84.             filledRect((nr_column*2+1)*screenWidth()/(nr_towers*2)-TOWERS_WIDTH/2, screenHeight()-((nr_disks+1)*DISKS_HEIGHT+FLOOR_HEIGHT), (nr_column*2+1)*screenWidth()/(nr_towers*2)+TOWERS_WIDTH/2, screenHeight()-FLOOR_HEIGHT-1, TOWERS_COLOR);
  85.         }
  86.  
  87.     for(nr_column = 0; nr_column < TOWERS_NUMBER; nr_column ++)
  88.         {
  89.         for(nr_row = 0; nr_row < DISKS_NUMBER; nr_row++)
  90.                 {
  91.                     if(disks_tab[nr_row][nr_column]!=0)
  92.                         {
  93.                             filledRect(screenWidth()/(nr_towers*2)*(1+2*nr_column)-DISKS_WIDTH*disks_tab[nr_row][nr_column]-TOWERS_WIDTH/2, screenHeight()-(nr_disks-nr_row)*DISKS_HEIGHT-FLOOR_HEIGHT, screenWidth()/(nr_towers*2)*(1+2*nr_column)+DISKS_WIDTH*disks_tab[nr_row][nr_column]+TOWERS_WIDTH/2, screenHeight()-((nr_disks-nr_row-1)*DISKS_HEIGHT)-FLOOR_HEIGHT-1, DISKS_COLOR);
  94.                
  95.                            rect(screenWidth()/(nr_towers*2)*(1+2*nr_column)-DISKS_WIDTH*disks_tab[nr_row][nr_column]-TOWERS_WIDTH/2,screenHeight()-(nr_disks-nr_row)*DISKS_HEIGHT-FLOOR_HEIGHT, screenWidth()/(nr_towers*2)*(1+2*nr_column)+DISKS_WIDTH*disks_tab[nr_row][nr_column]+TOWERS_WIDTH/2, screenHeight()-((nr_disks-nr_row-1)*DISKS_HEIGHT)-FLOOR_HEIGHT-1, FRAME_COLOR);
  96.                         }
  97.                 }
  98.         }
  99. }
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