Ok, I'm getting crazy.

Aug 2, 2010 at 7:01pm
I've tried everything I could think off, yet my problem stays.
I'm trying to make Dungeon Crawl (beginner exercise) and I think I'm almost done, but for some reason, when I make my first move, the program exits.

This is my code...And I know it's long, sorry :(

Main:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <cstdlib>
#include "TekenBord.h"
#include "Check_Move.h"
#include "Fout_Move.h"

using namespace std;

int main()
{
    int a = 1;
    int b = 1;
    int x = 1;
    int o = 1;

    char bord[7][9];

    while(x == 1)
    {
    system("CLS");
    TekenBord(bord, a, b, o);
    Check_Move(a, b);
    Fout_Move(a, b, x);
    }

    if (x == 2)
    cout<<"GAME OVER";

    if (x == 3)
    cout<<"You Won!";
}



Tekenbord.cpp:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include "TekenBord.h"
using namespace std;


char TekenBord(char bord[][9], int a, int b, int o)
{


        while ( o == 1)
        {
            for (int z = 0 ;z != 8 ; z++ )
            {
            for (int y = 0 ;y != 10 ;y++ )
            bord[z][y] = '.';
            }
            o = 2;
        }

    bord[6][7] = 'O';
    bord[4][4] = 'O';
    bord[5][7] = 'O';
    bord[7][9] = 'X';
    bord[a][b] = 'Y';

    cout<<bord[1][1]<<bord[1][2]<<bord[1][3]<<bord[1][4]<<bord[1][5]<<bord[1][6]<<bord[1][7]<<bord[1][8]<<bord[1][9]<<"\n";
    cout<<bord[2][1]<<bord[2][2]<<bord[2][3]<<bord[2][4]<<bord[2][5]<<bord[2][6]<<bord[2][7]<<bord[2][8]<<bord[2][9]<<"\n";
    cout<<bord[3][1]<<bord[3][2]<<bord[3][3]<<bord[3][4]<<bord[3][5]<<bord[3][6]<<bord[3][7]<<bord[3][8]<<bord[3][9]<<"\n";
    cout<<bord[4][1]<<bord[4][2]<<bord[4][3]<<bord[4][4]<<bord[4][5]<<bord[4][6]<<bord[4][7]<<bord[4][8]<<bord[4][9]<<"\n";
    cout<<bord[5][1]<<bord[5][2]<<bord[5][3]<<bord[5][4]<<bord[5][5]<<bord[5][6]<<bord[5][7]<<bord[5][8]<<bord[5][9]<<"\n";
    cout<<bord[6][1]<<bord[6][2]<<bord[6][3]<<bord[6][4]<<bord[6][5]<<bord[6][6]<<bord[6][7]<<bord[6][8]<<bord[6][9]<<"\n";
    cout<<bord[7][1]<<bord[7][2]<<bord[7][3]<<bord[7][4]<<bord[7][5]<<bord[7][6]<<bord[7][7]<<bord[7][8]<<bord[7][9]<<"\n";

    return a;
    return b;

}


Check_Move.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <cstdlib>

using namespace std;

int Check_Move(int a, int b)
{
int richting;

cin>>richting;

if (richting == 1)
b = b-1;
if (richting == 3)
b++;
if (richting == 2)
a++;
if (richting == 5)
a = a-1;

return a;
return b;
}


Fout_Move.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <cstdlib>

using namespace std;

int Fout_Move(int a, int b, int x)
{
        if (a == 6 && b == 7)
    {
        x = 2;
    }
        else if (a == 4 && b == 4)
    {
        x = 2;
    }
        else if (a == 5 && b == 7)
    {
        x = 2;
    }
        else if (a == 7 && b == 9)
    {
        x = 3;
    }

    return x;
}


I'd really appreciate help :(
Aug 2, 2010 at 8:39pm
overal in je code zie ik dat je bord[7][...] en bord[...][9] gebruikt

bijv:
1
2
3
4
5
6
7
    cout<<bord[1][1]<<bord[1][2]<<bord[1][3]<<bord[1][4]<<bord[1][5]<<bord[1][6]<<bord[1][7]<<bord[1][8]<<bord[1][9]<<"\n";
    cout<<bord[2][1]<<bord[2][2]<<bord[2][3]<<bord[2][4]<<bord[2][5]<<bord[2][6]<<bord[2][7]<<bord[2][8]<<bord[2][9]<<"\n";
    cout<<bord[3][1]<<bord[3][2]<<bord[3][3]<<bord[3][4]<<bord[3][5]<<bord[3][6]<<bord[3][7]<<bord[3][8]<<bord[3][9]<<"\n";
    cout<<bord[4][1]<<bord[4][2]<<bord[4][3]<<bord[4][4]<<bord[4][5]<<bord[4][6]<<bord[4][7]<<bord[4][8]<<bord[4][9]<<"\n";
    cout<<bord[5][1]<<bord[5][2]<<bord[5][3]<<bord[5][4]<<bord[5][5]<<bord[5][6]<<bord[5][7]<<bord[5][8]<<bord[5][9]<<"\n";
    cout<<bord[6][1]<<bord[6][2]<<bord[6][3]<<bord[6][4]<<bord[6][5]<<bord[6][6]<<bord[6][7]<<bord[6][8]<<bord[6][9]<<"\n";
    cout<<bord[7][1]<<bord[7][2]<<bord[7][3]<<bord[7][4]<<bord[7][5]<<bord[7][6]<<bord[7][7]<<bord[7][8]<<bord[7][9]<<"\n";


bord[7][9] gaat van [0][0] tot [6][8], niet van [1][1] tot [7][9], hetzelfde geldt voor alle arrays, altijd.

het bovenstaande stukje jun je trouwens in een simpele loop zetten:
1
2
3
4
5
6
for(int y = 0; y < 7; y++)
{
    for(int x = 0; x < 9; x++)
        cout << bord[y][x];
    cout << '\n';
}


en, write your code in english, always, so not only the dutch know what your variables and functions are for.
Last edited on Aug 2, 2010 at 8:43pm
Aug 3, 2010 at 7:40am
Ok, thank you.
But would that fix the problem?
Aug 3, 2010 at 7:49am
Most likely,..

You shouldnt be accessing bord[7][_] or bord[_][9], and you do it a LOT.

Have you tried?
Last edited on Aug 3, 2010 at 7:50am
Aug 3, 2010 at 9:22am
Yes I did.
Now, instead of exiting, It just does nothing :s
Aug 3, 2010 at 12:05pm
Post the new code
Aug 3, 2010 at 7:58pm
im not an expert so i dont know what you mean by dungeon crawl. but if you mean like a simple console RPG check out xoax.net, from the looks of it your objects aren't interacting with each-other like you want. in your takenboard cpp your returning a and b you cant call return twice in a function. the first one causes it to stop b4 the second gets read. and your not returning it to anything. you did get really close to the basic structure but check the link i gave you it has a good explanation how to make a console RPG. but if this is not what u r doing then NVM.
Aug 3, 2010 at 8:00pm
I found a fix, thanks for your help all :)
Topic archived. No new replies allowed.