Thread: my game.

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    25

    my game.

    my game isnt working...see? this is the code. it prints a board like this:
    10 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
    9 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
    8 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
    7 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
    6 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
    5 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
    4 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
    3 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
    2 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
    1 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
    1 2 3 4 5 6 7 8 9 10

    anyways i wanted a "smart" opponent (the game would be like chess, or fire emblem, if you've played it) so i made a thing that would alter the enimies position, if the player got too close. the problem is the eniemy, keeps moving to these coordinates, ignoring the player: 5,5 (designated to start here) 4,4 4,3 3,2 2,1. i dont know why its doing this, but heres the code:


    (yes i chould loop some stuff, and take out the variables...)
    (the "enemy" is in bold)


    #include <iostream>

    using namespace std;

    int main()
    {
    float a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, z;
    float A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z;
    float aa, ab, ac, ad, ae, af, ag, ah, ai, aj, ak, al, am, an, ao, ap, aq, ar, as;
    float at, au, av, aw, ax, ay, az, ba, bb, bc, bd, be, bf, bg, bh, bi, bj, bk, bl;
    float bm, bn, bo, bp, bq, br, bs, bt, bu, bv, bw, bx, by, bz, ca, cb, cc, cd, ce;
    float cf, cg, ch, ci, cj, ck, cl, cm, cn, co, cp, cq, cr, cs, ct, cu, cv, cw, cx;
    float cy, cz, da, db, dc, dd, de, df, dg, dh, di, dj, dk, dl, dm, dn, dp, dq, dr;
    float ds, dt, du, dv, dw, dx, dy, dz, ea, eb, ec, ed, ee, ef, eg, eh, ei, ej, ek;
    float el, em, en, eo, ep, eq, er, es, et, eu, ev, ew, ex, ey, ez, fa, fb, fc, fd;
    float fe, ff, fg, fh, fi, fj, fk, fl, fm, fn, fo, fp, fq, fr, fs, ft, fu, fv, fw;
    float fx, fy, fz, ga, gb, gc, gd, ge, gf, gg, gh, gi, gj, gk, gl, gm, gn, go, gp;
    float gq, gr, gs, gt, gu, gv, gw, gx, gy, gz, ha, hb, hc, hd, he, hf, hg, hh, hi;
    float hj, hk, hl, hm, hn, ho, hp, hq, hr, hs, ht, hu, hv, hw, hx, hy, hz, ia, ib;
    float ic, id, ie, ig, ih, ii, ij, ik, il, im, in, io, ip, iq, ir, is, it, iu, iv;
    float iw, ix, iy, iz, ja, jb, jc, jd, je, jf, jg, jh, ji, jj, jk, jl, jm, jn, jo;
    float jp, jq, jr, js, jt, jw, jx, jy, jz, ka, kb, kc, kd, ke, kf, kg, kh, ki, kj;
    float kk, kl, km, kn, ko, kp, kq, kr, ks, kt, ku, kw, kx, ky, kz;

    int x, y, world[10][10], sndx, sndy, zx, zy, aify, aifx;
    aifx=5;
    aify=5;
    d=0;



    cout<<"please note the world is a 10 by 10, empty grid\n";
    cout<<" _____________________ \n";
    cout<<" \\ Z MAP UV TH3 WUR1D/ \n";
    cout<<" ____\\<!!!TH3 WUR1D!!!>/____ \n";
    cout<<" \\ /-------------\\ / \n";
    cout<<" /____/ \\____\\ \n";
    cout<<"\n";
    cout<<"10 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]\n";
    cout<<"9 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]\n";
    cout<<"8 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]\n";
    cout<<"7 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]\n";
    cout<<"6 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]\n";
    cout<<"5 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]\n";
    cout<<"4 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]\n";
    cout<<"3 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]\n";
    cout<<"2 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]\n";
    cout<<"1 [ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]\n";
    cout<<" 1 2 3 4 5 6 7 8 9 10\n";
    cout<<"at (1,1) is the first portal\n";
    cin>> x >> y;

    do {


    world[0][0]=0;
    world[0][1]=0;
    world[0][2]=0;
    world[0][3]=0;
    world[0][4]=0;
    world[0][5]=0;
    world[0][6]=0;
    world[0][7]=0;
    world[0][8]=0;
    world[0][9]=0;
    world[1][9]=0;
    world[1][0]=0;
    world[1][1]=0;
    world[1][2]=0;
    world[1][3]=0;
    world[1][4]=0;
    world[1][5]=0;
    world[1][6]=0;
    world[1][7]=0;
    world[1][8]=0;
    world[1][9]=0;
    world[2][0]=0;
    world[2][1]=0;
    world[2][2]=0;
    world[2][3]=0;
    world[2][4]=0;
    world[2][5]=0;
    world[2][6]=0;
    world[2][7]=0;
    world[2][8]=0;
    world[2][9]=0;
    world[3][0]=0;
    world[3][1]=0;
    world[3][2]=0;
    world[3][3]=0;
    world[3][4]=0;
    world[3][5]=0;
    world[3][6]=0;
    world[3][7]=0;
    world[3][8]=0;
    world[3][9]=0;
    world[4][0]=0;
    world[4][1]=0;
    world[4][2]=0;
    world[4][3]=0;
    world[4][4]=0;
    world[4][5]=0;
    world[4][6]=0;
    world[4][7]=0;
    world[4][8]=0;
    world[4][9]=0;
    world[5][0]=0;
    world[5][1]=0;
    world[5][2]=0;
    world[5][3]=0;
    world[5][4]=0;
    world[5][5]=0;
    world[5][6]=0;
    world[5][7]=0;
    world[5][8]=0;
    world[5][9]=0;
    world[6][0]=0;
    world[6][1]=0;
    world[6][2]=0;
    world[6][3]=0;
    world[6][4]=0;
    world[6][5]=0;
    world[6][6]=0;
    world[6][7]=0;
    world[6][8]=0;
    world[6][9]=0;
    world[7][0]=0;
    world[7][1]=0;
    world[7][2]=0;
    world[7][3]=0;
    world[7][4]=0;
    world[7][5]=0;
    world[7][6]=0;
    world[7][7]=0;
    world[7][8]=0;
    world[7][9]=0;
    world[8][0]=0;
    world[8][1]=0;
    world[8][2]=0;
    world[8][3]=0;
    world[8][4]=0;
    world[8][5]=0;
    world[8][6]=0;
    world[8][7]=0;
    world[8][8]=0;
    world[8][9]=0;
    world[9][0]=0;
    world[9][1]=0;
    world[9][2]=0;
    world[9][3]=0;
    world[9][4]=0;
    world[9][5]=0;
    world[9][6]=0;
    world[9][7]=0;
    world[9][8]=0;
    world[9][9]=0;

    aify=aify-1;
    aifx=aifx-1;
    world[aifx][aify]=2; //cout enemy, on board

    x = x-1;//'cause of the "zeroeth"element
    y = y-1;

    world[x][y] = 1;//couts player on board

    cout<<"\n";
    cout<<"\n";
    cout<<"10 ";

    //couts the board, according to the values of world[][]==


    for ( x = 0 ; x < 10 ; x++ ){
    if (world[x][9] == 1)
    cout<<"[#]";
    if(world[x][9]==2)
    cout<<"[$]";
    else if (world[x][9] == 0)
    cout<<"[ ]";
    }

    cout<<"\n";
    cout<<"9 ";

    for ( x = 0 ; x < 10 ; x++ ){
    if (world[x][8] == 1)
    cout<<"[#]";
    if(world[x][8]==2)
    cout<<"[$]";
    else if (world[x][8] == 0)
    cout<<"[ ]";
    }

    cout<<"\n";
    cout<<"8 ";

    for ( x = 0 ; x < 10 ; x++ ){
    if (world[x][7] == 1)
    cout<<"[#]";
    if(world[x][7]==2)
    cout<<"[$]";
    else if (world[x][7] == 0)
    cout<<"[ ]";
    }

    cout<<"\n";
    cout<<"7 ";

    for ( x = 0 ; x < 10 ; x++ ){
    if (world[x][6] == 1)
    cout<<"[#]";
    if(world[x][6]==2)
    cout<<"[$]";
    else if (world[x][6] == 0)
    cout<<"[ ]";
    }

    cout<<"\n";
    cout<<"6 ";

    for ( x = 0 ; x < 10 ; x++ ){
    if (world[x][5] == 1)
    cout<<"[#]";
    if(world[x][5]==2)
    cout<<"[$]";
    else if (world[x][5] == 0)
    cout<<"[ ]";
    }

    cout<<"\n";
    cout<<"5 ";

    for ( x = 0 ; x < 10 ; x++ ){
    if (world[x][4] == 1)
    cout<<"[#]";
    if(world[x][4]==2)
    cout<<"[$]";
    else if (world[x][4] == 0)
    cout<<"[ ]";
    }

    cout<<"\n";
    cout<<"4 ";

    for ( x = 0 ; x < 10 ; x++ ){
    if (world[x][3] == 1)
    cout<<"[#]";
    if(world[x][3]==2)
    cout<<"[$]";
    else if (world[x][3] == 0)
    cout<<"[ ]";
    }

    cout<<"\n";
    cout<<"3 ";

    for ( x = 0 ; x < 10 ; x++ ){
    if (world[x][2] == 1)
    cout<<"[#]";
    if(world[x][2]==2)
    cout<<"[$]";
    else if (world[x][2] == 0)
    cout<<"[ ]";
    }

    cout<<"\n";
    cout<<"2 ";

    for ( x = 0 ; x < 10 ; x++ ){
    if (world[x][1] == 1)
    cout<<"[#]";
    if(world[x][1]==2)
    cout<<"[$]";
    else if (world[x][1] == 0)
    cout<<"[ ]";
    }

    cout<<"\n";
    cout<<"1 ";

    for ( x = 0 ; x < 10 ; x++ ){
    if (world[x][0] == 1)
    cout<<"[#]";
    if(world[x][0]==2)
    cout<<"[$]";
    else if (world[x][0] == 0)
    cout<<"[ ]";
    }

    cout<<"\n";
    cout<<" 1 2 3 4 5 6 7 8 9 10\n";
    cout<<"\n";
    do{
    cin>> x >> y;
    }
    while(x>10 || y>10||(x>10 && y>10));


    if(world[aifx][aify]=2){
    if(world[aifx+1][aify]==1){
    aifx=aifx+1;
    }
    if(world[aifx+2][aify]==1){
    aifx =aifx +1;
    }
    if(world[aifx-1][aify]==1){
    aifx =aifx -1;
    }
    if(world[aifx-2][aify]==1){
    aifx =aifx -1;
    }
    if(world[aifx][aify+1]==1){
    aify =aify +1;
    }
    if(world[aifx][aify+2]==1){
    aify =aify +1;
    }
    if(world[aifx][aify-2]==1){
    aify =aify -1;
    }
    if(world[aifx][aify-1]==1){
    aify =aify -1;
    }
    if(world[aifx+1][aify+1]==1){
    aifx =aifx +1;
    }
    if(world[aifx+1][aify-1]==1){
    aify =aify -1;
    }
    if(world[aifx-1][aify-1]==1){
    aify =aify-1;
    }
    if(world[aifx-1][aify+1]==1){
    aifx =aifx -1;
    }

    }
    }
    while ( x <= 10 && y<=10);//so x/y stays on board
    cin.get();
    }

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    25
    yep
    try it its kinda fun

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Please use code tags. Look at the sticky at the top of the forum for instructions and an explanation.

    And please stop posting unnecessary one-line posts.

  4. #4
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    cppdungeon we're very strict at these forums. You NEED to go use [CODE ] Tags [/ CODE] between ALL of your code! And DO NOT double post ever (I do sometimes, but it's because I'm a bad person ). So edit your first post, and add the code tags between your C++ code, and then delete your second post.

  5. #5
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Readability hint #2:
    All of the 'world[x][y] = 0' statements could be contained in a nested pair of loops, and that would make your code much shorter and more readable.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  6. #6
    UT2004 Addict Kleid-0's Avatar
    Join Date
    Dec 2004
    Posts
    656
    Code:
    world[0][0]=0;
     world[0][1]=0;
     world[0][2]=0;
     world[0][3]=0;
     world[0][4]=0;
     world[0][5]=0;
     world[0][6]=0;
     world[0][7]=0;
     world[0][8]=0;
     world[0][9]=0;
     world[1][9]=0;
     world[1][0]=0;
     world[1][1]=0;
     world[1][2]=0;
     world[1][3]=0;
     world[1][4]=0;
     world[1][5]=0;
     world[1][6]=0;
     world[1][7]=0;
     world[1][8]=0;
     world[1][9]=0;
     world[2][0]=0;
     world[2][1]=0;
     world[2][2]=0;
     world[2][3]=0;
     world[2][4]=0;
     world[2][5]=0;
     world[2][6]=0;
     world[2][7]=0;
     world[2][8]=0;
     world[2][9]=0;
     world[3][0]=0;
     world[3][1]=0;
     world[3][2]=0;
     world[3][3]=0;
     world[3][4]=0;
     world[3][5]=0;
     world[3][6]=0;
     world[3][7]=0;
     world[3][8]=0;
     world[3][9]=0;
     world[4][0]=0;
     world[4][1]=0;
     world[4][2]=0;
     world[4][3]=0;
     world[4][4]=0;
     world[4][5]=0;
     world[4][6]=0;
     world[4][7]=0;
     world[4][8]=0;
     world[4][9]=0;
     world[5][0]=0;
     world[5][1]=0;
     world[5][2]=0;
     world[5][3]=0;
     world[5][4]=0;
     world[5][5]=0;
     world[5][6]=0;
     world[5][7]=0;
     world[5][8]=0;
     world[5][9]=0;
     world[6][0]=0;
     world[6][1]=0;
     world[6][2]=0;
     world[6][3]=0;
     world[6][4]=0;
     world[6][5]=0;
     world[6][6]=0;
     world[6][7]=0;
     world[6][8]=0;
     world[6][9]=0;
     world[7][0]=0;
     world[7][1]=0;
     world[7][2]=0;
     world[7][3]=0;
     world[7][4]=0;
     world[7][5]=0;
     world[7][6]=0;
     world[7][7]=0;
     world[7][8]=0;
     world[7][9]=0;
     world[8][0]=0;
     world[8][1]=0;
     world[8][2]=0;
     world[8][3]=0;
     world[8][4]=0;
     world[8][5]=0;
     world[8][6]=0;
     world[8][7]=0;
     world[8][8]=0;
     world[8][9]=0;
     world[9][0]=0;
     world[9][1]=0;
     world[9][2]=0;
     world[9][3]=0;
     world[9][4]=0;
     world[9][5]=0;
     world[9][6]=0;
     world[9][7]=0;
     world[9][8]=0;
     world[9][9]=0;
    Would turn into this:
    Code:
    for(y=0; y<=9; ++y) {
     for(x=0; x<=9; x++) {
      world[x][y] = 0;
     }
    }

  7. #7
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Quote Originally Posted by Kleid-0
    Code:
    world[0][0]=0;
     world[0][1]=0;
     world[0][2]=0;
     //45 assignments snipped here
     world[9][8]=0;
     world[9][9]=0;
    Would turn into this:
    Code:
    for(y=0; y<=9; ++y) {
     for(x=0; x<=9; x++) {
      world[x][y] = 0;
     }
    }
    Or even this:
    Code:
    memset(world,0,sizeof(int)*100);
    As for the OP, I don't think I've ever used 336 floats before. If I'm reading your code correctly (and I can't guarantee that I am, since it doesn't have code tags), it looks like you're decrementing aifx and aify every loop. You should put those decrements outside of the do-while loop (or, even better, get rid of them altogether and initialize aifx and aify with 4). You also have a more subtle bug in the bolded section; you're subscripting outside of your array. Consider the enemy positioned at 10,10. Right after your if-statement (which is unnecessary):
    Code:
    if(world[aifx+1][aify]==1){
    aifx=aifx+1;
    }
    Assuming aifx would have a value of 9, then you'd be accessing world[10][9], which is outside the bounds of your array.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-08-2010, 12:08 AM
  2. Open Source / Semi Open source game idea. Help needed
    By CaptainPatent in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 05-16-2007, 10:44 AM
  3. game engine advice?
    By stien in forum Game Programming
    Replies: 0
    Last Post: 01-23-2007, 03:46 PM
  4. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM