Correct my Code, please

Hello,

I have been learning Perl, C++ and Python for the last 5 months and I think I am learning very well. I searched for some online-exercises and tried myself on a Dungeoncrawler Program.

Can you look through my code and find common mistakes and bad coding-behaviour and other things in general I should try to change, like notation, placement and so on?

(Also I know I should stick to one language but it works pretty well for now)

I uploaded my code on codepad.co for a better view! (tell me if it isn't allowed, thanks!)

https://codepad.co/snippet/xS4rz8DO
Last edited on
I'm not sure why you have the trapPOS and enemyPos arrays. Why not just place the traps and enemies on the board as you create them. The code would be a lot easier:
1
2
3
4
5
6
7
8
9
10
    // Create POS for Traps
    for (i = 0; i <= TRAPS; i++) {
        // Keep picking locations until you find an empty one
        int x, y;
        do {
            x = distRows(mt);
            y = distCols(mt);
        } while (board[x][y] != boarddot);
        board[x][y] = trap;
    }


After each move, you refill the entire board. Why not just move the player from the previous position to the next?

gameWon() and gameOver() need to always return something.
The code for each move is nearly identical. See if you can factor out most of it.

Consider putting all data and methods into a class Game or class Board. If you do this, then it becomes much easier to do things like having the computer play because you can create new boards, move on them, and see what happens.
Topic archived. No new replies allowed.