diff --git a/CXXBattleShip.cpp b/CXXBattleShip.cpp new file mode 100644 index 0000000..c03e55a --- /dev/null +++ b/CXXBattleShip.cpp @@ -0,0 +1,138 @@ +#include +#include + +using std::cin; +using std::cout; + +#ifdef WIN32 +#define CLEAR system("cls") +#else +#define CLEAR system("clear") +#endif + +void printmatrix(int matrix[6][6]) +{ + for (int i = 0; i < 6; i++) { + for (int ii = 0; ii < 6; ii++) + cout << matrix[i][ii] << " "; + cout << "\n"; + } +} + +void check(int matrix[6][6], int &j) +{ + for (int i = 0; i < 6; i++) { + for (int ii = 0; ii < 6; ii++) + if (matrix[i][ii] == 0) j++; + } +} + +void getfirecoordinates(int &r, int &c) +{ + do { + cout << "\n\nFire at ROWS: "; + cin >> r; + } while (r < 0 || r > 6); + + do { + cout << "\nFire at COLUMNS: "; + cin >> c; + } while (c < 0 || c > 6); +} + +int main() +{ + int p1[6][6]; + int p2[6][6]; + + int r, c; // Collects coordinates to fire + int j; // Counter used to check for victory + + // Seeds the pseudo RNG with the current time + srand((unsigned int)time(NULL)); +restart: + + CLEAR; + cout << "\n▂▃▄▅▆▇█▓▒░ CXXBattleShip ░▒▓█▇▆▅▄▃▂"; + cout << "\n\nWelcome!"; + cout << "\n\n(1) Start [2P mode]\n\n(2) Credits\n\n(3) Exit...\n"; + cin >> j; + + switch (j) { + case 1: + CLEAR; + break; + case 2: + CLEAR; + cout << "\n▂▃▄▅▆▇█▓▒░ CXXBattleShip ░▒▓█▇▆▅▄▃▂"; + cout << "\n\nDeveloped by: Borededdy\nSome minor help: MGislv"; + cout << "\n\nThank you for playing this!"; + cout << "\nIf you enjoyed it, please star our repo ;)"; + return 0; + default: + return 0; + } + + // Populate 2d arrays + for (int i = 0; i < 6; i++) { + for (int ii = 0; ii < 6; ii++) { + p1[ii][i] = rand() % 2; + p2[ii][i] = rand() % 2; + } + } + + j = 0; + while (1) { + cout << "#-----Player 1-----#\n\n\n"; + printmatrix(p1); + + getfirecoordinates(r, c); + + if (p2[r][c] == 1) { + cout << "\n\nPLAYER 1 > Scored a hit!\n"; + p2[r][c] = 0; + } else { + cout << "\n\nPLAYER 1 > Missed!\n"; + } + sleep(4); + + CLEAR; + check(p2, j); + + if (j == 36) { + cout << "PLAYER 1 > Wins!\n"; + break; + } + j = 0; + + cout << "#-----Player 2-----#\n\n\n"; + printmatrix(p2); + + getfirecoordinates(r, c); + + if (p1[r][c] == 1) { + cout << "\n\nPLAYER 2 > Scored a hit!\n"; + p1[r][c] = 0; + } else { + cout << "\n\nPLAYER 2 > Missed!\n"; + } + sleep(4); + + CLEAR; + check(p1, j); + + if (j == 36) { + cout << "PLAYER 2 > Wins!"; + break; + } + j = 0; + } + + cout << "\n\nWant to restart? [0 = yes]\n"; + cin >> j; + + if (j == 0) + goto restart; + else + return 0; +} diff --git a/Mac OS/CXXBattleShip b/Mac OS/CXXBattleShip deleted file mode 100644 index dc5e058..0000000 Binary files a/Mac OS/CXXBattleShip and /dev/null differ diff --git a/Mac OS/CXXBattleShip.cpp b/Mac OS/CXXBattleShip.cpp deleted file mode 100644 index c2972d0..0000000 --- a/Mac OS/CXXBattleShip.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include -#include -#include -using namespace std; - -//Defining clear shortcut -#define CLEAR system("clear") - -//Player Vars -int p1[4][4]; -int p2[4][4]; - -void action(){ - int r, c; //Collects coordinates to fire - int l = 0; //Counter used to check win - int e = 0; //End Match - while(e < 1){ - cout << "#-----Player 1-----#\n\n\n"; - for(int i = 0; i < 4; i++){ - for(int ii = 0; ii < 4; ii++){ - cout << p1[ii][i] << " "; - } - cout << "\n"; - } - cout << "\n\nFire at ROWS: "; - cin >> r; - cout << "\nFire at COLUMNS: "; - cin >> c; - if (p2[r][c] == 1){ - cout << "\n\nPLAYER 1 > Hit!\n"; - sleep(6); - p2[r][c] = 0; - }else{ - cout << "\n\nPLAYER 1 > Miss!\n"; - sleep(6); - } - cout << CLEAR; - for(int c = 0; c < 4; c++){ - for(int cc = 0; cc < 4; cc++){ - if(p2[cc][c] == 0){ - l++; - } - } - } - if(l == 16){ - cout << "\n\nPLAYER 1 > Wins!\n"; - sleep(6); - exit(0); - } - l = 0; - cout << "#-----Player 2-----#\n\n\n"; - for(int i = 0; i < 4; i++){ - for(int ii = 0; ii < 4; ii++){ - cout << p2[ii][i] << " "; - } - cout << "\n"; - } - cout << "\n\nFire at ROWS: "; - cin >> r; - cout << "\nFire at COLUMNS: "; - cin >> c; - if (p1[r][c] == 1){ - cout << "\n\nPLAYER 2 > Hit!\n"; - sleep(6); - p1[r][c] = 0; - }else{ - cout << "\n\nPLAYER 2 > Miss!\n"; - sleep(6); - } - cout << CLEAR; - for(int c = 0; c < 4; c++){ - for(int cc = 0; cc < 4; cc++){ - if(p1[cc][c] == 0){ - l++; - } - } - } - if(l == 16){ - cout << "\n\nPLAYER 1 > Wins!"; - sleep(6); - exit(0); - } - l = 0; - } -} - -void charging(){ - for(int i = 0; i < 4; i++){ - for(int ii = 0; ii < 4; ii++){ - p1[ii][i] = rand() % 2; - p2[ii][i] = rand() % 2; - } - } -} - -int main(){ - - //Casting of TIME for srand - srand((unsigned int) time(NULL)); - - charging(); - action(); -} diff --git a/Mac OS/macOS.md b/Mac OS/macOS.md deleted file mode 100644 index 8b13789..0000000 --- a/Mac OS/macOS.md +++ /dev/null @@ -1 +0,0 @@ - diff --git a/README.md b/README.md index 4af5cf2..60e6300 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,25 @@ # 🚢 CXXBattleShip -A simple but functional terminal BattleShip game, written in c++ -To Open the game follow the instructions down here or in the wiki. +A simple yet functional terminal BattleShip game, written in C++ +To compile the game follow the instructions. -#### - Linux +You need a C++ compiler, e.g. Clang, GCC, MSVC... -In the terminal type:
-`g++ battleship.cpp`
-make sure that you have installed **Clang** or any **C++ Compilator**
-After that done type:
-`./a.out`
-To launch the executible file. +#### - Unix -#### - MacOS - -In the bash terminal install **command line tools**
-`xcode-select --install`
-Then in the terminal type:
-`g++ battleship.cpp`
-After that done launch the .exec file
-To launch the executible file or just **open that in the folder of the game** +On MacOS you can install **Xcode** from the store or using the terminal: +`xcode-select --install` + +Else use [Homebrew](https://brew.sh/) + +Then compile: +`cpp CXXBattleShip.cpp` +And execute the generated file. #### - Windows -Download the Windows release (this contains more instructions just for windows :/ )
-Go in the game folder and launch the `.exe` file.
-
+Use Mingw/[MSYS2](https://www.msys2.org/) or MSVC + +### Binaries are available in the release section + Enjoy the game :) diff --git a/Source Code/CXXBattleShip.cpp b/Source Code/CXXBattleShip.cpp deleted file mode 100644 index ed3af17..0000000 --- a/Source Code/CXXBattleShip.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include -#include -#include -using namespace std; - -//Defining clear shortcut -#define CLEAR system("clear") - -//Player Vars -int p1[4][4]; -int p2[4][4]; - -int action(){ - int r, c; //Collects coordinates to fire - int l = 0; //Counter used to check win - int e = 0; //End Match - while(e < 1){ - cout << "#-----Player 1-----#\n\n\n"; - for(int i = 0; i < 4; i++){ - for(int ii = 0; ii < 4; ii++){ - cout << p1[ii][i] << " "; - } - cout << "\n"; - } - cout << "\n\nFire at ROWS: "; - cin >> r; - cout << "\nFire at COLUMNS: "; - cin >> c; - if (p2[r][c] == 1){ - cout << "\n\nPLAYER 1 > Hit!\n"; - sleep(6); - p2[r][c] = 0; - }else{ - cout << "\n\nPLAYER 1 > Miss!\n"; - sleep(6); - } - cout << CLEAR; - for(int c = 0; c < 4; c++){ - for(int cc = 0; cc < 4; cc++){ - if(p2[cc][c] == 0){ - l++; - } - } - } - if(l == 16){ - cout << "\n\nPLAYER 1 > Wins!\n"; - sleep(6); - exit(0); - } - l = 0; - cout << "#-----Player 2-----#\n\n\n"; - for(int i = 0; i < 4; i++){ - for(int ii = 0; ii < 4; ii++){ - cout << p2[ii][i] << " "; - } - cout << "\n"; - } - cout << "\n\nFire at ROWS: "; - cin >> r; - cout << "\nFire at COLUMNS: "; - cin >> c; - if (p1[r][c] == 1){ - cout << "\n\nPLAYER 2 > Hit!\n"; - sleep(6); - p1[r][c] = 0; - }else{ - cout << "\n\nPLAYER 2 > Miss!\n"; - sleep(6); - } - cout << CLEAR; - for(int c = 0; c < 4; c++){ - for(int cc = 0; cc < 4; cc++){ - if(p1[cc][c] == 0){ - l++; - } - } - } - if(l == 16){ - cout << "\n\nPLAYER 1 > Wins!"; - sleep(6); - exit(0); - } - l = 0; - } -} - -void charging(){ - for(int i = 0; i < 4; i++){ - for(int ii = 0; ii < 4; ii++){ - p1[ii][i] = rand() % 2; - p2[ii][i] = rand() % 2; - } - } -} - -int main(){ - - //Casting of TIME for srand - srand((unsigned int) time(NULL)); - - charging(); - action(); -} diff --git a/Windows/CXXBattleShipWIN.cpp b/Windows/CXXBattleShipWIN.cpp deleted file mode 100644 index 7212282..0000000 --- a/Windows/CXXBattleShipWIN.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include -#include -#include -using namespace std; - -//Defining clear shortcut -#define CLEAR system("CLS") - -//Player Vars -int p1[4][4]; -int p2[4][4]; - -int action(){ - int r, c; //Collects coordinates to fire - int l = 0; //Counter used to check win - int e = 0; //End Match - while(e < 1){ - cout << "#-----Player 1-----#\n\n\n"; - for(int i = 0; i < 4; i++){ - for(int ii = 0; ii < 4; ii++){ - cout << p1[ii][i] << " "; - } - cout << "\n"; - } - cout << "\n\nFire at ROWS: "; - cin >> r; - cout << "\nFire at COLUMNS: "; - cin >> c; - if (p2[r][c] == 1){ - cout << "\n\nPLAYER 1 > Hit!\n"; - sleep(6); - p2[r][c] = 0; - }else{ - cout << "\n\nPLAYER 1 > Miss!\n"; - sleep(6); - } - cout << CLEAR; - for(int c = 0; c < 4; c++){ - for(int cc = 0; cc < 4; cc++){ - if(p2[cc][c] == 0){ - l++; - } - } - } - if(l == 16){ - cout << "\n\nPLAYER 1 > Wins!\n"; - sleep(6); - exit(0); - } - l = 0; - cout << "#-----Player 2-----#\n\n\n"; - for(int i = 0; i < 4; i++){ - for(int ii = 0; ii < 4; ii++){ - cout << p2[ii][i] << " "; - } - cout << "\n"; - } - cout << "\n\nFire at ROWS: "; - cin >> r; - cout << "\nFire at COLUMNS: "; - cin >> c; - if (p1[r][c] == 1){ - cout << "\n\nPLAYER 2 > Hit!\n"; - sleep(6); - p1[r][c] = 0; - }else{ - cout << "\n\nPLAYER 2 > Miss!\n"; - sleep(6); - } - cout << CLEAR; - for(int c = 0; c < 4; c++){ - for(int cc = 0; cc < 4; cc++){ - if(p1[cc][c] == 0){ - l++; - } - } - } - if(l == 16){ - cout << "\n\nPLAYER 1 > Wins!"; - sleep(6); - exit(0); - } - l = 0; - } -} - -void charging(){ - for(int i = 0; i < 4; i++){ - for(int ii = 0; ii < 4; ii++){ - p1[ii][i] = rand() % 2; - p2[ii][i] = rand() % 2; - } - } -} - -int main(){ - - //Casting of TIME for srand - srand((unsigned int) time(NULL)); - - charging(); - action(); -} diff --git a/Windows/CXXBattleShipWIN.exe b/Windows/CXXBattleShipWIN.exe deleted file mode 100644 index 5e793b4..0000000 Binary files a/Windows/CXXBattleShipWIN.exe and /dev/null differ