From 9b10f05cee36a9b41fbd2e1d67dd99b4098ba69e Mon Sep 17 00:00:00 2001 From: "Hamza2.Libah@live.uwe.ac.uk" <hamza2.libah@live.uwe.ac.uk> Date: Mon, 5 May 2025 19:50:05 +0000 Subject: [PATCH] Edit README.md --- README.md | 143 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 80 insertions(+), 63 deletions(-) diff --git a/README.md b/README.md index 7c2dc14..f71de3d 100644 --- a/README.md +++ b/README.md @@ -1,93 +1,110 @@ -# 2048cpp +### 2048CPP game +this README will highlight the code and what was the process, further details will be told during the presentation +`#include "GameLogic.h +#include <ncurses.h> +#include <string> +#include <iostream> +#include <vector> +#include <random> +#include <ctime> -## Getting started +#define BOARD_SIZE 4 +#define EMPTY_CELL 0 +#define COLOR_TEAL 8 +#define MAX_RAINDROPS 80 -To make it easy for you to get started with GitLab, here's a list of recommended next steps. +int board[BOARD_SIZE][BOARD_SIZE]; +int score = 0; +pid_t music_pid = -1; +bool isMusicPlaying = false; `` -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! +These are just the imported libaries also not included is due to the nature of the UWE systems sudo was restricted which obvious for security reasons. furthermore, the code was conducted using WSL as of ncurses, but i did use music which was using the system as ncurese only controls the termianls which has its limitations such as not being able to change its fonts size etc. -## Add your files +Chosen a board size of 4 due to it looking most clean on my system compared to other sizes which was than using 0 to fill in blank spaces -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command: +## Raindrop -``` -cd existing_repo -git remote add origin https://gitlab.uwe.ac.uk/h2-libah/2048cpp.git -git branch -M main -git push -uf origin main -``` +this area of the code needs its own section as unlike the 2048 wheres its similar across the board, I wanted to push myself by making mine unquie so ive implemented code rain i found via blogs. -## Integrate with your tools +with this ```MAX_RAINDROP 80``` I had to make sure there was a limit with as it would overflow and cause my RAM to go in **Overdrive** and cause my sytem to crash this was implemented to set a hard limit of the amount of characters set in place -- [ ] [Set up project integrations](https://gitlab.uwe.ac.uk/h2-libah/2048cpp/-/settings/integrations) +struct Raindrop { + int x; // Horizontal position + int row; // Vertical position + int length; // Trail length (5-15 chars) + int speed; // Fall speed (1-3 rows/frame) + int counter; // Animation timing counter + char head; // Leading character (random ASCII) + bool active; // Active state flag +}; -## Collaborate with your team +vector<Raindrop> raindrops; // Collection of active drops +bool rainInitialized = false; // Initialization status``` -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/) +these code comments tell you what they do which i will expand furthermore in person but TLDR row, x track the terminal cell and length is what make the rain effect -## Test and Deploy + void initRain(int width, int height) { + raindrops.clear(); // Remove old drops (if any) -Use the built-in continuous integration in GitLab. + // Random number generators for different properties + std::mt19937 rng(std::time(0)); // Better randomness + std::uniform_int_distribution<int> x_dist(0, width-1); // R column + std::uniform_int_distribution<int> len_dist(5, 15); // R distance + std::uniform_int_distribution<int> speed_dist(1, 3); // R speed + std::uniform_int_distribution<int> char_dist(33, 126); // R ASCII character -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) + // Create up to MAX_RAINDROPS (80) raindrops + int numDrops = std::min(width / 8, MAX_RAINDROPS); + raindrops.resize(numDrops); -*** + // Set random properties for each drop + for (auto& drop : raindrops) { + drop.x = x_dist(rng); // Random column (0 to screen width) + drop.row = -rand() % 20; // Start above screen (so they enter gradually) + drop.length = len_dist(rng); // Random trail length + drop.speed = speed_dist(rng); // Random speed + drop.head = char_dist(rng); // Random starting character + drop.active = true; // Make it visible + drop.counter = 0; // Reset counter + } + rainInitialized = true; // Mark as ready +} -# Editing this README +to break this line by line -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template. +``std::mt19937 rng(std::time(0));`` +mtn19937 is the Mersenne Twister alogrithmn which using (2^ 19937 -1) +the std::time is for the current time as well creating a rng +which allows it to have a different style as it changes to the current time -## Suggestions for a good README +```std::uniform_int_distribution<int> x_dist(0, width-1);``` +this line followed a similar pattern of asking the system to pick a random number 1-100 and apply bit-shifting -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. +``std::uniform_int_distribution<int> len_dist (5, 15);`` +creates the shortest trail 5 as was as the longest trail of 15 this to give diversity of the code rain matrix looki and not creating a screen full of lines pf code such as this -## Name -Choose a self-explaining name for your project. +```std::uniform_int_distribution<int> speed_dist(1, 3);``` +this the speed control of the code rain and how itll create the falling illusion by with every frame itll travel 60 row/sec than 30 than 20 to creating to slow falling -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. +```std::uniform_int_distribution<int> char_dist(33, 126);``` +this just has all the ASCII keys it can chose from ranging from numbers to special characters -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. +this section focuses on the calcution -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. +``` int numDrops= std::min(width /8, MAX_RAINDROPS);``` -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. +This just declares the the width which is -1 drop per 8 columns as well referring to the MAX_RAINDROPS as its the hardware limit for my laptop -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. +`` raindrops.resize(numDrops); `` -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. +allocates contiguous block for numDrops x sizeof (Raindrop) which has the size of 28 bytes -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. +`` drop.x = x_dist(rng); `` creates spatial distribution as well as validate the edge handling -## Contributing -State if you are open to contributions and what your requirements are for accepting them. +`` drop.row = -rand() %20; `` row ranging from +-19, -1 so it can avoid synchroised waves and make it more natural -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. - -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. - -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. - -## License -For open source projects, say how it is licensed. - -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. +than the rest is self explained the rest i used this as [reference] (https://labex.io/courses/project-creating-a-code-rain-in-c-using-ncurses) as well as a guide i tweaked noticable the colour just being dark green as i wanted a more matrix look +the debugging and trouble was done with the help of AI but this is my own work \ No newline at end of file -- GitLab