Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
11/29
//clang 6.0.0 #include <iostream> #include <ctime> #include <vector> #include <string> using namespace std; //int easyBoard() const int eRows = 5; const int eElements = 5; int EasyMatrix[eRows][eElements]; int eShips = 4; void eClear() { for (int i = 0; i < eRows; i++) { for (int j = 0; j < eElements; j++) { EasyMatrix[i][j] = 0; } } } int eNumber() { int c = 0; for (int i = 0; i < eRows; i++) { for (int j = 0; j < eElements; j++) { if (EasyMatrix[i][j] == 1) c++; } } return c; } void eSetShips() { int eS = 0; while (eS < eShips) { int x = rand() % eRows; int y = rand() % eElements; if (EasyMatrix[x][y] != 1) { eS++; EasyMatrix[x][y] = 1; } } } bool Attack(int x,int y) { if(EasyMatrix[x][y] == 1) { EasyMatrix[x][y] = 2; return true; } return false; } int eMain() { srand(time(NULL)); eClear(); eSetShips(); int pos1,pos2; while(1) { cout << "Please input target location: "; cin >> pos1 >> pos2; if(Attack(pos1,pos2)) cout << "It's a Hit! Shoot Again!" << endl; else cout << "You Missed! Try Again!" << endl; cout << "Number of ships left: " << eNumber() << endl << endl; } cout << "Game over!" << endl; system("pause"); } int main() { cout << "Hello, what is your name?" << endl; string userName; cin >> userName; cout << userName << ", choose the Difficulty: " << endl << "Easy, Medium, or Hard" << endl; string gameDifficulty; cin >> gameDifficulty; if ((gameDifficulty == "Easy")||(gameDifficulty == "easy")) { cout << "easy" << "\n"; } if ((gameDifficulty == "Medium")||(gameDifficulty == "medium")) { cout << "medium" << "\n"; } if ((gameDifficulty == "Hard")||(gameDifficulty == "hard")) { cout << "hard" << "\n"; } return 0; }
run
|
edit
|
history
|
help
0
Magic, why 1 2?
Thread-safe Interval Average Calculator
C++ standard
Mock Interview Question
illegal instruction (SIGILL)
constructor-is-not-called-in-this-aggregation-class
Graphs Iteration 2.1 Directed Graphs
void pointer
Move Construction
ljblblljkl