### Rush Hour Game

Hello, I wanted to create a Rush Hour game in C++ in console application,
but I don't know, from where to start and what to do, any ideas or tactics are greatly appreciated.
What do you mean by Rush Hour?

And I would start by reading the information on this website
Rush Hour is a board game, where there are some cars in a parking lot, in a random position, your goal is to find a path (by moving other cars horizontally or vertically) to exit the parking lot.
For detailed description check the link below: http://en.wikipedia.org/wiki/Rush_Hour_(board_game)

Last edited on
I would start by making a function to draw an empty parking lot. Then make a container (array, vector, whatever) to describe whether or not there is a car in a space. Implement this container in the first function so that the board is always drawn correctly. Then write a function to seed the container with random cars. Figure out a good way to have the user enter a car that he/she wishes to move, and then move that car (while makeing sure the choice of car and direction of moving are valid).

Once the board and user input is done correctly, I would start programming the rules of the game.
Last edited on
Can I use struct in order to draw an empty parking lot? and should I put the container in the the struct? I need help.
Can somebody write a sample to draw an empty parking lot? I am a bit confused..
Thanks for any help.
You could, but probably not needed.

My approach:
 ``1234567891011121314151617181920212223242526272829303132`` ``````#include using namespace std; char spaces[4]; void initSpaces(void) { for (int i = 0; i < 4; i++) { spaces[i] = ' '; } } void drawBoard(void) { cout << '|' << spaces[0] << '|' << spaces[1] << '|' << spaces[2] << '|' << spaces[3] << '|' << endl; } int main(void) { initSpaces(); cout << "Empty Lot\n"; drawSpaces(); spaces[1] = '*'; spaces[2] = '*'; cout << "With some cars\n"; drawSpaces(); return 0; }``````
Last edited on
Thanks Lowestone, it helped me a lot, but there is an issue popped up, if I want to draw a 6x6 matrix-like parking lot and insert some cars in randomly horizontally or vertically, probably I will need some more complicated code, will 2D Array help me in that?
Last edited on
 will 2D Array help me in that?

It might. I don't think I would do that though, but that is because the way I set it up. My parking lot is not drawn in a loop, so I'm typing the actual index of the array every time. Having it be 2d might make that more complicated.

Also, think about the way that you are randomly making cars, 1d array is easy:
 ``1234`` ``````for (int i = 0; i < SIZE_OF_ARRAY; i++) { if (aRandomResultIsTrue()) spaces[i] = '*'; }``````

not as easy with 2d.

It's up you though, somethings are easier, somethings might take some thinking.
Last edited on
Topic archived. No new replies allowed.