Need help with direction and shooting

Ive created a little program that the '@' symbol represents the user the other is the CPU, im trying to get the warrior to have direction but i dont know how i would do such a struct, also im trying to get him to shoot. Please HELP

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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctime>
#include "color.h"


using namespace std;
using namespace Petter;

struct pos
{
    int x;
    int y;
};
struct warrior
{
    char symbol;
    int health;
    int ammo;
    int hunger;
    int weapon;
    int kills;
    int deaths;
    pos position;

    void initwarrior ()
    {
        symbol = '@';
        health = 20;
        hunger = 10;
        ammo = 15;
        weapon = 1;
        kills = 0;
        deaths = 0;
        position.x = 5;
        position.y = 8;

    }

};
struct poss
{
    int x;
    int y;
};
struct zombie
{
    int symboll;
    int healthh;
    int ammoo;
    int weaponn;
    poss positionn;

    void initZombie ()
    {
        symboll = 194;
        healthh = 10;
        ammoo = 15;
        weaponn = 2;
    }

};

const int COL = 17;
const int COL2 = 19;
void menu (int);
void initBoard(char[][COL], int, int);
void showBoard(char[][COL], int, int);
void instructions();
void checkChoice (int);
void zombiePos (char[][COL], zombie, warrior, int, int);
void scoreBoard(warrior, int, int);
void moveWarrior(warrior&, char[][COL], char, int, int, int, int&);
void userInput(int& choice);
void checkInput(int choice);
void initVect(char vect[][COL2], int rowSize, int colSize);
void showVect(char vect[][COL2], int rowSize, int colSize);


int main()
{
    int opt;
    int counterr = 0;
    const char SYMBOL = '@';
    const int MAX_HEALTH = 20;
    const int MIN_HEALTH = 0;
    const int HUNGER = 10;
    const int AMMO = 15;
    const int ROW = 17;
    const int ROW2 = 19;
    const int MAX_MOVES = 10;
    char board[ROW][COL];
    char overlay[ROW2][COL2];
    char movement;

    userInput(opt);
    switch (opt)
    {
        case 1:
            cout << GREEN   << "EASY MODE\n" << endl;
                zombie dead;
                dead.initZombie();
                warrior ninja;
                ninja.initwarrior();
                initBoard(board, ROW, COL);
                zombiePos (board, dead, ninja, ROW, COL);
                board[ninja.position.x][ninja.position.y] = ninja.symbol;
                movement = ' ';

                while(opt == 1 && movement != 'q')
                {
                instructions();
                showBoard(board, ROW, COL);
                scoreBoard(ninja, counterr, MAX_MOVES);
                cout << "Move your warrior" << endl;
                cin >> movement;
                    if(movement != 'q')
                    {
                     moveWarrior(ninja, board, movement, ROW, COL, MAX_MOVES, counterr);
                    }
                    else
                    {
                     cout << "You Quit." << endl;
                    }
                }
                break;

        case 2:
            {
                cout << "Maybe Next Time.";
            }

    }





    return 0;
}


void userInput(int& choice)
{
        cout << RED << "\t\tWelcome to Zombie Hunter\n"
             << "Please choose an option from the menu\n\n"
             << endl;
        cout << BLUE << "1.  Easy Mode\n"
             << "2.  Quit\n"
             << "Enter your choice by its numeric value: ";
         cin >> choice;
}

void initBoard(char arrays[][COL], int rowSize, int colSize)
{
    for(int row = 0; row < rowSize; row++)
    {
        for(int col = 0; col < colSize; col++)
        {
            arrays[row][col] = 250;
        }
    }
    for(int col = 0; col < colSize; col++)
    {
        arrays[0][col] = 205;
        arrays[rowSize-1][col] = 205;
    }
    for(int row =0; row < rowSize; row++)
    {
        arrays[row][0] = 186;
        arrays[row][colSize-1] = 186;
    }
    arrays[0][0] = 201;
    arrays[0][colSize-1] = 187;
    arrays[rowSize-1][0] = 200;
    arrays[rowSize-1][colSize-1] = 188;
}

void showBoard(char arrays[][COL], int rowSize, int colSize)
{
    cout << WHITE << endl;
    for(int row = 0; row < rowSize; row++)
    {
        for(int col = 0; col < colSize; col++)
        {
            cout << arrays[row][col];
        }
        cout << endl;
    }
}

void moveWarrior(warrior& nin, char arrays[][COL], char moves, int row, int col, int maxMoves, int& counter)
{
    if(counter < maxMoves)
    {

        if(moves == 's' && nin.position.x < row-2)
        {
            arrays[nin.position.x][nin.position.y] = 250;
            nin.position.x += 1;
            arrays[nin.position.x][nin.position.y] = nin.symbol;
            system("cls");
            counter++;
        }
        else if(moves == 'a' && nin.position.y > 1)
        {

            arrays[nin.position.x][nin.position.y] = 250;
            nin.position.y -= 1;
            arrays[nin.position.x][nin.position.y] = nin.symbol;
            system("cls");
            counter++;

        }
        else if(moves == 'd' && nin.position.y < col-2)
        {
            arrays[nin.position.x][nin.position.y] = 250;
            nin.position.y += 1;
            arrays[nin.position.x][nin.position.y] = nin.symbol;
            system("cls");
            counter++;

        }
        else if(moves == 'w' && nin.position.x > 1)
        {
            arrays[nin.position.x][nin.position.y] = 250;
            nin.position.x -= 1;
            arrays[nin.position.x][nin.position.y] = nin.symbol;
            system("cls");
            counter++;
        }
        else if (moves == 'q')
        {
        cout << "You Quit." << endl;
        }
        else if (counter == maxMoves)
        {
            cout << "You've Maxed Out" << endl;
            moves == 'q';
            system("pause");
        }
    }
}

void instructions()
{
     cout << YELLOW  << "Movement:\n"
               << "\t\tw = UP"
               << "\t\ta = LEFT\n"
               << "\t\ts = DOWN"
               << "\t\td = RIGHT\n"
               << "\t\tq = QUIT\n"
               << "\tYour Warrior is the @ symbol. There's a zombie invasion.\n"
               << "\tGood Luck." << endl;
}

void scoreBoard(warrior nin, int counter, int maxMoves)
{
    cout << RED << endl;
    cout << "Kills: " << nin.kills << endl;
    cout << "Deaths: " << nin.deaths << endl;
    cout << "Weapon: " << nin.weapon << endl;
    cout << "Ammo: " << nin.ammo << endl;
    cout << "Health: " << nin.health << endl;
    cout << "Moves: " << counter << "/" << maxMoves << endl;
    cout << WHITE << endl;

}

void zombiePos (char arrays[][COL], zombie z, warrior w, int row, int col)
{
    srand(time(0));
    z.positionn.x = rand() % 15 + 1;
    z.positionn.y = rand() % 15 + 1;

    while(z.positionn.x == w.position.x && z.positionn.y == w.position.y && z.positionn.x > row-2 && z.positionn.y < 1 && z.positionn.y > col-2 && z.positionn.x < 1)
    {
        z.positionn.x = rand() % 15 + 1;
        z.positionn.y = rand() % 15 + 1;
    }

    arrays[z.positionn.x][z.positionn.y] = z.symboll;

}

void initVect(char vect[][COL2], int rowSize, int colSize)
{
    for(int row = 0; row < rowSize; row++)
    {
        for(int col = 0; col < colSize; col++)
        {
            vect[row][col] = ' ';
        }
    }
}

void showVect(char vect[][COL2], int rowSize, int colSize)
{
    cout << WHITE << endl;
    for(int row = 0; row < rowSize; row++)
    {
        for(int col = 0; col < colSize; col++)
        {
            cout << vect[row][col];
        }
        cout << endl;
    }
}
Topic archived. No new replies allowed.