Hi.
I know it's now rly allowed to post homework and stuff. But i just need some help, like hints, or examples. =]
Don't fully understand how arrays(marked as mass in prog.) work yet. Arrays = massivs (in the countries language where i live)
[ The point is to have the X (character) walk around the playing field, and collect something (stars -> '*' ), that are invisible to the player until he walks over them ]
So what i need some help with is:
1) The x ( the so called character), goes beyond the playing field...
How to make it so, when the next "move" would go onto the filed line, to stop it, and say like "Can't go that way".
2)Need to the make the (*) invisible until he walks over em. And when he gets all of em, the game stops and shows the game is over message.
=========================================
This is what i got so far.
#include <iostream>
#include <iomanip>
using namespace std;
const int height = 18; // tak kak pole 16, a 2 stroki liniji
const int width = 18;
void Gamefield( char mass[][width + 1] );
int main()
{
int k = 0;
char location;
int x = 5; // Na4alo igri
int y = 5;
char mass [ height ][ width + 1 ] = {
"|---------------|",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"|---------------|" };
mass[ x ][ y ] = 'X'; // Player
mass[ 8 ][ 5 ] = '*';
mass[ 2 ][ 14 ] = '*'; //Objects
mass[ 10 ][ 3 ] = '*';
mass[ 15 ][ 15 ] = '*';
mass[ 15 ][ 7 ] = '*';
mass[ 3 ][ 2 ] = '*';
cout << " Welcome to the game!" << endl
<< "Use the W/S/A/D buttons to move! " << endl << endl;
for(int j=1;j>0;j++) {
Gamefield (mass);
cout << "Which side to go? ";
cin >> location;
if (location == 'w') {
mass[ x-1 ][ y ] = 'x';
mass[ x ][ y ] = ' ';
x--;
}
else if (location == 's') {
mass[ x+1 ][ y ] = 'x';
mass[ x ][ y ] = ' ';
x++;
}
else if (location == 'd') {
mass[ x ][ y +1 ] = 'x';
mass[ x ][ y ] = ' ';
y++;
}
else if (location == 'a') {
mass[ x ][ y-1 ] = 'x';
mass[ x ][ y ] = ' ';
y--;
}
else {
cout << endl << endl << "You typed in a wrong direction!"
<< " (W/S/A/D are the direction keys)"
<< endl << "Which direction do you want to go now?: ";
cin >> location;
}
system("CLS"); // Clear screen
}
return 0;
}
void Gamefield( char mass [ height ][ width + 1 ] ){
for (int i=0; i<height; i++){
cout << mass[i] << endl;
}
cout << endl << endl;
}