1. #include <stdio.h>
  2. #include <math.h>
  3. #include <unistd.h>
  4. #include "primlib.h"
  5.  
  6. /* - Program Definition - */
  7. #define PEG 3
  8. #define BLOCK 11
  9.  
  10. int drawPeg();
  11. int drawBlock();
  12.  
  13. /* - Program Body - */
  14. int main(void)
  15. {
  16. drawPeg();
  17. SDL_Delay(1000);
  18. drawBlock();
  19. SDL_Delay(3000);
  20.  
  21. return 0;
  22. }
  23.  
  24. /* - Function Drawing Peg's - */
  25. int drawPeg(void)
  26. {
  27. int tempWidth;
  28. int tempHeight;
  29. int loopCount = 1;
  30.  
  31. if (initGraph()) exit(1);
  32. filledRect(0, 0, screenWidth()-1, screenHeight()-1, BLACK);
  33.  
  34. do{
  35. tempWidth = screenWidth()/(PEG+1);
  36. tempWidth = tempWidth * loopCount;
  37. tempHeight = screenHeight()/(BLOCK+1);
  38. filledRect(tempWidth-2, tempHeight, tempWidth+2, screenHeight()-30, RED);
  39. loopCount++;
  40. SDL_Delay(50);
  41. }while(loopCount < (PEG+1));
  42.  
  43. updateScreen();
  44. return 1;
  45. }
  46. /* - Function Drawing Block's - */
  47. int drawBlock(void)
  48. {
  49. /* 0 Stand for no block, 1 biggest, 2 smaller etc */
  50. int pegBlock[PEG][BLOCK];
  51. int setup = 0;
  52. int firstLoop = 1;
  53. int secondLoop = 1;
  54. int blockLocX;
  55. int blockWidth = 0;
  56. int blockLocY;
  57. int blockHeight = screenHeight()/(BLOCK +1);
  58.  
  59. /* - Fill the first Peg with Blocks - */
  60. for(setup = 0; setup < BLOCK; setup++)
  61. {
  62. pegBlock[0][setup] = BLOCK - setup;
  63. }
  64.  
  65. if (initGraph()) exit(1);
  66. filledRect(0, 0, screenWidth()-1, screenHeight()-1, BLACK);
  67.  
  68. do{
  69. do{
  70. blockLocX = screenWidth()/(PEG+1);
  71. blockLocX = blockLocX * firstLoop;
  72. blockLocY = screenHeight()/(BLOCK+1);
  73. blockLocY = blockLocY * secondLoop;
  74. blockHeight = blockHeight / 10;
  75. blockWidth = (pegBlock[firstLoop][secondLoop] * 2) + 2;
  76. if(pegBlock[firstLoop][secondLoop] != 0)
  77. {
  78. filledRect(blockLocX - blockWidth, blockLocY - blockHeight, blockLocX + blockWidth, blockLocY + blockHeight, BLUE);
  79. }
  80. secondLoop++;
  81. }while(secondLoop < (BLOCK+1));
  82. firstLoop++;
  83. }while(firstLoop < (PEG+1));
  84. updateScreen();
  85.  
  86. return 1;
  87. }