Advertisement
KingAesthetic

C Example 3

Aug 10th, 2024
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. // define the kind of structure for the puzzle piece.
  6.  
  7. typedef struct {
  8.     int id;
  9.     char shape[20];
  10. } PuzzlePiece;
  11.  
  12. // define the enum for achievements.
  13.  
  14. typedef enum {
  15.     ACHIEVEMENT_LEVEL1,
  16.     ACHIEVEMENT_LEVEL2,
  17.     ACHIEVEMENT_LEVEL3
  18. } Achievement;
  19.  
  20. // function for solving a puzzle piece.
  21.  
  22. void solvePuzzlePiece(PuzzlePiece piece, bool isConnected) {
  23.     printf("Solving piece %d with shape: %s\n", piece.id, piece.shape);
  24.  
  25.     if (isConnected) {
  26.         printf("Piece %d is connected to the puzzle!\n", piece.id);
  27.     } else {
  28.         printf("Piece %d is not connected yet.\n", piece.id);
  29.     }
  30. }
  31.  
  32. // function for tracking achievements.
  33.  
  34. void trackAchievement(Achievement achievement) {
  35.     switch (achievement) {
  36.         case ACHIEVEMENT_LEVEL1:
  37.             printf("Unlocked Level 1 achievement!\n");
  38.             break;
  39.         case ACHIEVEMENT_LEVEL2:
  40.             printf("Unlocked Level 2 achievement!\n");
  41.             break;
  42.         case ACHIEVEMENT_LEVEL3:
  43.             printf("Unlocked Level 3 achievement!\n");
  44.             break;
  45.         default:
  46.             printf("Unknown achievement!\n");
  47.     }
  48. }
  49.  
  50. // function to unlock an achievement.
  51.  
  52. void unlockAchievement(const char* achievementName) {
  53.      if (!unlockedAchievements[achievement]) {
  54.         unlockedAchievements[achievement] = true;
  55.         printf("Unlocked achievement: ");
  56.         switch (achievement) {
  57.             case ACHIEVEMENT_LEVEL1:
  58.                 printf("Level 1\n");
  59.                 break;
  60.             case ACHIEVEMENT_LEVEL2:
  61.                 printf("Level 2\n");
  62.                 break;
  63.             case ACHIEVEMENT_LEVEL3:
  64.                 printf("Level 3\n");
  65.                 break;
  66.             default:
  67.                 printf("Unknown achievement!\n");
  68.         }
  69.     } else {
  70.         printf("Achievement already unlocked!\n");
  71.     }
  72. }
  73.  
  74. // function for rolling a dice.
  75.  
  76. int rollDice() {
  77.     srand(time(NULL)); // seeding a random number generator.
  78.     return rand() % 6 + 1; // Roll a 6-sided dice
  79. }
  80.  
  81. // Bible verses (KJV)
  82.  
  83. const char* bibleVerses[] = {
  84.     "For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life. - John 3:16",
  85.     "The Lord is my shepherd; I shall not want. - Psalm 23:1",
  86.     "In the Begining was the word, and the word was with God, and the word was God. - John 1:1".
  87. };
  88.  
  89. // function that generates a random Bible Verse.
  90.  
  91. const char* getRandomBibleVerse() {
  92.     srand(time(NULL)); // seeding the random number generator.
  93.     int numVerses = sizeof(bibleVerses) / sizeof(bibleVerses[0]);
  94.     int randomIndex = rand() % numVerses;
  95.     return bibleVerses[randomIndex];
  96. }
  97.  
  98. // main function:
  99.  
  100. int main() {
  101.     PuzzlePiece piece1 = {1, "Corner"};
  102.     solvePuzzlePiece(piece1);
  103.  
  104.     trackAchievement(ACHIEVEMENT_LEVEL2);
  105.  
  106.     unlockAchievement("Master of Puzzles");
  107.  
  108.     printf("Rolled: %d\n", rollDice());
  109.  
  110.     printf("Random Bible verse: %s\n", getRandomBibleVerse());
  111.  
  112.     return 0;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement