SHARE
TWEET

hanoi drawing

Mary_99 Mar 26th, 2019 58 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" /*This is graphics library*/
  4.  
  5. #define BACKGROUND_COLOR BLACK
  6. /*This variable represents the color ofthe background*/
  7. #define FLOOR_COLOR YELLOW
  8. /*This variable represents the color of the floor*/
  9. #define TOWERS_COLOR RED
  10. /*This variable represents the color of the towers*/
  11. #define DISKS_COLOR MAGENTA
  12. /*This variable represents the color of the disks*/
  13. #define FRAME_COLOR BLUE
  14. /*This variable represents the color of the frames of the disks*/
  15. #define TEXT_COLOR YELLOW
  16. /*This variable represents the color ofthe text used in the programm */
  17. #define TOWERS_NUMBER 5
  18. /*This variable represents the number of towers */
  19. #define DISKS_NUMBER 4
  20. /*This variable represents the number of disks */
  21. #define TOWERS_WIDTH 6
  22. /*This variable represents the width of the towers */
  23. #define FLOOR_HEIGHT 30
  24. /*This variable represents the height of the floor */
  25. #define DISKS_WIDTH 3
  26. /*This variable represents the width of the smallest disk minus tower's width and divided by two*/
  27. #define STEP 2
  28. /*This variable represents the step per iteration of the moving disks */
  29. #define DISKS_HEIGHT 10
  30. /*This variable represents the height of the disks */
  31.  
  32. /******************************************************************************************************************************************************************************************/
  33. /* global variables */
  34.  
  35. int how_many_disks_arr[TOWERS_NUMBER];
  36. /*This array stores information about how many disks are on the current tower*/
  37.  
  38. int disks_arr[DISKS_NUMBER+1][TOWERS_NUMBER];
  39. /*In this array we store the sizes of individual disks which occupy current position on towers */
  40.  
  41. float nr_towers=TOWERS_NUMBER; /*This variable represents the number of towers*/
  42.  
  43. float nr_disks=DISKS_NUMBER; /*This variable represents the numbe*/
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52. void drawing(void) /*This function is drawing on the screen everything that is going on in the programm: backgroung, floor, disks, towers */
  53. {
  54.     int row,column;
  55.     /*row - counter in operations concerning number of rows
  56.       column - counter in operations concerning number of columns*/
  57.    
  58.     filledRect(0, 0, screenWidth(), screenHeight(), BACKGROUND_COLOR);
  59.     /*This function creates the background*/   
  60.     filledRect(0, screenHeight()-FLOOR_HEIGHT, screenWidth(), screenHeight(), FLOOR_COLOR);
  61.     /*This function creates the floor*/
  62.    
  63.     for(column=0;column<TOWERS_NUMBER;column++)   /*This for loop draws towers*/
  64.         {
  65.         filledRect((column*2+1)*screenWidth()/(nr_towers*2)-TOWERS_WIDTH/2, screenHeight()-((nr_disks+1)*DISKS_HEIGHT+FLOOR_HEIGHT), (column*2+1)*screenWidth()/(nr_towers*2)+TOWERS_WIDTH/2, screenHeight()-FLOOR_HEIGHT-1, TOWERS_COLOR);
  66.         }
  67.  
  68.     for(column=0;column<TOWERS_NUMBER;column++)  /*This two loops create disks and their frames according to the current position of disks written in the array*/
  69.         {
  70.         for(row=0;row<DISKS_NUMBER;row++)
  71.                 {
  72.             if(disks_arr[row][column]!=0)
  73.                 {
  74.                 filledRect(screenWidth()/(nr_towers*2)*(1+2*column)-DISKS_WIDTH*disks_arr[row][column]-TOWERS_WIDTH/2,      screenHeight()-(nr_disks-row)*DISKS_HEIGHT-FLOOR_HEIGHT, screenWidth()/(nr_towers*2)*(1+2*column)+DISKS_WIDTH*disks_arr[row][column]+TOWERS_WIDTH/2, screenHeight()-((nr_disks-row-1)*DISKS_HEIGHT)-FLOOR_HEIGHT-1, DISKS_COLOR);
  75.                
  76.                 rect(screenWidth()/(nr_towers*2)*(1+2*column)-DISKS_WIDTH*disks_arr[row][column]-TOWERS_WIDTH/2,      screenHeight()-(nr_disks-row)*DISKS_HEIGHT-FLOOR_HEIGHT, screenWidth()/(nr_towers*2)*(1+2*column)+DISKS_WIDTH*disks_arr[row][column]+TOWERS_WIDTH/2, screenHeight()-((nr_disks-row-1)*DISKS_HEIGHT)-FLOOR_HEIGHT-1, FRAME_COLOR);
  77.                 }
  78.                 }
  79.             }
  80. }
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103. int main(int argc, char* argv[])
  104. {  
  105.  
  106.     //initial_state(); /*This function writes the initial position of the disks into the array*/
  107.  
  108.     if(initGraph()) /*Initialization of graphics. Exit on error*/
  109.        exit(3);
  110.    
  111.     do
  112.         {
  113.         drawing(); /*This function is drawing on the screen everything that is going on in the programm: backgroung, floor, disks, towers */
  114.         updateScreen();
  115.    
  116.         //winning(); /* This function prints the text when the user wins the game*/
  117.         //if(winning()==1) /*Function 'winning()' returns value 1 if the user won the game so the main loop of the game is terminated by the 'break' expression*/
  118.         //  break;
  119.  
  120.     //  array_transport(); /*This function is responsible for operations on disks_array. If the conditions to move a disk from one towers to the other are satisfied then it launches the moving() function*/
  121.         //updateScreen();
  122.  
  123.         }while(pollkey()!=SDLK_ESCAPE); /*This loop makes the programm to work until the user will close the window*/
  124.    
  125.     return 0;
  126. }
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