Basically, what I am trying to do is a simple text based rpg where the player can select whether he wants to go North, East, South or West.
I would like the grid pattern to look something like this:
0 0 0 0 0
0 0 0 0 0
0 X 0 0 0
0 0 0 0 0
0 0 0 0 0
Where the X marks the players current position. So far, I have been able to get the grid of zeroes to show but, I am not sure how to show the X and then update it after user input.
Thanks you, in advance.
Any help is welcome :)
Also please say if you think I am getting too ahead of myself, this seems like a simple task to set myself. Also, I am currently learning from 'C++ A beginner's guide' by Herbert Schildt. Has anyone hear of it?
have you read about functions yet? I would refactor your code to look something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
usingnamespace std;
staticchar adventuregrid[5][5];
void initGrid() {
// you fill in here
}
void printGrid() {
// you fill in here
}
main() {
initGrid();
adventuregrid[2][1] = 'X'; // place me at 3 rows down, 2 rows to the right
printGrid();
}
when you get more advanced, I recommend that you put adventuregrid and any other important information in a struct or class and pass an instance of that around
I have only touched on simple functions in the second chapter of the book however, later on there is a big chapter on taking these to a more advanced level.
This has answered my question perfectly, it is a great help.
I know that I am trying to do this project a bit early but, I find it best to learn as you go along sort of thing, while referring to this forum or my book when needed. However, after I get this project finished I will read on in the book.
I know I am meant to bring the code but, would you able to quickly be able to write me a short program which displays a grid of circles but, one of the circles is replaced by an 'X' that is placed there by an x and y variable than is determined by the user?
I know this is a lot to ask but, this would help me hugely in understanding how arrays work and it will generally improve my understanding of the whole programming language.
if you fill out Lines 8 and 12 the code above will do exactly what you are asking for!
all you have to do grab x,y from cin if you want the user to enter them.
everything is already there in this thread... ...so if you still cannot figure it out, you need to read more so you can actually understand better what you are doing.