-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew.cpp
More file actions
87 lines (54 loc) · 1.38 KB
/
new.cpp
File metadata and controls
87 lines (54 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <cstdlib> // rand, srand
#include <ctime> // time
#include <iostream>
//A=player
//*=empty space
#include <random>
#include <random>
int randomValueForEnemy(int size)
{
static std::mt19937 generator{ std::random_device{}() };
std::uniform_int_distribution<int> distribution(0, size - 1);
return distribution(generator);
}
int arrPinter(char arr[]) {
for (int i = 0; i < 5; i++)
{
std::cout << arr[i] << " ";
}
std::cout << '\n';
return 0;
}
int userMainInput() {
int wantToPlay{1}; // all are empty rn
int enemyPosition{ randomValueForEnemy(5)};
while (wantToPlay == 1 ) {
char enemyArr[5]{ '*','*','*','*','*' };
std::cout << "\033[32m" << enemyPosition<<'\n';
int won{};
while (won==0) {
enemyArr[enemyPosition] = 'A';
std::cout << "Enter Which Place To Shoot (0-4)-";
int userPossitionToShoot{};
std::cin >> userPossitionToShoot;
if (userPossitionToShoot==enemyPosition)
{
std::cout << "You Won\n";
std::cout << "Your Enemy Possition In The Arr - ";
arrPinter(enemyArr);
won = 1;
}else if (userPossitionToShoot!=enemyPosition) {
std::cout << "Try Again!";
}
else
{
std::clog << "Some Thing Went Wrong!!!!!";
break;
}
}
std::cout << "Want To Play More ? (Yes-1 / No-0) -";
enemyPosition = randomValueForEnemy(5);
std::cin >> wantToPlay;
}
return 0;
}