From f0b46261f43f5c636792e0803e363e392385814f Mon Sep 17 00:00:00 2001 From: Hari Hristov <134207618+Hari-Hristov@users.noreply.github.com> Date: Tue, 23 Jan 2024 18:20:18 +0200 Subject: [PATCH 1/2] Delete scrabble old.txt --- scrabble old.txt | 305 ----------------------------------------------- 1 file changed, 305 deletions(-) delete mode 100644 scrabble old.txt diff --git a/scrabble old.txt b/scrabble old.txt deleted file mode 100644 index b508f49..0000000 --- a/scrabble old.txt +++ /dev/null @@ -1,305 +0,0 @@ -#include -#include -#include -#include - -using namespace std; - -const int MAX_ROUNDS = 100; -const int MIN_ROUNDS = 1; -const int MAX_LETTERS = 100; -const int MIN_LETTERS = 1; - -void printStartMenu() -{ - cout << "\t\tWelcome to Scrabble!" << endl; - cout << "Please select the number representing your choice:" << endl; - cout << "1.Start" << endl; - cout << "2.Settings" << endl; - cout << "3.Add a new word" << endl; - cout << "4.Exit" << endl << endl; -} - -//opravi go za sluchaq kogato e simvol che vurti bexkraino -int choiceSelection(int choice, int min, int max) -{ - if (choice < min || choice > max) - { - cout << "Invalid choice, please try again:" << endl; - int newChoice = 0; - cout << "Enter your new choice: "; - cin >> newChoice; - choice = choiceSelection(newChoice, min, max); - } - - return choice; -} - -void toLower(char &letter) -{ - if (65 <= letter && letter <= 90) - { - letter = letter + 32; - } -} - -void printLettersOnRow(char* arr, int length) -{ - for (int i = 0; i < length; i++) - { - if (i == length - 1) - { - cout << arr[i]; - cout << endl; - break; - } - cout << arr[i] << ", "; - } -} - -bool contains(char* arr, int length, char symbol) -{ - for (int i = 0; i < length; i++) - { - if (arr[i] == symbol) - { - arr[i] = NULL; - return true; - } - } - - return false; -} - -void fillArrWithRndChars(char* arr, int length) -{ - char c; - int rnd = 0; - - srand(time(NULL)); // initialize the random number generator - for (int j = 0; j < length; j++) - { - rnd = rand() % 26; - c = 'a' + rnd; - arr[j] = c; - } -} - -bool checkIfWordContainsWrongLetter(char* arr, int length, int letters, string word) -{ - for (int j = 0; j < length; j++) - { - if (!contains(arr, letters, word[j])) - { - return true; - } - } - return false; -} - -string toUpper(string word) -{ - for (int i = 0; i < word.length(); i++) - { - word[i] = toupper(word[i]); - } - - return word; -} - -bool checkIfWordIsInDict(string word) -{ - word = toUpper(word); - fstream file; - - file.open("scrabble dict.txt"); - - if (!file.is_open()) - { - cout << "Error opening the file" << endl; - } - - while (!file.eof()) - { - string currentWord; - getline(file, currentWord); - - if (word == currentWord) - { - file.close(); - return true; - } - } - - file.close(); - return false; -} - -void printColorText(string text, int colorCode) -{ - HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); - SetConsoleTextAttribute(h, colorCode); - cout << text << endl; - SetConsoleTextAttribute(h, 7); -} - -void printOutputFromRound(string word, int &points, int currentRound, int rounds, bool wrongWord) -{ - string output; - if (!wrongWord) - { - if (checkIfWordIsInDict(word)) - { - points += word.length(); - output = "Correct word. Your current points are: " + to_string(points); - printColorText(output, 2); //green - } - else - { - output = "Your word is not in the dictionary. You are awarded 0 points."; - printColorText(output, 4); //red - } - } - else - { - output = "Your word is incorrect. You are awarded 0 points."; - printColorText(output, 4); //red - } - - if (currentRound == rounds) - { - output = "Your final score is: " + to_string(points); - output += ". Thank you for playing!"; - printColorText(output, 11); //bright cyan - } -} - -void game(int rounds, int letters) -{ - cout << "\tGame starting:" << endl; - int points = 0; - - for (int i = 1; i <= rounds; i++) - { - cout << "Round " << i <<":" << endl; - - char* lettersOnRow = new char[letters] {}; - fillArrWithRndChars(lettersOnRow, letters); - - cout << "The letters availiable to use are: "; - printLettersOnRow(lettersOnRow, letters); - - string word; - cout << "Enter your word: "; - cin >> word; - int wordLength = word.length(); - - bool wordContainsWrongLetter = checkIfWordContainsWrongLetter(lettersOnRow, wordLength, letters, word); - - printOutputFromRound(word, points, i, rounds, wordContainsWrongLetter); - } -} - -void printPossibleSettings(int rounds, int letters) -{ - cout << "\tSetting options:" << endl; - cout << "1.Change the number of letters per round(current number is " << letters << ")" << endl; - cout << "2.Change the number of round(current number is " << rounds << ")" << endl; - cout << "3.Back" << endl; -} - -void changingSettings(int &rounds, int &letters) -{ - printPossibleSettings(rounds, letters); - - int minSettingNum = 1; - int maxSettingNum = 3; - - int settingChoice = 0; - - cout << "Enter your choice: "; - cin >> settingChoice; - settingChoice = choiceSelection(settingChoice, minSettingNum, maxSettingNum); - - if (settingChoice == 2) - { - int newRounds = 0; - cin >> newRounds; - - rounds = choiceSelection(newRounds, MIN_ROUNDS, MAX_ROUNDS); - } - else if(settingChoice == 1) - { - int newLetters = 0; - cin >> newLetters; - - letters = choiceSelection(newLetters, MIN_LETTERS, MAX_LETTERS); - } -} - -void addWord() -{ - string word; - string output; - cin >> word; - - fstream file; - - file.open("scrabble dict.txt", ios::app); - - if (file.fail()) - { - cout << "Error opening the file."; - return; - } - - if (checkIfWordIsInDict(word)) - { - output = word + " is already in the dictionary."; - printColorText(output, 12); - return; - } - - file << "\n" + toUpper(word); - output = word + " was successfully added to the dictionary."; - printColorText(output, 14); - - file.close(); -} - -int main() -{ - int choice = 0; - int minChoice = 1; - int maxChoice = 4; - int rounds = 10; - int numberOfLetters = 10; - - while (true) - { - printStartMenu(); - cout << "Enter your choice: "; - cin >> choice; - choice = choiceSelection(choice, minChoice, maxChoice); - - switch (choice) - { - case 1: - game(rounds, numberOfLetters); - break; - case 2: - changingSettings(rounds, numberOfLetters); - break; - case 3: - addWord(); - break; - case 4: - string exitText = "Thank you for playing Scrabble!"; - printColorText(exitText, 13); - return 0; - } - - cout << endl; - cout << endl; - } -} \ No newline at end of file From 58bff30d4c368204c475083aa0ba493d0ceb13df Mon Sep 17 00:00:00 2001 From: Hari Hristov <134207618+Hari-Hristov@users.noreply.github.com> Date: Wed, 24 Jan 2024 01:16:31 +0200 Subject: [PATCH 2/2] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b6a22fb --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Hari Hristov + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE.