├── NumberGuessGame ├── easy.cpp ├── gamebase.cpp ├── gameplay.cpp ├── guessgame.hpp ├── hard.cpp ├── main.cpp └── readme.txt ├── README.md └── RockPaperScissor ├── README.md └── main.cpp /NumberGuessGame/easy.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file implements the EasyGame class which is responsible for the easy mode of the NumberGuessGame 4 | 5 | */ 6 | 7 | #include "gamebase.cpp" // The base file is included that includes the implementation of GameBase class. 8 | 9 | void EasyGame :: comp() // This method computes random number for computer. 10 | { 11 | cn = (rand() % 10) + 1; 12 | } 13 | 14 | void EasyGame :: play() // This method implements the easy mode gameplay. 15 | { 16 | EasyGame ob; 17 | ob.input(); 18 | if(un==0) 19 | { 20 | std::cout<<"Session being terminated...\n"; 21 | exit(0); 22 | } 23 | else if(un>10 || un<0) 24 | { 25 | std::cout<<"Invalid input! Session being terminated...\n"; 26 | exit(0); 27 | } 28 | else 29 | { 30 | char ch; 31 | ob.comp(); 32 | ob.display(); 33 | cout<<"Would you like to continue?(y/n)\n"; 34 | cin>>ch; 35 | if(ch == 'n' || ch == 'N') 36 | exit(0); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /NumberGuessGame/gamebase.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file implements the GameBase class which acts as the base class for EasyGame and HardGame class. 4 | 5 | */ 6 | 7 | // header guards included to prevent redefinition of class 8 | #ifndef base 9 | #define base 10 | 11 | #include "guessgame.hpp" 12 | #include 13 | using namespace std; 14 | 15 | int un, cn; 16 | bool GameBase :: checkWin() // This method check who wins 17 | { 18 | if(un == cn) 19 | { 20 | return true; 21 | } 22 | return false; 23 | } 24 | 25 | void GameBase :: input() // This method takes user input 26 | { 27 | cout<<"Enter a number between 1 and 10 (both inclusive)\n"; 28 | cout<<"Enter \"0\" to exit.\n\n"; 29 | cout<<"=> "; 30 | cin>>un; 31 | } 32 | 33 | void GameBase :: display() // This method displays the results 34 | { 35 | cout<<"\nYour choice: "< 11 | #include "gamebase.cpp" 12 | #include "easy.cpp" 13 | #include "hard.cpp" 14 | 15 | #define clrscr() cout<<"\033[2J\033[1;1H" // Implments Clear screen function 16 | 17 | using namespace std; 18 | 19 | int c; 20 | 21 | void NumberGuessGame :: play() // this method implements easy or hard game mode as per user's choice. 22 | { 23 | clrscr(); 24 | cout<<"========================\n"; 25 | cout<<" Number Guessing Game \n"; 26 | cout<<"========================\n"; 27 | cout<<" 1. Hard mode. \n"; 28 | cout<<" 2. Easy mode. \n"; 29 | cout<<" Enter your choice: \n"; 30 | cin>>c; 31 | cout<<"\n\n"; 32 | 33 | switch(c) 34 | { 35 | case 1: 36 | HardGame :: play(); 37 | break; 38 | case 2: 39 | EasyGame :: play(); 40 | break; 41 | default: 42 | cout<<"Wrong choice!\n"; 43 | exit(0); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /NumberGuessGame/guessgame.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | OVERVIEW OF THE FILE 4 | 5 | This is the header file for the NumberGuessGame project. 6 | 7 | It includes the declarartions of all the classes that have been created in the project. 8 | 9 | */ 10 | 11 | /* 12 | 13 | GameBase class behaves as the base class for the EasyGame and HardGame classes that share similar functionality. 14 | 15 | */ 16 | class GameBase 17 | { 18 | private: 19 | 20 | bool checkWin(); 21 | 22 | protected: 23 | 24 | void input(); 25 | void display(); 26 | }; 27 | 28 | 29 | /* 30 | 31 | HardGame class includes the implementation of the hard mode of the NumberGuessGame. 32 | This class inherits from GameBase class. 33 | 34 | */ 35 | class HardGame : virtual protected GameBase 36 | { 37 | private: 38 | 39 | void comp(); 40 | 41 | protected: 42 | 43 | void play(); 44 | }; 45 | 46 | 47 | /* 48 | 49 | EasyGame class includes the implementation of the easy mode of the NumberGuessGame. 50 | This class inherits from GameBase class. 51 | 52 | */ 53 | class EasyGame : virtual protected GameBase 54 | { 55 | private: 56 | 57 | void comp(); 58 | 59 | protected: 60 | 61 | void play(); 62 | }; 63 | 64 | 65 | /* 66 | 67 | NumberGuessGame class implements the gameplay of both the easy and hard modes of the game. 68 | This class inherits from EasyGame class and HardGame class. 69 | 70 | */ 71 | class NumberGuessGame : virtual EasyGame, virtual HardGame 72 | { 73 | public: 74 | 75 | void play(); 76 | }; 77 | -------------------------------------------------------------------------------- /NumberGuessGame/hard.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file implements the EasyGame class which is responsible for the easy mode of the NumberGuessGame 4 | 5 | */ 6 | 7 | #include "gamebase.cpp" // GameBase class implementation included. 8 | #include 9 | 10 | void HardGame :: comp() // This method computes random number for computer in such a way that user never wins. 11 | { 12 | if(un == 1 || un == 10) 13 | { 14 | cn = (rand() % 9) +1; 15 | } 16 | else 17 | { 18 | while(true) 19 | { 20 | cn = (rand() % 10) +1; 21 | if(cn != un) 22 | { 23 | break; 24 | } 25 | } 26 | } 27 | } 28 | 29 | void HardGame :: play() // This method implements the hard mode gameplay 30 | { 31 | HardGame ob; 32 | ob.input(); 33 | if(un==0) 34 | { 35 | std::cout<<"Session being terminated...\n"; 36 | exit(0); 37 | } 38 | else if(un>10 || un<0) 39 | { 40 | std::cout<<"Invalid input! Session being terminated...\n"; 41 | exit(0); 42 | } 43 | else 44 | { 45 | char ch; 46 | ob.comp(); 47 | ob.display(); 48 | cout<<"Would you like to continue?(y/n)\n"; 49 | cin>>ch; 50 | if(ch == 'n' || ch == 'N') 51 | exit(0); 52 | } 53 | } 54 | 55 | else if(un>10 || un<0) 56 | { 57 | std::cout<<"Invalid input! Session being terminated...\n"; 58 | exit(0); 59 | } 60 | else 61 | { 62 | ob.comp(); 63 | ob.display(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /NumberGuessGame/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This file executes the project. 4 | 5 | */ 6 | 7 | #include "gameplay.cpp" 8 | 9 | int main() 10 | { 11 | NumberGuessGame ob; 12 | 13 | while (true) 14 | { 15 | ob.play(); 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /NumberGuessGame/readme.txt: -------------------------------------------------------------------------------- 1 | This is a beginner level project in c++ to help in logic building and get familiar with concept of OOP. 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BeginnerProjects 2 | C++ projects for beginners. 3 | 4 | # Hacktoberfest 2022 5 | 6 | Hacktoberfest is the easiest way to get into open source! Hacktoberfest is a month long festival of open source code presented by Digital Ocean and DEV this year in 2022. 7 | 8 | During the entire month of October 2022, all you have to do is contribute to any open source projects and open at least 4 pull requests. Yes, any project and any kind of contributions. It can be a be a bug fix, improvement, or even a documentation change! And win a T-Shirt and awesome stickers. 9 | 10 | If you’ve never contributed to open source before, this is the perfect time to get started because Hacktoberfest provides a large list of available contribution opportunities (and yes, there are always plenty for beginners too). 11 | 12 | # How to contribute? 13 | 14 | 1. Star this repository. 15 | 16 | 2. Fork this repository. 17 | 18 | 3. Clone the forked repository. 19 | 20 | 4. Navigate to the project directory. 21 | 22 | 5. Create a new branch. 23 | 24 | 6. Make changes. 25 | 26 | 7. Stage your changes and commit 27 | 28 | 8. Push your local commits to the remote repo. 29 | 30 | 9. Create a Pull Request. 31 | 32 | Congratulations! 🎉 you've made your contribution, and it would be accepted if it has a good quality. 33 | 34 | # Code of Conduct 35 | 36 | Examples of behavior that contributes to creating a positive environment : 37 | 38 | Using welcoming and inclusive language 39 | Gracefully accepting constructive criticism 40 | Focusing on what is best for the community 41 | Being respectful of differing viewpoints and experiences 42 | Examples of unacceptable behavior by participants include: 43 | 44 | Trolling, insulting/derogatory comments, and personal or political attacks 45 | Public or private harassment 46 | Publishing others' private information, such as a physical or electronic address, without explicit permission 47 | -------------------------------------------------------------------------------- /RockPaperScissor/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Rock Paper Scissors Game 3 | 4 | This is a simple game of rock paper scissors. The game is played against the computer. The computer randomly chooses rock, paper, or scissors. The user is prompted to choose rock, paper, or scissors. The winner is determined by the rules of rock paper scissors. The user can play as many times as they want. The user can also choose to quit the game at any time. 5 | 6 | ## Installation 7 | 8 | To install this game, clone this repository and run the following command: 9 | 10 | ```bash 11 | $ git clone https://github.com/VickyTheRocker/BeginnerProjects.git 12 | ``` 13 | 14 | 15 | ## Run the Game 16 | 17 | To run the game, navigate to the directory where the game is located and run the following command: 18 | 19 | ```bash 20 | $ g++ main.cpp -o main 21 | $ ./main 22 | ``` 23 | 24 | ## How to Play 25 | 26 | To play the game, follow the instructions on the screen. The game will prompt you to choose rock, paper, or scissors. The game will then randomly choose rock, paper, or scissors. The winner will be determined by the rules of rock paper scissors. The game will then prompt you to play again. If you choose to play again, the game will repeat. If you choose to quit, the game will end. 27 | 28 | -------------------------------------------------------------------------------- /RockPaperScissor/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int a[3] = {1, 2, 3}; 7 | int w; 8 | string b[3] = {"Rock", "Paper", "Scissor"}; 9 | int uc, cc, c; 10 | 11 | while(true) 12 | { 13 | cout<<"Enter 1 for Rock.\n"; 14 | cout<<"Enter 2 for Paper.\n"; 15 | cout<<"Enter 3 for Scissor.\n"; 16 | cout<<"Enter your choice:\n"; 17 | cin>>uc; 18 | 19 | cc = a[(rand() % 3)]-1; 20 | 21 | cout<<"You chose: "<>c; 87 | 88 | if(c == 2) 89 | { 90 | cout<<"Session being terminated...\n"; 91 | exit(0); 92 | } 93 | else if(c != 1) 94 | { 95 | cout<<"Wrong choice! Session being terminated...\n"; 96 | exit(0); 97 | } 98 | else 99 | { 100 | cout<<"\e[1;1H\e[2J"; 101 | cc=0; 102 | uc=0; 103 | } 104 | } 105 | 106 | 107 | 108 | return 0; 109 | } 110 | --------------------------------------------------------------------------------