HELP- Array char rotation and arrow key usage

Hi im doing a project for a class which involves making a game where there is an arrray that holds a player (you) and a zombie (comp). The player is suppose to be able to turn clockwise or counter clockwise, move forward, and backward and shoot. Im having trouble trying to rotate the char in an array please help. I am also trying to switch from using the W,S,D,A to the arrow keys but doesnt seem to work. Thanks.

#include <iostream>
#include <windows.h>
#include "color.h"

using namespace std;
using namespace Petter;

const int COL = 15;
void initBoard(char[][COL], int, int);
void showBoard(char[][COL], int, int);
struct pos
{
int x;
int y;
};
struct warrior
{
char symbol;
//char direction;
int health;
int hunger;
int ammo;
int weapon;
int kills;
int deaths;
pos position;

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

}

};

void moveWarrior(warrior&, char[][COL], char);
void menu (int);


int main()
{
int opt;
const int ROW = 15;
char board[ROW][COL];
char movement;
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\n"
<< "Enter your choice by its numeric value: ";
cin >> opt;

switch (opt)
{
case 1:
cout << GREEN << "EASY MODE\n\n" << endl;
warrior ninja;
ninja.initwarrior();
initBoard(board, ROW, COL);
board[ninja.position.x][ninja.position.y] = ninja.symbol;
while(movement != 'q')
{
cout << YELLOW << "Movement:\n"
<< "\t\tw = UP\n"
<< "\t\ta = LEFT\n"
<< "\t\ts = DOWN\n"
<< "\t\td = RIGHT\n"
<< "\t\tq = QUIT\n"
<< "\tYour Warrior is the @ symbol. There's a zombie invasion.\n"
<< "\tGood Luck." << endl;
cout << WHITE << endl;
showBoard(board, ROW, COL);
cout << "move your warrior" << endl;
cin >> movement;
moveWarrior(ninja, board, movement);
}
break;

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

}





return 0;
}



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

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

void moveWarrior(warrior& nin, char arrays[][COL], char moves)
{
if(moves == GetAsyncKeyState(VK_DOWN))
{
arrays[nin.position.x][nin.position.y] = 250;
nin.position.x += 1;
arrays[nin.position.x][nin.position.y] = nin.symbol;
system("pause");
system("cls");
}
else if(moves == GetAsyncKeyState(VK_LEFT))
{
arrays[nin.position.x][nin.position.y] = 250;
nin.position.y -= 1;
arrays[nin.position.x][nin.position.y] = nin.symbol;
system("pause");
system("cls");
}
else if(moves == GetAsyncKeyState(VK_RIGHT))
{
arrays[nin.position.x][nin.position.y] = 250;
nin.position.y += 1;
arrays[nin.position.x][nin.position.y] = nin.symbol;
system("pause");
system("cls");
}
else if(moves == GetAsyncKeyState(VK_UP))
{
arrays[nin.position.x][nin.position.y] = 250;
nin.position.x -= 1;
arrays[nin.position.x][nin.position.y] = nin.symbol;
system("pause");
system("cls");
}
else if(moves == 'q')
{
cout << "\n\t\tYOU ARE A QUITTER!" << endl;
}
else
{
cout << "You've entered the wrong input" << endl;
}
}
Use
[code][/code]
tags.
Explain?
As your code is shown now, it is unreadable because the indentation was not preserved. If you put before your code and after it with reasonable indentation, it can read.
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
#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
{
    bool North;
    bool East;
    bool South;
    bool West;

    char symbol;
    int health;
    int ammo;
    int hunger;
    int weapon;
    int kills;
    int deaths;
    pos position;

    void initwarrior ()
    {
        bool North = true;
        bool East = false;
        bool South = false;
        bool West = false;
        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 = 15;
void moveWarrior(warrior&, char[][COL], char, int, int, int&, int);
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);

int Gamespeed = 100;

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

    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 >> opt;

    checkChoice (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;
            while(movement != 'q')
            {
                instructions();
                showBoard(board, ROW, COL);
                scoreBoard(ninja, counterr, MAX_MOVES);
                cout << "Move your warrior" << endl;
                cin >> movement;
                moveWarrior(ninja, board, movement, ROW, COL, counterr, MAX_MOVES);

            }
            break;

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

    }





    return 0;
}



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

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

void moveWarrior(warrior& nin, char arrays[][COL], char moves, int row, int col, int& counter, int maxMoves)
{
   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;
             counter++;
            system("cls");

        }
        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;
             counter++;
            system("cls");
        }
        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;
            counter++;
            system("cls");

        }
        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;
             counter++;
            system("cls");
        }
    }
    else if(moves == 'q')
    {
            cout << "\n\t\tYOU ARE A QUITTER!" << endl;
            system("cls");
    }
    else
    {
            cout << "You've entered the wrong input" << endl;
            system("cls");
    }
    if(counter == maxMoves)
        cout << "You have used up all your moves!\n";
}

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

void checkChoice (int choice)
{
    if(choice != 1 || choice != 2)
        cout << "\nYou do not meet the minumal requirements\nto play this game. IQ > 20\n";
}

void scoreBoard(warrior nin, int counter, int maxMoves)
{
    cout << "Kills: " << nin.kills << endl;
    cout << "Deaths: " << nin.deaths << endl;
    cout << "Ammo: " << nin.ammo << endl;
    cout << "Health: " << nin.health << endl;
    cout << "Moves: " << counter << "/" << maxMoves << 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;

}
[code]
[/code]
sorry about that I thought it had done it. I need to give my warrior -ninja- direction so that he can shoot. please help
Topic archived. No new replies allowed.