{"id":19427868,"url":"https://github.com/gappeah/fcc-number-guessing-game","last_synced_at":"2025-02-25T05:22:33.414Z","repository":{"id":255784139,"uuid":"852786793","full_name":"gappeah/fcc-number-guessing-game","owner":"gappeah","description":"This project is part of the FreeCodeCamp Relational Database certification. The objective was to build a PostgreSQL database to store user information and their game results and create a Bash script to handle the game logic and interact with the database.","archived":false,"fork":false,"pushed_at":"2024-09-09T15:33:54.000Z","size":12,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-07T19:44:29.378Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gappeah.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-05T12:29:18.000Z","updated_at":"2024-09-09T15:33:57.000Z","dependencies_parsed_at":"2024-09-09T18:47:28.594Z","dependency_job_id":null,"html_url":"https://github.com/gappeah/fcc-number-guessing-game","commit_stats":null,"previous_names":["gappeah/fcc-number-guessing-game"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gappeah%2Ffcc-number-guessing-game","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gappeah%2Ffcc-number-guessing-game/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gappeah%2Ffcc-number-guessing-game/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gappeah%2Ffcc-number-guessing-game/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gappeah","download_url":"https://codeload.github.com/gappeah/fcc-number-guessing-game/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240607635,"owners_count":19828272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T14:13:08.046Z","updated_at":"2025-02-25T05:22:33.367Z","avatar_url":"https://github.com/gappeah.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Number Guessing Game\n\nThis project is part of the FreeCodeCamp Relational Database certification. The objective was to build a PostgreSQL database to store user information and game results, as well as create a Bash script to handle the game logic and interact with the database.\n\n## Project Structure\n\n- **Database**: The database is managed using PostgreSQL.\n- **Script**: A Bash script (`number_guess.sh`) was created to interact with the database by allowing users to play a number guessing game.\n\n### Files\n\n- `number_guess.sql`: Contains SQL commands to create the database, including tables for users and their game results.\n- `number_guess.sh`: A Bash script to play the number guessing game, store user data, and track game results.\n\n## Database Schema\n![diagram-export-09-09-2024-16_32_56](https://github.com/user-attachments/assets/b4a9aa87-59c4-4884-a45c-edd4d3489539)\n\nThe database consists of the following tables:\n\n### `users` Table\n\n| Column Name | Data Type    | Constraints      |\n| ----------- | ------------ | ---------------- |\n| `user_id`   | SERIAL       | PRIMARY KEY      |\n| `username`  | VARCHAR(20)  | UNIQUE, NOT NULL |\n\n### `games` Table\n\n| Column Name      | Data Type | Constraints                           |\n| ---------------- | --------- | ------------------------------------- |\n| `game_id`        | SERIAL    | PRIMARY KEY                           |\n| `number_guesses` | INTEGER   | NOT NULL                              |\n| `user_id`        | INTEGER   | REFERENCES `users(user_id)`            |\n\n## Usage\n\n### Prerequisites\n\n- **PostgreSQL**: Ensure PostgreSQL is installed and running on your machine. Connect to the database using:\n\n  ```bash\n  psql --username=freecodecamp --dbname=number_guess\n  ```\n\n- **Database Setup**: The database should be created and populated using the provided `number_guess.sql` file.\n\n### Running the Script\n\nThe `number_guess.sh` script allows users to play the number guessing game and saves the results to the database. To run the script:\n\n```bash\n./number_guess.sh\n```\n\n### Game Play Instructions\n\n1. **Enter Username**: The script will prompt you to enter your username. If it is your first time, the username will be added to the `users` table.\n   - If you are a returning user, the script will display the number of games you have played and your best game result (least number of guesses).\n  \n2. **Guess the Secret Number**: The script will randomly generate a number between 1 and 1000. You will be prompted to guess the number.\n   - If your guess is too high or too low, you will be prompted to try again.\n   - The game continues until you correctly guess the number.\n\n3. **Save Game Results**: Once you guess the number, the script will tell you how many attempts it took, and the result will be saved to the database.\n\n### Example Gameplay\n\n```bash\nEnter your username:\nJohnDoe\n\nWelcome back, JohnDoe! You have played 5 games, and your best game took 3 guesses.\n\nGuess the secret number between 1 and 1000:\n500\nIt's lower than that, guess again:\n250\nIt's higher than that, guess again:\n375\nIt's lower than that, guess again:\n312\nYou guessed it in 4 tries. The secret number was 312. Nice job!\n```\n\n### Database Queries\n\nThe following information is stored in the database:\n- **Usernames**: Stored in the `users` table.\n- **Game Results**: Stored in the `games` table, tracking how many guesses each game took and which user played the game.\n\n## Project Completion\n\n### Git Repository\n\nThe project folder was initialized as a Git repository:\n\n```bash\ngit init\n```\n\nThe repository was ensured to have a `main` branch with at least five commits, using conventional prefixes like `fix:`, `feat:`, `refactor:`, etc.\n\n### Bash Script\n\nThe `number_guess.sh` script was developed to handle user input, generate random numbers, and store game results in the database.\n\n## Installation\n\n1. Clone this repository.\n2. Set up the database:\n   - Log in to PostgreSQL:\n     ```bash\n     psql --username=freecodecamp --dbname=postgres\n     ```\n   - Run the SQL commands in `number_guess.sql` to create and populate the database:\n     ```sql\n     \\i number_guess.sql\n     ```\n3. Make sure the `number_guess.sh` script has execution permissions:\n   ```bash\n   chmod +x number_guess.sh\n   ```\n\n4. Run the script as described above.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgappeah%2Ffcc-number-guessing-game","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgappeah%2Ffcc-number-guessing-game","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgappeah%2Ffcc-number-guessing-game/lists"}