1. ## Dynamic 2D Array.

Hello world. I am new at programming. I have started programming at C(in Ubuntu) just when I entered univercity last October. It is hard but I like it. But I have a project where I need to make a, basically a game. The game must be played in the terminal. I have 9 days to complete it and send it. I cannot think of anything else. The game has a board(the board must be at the terminal and must be created and filled dynamically as a 2d array)either a square or a rectangular. The dimencions must be between a certain min N*M(maybe a 3*5) and a max N*M(maybe a 10*15). The main hero is a stingy knight(must be shown as \$) and doesn't want to lose much money(which also must be shown at the end how much he lost). He fights enemies(must be shown 1,2,3 depending on how many hits they need till death). In the board there must be, also, some obstacles(must be shown as #). The pathes from where the knight can move must be shown as (. a dot). When the knight kills all the enemies the game updates and the board gets bigger by 1 in both dimencions and if one of the dimencions is at max then it changes only the other. The game ends when the player wins the max N*M board. The player must in the start give to the programme the starting N*M dimencions which the game must start from.

The game has three difficulty levels.
Easy: where both the enemies and the obstacles take a 5% of the N*Mof each level

Medium: where obstacles take a 5% and enemies take 10%.

Hard: where enemies and obstacles take 10%.

The obstacles can be in differenr positions but each enemy must be next to at least one other enemy (up, down, left, right and NOT diagonal).This must be done with a rand().

To show the board each line and each column must have above and in the left the number of each line and column.

To move the knight the user must give (U/u, D/d, L/l, R/r)and a number(1-9). For example, U7 d4 L3 r2. If the programme finds out that there is an obstacle or an enemy it asks again for moving. That costs 5.

Punch.
Punch costs 50. To do a punch the user writes (F or f) and removes 1 health point from the enemy next to the knight. After that if behind the enemy there is nothing it moves one position behind. If not enemy doesn't move.

Chop with an axe.
That costs 70. To do that the user must write (A or a). That removes 1 health point from the enemy next to the knight and also the on behind that enemy. If chop is done correctly and hit the enemies they go back one block back if no obstacles or other enemy is behind. Also, if the second enemy dies and the one next to the knight doesn't that enemy goes back where the dead enemy was.

Slash.
That costs 80. To do that the user must write (S or s). That removes 1 health point from the 3 enemies who are in front of the knight(Up,down,left,right).If there is an obstacle or an enemy behind them then they don't go back else they do.

Bow Attack.
That costs 60. To do that the user must write (B or b). That removes 1 health point from an enemy who is one block far from the knight. If there is an obstacle or an enemy behind the enemy does NOT go back else they do.

If the attacks does not hit an enemy then the cost is 0.

To end the game the player must write (X or x).

Also, the knight can move from the one end of the board to the other.

If the player gives different letters the program must ask again.

Here are one example.

1 2 3 4 5 6 7 8 91011
------------------------------
1 | . #. . . 1 3 . # . .
2 | . . . . 2 2 1 . . . .
3 | . . . . . . 3 . . . .
4 | # . . . . . . . . . .
5 | . . . . . . . . . . .
6 | . . . . . . . . . . .
7 | . . . . . . . . . . .
8 | . . . . . \$ . . . . .
9 | . . . . . . . . . . .
10| # . . . . . . . . . .
 stingy
 stingy

Level money spent: 25
Game money spent: 300

Thanks for the help.

2. I need help. This is very difficult.

3. > The dimencions must be between a certain min N*M(maybe a 3*5) and a max N*M(maybe a 10*15).
So start with 10x15 as a fixed sized array, then get everything else working.

You can still choose any size up to those limits, and all you're wasting is a bit of memory.

Changing it to be dynamic later on is pretty easy.

4. Thanks. But I have another question, also. In the array how can I put the enemies and the obstacles there?

Code:
```char board[5][5] = {
"..1..",
".#...",
".....",
"...\$.",
".....",
};```
You can test ALL of this without changing anything about the board.
To move the knight the user must give (U/u, D/d, L/l, R/r)and a number(1-9). For example, U7 d4 L3 r2. If the programme finds out that there is an obstacle or an enemy it asks again for moving. That costs 5.

Punch.
Punch costs 50. To do a punch the user writes (F or f) and removes 1 health point from the enemy next to the knight. After that if behind the enemy there is nothing it moves one position behind. If not enemy doesn't move.

Chop with an axe.
That costs 70. To do that the user must write (A or a). That removes 1 health point from the enemy next to the knight and also the on behind that enemy. If chop is done correctly and hit the enemies they go back one block back if no obstacles or other enemy is behind. Also, if the second enemy dies and the one next to the knight doesn't that enemy goes back where the dead enemy was.

Slash.
That costs 80. To do that the user must write (S or s). That removes 1 health point from the 3 enemies who are in front of the knight(Up,down,left,right).If there is an obstacle or an enemy behind them then they don't go back else they do.

Bow Attack.
That costs 60. To do that the user must write (B or b). That removes 1 health point from an enemy who is one block far from the knight. If there is an obstacle or an enemy behind the enemy does NOT go back else they do.

If the attacks does not hit an enemy then the cost is 0.

To end the game the player must write (X or x).

6. But how can I use the rand() to fill the board with the enemies, the obstacles and the knight?

7. > But how can I use the rand() to fill the board with the enemies, the obstacles and the knight?
Why do you even care about that at the moment, when you can't even work with a fixed map?
A development process

Stop trying to eat the entire elephant in one meal.

You need to split the problem into sub-tasks.

If you can make everything work with the fixed map I posted, you'll be in pretty good shape for then adding
- randomised positions
- expanding maps

But until then, they're distractions you need to ignore.

8. Can you give me a guideline and some tips(especially if that are in a piece of programme) so I can make it good?

9. Well you don't write code just by picking up your assignment and start typing.

A key skill (which you just haven't recognised you need) is to be able to look at a long list of requirements (like the ones you posted) and break that down into a series of smaller steps.

> I have 9 days to complete it
It's better than showing up with only 3 hours to go, hoping for miracles.

How about these activities per day
1 Lots of paper, research, making notes about the things you need
2 Basic map, knight can move around anywhere
3 knight recognises obstacles and enemies (you just print "there is a ? here")
4 Implement punch and chop
5 Implement slash and bow
6 Add the scoring and costs
7 Add easy/med/hard random positioning of enemies and obstacles
8 Add increasingly large play areas until max NxM is reached.
9 Polish user interface and submit

10. How can I print the static array you made before?

11. Just found out. No need to do it.

12. You should start by learning what loops can do.