diff --git a/Chat server.ilk b/Chat server.ilk new file mode 100644 index 0000000..f07d6f9 Binary files /dev/null and b/Chat server.ilk differ diff --git a/Chat server.pdb b/Chat server.pdb new file mode 100644 index 0000000..2711478 Binary files /dev/null and b/Chat server.pdb differ diff --git a/Debug/Project2.Build.CppClean.log b/Debug/Project2.Build.CppClean.log new file mode 100644 index 0000000..1574b95 --- /dev/null +++ b/Debug/Project2.Build.CppClean.log @@ -0,0 +1,43 @@ +\\mac\home\documents\github\pineapplepen\debug\vc140.pdb +\\mac\home\documents\github\pineapplepen\debug\vc140.idb +\\mac\home\documents\github\pineapplepen\debug\alphabet.obj +\\mac\home\documents\github\pineapplepen\debug\countdown.obj +\\mac\home\documents\github\pineapplepen\debug\gymmenu.obj +\\mac\home\documents\github\pineapplepen\debug\inventory.obj +\\mac\home\documents\github\pineapplepen\debug\jobmenu.obj +\\mac\home\documents\github\pineapplepen\debug\jumble.obj +\\mac\home\documents\github\pineapplepen\debug\librarymenu.obj +\\mac\home\documents\github\pineapplepen\debug\main.obj +\\mac\home\documents\github\pineapplepen\debug\mainmenu.obj +\\mac\home\documents\github\pineapplepen\debug\memorygame.obj +\\mac\home\documents\github\pineapplepen\debug\player.obj +\\mac\home\documents\github\pineapplepen\debug\playermenu.obj +c:\users\barim3\desktop\pineapplepen\debug\vc142.pdb +c:\users\barim3\desktop\pineapplepen\debug\vc142.idb +c:\users\barim3\desktop\pineapplepen\debug\player.obj +c:\users\barim3\desktop\pineapplepen\debug\playermenu.obj +c:\users\barim3\desktop\pineapplepen\debug\memorygame.obj +c:\users\barim3\desktop\pineapplepen\debug\mainmenu.obj +c:\users\barim3\desktop\pineapplepen\debug\main.obj +c:\users\barim3\desktop\pineapplepen\debug\librarymenu.obj +c:\users\barim3\desktop\pineapplepen\debug\jumble.obj +c:\users\barim3\desktop\pineapplepen\debug\jobmenu.obj +c:\users\barim3\desktop\pineapplepen\debug\inventory.obj +c:\users\barim3\desktop\pineapplepen\debug\gymmenu.obj +c:\users\barim3\desktop\pineapplepen\debug\countdown.obj +c:\users\barim3\desktop\pineapplepen\debug\check.obj +c:\users\barim3\desktop\pineapplepen\debug\alphabet.obj +\\mac\home\documents\github\pineapplepen\debug\project2.pdb +c:\users\barim3\desktop\pineapplepen\debug\vc140.idb +c:\users\barim3\desktop\pineapplepen\debug\project2.pdb +c:\users\barim3\desktop\pineapplepen\debug\vc140.pdb +c:\users\barim3\desktop\pineapplepen\debug\project2.tlog\cl.command.1.tlog +c:\users\barim3\desktop\pineapplepen\debug\project2.tlog\cl.read.1.tlog +c:\users\barim3\desktop\pineapplepen\debug\project2.tlog\cl.write.1.tlog +c:\users\barim3\desktop\pineapplepen\debug\project2.tlog\link-cvtres.read.1.tlog +c:\users\barim3\desktop\pineapplepen\debug\project2.tlog\link-cvtres.write.1.tlog +c:\users\barim3\desktop\pineapplepen\debug\project2.tlog\link-rc.read.1.tlog +c:\users\barim3\desktop\pineapplepen\debug\project2.tlog\link-rc.write.1.tlog +c:\users\barim3\desktop\pineapplepen\debug\project2.tlog\link.command.1.tlog +c:\users\barim3\desktop\pineapplepen\debug\project2.tlog\link.read.1.tlog +c:\users\barim3\desktop\pineapplepen\debug\project2.tlog\link.write.1.tlog diff --git a/Debug/Project2.exe b/Debug/Project2.exe new file mode 100644 index 0000000..e1341fe Binary files /dev/null and b/Debug/Project2.exe differ diff --git a/Debug/Project2.ilk b/Debug/Project2.ilk new file mode 100644 index 0000000..0c47fb0 Binary files /dev/null and b/Debug/Project2.ilk differ diff --git a/Debug/Project2.log b/Debug/Project2.log new file mode 100644 index 0000000..f4c7cf4 --- /dev/null +++ b/Debug/Project2.log @@ -0,0 +1,4 @@ + main.cpp +\\Mac\Home\Documents\GitHub\PineapplePen\room.h(42,12): warning C4129: '/': unrecognized character escape sequence +\\Mac\Home\Documents\GitHub\PineapplePen\room.h(44,12): warning C4129: '_': unrecognized character escape sequence + Project2.vcxproj -> \\Mac\Home\Documents\GitHub\PineapplePen\Debug\Project2.exe diff --git a/Debug/Project2.pdb b/Debug/Project2.pdb new file mode 100644 index 0000000..d90462b Binary files /dev/null and b/Debug/Project2.pdb differ diff --git a/Debug/Project2.tlog/CL.command.1.tlog b/Debug/Project2.tlog/CL.command.1.tlog new file mode 100644 index 0000000..6ca45b3 Binary files /dev/null and b/Debug/Project2.tlog/CL.command.1.tlog differ diff --git a/Debug/Project2.tlog/CL.read.1.tlog b/Debug/Project2.tlog/CL.read.1.tlog new file mode 100644 index 0000000..a240783 Binary files /dev/null and b/Debug/Project2.tlog/CL.read.1.tlog differ diff --git a/Debug/Project2.tlog/CL.write.1.tlog b/Debug/Project2.tlog/CL.write.1.tlog new file mode 100644 index 0000000..b4faaad Binary files /dev/null and b/Debug/Project2.tlog/CL.write.1.tlog differ diff --git a/Debug/Project2.tlog/Project2.lastbuildstate b/Debug/Project2.tlog/Project2.lastbuildstate new file mode 100644 index 0000000..e990c49 --- /dev/null +++ b/Debug/Project2.tlog/Project2.lastbuildstate @@ -0,0 +1,2 @@ +#TargetFrameworkVersion=v4.0:PlatformToolSet=v142:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0 +Debug|Win32|\\Mac\Home\Documents\GitHub\PineapplePen\| diff --git a/Debug/Project2.tlog/link.command.1.tlog b/Debug/Project2.tlog/link.command.1.tlog new file mode 100644 index 0000000..db5119c Binary files /dev/null and b/Debug/Project2.tlog/link.command.1.tlog differ diff --git a/Debug/Project2.tlog/link.read.1.tlog b/Debug/Project2.tlog/link.read.1.tlog new file mode 100644 index 0000000..0a10870 Binary files /dev/null and b/Debug/Project2.tlog/link.read.1.tlog differ diff --git a/Debug/Project2.tlog/link.write.1.tlog b/Debug/Project2.tlog/link.write.1.tlog new file mode 100644 index 0000000..4ba6d63 Binary files /dev/null and b/Debug/Project2.tlog/link.write.1.tlog differ diff --git a/Debug/Source.obj b/Debug/Source.obj new file mode 100644 index 0000000..e237943 Binary files /dev/null and b/Debug/Source.obj differ diff --git a/Debug/alphabet.obj b/Debug/alphabet.obj new file mode 100644 index 0000000..ef23e25 Binary files /dev/null and b/Debug/alphabet.obj differ diff --git a/Debug/check.obj b/Debug/check.obj new file mode 100644 index 0000000..1e20264 Binary files /dev/null and b/Debug/check.obj differ diff --git a/Debug/countdown.obj b/Debug/countdown.obj new file mode 100644 index 0000000..675eb91 Binary files /dev/null and b/Debug/countdown.obj differ diff --git a/Debug/gymmenu.obj b/Debug/gymmenu.obj new file mode 100644 index 0000000..b988970 Binary files /dev/null and b/Debug/gymmenu.obj differ diff --git a/Debug/inventory.obj b/Debug/inventory.obj new file mode 100644 index 0000000..b9158d7 Binary files /dev/null and b/Debug/inventory.obj differ diff --git a/Debug/jobmenu.obj b/Debug/jobmenu.obj new file mode 100644 index 0000000..3794bd2 Binary files /dev/null and b/Debug/jobmenu.obj differ diff --git a/Debug/jumble.obj b/Debug/jumble.obj new file mode 100644 index 0000000..49f2572 Binary files /dev/null and b/Debug/jumble.obj differ diff --git a/Debug/librarymenu.obj b/Debug/librarymenu.obj new file mode 100644 index 0000000..c7d1321 Binary files /dev/null and b/Debug/librarymenu.obj differ diff --git a/Debug/main.obj b/Debug/main.obj new file mode 100644 index 0000000..700ed8d Binary files /dev/null and b/Debug/main.obj differ diff --git a/Debug/mainmenu.obj b/Debug/mainmenu.obj new file mode 100644 index 0000000..11d47c8 Binary files /dev/null and b/Debug/mainmenu.obj differ diff --git a/Debug/memorygame.obj b/Debug/memorygame.obj new file mode 100644 index 0000000..f569e90 Binary files /dev/null and b/Debug/memorygame.obj differ diff --git a/Debug/player.obj b/Debug/player.obj new file mode 100644 index 0000000..da36730 Binary files /dev/null and b/Debug/player.obj differ diff --git a/Debug/playermenu.obj b/Debug/playermenu.obj new file mode 100644 index 0000000..23d0df3 Binary files /dev/null and b/Debug/playermenu.obj differ diff --git a/Debug/spacebar.obj b/Debug/spacebar.obj new file mode 100644 index 0000000..71d679a Binary files /dev/null and b/Debug/spacebar.obj differ diff --git a/Debug/sqlite3.dll b/Debug/sqlite3.dll new file mode 100644 index 0000000..8ec8617 Binary files /dev/null and b/Debug/sqlite3.dll differ diff --git a/Debug/stats.db b/Debug/stats.db new file mode 100644 index 0000000..c5ef180 Binary files /dev/null and b/Debug/stats.db differ diff --git a/Debug/table1.obj b/Debug/table1.obj new file mode 100644 index 0000000..cb14e52 Binary files /dev/null and b/Debug/table1.obj differ diff --git a/Debug/vc140.idb b/Debug/vc140.idb new file mode 100644 index 0000000..cd23995 Binary files /dev/null and b/Debug/vc140.idb differ diff --git a/Debug/vc140.pdb b/Debug/vc140.pdb new file mode 100644 index 0000000..bc0e63f Binary files /dev/null and b/Debug/vc140.pdb differ diff --git a/Debug/vc142.idb b/Debug/vc142.idb new file mode 100644 index 0000000..0487860 Binary files /dev/null and b/Debug/vc142.idb differ diff --git a/Debug/vc142.pdb b/Debug/vc142.pdb new file mode 100644 index 0000000..94c3149 Binary files /dev/null and b/Debug/vc142.pdb differ diff --git a/alphabet.cpp b/alphabet.cpp new file mode 100644 index 0000000..a6167f4 --- /dev/null +++ b/alphabet.cpp @@ -0,0 +1,71 @@ +#include "alphabet.h" +using namespace std; + +const int alpha_max = 26; +string answer; + +void sortstring(string &str) +{ + int charCount[alpha_max] = { 0 }; + + for (int index = 0;index < str.length();index++) + + charCount[str[index] - 'a']++; + + for (int index = 0;index < alpha_max;index++) + for (int j = 0;j < charCount[index];j++) + { + char c = ('a' + index); + answer += c; + } +} + +void Alphabet :: random_word() +{ + cout << "To earn money type the letters of the following word in alphabetical order: " << endl; + string word_list[] = + { "confinement", + "penitentiary", + "reformatory", + "guardhouse", + "punishment", + "conviction", + "imprisonment", + "incarceration", + "sentencing", + "criminology" }; + + int word_index = rand() % 11; + string word = word_list[word_index]; + cout << word << endl; + sortstring(word); +} + + +void check(string &userin) +{ + JobMenu j; + PlayerMenu playermenu; + Sql sql; + if (answer == userin) + { + cout << "Well done! You have completed all of the laundry. 5 pounds has been added to your account." << endl; + sql.updateBalanceCleaningTable(); + Sleep(2000); + + playermenu.ppmenu(); + } + else if (answer != userin) + { + cout << "Oh no! You have turned all of your inmates clothes pink! This will be deducted from your wages." << endl; + j.jobmenu(); + } +} +void Alphabet :: user_input() +{ + string userin; + cout << "Write the letters of this word in alphabetical order:" << endl;; + cin >> userin; + check(userin); + +} \ No newline at end of file diff --git a/alphabet.h b/alphabet.h new file mode 100644 index 0000000..77056fd --- /dev/null +++ b/alphabet.h @@ -0,0 +1,27 @@ +#ifndef ALPHABET_H +#define ALPHABET_H + +#include +#include +#include + + +#include "jobmenu.h" +#include "playermenu.h" +#include "player.h" + +using namespace std; + +class Alphabet +{ +public: + Alphabet() + { + + } + void random_word(); + void user_input(); +}; + + +#endif diff --git a/chatserver.exe b/chatserver.exe new file mode 100644 index 0000000..e8e58db Binary files /dev/null and b/chatserver.exe differ diff --git a/chatserver/Chat client/Chat client.vcxproj b/chatserver/Chat client/Chat client.vcxproj new file mode 100644 index 0000000..e0cf44b --- /dev/null +++ b/chatserver/Chat client/Chat client.vcxproj @@ -0,0 +1,119 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {33EDC9A8-2ECC-4696-8EDA-4E2F6CE1E2B8} + BarebonesServer + 10.0 + Chat server + + + + Application + true + v142 + MultiByte + + + Application + false + v142 + true + MultiByte + + + Application + true + v142 + MultiByte + + + Application + false + v142 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + true + + + + + Level3 + Disabled + true + + + + + Level3 + MaxSpeed + true + true + true + + + true + true + + + + + Level3 + MaxSpeed + true + true + true + + + true + true + + + + + + + + + \ No newline at end of file diff --git a/chatserver/Chat client/Chat client.vcxproj.filters b/chatserver/Chat client/Chat client.vcxproj.filters new file mode 100644 index 0000000..d5fe22c --- /dev/null +++ b/chatserver/Chat client/Chat client.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/chatserver/Chat client/Chat client.vcxproj.user b/chatserver/Chat client/Chat client.vcxproj.user new file mode 100644 index 0000000..0f14913 --- /dev/null +++ b/chatserver/Chat client/Chat client.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/chatserver/Chat client/Debug/Chat client.log b/chatserver/Chat client/Debug/Chat client.log new file mode 100644 index 0000000..e1525e2 --- /dev/null +++ b/chatserver/Chat client/Debug/Chat client.log @@ -0,0 +1,3 @@ +C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets(459,5): warning MSB8028: The intermediate directory (Debug\) contains files shared from another project (Chat client.vcxproj). This can lead to incorrect clean and rebuild behavior. + main.cpp + Chat client.vcxproj -> C:\Users\muskeen\source\repos\chat server\Debug\Chat server.exe diff --git a/chatserver/Chat client/Debug/Chat client.tlog/CL.command.1.tlog b/chatserver/Chat client/Debug/Chat client.tlog/CL.command.1.tlog new file mode 100644 index 0000000..1151031 Binary files /dev/null and b/chatserver/Chat client/Debug/Chat client.tlog/CL.command.1.tlog differ diff --git a/chatserver/Chat client/Debug/Chat client.tlog/CL.read.1.tlog b/chatserver/Chat client/Debug/Chat client.tlog/CL.read.1.tlog new file mode 100644 index 0000000..17e44aa Binary files /dev/null and b/chatserver/Chat client/Debug/Chat client.tlog/CL.read.1.tlog differ diff --git a/chatserver/Chat client/Debug/Chat client.tlog/CL.write.1.tlog b/chatserver/Chat client/Debug/Chat client.tlog/CL.write.1.tlog new file mode 100644 index 0000000..806448c Binary files /dev/null and b/chatserver/Chat client/Debug/Chat client.tlog/CL.write.1.tlog differ diff --git a/chatserver/Chat client/Debug/Chat client.tlog/Chat client.lastbuildstate b/chatserver/Chat client/Debug/Chat client.tlog/Chat client.lastbuildstate new file mode 100644 index 0000000..f3f741d --- /dev/null +++ b/chatserver/Chat client/Debug/Chat client.tlog/Chat client.lastbuildstate @@ -0,0 +1,2 @@ +#TargetFrameworkVersion=v4.0:PlatformToolSet=v142:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0 +Debug|Win32|C:\Users\muskeen\source\repos\chat server\| diff --git a/chatserver/Chat client/Debug/Chat client.tlog/link.command.1.tlog b/chatserver/Chat client/Debug/Chat client.tlog/link.command.1.tlog new file mode 100644 index 0000000..253c0eb Binary files /dev/null and b/chatserver/Chat client/Debug/Chat client.tlog/link.command.1.tlog differ diff --git a/chatserver/Chat client/Debug/Chat client.tlog/link.read.1.tlog b/chatserver/Chat client/Debug/Chat client.tlog/link.read.1.tlog new file mode 100644 index 0000000..d0631bf Binary files /dev/null and b/chatserver/Chat client/Debug/Chat client.tlog/link.read.1.tlog differ diff --git a/chatserver/Chat client/Debug/Chat client.tlog/link.write.1.tlog b/chatserver/Chat client/Debug/Chat client.tlog/link.write.1.tlog new file mode 100644 index 0000000..ebd7ad7 Binary files /dev/null and b/chatserver/Chat client/Debug/Chat client.tlog/link.write.1.tlog differ diff --git a/chatserver/Chat client/Debug/Chat server.tlog/CL.command.1.tlog b/chatserver/Chat client/Debug/Chat server.tlog/CL.command.1.tlog new file mode 100644 index 0000000..7f956b9 Binary files /dev/null and b/chatserver/Chat client/Debug/Chat server.tlog/CL.command.1.tlog differ diff --git a/chatserver/Chat client/Debug/Chat server.tlog/CL.read.1.tlog b/chatserver/Chat client/Debug/Chat server.tlog/CL.read.1.tlog new file mode 100644 index 0000000..17e44aa Binary files /dev/null and b/chatserver/Chat client/Debug/Chat server.tlog/CL.read.1.tlog differ diff --git a/chatserver/Chat client/Debug/Chat server.tlog/CL.write.1.tlog b/chatserver/Chat client/Debug/Chat server.tlog/CL.write.1.tlog new file mode 100644 index 0000000..806448c Binary files /dev/null and b/chatserver/Chat client/Debug/Chat server.tlog/CL.write.1.tlog differ diff --git a/chatserver/Chat client/Debug/Chat server.tlog/Chat server.lastbuildstate b/chatserver/Chat client/Debug/Chat server.tlog/Chat server.lastbuildstate new file mode 100644 index 0000000..f3f741d --- /dev/null +++ b/chatserver/Chat client/Debug/Chat server.tlog/Chat server.lastbuildstate @@ -0,0 +1,2 @@ +#TargetFrameworkVersion=v4.0:PlatformToolSet=v142:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0 +Debug|Win32|C:\Users\muskeen\source\repos\chat server\| diff --git a/chatserver/Chat client/Debug/Chat server.tlog/link.command.1.tlog b/chatserver/Chat client/Debug/Chat server.tlog/link.command.1.tlog new file mode 100644 index 0000000..9092b2c Binary files /dev/null and b/chatserver/Chat client/Debug/Chat server.tlog/link.command.1.tlog differ diff --git a/chatserver/Chat client/Debug/Chat server.tlog/link.read.1.tlog b/chatserver/Chat client/Debug/Chat server.tlog/link.read.1.tlog new file mode 100644 index 0000000..d0631bf Binary files /dev/null and b/chatserver/Chat client/Debug/Chat server.tlog/link.read.1.tlog differ diff --git a/chatserver/Chat client/Debug/Chat server.tlog/link.write.1.tlog b/chatserver/Chat client/Debug/Chat server.tlog/link.write.1.tlog new file mode 100644 index 0000000..d21b043 Binary files /dev/null and b/chatserver/Chat client/Debug/Chat server.tlog/link.write.1.tlog differ diff --git a/chatserver/Chat client/Debug/main.obj b/chatserver/Chat client/Debug/main.obj new file mode 100644 index 0000000..3597028 Binary files /dev/null and b/chatserver/Chat client/Debug/main.obj differ diff --git a/chatserver/Chat client/Debug/vc140.idb b/chatserver/Chat client/Debug/vc140.idb new file mode 100644 index 0000000..498296b Binary files /dev/null and b/chatserver/Chat client/Debug/vc140.idb differ diff --git a/chatserver/Chat client/Debug/vc140.pdb b/chatserver/Chat client/Debug/vc140.pdb new file mode 100644 index 0000000..e86a2bc Binary files /dev/null and b/chatserver/Chat client/Debug/vc140.pdb differ diff --git a/chatserver/Chat client/Debug/vc142.idb b/chatserver/Chat client/Debug/vc142.idb new file mode 100644 index 0000000..36b26bc Binary files /dev/null and b/chatserver/Chat client/Debug/vc142.idb differ diff --git a/chatserver/Chat client/Debug/vc142.pdb b/chatserver/Chat client/Debug/vc142.pdb new file mode 100644 index 0000000..d3bfc46 Binary files /dev/null and b/chatserver/Chat client/Debug/vc142.pdb differ diff --git a/chatserver/Chat client/main.cpp b/chatserver/Chat client/main.cpp new file mode 100644 index 0000000..a7927df --- /dev/null +++ b/chatserver/Chat client/main.cpp @@ -0,0 +1,203 @@ +#include +#include +#include +#include +#include +#include + +#pragma comment (lib, "Ws2_32.lib") + +#define IP_ADDRESS "127.0.0.1" +#define DEFAULT_PORT "3504" +#define DEFAULT_BUFLEN 512 + +struct client_type +{ + int id; + SOCKET socket; + +}; + +const char OPTION_VALUE = 1; +const int MAX_CLIENTS = 5; + +//Function Prototypes + + + +int process_client(client_type & new_client, std::vector & client_array, std::thread & thread); +int main(); + + +int process_client(client_type& new_client, std::vector& client_array, std::thread& thread) +{ + std::string msg = ""; + char tempmsg[DEFAULT_BUFLEN] = ""; + + //Session + while (1) + { + memset(tempmsg, 0, DEFAULT_BUFLEN); + + if (new_client.socket != 0) + { + int iResult = recv(new_client.socket, tempmsg, DEFAULT_BUFLEN, 0); + + if (iResult != SOCKET_ERROR) + { + + if (strcmp("", tempmsg)) + + msg = "Player #" + std::to_string(new_client.id) + ": " + tempmsg; + + std::cout << msg.c_str() << std::endl; + + //Broadcast that message to the other clients + for (int i = 0; i < MAX_CLIENTS; i++) + { + if (client_array[i].socket != INVALID_SOCKET) + if (new_client.id != i) + iResult = send(client_array[i].socket, msg.c_str(), strlen(msg.c_str()), 0); + } + } + else + { + msg = "Player #" + std::to_string(new_client.id) + " Disconnected"; + + std::cout << msg << std::endl; + + closesocket(new_client.socket); + closesocket(client_array[new_client.id].socket); + client_array[new_client.id].socket = INVALID_SOCKET; + + //Broadcast the disconnection message to the other clients + for (int i = 0; i < MAX_CLIENTS; i++) + { + if (client_array[i].socket != INVALID_SOCKET) + iResult = send(client_array[i].socket, msg.c_str(), strlen(msg.c_str()), 0); + } + + break; + } + } + } //end while + + + thread.detach(); + + return 0; +} + +int main() +{ + WSADATA wsaData; + struct addrinfo hints; + struct addrinfo* server = NULL; + SOCKET server_socket = INVALID_SOCKET; + std::string msg = ""; + std::vector client(MAX_CLIENTS); + int num_clients = 0; + int temp_id = -1; + std::thread my_thread[MAX_CLIENTS]; + + //Initialize Winsock + std::cout << "Intializing Winsock... (IMPORTANT)" << std::endl; + WSAStartup(MAKEWORD(2, 2), &wsaData); + + //Setup hints + ZeroMemory(&hints, sizeof(hints)); + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + hints.ai_flags = AI_PASSIVE; + + //Setup Server + std::cout << "Setting up the batmobile..." << std::endl; + getaddrinfo(static_cast(IP_ADDRESS), DEFAULT_PORT, &hints, &server); + + //Create a listening socket for connecting to server + std::cout << "Setting up the launchpad..." << std::endl; + server_socket = socket(server->ai_family, server->ai_socktype, server->ai_protocol); + + //Setup socket options + setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, &OPTION_VALUE, sizeof(int)); //Make it possible to re-bind to a port that was used within the last 2 minutes + setsockopt(server_socket, IPPROTO_TCP, TCP_NODELAY, &OPTION_VALUE, sizeof(int)); //Used for interactive programs + + //Assign an address to the server socket. + std::cout << "INITIATION COMPLETE..." << std::endl; + bind(server_socket, server->ai_addr, (int)server->ai_addrlen); + + //Listen for incoming connections. + std::cout << "Listening to emergency calls..." << std::endl; + listen(server_socket, SOMAXCONN); + + //Initialize the client list + for (int i = 0; i < MAX_CLIENTS; i++) + { + client[i] = { -1, INVALID_SOCKET }; + } + + while (1) + { + + SOCKET incoming = INVALID_SOCKET; + incoming = accept(server_socket, NULL, NULL); + + if (incoming == INVALID_SOCKET) continue; + + //Reset the number of clients + num_clients = -1; + + //Create a temporary id for the next client + temp_id = -1; + for (int i = 0; i < MAX_CLIENTS; i++) + { + if (client[i].socket == INVALID_SOCKET && temp_id == -1) + { + client[i].socket = incoming; + client[i].id = i; + temp_id = i; + } + + if (client[i].socket != INVALID_SOCKET) + num_clients++; + + //std::cout << client[i].socket << std::endl; + } + + if (temp_id != -1) + { + //Send the id to that client + std::cout << "Player #" << client[temp_id].id << " Accepted" << std::endl; + msg = std::to_string(client[temp_id].id); + send(client[temp_id].socket, msg.c_str(), strlen(msg.c_str()), 0); + + //Create a thread process for that client + my_thread[temp_id] = std::thread(process_client, std::ref(client[temp_id]), std::ref(client), std::ref(my_thread[temp_id])); + } + else + { + msg = "Server is full"; + send(incoming, msg.c_str(), strlen(msg.c_str()), 0); + std::cout << msg << std::endl; + } + } //end while + + + //Close listening socket + closesocket(server_socket); + + //Close client socket + for (int i = 0; i < MAX_CLIENTS; i++) + { + my_thread[i].detach(); + closesocket(client[i].socket); + } + + //Clean up Winsock + WSACleanup(); + std::cout << "Program has ended successfully" << std::endl; + + system("pause"); + return 0; +} \ No newline at end of file diff --git a/chatserver/Chat client/x64/Debug/Chat client.log b/chatserver/Chat client/x64/Debug/Chat client.log new file mode 100644 index 0000000..fb836b5 --- /dev/null +++ b/chatserver/Chat client/x64/Debug/Chat client.log @@ -0,0 +1,6 @@ + main.cpp +C:\Users\muskeen\source\repos\chat server\Chat client\main.cpp(90,56): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data +C:\Users\muskeen\source\repos\chat server\Chat client\main.cpp(124,24): warning C4018: '<': signed/unsigned mismatch +C:\Users\muskeen\source\repos\chat server\Chat client\main.cpp(133,58): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data +C:\Users\muskeen\source\repos\chat server\Chat client\main.cpp(155,44): warning C4267: 'argument': conversion from 'size_t' to 'int', possible loss of data + Chat client.vcxproj -> C:\Users\muskeen\source\repos\chat server\x64\Debug\Chat client.exe diff --git a/chatserver/Chat client/x64/Debug/Chat client.tlog/CL.command.1.tlog b/chatserver/Chat client/x64/Debug/Chat client.tlog/CL.command.1.tlog new file mode 100644 index 0000000..75b49ca Binary files /dev/null and b/chatserver/Chat client/x64/Debug/Chat client.tlog/CL.command.1.tlog differ diff --git a/chatserver/Chat client/x64/Debug/Chat client.tlog/CL.read.1.tlog b/chatserver/Chat client/x64/Debug/Chat client.tlog/CL.read.1.tlog new file mode 100644 index 0000000..b6bfac7 Binary files /dev/null and b/chatserver/Chat client/x64/Debug/Chat client.tlog/CL.read.1.tlog differ diff --git a/chatserver/Chat client/x64/Debug/Chat client.tlog/CL.write.1.tlog b/chatserver/Chat client/x64/Debug/Chat client.tlog/CL.write.1.tlog new file mode 100644 index 0000000..d20ab26 Binary files /dev/null and b/chatserver/Chat client/x64/Debug/Chat client.tlog/CL.write.1.tlog differ diff --git a/chatserver/Chat client/x64/Debug/Chat client.tlog/Chat client.lastbuildstate b/chatserver/Chat client/x64/Debug/Chat client.tlog/Chat client.lastbuildstate new file mode 100644 index 0000000..7d84a99 --- /dev/null +++ b/chatserver/Chat client/x64/Debug/Chat client.tlog/Chat client.lastbuildstate @@ -0,0 +1,2 @@ +#TargetFrameworkVersion=v4.0:PlatformToolSet=v142:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0 +Debug|x64|C:\Users\muskeen\source\repos\chat server\| diff --git a/chatserver/Chat client/x64/Debug/Chat client.tlog/link.command.1.tlog b/chatserver/Chat client/x64/Debug/Chat client.tlog/link.command.1.tlog new file mode 100644 index 0000000..8b746e1 Binary files /dev/null and b/chatserver/Chat client/x64/Debug/Chat client.tlog/link.command.1.tlog differ diff --git a/chatserver/Chat client/x64/Debug/Chat client.tlog/link.read.1.tlog b/chatserver/Chat client/x64/Debug/Chat client.tlog/link.read.1.tlog new file mode 100644 index 0000000..404fc93 Binary files /dev/null and b/chatserver/Chat client/x64/Debug/Chat client.tlog/link.read.1.tlog differ diff --git a/chatserver/Chat client/x64/Debug/Chat client.tlog/link.write.1.tlog b/chatserver/Chat client/x64/Debug/Chat client.tlog/link.write.1.tlog new file mode 100644 index 0000000..c2266c4 Binary files /dev/null and b/chatserver/Chat client/x64/Debug/Chat client.tlog/link.write.1.tlog differ diff --git a/chatserver/Chat client/x64/Debug/main.obj b/chatserver/Chat client/x64/Debug/main.obj new file mode 100644 index 0000000..2a05912 Binary files /dev/null and b/chatserver/Chat client/x64/Debug/main.obj differ diff --git a/chatserver/Chat client/x64/Debug/vc142.idb b/chatserver/Chat client/x64/Debug/vc142.idb new file mode 100644 index 0000000..2cd1c77 Binary files /dev/null and b/chatserver/Chat client/x64/Debug/vc142.idb differ diff --git a/chatserver/Chat client/x64/Debug/vc142.pdb b/chatserver/Chat client/x64/Debug/vc142.pdb new file mode 100644 index 0000000..2c6e8d4 Binary files /dev/null and b/chatserver/Chat client/x64/Debug/vc142.pdb differ diff --git a/chatserver/Chat server.sln b/chatserver/Chat server.sln new file mode 100644 index 0000000..dc1a4b2 --- /dev/null +++ b/chatserver/Chat server.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29806.167 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Chat client", "Chat client\Chat client.vcxproj", "{33EDC9A8-2ECC-4696-8EDA-4E2F6CE1E2B8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {33EDC9A8-2ECC-4696-8EDA-4E2F6CE1E2B8}.Debug|x64.ActiveCfg = Debug|x64 + {33EDC9A8-2ECC-4696-8EDA-4E2F6CE1E2B8}.Debug|x64.Build.0 = Debug|x64 + {33EDC9A8-2ECC-4696-8EDA-4E2F6CE1E2B8}.Debug|x86.ActiveCfg = Debug|Win32 + {33EDC9A8-2ECC-4696-8EDA-4E2F6CE1E2B8}.Debug|x86.Build.0 = Debug|Win32 + {33EDC9A8-2ECC-4696-8EDA-4E2F6CE1E2B8}.Release|x64.ActiveCfg = Release|x64 + {33EDC9A8-2ECC-4696-8EDA-4E2F6CE1E2B8}.Release|x64.Build.0 = Release|x64 + {33EDC9A8-2ECC-4696-8EDA-4E2F6CE1E2B8}.Release|x86.ActiveCfg = Release|Win32 + {33EDC9A8-2ECC-4696-8EDA-4E2F6CE1E2B8}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {92D7CDE8-D3A2-4939-909F-C2CC6E9A144F} + EndGlobalSection +EndGlobal diff --git a/chatserver/Debug/Chat server.ilk b/chatserver/Debug/Chat server.ilk new file mode 100644 index 0000000..f07d6f9 Binary files /dev/null and b/chatserver/Debug/Chat server.ilk differ diff --git a/chatserver/Debug/Chat server.pdb b/chatserver/Debug/Chat server.pdb new file mode 100644 index 0000000..2711478 Binary files /dev/null and b/chatserver/Debug/Chat server.pdb differ diff --git a/chatserver/Debug/Chatserver.exe b/chatserver/Debug/Chatserver.exe new file mode 100644 index 0000000..e8e58db Binary files /dev/null and b/chatserver/Debug/Chatserver.exe differ diff --git a/chatserver/x64/Debug/Chat client.exe b/chatserver/x64/Debug/Chat client.exe new file mode 100644 index 0000000..e67231f Binary files /dev/null and b/chatserver/x64/Debug/Chat client.exe differ diff --git a/chatserver/x64/Debug/Chat client.ilk b/chatserver/x64/Debug/Chat client.ilk new file mode 100644 index 0000000..ae62626 Binary files /dev/null and b/chatserver/x64/Debug/Chat client.ilk differ diff --git a/chatserver/x64/Debug/Chat client.pdb b/chatserver/x64/Debug/Chat client.pdb new file mode 100644 index 0000000..3f302f6 Binary files /dev/null and b/chatserver/x64/Debug/Chat client.pdb differ diff --git a/check.h b/check.h new file mode 100644 index 0000000..99a8091 --- /dev/null +++ b/check.h @@ -0,0 +1,2 @@ + + diff --git a/countdown.cpp b/countdown.cpp new file mode 100644 index 0000000..073747d --- /dev/null +++ b/countdown.cpp @@ -0,0 +1,16 @@ +#include "countdown.h" +using namespace std; + +string user_answer; +void countdown1() +{ + for (int i = 10; i >= 0; i--) + { + cout << i << endl; + Sleep(1000); + } + system("cls"); + cout << "Write the letters in the order that was shown: " << endl; + cin >> user_answer; + memorycheck(user_answer); +} diff --git a/countdown.h b/countdown.h new file mode 100644 index 0000000..ab6ff80 --- /dev/null +++ b/countdown.h @@ -0,0 +1,17 @@ +#ifndef COUNTDOWN_H +#define COUNTDOWN_H + +#include +#include +#include +#include +#include "memorygame.h" + + +using namespace std; + +void countdown1(); + + +#endif + diff --git a/gymmenu.cpp b/gymmenu.cpp new file mode 100644 index 0000000..bc6feb6 --- /dev/null +++ b/gymmenu.cpp @@ -0,0 +1,96 @@ +#include "gymmenu.h" +using namespace std; + + + + +void Gym::gymmenu() +{ + Sql sql; + PlayerMenu playermenu; + int selection; + cout << "\n==================="; + + cout << "\n Welcome to the Gym"; + + cout << "\n==================="; + + cout << "\n 1 - WeightLifting"; + + cout << "\n 2 - Cardio"; + + + cout << "\n Enter selection: "; + + cin >> selection; + + if (selection == 1) + { + cout << "Press Spacebar 6 Times to Weightlift" << endl; + char key = _getch(); + int value = key; + int counter = 0; + + while (1) + { + key = _getch(); + + if (key == KEY_SPACE) + { + + counter++; + } + if (counter == 4) + { + //cout << "UPDATED" << endl; + sql.updateStrengthTable(); + sql.updateDehydrationTable(); + break; + } + } + key = _getch(); + value = key; + + system("cls"); + playermenu.ppmenu(); + + + + } + else if (selection == 2) + { + char key = _getch(); + int value = key; + int counter = 0; + + while (1) + { + key = _getch(); + + if (key == KEY_SPACE) + { + counter++; + } + if (counter == 4) + { + + + sql.updateDehydrationTable(); + sql.updateStaminaTable(); + break; + } + } + key = _getch(); + value = key; + + system("cls"); + playermenu.ppmenu(); + + + } + + else { + cout << "\n Invalid selection"; + + } + } \ No newline at end of file diff --git a/gymmenu.h b/gymmenu.h new file mode 100644 index 0000000..c8cb248 --- /dev/null +++ b/gymmenu.h @@ -0,0 +1,52 @@ +#ifndef GYMMENU_H +#define GYMMENU_H + +#include +#include +#include "playermenu.h" +#include "player.h" +#include "menuoptions.h" +#include "menuclass.h" +#define KEY_SPACE 32 + +using namespace std; + +class Gym : public Menu +{ +public: + Gym(MenuSwitch* myGame) + { + game = myGame; + } + Gym() + { + + } + void gymmenu(); + void update(int input) + { + + if (input == 1) + { + game->currentMenu = game->menuOption[input]; + cout << "Menu changed to player menu" << endl; + } + else if (input == 2) + { + game->currentMenu = game->menuOption[input]; + cout << "Menu changed to job menu" << endl; + } + else if (input == 3) + { + game->currentMenu = game->menuOption[input]; + cout << "Menu changed to library menu" << endl; + } + else if (input == 4) + { + cout << "Menu unchanged - still gym menu" << endl; + gymmenu(); + } + } +}; + +#endif \ No newline at end of file diff --git a/inventory.cpp b/inventory.cpp new file mode 100644 index 0000000..37b15a0 --- /dev/null +++ b/inventory.cpp @@ -0,0 +1,173 @@ +#include "inventory.h" +using namespace std; + +void removeItem(int inventoryCount[4]); +void openInventory(int inventory[10]); +void addItem(); +int inven[10] = {'0','1','0','0','1','0','0','2','2','2'}; +std::map itemDictionary; + +int INV::inv() +{ + /* string choice; + while (choice != "quit" ) + { + cin >> choice; + if (choice == "open") + {*/ + system("cls"); + openInventory(inven); + /* } + }*/ + return 0; +} + + + +void openInventory(int inventory[10]) +{ + PlayerMenu playermenu; + itemDictionary.insert(std::make_pair(0,"empty slot")); + itemDictionary.insert(std::make_pair(1,"soap")); + itemDictionary.insert(std::make_pair(2,"shiv")); + itemDictionary.insert(std::make_pair(3,"pickaxe")); + int inventoryCount[4]= {0,0,0,0}; + cout<<"*****Inventory******" << '\n'; + for( int i = 0; i < 10; i = i + 1 ) + { + switch(inventory[i]) + { + case '0' : + inventoryCount[0] = inventoryCount[0] + 1; + break; + case '1' : + inventoryCount[1] = inventoryCount[1] + 1; + break; + case '2' : + inventoryCount[2] = inventoryCount[2] + 1; + break; + case '3' : + inventoryCount[3] = inventoryCount[3] + 1; + break; + default : + cout << "Invalid item" << '\n'; + cout << (inventory[i]) << '\n'; + break; + } + } + for( int i = 0; i < 4; i = i + 1 ) + { + if (inventoryCount[i]>0) + { + cout << inventoryCount[i]<< " " << itemDictionary[i]; + cout << '\n'; + } + } + int userchoice; + cout << '\n' << "********************************************"<< '\n'; + cout << '\n' << "What would you like to do "<< '\n'; + cout <<"1 - drops an item of your choosing" <<'\n'; + cout <<"2 - picks up an item of your choosing (option is only here for testing purposes until a legitimate means of getting items is included)" <<'\n'; + cout <<"3 - leaves this interface " <<'\n'; + cin >>userchoice; + switch(userchoice) + { + case 1 : + removeItem(inventoryCount); + break; + case 2 : + addItem(); + cout << '\n'; + break; + case 3 : + cout << '\n'<< "exiting inventory..."<< '\n'; + Sleep(1000); + system("cls"); + playermenu.ppmenu(); + break; + default : + cout<< "Invalid input!" << '\n'; + break; + } +} + + +void addItem() +{ + cout << '\n' << "********************************************"<< '\n'; + cout << '\n' <<"What item would you like added to your inventory?" << '\n'; + cout << '\n' << "********************************************"<< '\n'; + cout <<"1 - soap" <<'\n'; + cout <<"2 - shiv" <<'\n'; + cout <<"3 - pickaxe" <<'\n'; + char newitem; + cin >> newitem; + switch(newitem) + { + case '1' : + cout << '\n' << "attempting to soap item to inventory"<< '\n'; + break; + case '2' : + cout << '\n' << "attempting to shiv item to inventory"<< '\n'; + break; + case '3' : + cout << '\n' << "attempting to pickaxe item to inventory"<< '\n'; + break; + default : + cout<< "Invalid input!" << '\n'; + break; + } + int check= 0; + for( int a = 0; a < 10; a = a + 1 ) + { + if (inven[a] == 48) + { + if (check == 0) + { + inven[a] = newitem; + check = 1; + cout << '\n' << "Item added to inventory"<< '\n'; + } + + } + } + if (check == 0) + { + cout << '\n' << "No empty slots found, item adding failed"<< '\n'; + } +} + + +void removeItem(int inventoryCount[4]) + { + std::string itemname; + cout << "What item would you like to drop?"<< '\n'; + cin >> itemname; + for( int i = 0; i < 4; i = i + 1 ) + { + if (itemDictionary[i] == itemname) + { + if (inventoryCount[i] != 0) + { + int check= 0; + for( int a = 0; a < 10; a = a + 1 ) + { + if (inven[a] == (48+i)) + { + if (check == 0) + { + cout<< '\n'<< "Item dropped."<< '\n'; + inven[a]= '0'; + check = 1; + } + } + } + } + else + { + cout << "You dont have any of that item to drop!"; + } + } + } + } + diff --git a/inventory.h b/inventory.h new file mode 100644 index 0000000..7e0b829 --- /dev/null +++ b/inventory.h @@ -0,0 +1,20 @@ +#ifndef INVENTORY_H +#define INVENTORY_H + +#include +#include +#include +#include +#include +#include "playermenu.h" + +using namespace std; +class INV +{ +public: + int inv(); +}; + + + +#endif \ No newline at end of file diff --git a/jobmenu.cpp b/jobmenu.cpp new file mode 100644 index 0000000..36c2dbb --- /dev/null +++ b/jobmenu.cpp @@ -0,0 +1,58 @@ +#include "jobmenu.h" +using namespace std; + +void JobMenu::jobmenu() + +{ + + int selection; + + cout << "\n==================="; + + cout << "\n Job Menu"; + + cout << "\n==================="; + + cout << "\n 1 - Cleaning: 5"; + + cout << "\n 2 - Laundry: 10"; + + cout << "\n 3 - Jumble minigame: 20"; + + cout << "\n 4 - Go Back"; + + + cout << "\n Enter selection: "; + + cin >> selection; + + if (selection == 1) + { + Alphabet a; + a.random_word(); + a.user_input(); + } + else if (selection == 2) + { + randomsequence(); + //memorycheck(string &answer); + } + else if (selection == 3) + { + jumble(); + + } + else if (selection == 4) + { + cout << "0 - Chatroom." << endl; + cout << "1 - Game Menu." << endl; + cout << "2 - Job Menu." << endl; + cout << "3 - Library Menu" << endl; + cout << "Enter Selection:" << endl; + + /*int menuInput; + + cin >> menuInput; + JobMenu::update(menuInput);*/ + } +} diff --git a/jobmenu.h b/jobmenu.h new file mode 100644 index 0000000..bee6fca --- /dev/null +++ b/jobmenu.h @@ -0,0 +1,53 @@ +#ifndef JOBMENU_H +#define JOBMENU_H + +#include +#include "alphabet.h" +#include "jumble.h" +#include "memorygame.h" +#include "menuoptions.h" +#include "menuclass.h" + +using namespace std; + +class JobMenu : public Menu +{ +public: + + JobMenu(MenuSwitch* myGame) + { + game = myGame; + } + JobMenu() + { + + } + void jobmenu(); + + void update(int input) + { + if (input == 1) + { + game->currentMenu = game->menuOption[input]; + cout << "Menu changed to player menu" << endl; + } + else if (input == 3) + { + game->currentMenu = game->menuOption[input]; + cout << "Menu changed to library menu" << endl; + } + else if (input == 4) + { + game->currentMenu = game->menuOption[input]; + cout << "Menu changed to gym menu" << endl; + } + else if (input == 2) + { + cout << "Menu unchanged - still job menu" << endl; + system("cls"); + jobmenu(); + } + } +}; + +#endif diff --git a/jumble.cpp b/jumble.cpp new file mode 100644 index 0000000..8af67d7 --- /dev/null +++ b/jumble.cpp @@ -0,0 +1,93 @@ +#include "jumble.h" +using namespace std; + +int jumble() +{ + PlayerMenu playermenu; + Sql sql; + + int score; + score = 0; + + enum fields { WORD, HINT, NUM_FIELDS }; + const int NUM_WORDS = 9; + const string WORDS[NUM_WORDS][NUM_FIELDS] = + { + { "wall", "Do you feel like banging your head against something?" }, + { "glasses", "These might help you see the answer" }, + { "persistant", "keep at it" }, + { "jumble", "It's what the game is all about!", }, + { "decorate", "Add to something to make it more attractive", }, + { "Rome", "Capital of Italy, " }, + { "advocate", "A person who pleads for a person, cause, or idea", }, + { "sanguine", "Confidently optimistic and cheerful", }, + { "didactic", "Instructive with a moral intent", } + + }; + + srand(time(0)); + + int choice = (rand() % NUM_WORDS); + string theWord = WORDS[choice][WORD]; //word to guess + string theHint = WORDS[choice][HINT]; //hint + + //to jumble the word + + string jumble = theWord; //jumbled version of the word + int length = jumble.size(); + for (int i = 0; i < length; ++i) + { + int index1 = (rand() % length); + int index2 = (rand() % length); + char temp = jumble[index1]; + jumble[index1] = jumble[index2]; + jumble[index2] = temp; + score = length; // score based on the length of the word + + + } + + // welcome the player + + cout << "\t\tWelcome to Word Jumble\n\n"; + cout << "Let's start our game\n"; + cout << "Unscarmble the letters to make a word.\n"; + cout << "Enter 'hint' for a hint.\n"; + cout << "Enter 'quit' to quit the game\n\n"; + cout << "The jumble is " << jumble; + + string guess; + cout << "\n\nYour guess: "; + cin >> guess; + + //entering the game loop + + while ((guess != theWord) && (guess != "quit")) + { + + if (guess == "hint") + cout << theHint; + + + + else + cout << "Sorry! That is not the correct word..."; + --score; //subtracts points for hint or if you guess wrong + + cout << "\n\nYour guess: "; + cin >> guess; + + } + + if (guess == theWord) + { + cout << "\nThat's it! Congrats!! You guessed it! You have a score of " << score << endl; + sql.updateBalanceCleaningTable(); + + cout << "\nThanks for playing!\n"; + + playermenu.ppmenu(); + } + return 0; + +} diff --git a/jumble.h b/jumble.h new file mode 100644 index 0000000..ee1a0aa --- /dev/null +++ b/jumble.h @@ -0,0 +1,11 @@ +#include +#include +#include +#include +#include "playermenu.h" +#include "player.h" + +using namespace std; + +int jumble(); + diff --git a/librarymenu.cpp b/librarymenu.cpp new file mode 100644 index 0000000..70c3c26 --- /dev/null +++ b/librarymenu.cpp @@ -0,0 +1,71 @@ +#include "librarymenu.h" +using namespace std; + +void LibraryMenu :: librarymenu() +{ + Sql sql; + //PlayerMenu PlayerMenu; + + int selection; + + cout << "\n==================="; + + cout << "\n Welcome to the Library"; + + cout << "\n==================="; + + cout << "\n 1 - Read Books and Journals"; + + cout << "\n 2 - Go Back"; + + cout << "\n Enter selection: "; + + cin >> selection; + + if (selection == 1) + { + cout << "\n you are reading ....... " << endl; + + { + char key = _getch(); + int value = key; + int counter = 0; + + while (1) + { + key = _getch(); + + if (key == KEY_SPACE) + { + counter++; + } + if (counter == 4) + { + + sql.updateIntelligenceTable(); + break; + } + } + key = _getch(); + value = key; + system("cls"); + room MI; + MI.DrawFrontBorder(); + //PlayerMenu.ppmenu(); + } + + } + else if (selection == 2) + { + cout << "0 - Chatroom." << endl; + cout << "1 - Game Menu." << endl; + cout << "2 - Job Menu." << endl; + cout << "3 - Library Menu" << endl; + cout << "Enter Selection:" << endl; + + /*int menuInput; + + cin >> menuInput; + LibraryMenu::update(menuInput);*/ + } +} diff --git a/librarymenu.h b/librarymenu.h new file mode 100644 index 0000000..fa859be --- /dev/null +++ b/librarymenu.h @@ -0,0 +1,60 @@ +#pragma once +#ifndef LIBRARYMENU_H +#define LIBRARYMENU_H +#include +#include "player.h" +#define KEY_X 120 +#define KEY_SPACE 32 +#include + + +#include "playermenu.h" +#include "room.h" + + +#include "menuoptions.h" +#include "menuclass.h" + +using namespace std; + +class LibraryMenu : public Menu +{ +public: + LibraryMenu(MenuSwitch* myGame) + { + game = myGame; + } + LibraryMenu() + { + + } + void librarymenu(); + + void update(int input) + { + + if (input == 1) + { + game->currentMenu = game->menuOption[input]; + cout << "Menu changed to player menu" << endl; + } + else if (input == 2) + { + game->currentMenu = game->menuOption[input]; + cout << "Menu changed to job menu" << endl; + } + else if (input == 4) + { + game->currentMenu = game->menuOption[input]; + cout << "Menu changed to gym menu" << endl; + } + else if (input == 3) + { + cout << "Menu unchanged - still library menu" << endl; + system("cls"); + librarymenu(); + } + } + +}; +#endif \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..07d48ca --- /dev/null +++ b/main.cpp @@ -0,0 +1,289 @@ +#include +#include +#include +#include +#include "room.h" +//#include "mainmenu.h" +#include "playermenu.h" +#include "jobmenu.h" +#include "librarymenu.h" +#include "player.h" +#include +#include +#include "menuclass.h" +#include "menuoptions.h" +#include "gymmenu.h" + +#include +#include +#include + +using namespace std; + +using std::cout; // slow text +using std::flush; +using std::string; +using std::this_thread::sleep_for; +using std::chrono::milliseconds; + +#pragma comment (lib, "Ws2_32.lib") + +#define DEFAULT_BUFLEN 512 +#define IP_ADDRESS "127.0.0.1" //change this to your IPV4 address +#define DEFAULT_PORT "3504" + +struct client_type +{ + SOCKET socket; + int id; + char received_message[DEFAULT_BUFLEN]; +}; + +void slow_print(const string& message, unsigned int millis_per_char) +{ + + for (const char c : message) + { + + cout << c << flush; + sleep_for(milliseconds(millis_per_char)); + } +} + +int process_client(client_type& new_client) +{ + while (1) + { + memset(new_client.received_message, 0, DEFAULT_BUFLEN); + + if (new_client.socket != 0) + { + int iResult = recv(new_client.socket, new_client.received_message, DEFAULT_BUFLEN, 0); + + if (iResult != SOCKET_ERROR) + cout << new_client.received_message << endl; + + } + } + + if (WSAGetLastError() == WSAECONNRESET) + cout << "The server has disconnected" << endl; + + return 0; +} +int main() +{ + Sql sql; + bool exists = sql.Query(false); + int selection; + cout << "1 - Enter Chat client" << endl; + cout << "2 - Enter Game" << endl; + cin >> selection; + if (selection == 1) + { + + + WSAData wsa_data; + struct addrinfo* result = NULL, * ptr = NULL, hints; + string sent_message = ""; + client_type client = { INVALID_SOCKET, -1, "" }; + int iResult = 0; + string message; + + cout << "Turning the engines on...\n"; + + // Initialize Winsock + iResult = WSAStartup(MAKEWORD(2, 2), &wsa_data); + if (iResult != 0) { + cout << "WSAStartup() failed with error: " << iResult << endl; + return 1; + } + + ZeroMemory(&hints, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + + cout << "Connecting...\n"; + + // Resolve the server address and port + iResult = getaddrinfo(static_cast(IP_ADDRESS), DEFAULT_PORT, &hints, &result); + if (iResult != 0) { + cout << "getaddrinfo() failed with error: " << iResult << endl; + WSACleanup(); + system("pause"); + return 1; + } + + // Attempt to connect to an address until one succeeds + for (ptr = result; ptr != NULL; ptr = ptr->ai_next) { + + // Create a SOCKET for connecting to server + client.socket = socket(ptr->ai_family, ptr->ai_socktype, + ptr->ai_protocol); + if (client.socket == INVALID_SOCKET) { + cout << "socket() failed with error: " << WSAGetLastError() << endl; + WSACleanup(); + system("pause"); + return 1; + } + + // Connect to server. + iResult = connect(client.socket, ptr->ai_addr, (int)ptr->ai_addrlen); + if (iResult == SOCKET_ERROR) { + closesocket(client.socket); + client.socket = INVALID_SOCKET; + continue; + } + break; + } + + freeaddrinfo(result); + + if (client.socket == INVALID_SOCKET) { + cout << "Unable to connect to server!" << endl; + WSACleanup(); + system("pause"); + return 1; + } + + cout << "Successfully Connected" << endl; + + //Obtain id from server for this client; + recv(client.socket, client.received_message, DEFAULT_BUFLEN, 0); + message = client.received_message; + + if (message != "Server is full") + { + client.id = atoi(client.received_message); + + //when i wrap threads in a class it throws an error otherwise outside the class it work :( + + thread threads(process_client, ref(client)); + //thread threads(&client::process_client, ref(client)); + //thread threads(&client::process_client, this, ref(client)); + //thread threads(&client::process_client, this); + + while (1) + { + int warningcounter = 0; + string warning = "Type something please!"; + + getline(cin, sent_message); + iResult = send(client.socket, sent_message.c_str(), strlen(sent_message.c_str()), 0); + + if (iResult <= 0) + { + + //cout << "send() function error ---> " << WSAGetLastError() << endl; + // break; + + // warningcounter++; //warningcounter = warningcounter + 1; + cout << warning << endl; + //cout << warningcounter << endl; + + } + else if (sent_message == "!") + { + cout << "You broke the rule of the server! adios ;)" << endl; + + main(); + } + + } + + //Shutdown the connection since no more data will be sent + threads.detach(); + } + else + cout << client.received_message << endl; + cout << "Shutting down socket..." << endl; + iResult = shutdown(client.socket, SD_SEND); + if (iResult == SOCKET_ERROR) { + cout << "shutdown() function failed ----> " << WSAGetLastError() << endl; + closesocket(client.socket); + WSACleanup(); + system("pause"); + return 1; + } + + closesocket(client.socket); + WSACleanup(); + + system("pause"); + return 1; + + } + + else if (selection == 2) + { + + + + + room MainInterface; + MainInterface.Draw(); + + //int exit; // to prevent console closing + //cin >> exit; + MenuSwitch* game = new MenuSwitch(); // declares a pointer (game) and allocates memory to (size of(MenuSwitch)) + + //MainMenu* mainMenu = new MainMenu(game); + + PlayerMenu* playerMenu = new PlayerMenu(game); + + JobMenu* jobMenu = new JobMenu(game); + + LibraryMenu* libraryMenu = new LibraryMenu(game); + + Gym* gymMenu = new Gym(game); + + game->assignMenu(playerMenu, jobMenu, libraryMenu, gymMenu); + + string message = "\n You have been imprisoned \n You believe you did not do the crimes committed;\n You need to escape the prison to clear your name!\n Tread Carefully. \n There are traps and riddles which need to be avoided and answered to gain an insight on how to escape.\n \n"; + slow_print(message, 10); + + + cout << "1 - Game Menu." << endl; + cout << "2 - Job Menu." << endl; + cout << "3 - Library Menu" << endl; + cout << "4 - Gym Menu" << endl; + cout << "Enter Selection:" << endl; + + int menuInput; + + cin >> menuInput; + + while (true) + { + if (menuInput == 0) + { + system("cls"); + main(); + } + if (menuInput == 1 || menuInput == 2 || menuInput == 3 || menuInput == 4) + { + game->currentMenu->update(menuInput); + } + else + { + cout << "Input 1 - Player Menu, 2 - Job Menu, 3 - Library Menu or 4 - Gym Menu || to change menu, or 0 to return to the main menu." << endl; + } + cin >> menuInput; + + + } + } + //else if (selection == 3) + // { + + // //system("start chatserver.exe"); + // + // system("pause"); + // } + + + + +}; + diff --git a/mainmenu.cpp b/mainmenu.cpp new file mode 100644 index 0000000..2ccc5e4 --- /dev/null +++ b/mainmenu.cpp @@ -0,0 +1,61 @@ +#include "mainmenu.h" + + + +void MainMenu :: mmenu() +{ + PlayerMenu playermenu; + int selection; + + cout << "\n Menu"; + + cout << "\n==================="; + + cout << "\n 0 - Exit Game"; + + cout << "\n 1 - Play Game"; + + cout << "\n 2 - Save and Load game"; + + cout << "\n 3 - Settings"; + + cout << "\n 4 - Go back"; + + + cout << "\n Enter selection: "; + + cin >> selection; + + if (selection == 1) + { + cout << "\n you have been imprisoned and you believe you did not do the crimes committed; You need to escape the prison to clear your name! Tread Carefully. There are traps and riddles which need to be avoided and answered to gain an insight on how to escape."; + } + else if (selection == 2) + { + cout << "\n this is choice 2 "; + } + else if (selection == 3) + { + cout << "\n this is choice 3 "; + } + else if (selection == 0) + { + exit(0); + } + /*else if (selection == 4) + { + cout << "Input 0 to exit the game." << endl; + cout << "Input 1 for Main Menu." << endl; + cout << "Input 2 for Player Menu." << endl; + cout << "Input 3 for Job Menu." << endl; + cout << "Input 4 for Library Menu" << endl; + + int menuInput; + + cin >> menuInput; + MainMenu::update(menuInput); + }*/ + + +}; + diff --git a/mainmenu.h b/mainmenu.h new file mode 100644 index 0000000..d448958 --- /dev/null +++ b/mainmenu.h @@ -0,0 +1,60 @@ +#ifndef MAINMENU_H +#define MAINMENU_H + +#include +#include +//#include +#include "playermenu.h" +#include "menuoptions.h" +#include "librarymenu.h" +#include "menuclass.h" + +using namespace std; + +class MainMenu : public Menu //class name +{ + public: // access specifier + + MainMenu(MenuSwitch* myGame) //paramatised constructor + { + game = myGame; + } + MainMenu() //default constructor + { + + } + void mmenu(); + void print() + { + mmenu(); + } + void update(int input) + { + + if (input == 2) + { + //Line below changes the value stored in currentMenu to the input from the player. + game->currentMenu = game->menuOption[input]; //game = pointer_name, holds value in variable_name. + cout << "Menu changed to player menu" << endl; + + } + else if (input == 3) + { + game->currentMenu = game->menuOption[input]; + cout << "Menu changed to job menu" << endl; + } + else if (input == 4) + { + game->currentMenu = game->menuOption[input]; + cout << "Menu changed to library menu" << endl; + } + else if (input == 1) + { + cout << "Menu unchanged - still main menu" << endl; + mmenu(); + } + } +}; + +#endif + \ No newline at end of file diff --git a/memorygame.cpp b/memorygame.cpp new file mode 100644 index 0000000..41586e8 --- /dev/null +++ b/memorygame.cpp @@ -0,0 +1,34 @@ +#include "memorygame.h" +using namespace std; + + +string sequence; + +int randomsequence() +{ + char full_alpha[27] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; + + cout << "You have 10 seconds to memorise the following list of words!" << endl; + + for (int i = 0; i < 6; i++) + { + string c; + int random_number = rand() % 26; // generate a random number + c = 'a' + random_number; // Convert to a character from a-z + sequence += c; + } + cout << sequence << endl; + return 0; +} + +void memorycheck(string &answer) +{ + if (sequence == answer) + { + cout << "Well done! You have cooked a great meal! 20 pounds has been added to your account." << endl; + } + else if (sequence != answer) + { + cout << "Oh no! You have burnt all the food! This will be deducted from your wages." << endl; + } +} diff --git a/memorygame.h b/memorygame.h new file mode 100644 index 0000000..33dbb96 --- /dev/null +++ b/memorygame.h @@ -0,0 +1,18 @@ +#ifndef MEMORYGAME_H +#define MEMORYGAME_H + +#include +#include +#include +#include "countdown.h" + + +using namespace std; + +int randomsequence(); +void memorycheck(string &answer); + + + +#endif + diff --git a/menu.h b/menu.h new file mode 100644 index 0000000..f341cd1 --- /dev/null +++ b/menu.h @@ -0,0 +1,23 @@ +#ifndef MENU_H +#define MENU_H +#include +#include "menuoptions.h" + +class MainMenu : public Menu +{ +public: + MainMenu(MenuSwitch* myGame) + { + game = myGame; + } + + void update(int input) + { + if (input == 1) + { + game->currentMenu = game->menuOptions[input]; //assigns menu + std::cout << "Menu changed to Player Menu" << std::endl; + } + } +}; +#endif \ No newline at end of file