简体   繁体   English

C ++预期的主要表达

[英]c++ expected primary expression

I'm working on a very simple game (essentially an ice sliding puzzle), for now the whole things in one file and the only level is completely blank of any form of obstacle. 我正在开发一个非常简单的游戏(本质上是一个滑冰难题),目前所有内容都放在一个文件中,唯一的层次是完全没有任何形式的障碍。 It throws up a few errors. 它引发了一些错误。 My current annoyance is an expected primary expression error, can anyone tell me how to fix it (it throws up at line 99)? 我当前的烦恼是预期的主要表达错误,有人可以告诉我如何解决(它出现在第99行)吗?

Here's the whole thing, 这就是全部

#include <allegro.h>

BITMAP* buffer;

int x = 15;
int y = 11;

int tempX = 15;
int tempY = 11;

//This will be our background, 1 = clouds, 2 = brick, 3 = floor
int map[24][32] = {{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,3,3,3,3,3,3,3,3,3,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
                   {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};

//This will contain all the objects, 100 = player
int objMap[24][32] = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};

void setupGame(){

     buffer = create_bitmap( 640, 480);

    for (int i = 0; i <= 24; i++){

        for( int t = 0; t <= 32; t++){

            if( map[i][t] == 1) rectfill( buffer, t * 20, i * 20, (t + 1) * 20, (i + 1) * 20, makecol( 128, 255, 255));
            else if( map[i][t] == 2) rectfill( buffer, t * 20, i * 20, (t + 1) * 20, (i + 1) * 20, makecol( 255, 128, 0));
            else if( map[i][t] == 3) rectfill( buffer, t * 20, i * 20, (t + 1) * 20, (i + 1) * 20, makecol( 0, 0, 255));

           }       

    }

    for (int i = 0; i <= 24; i++){

        for( int t = 0; t <= 32; t++){

            if( objMap[i][t] == 100) circlefill( buffer, (t * 20) + 10, (i * 20) + 10, 10, makecol( 255, 255, 0));

           }       

    }

    draw_sprite( screen, buffer, 0, 0);

}

void movePlayer(){

     tempX = x;
     tempY = y;

     if ( key[KEY_UP] && map[y - 1][x] == 3){
          for ([y - 1][x] == 3; --y){  // these lines are the ones            
              }
              }

     else if( key[KEY_DOWN] && map[y + 1][x] == 3){
          for ([y + 1][x] == 3; ++y){
              }
              }

     else if( key[KEY_RIGHT] && map[y][x + 1] == 3){
          for ([y][x + 1] == 3; ++x){
              }
              }

     else if( key[KEY_LEFT] && map[y][x - 1] == 3){
          for ([y][x - 1] == 3; --x){
              }
              }

     acquire_screen();

     rectfill( buffer, tempX * 20, tempY * 20, (tempX + 1) * 20, (tempY + 1) * 20, makecol( 255, 0, 0));

     circlefill( buffer, (x * 20) + 10, (y * 20) + 10, 10, makecol( 255, 255, 0));

     draw_sprite( screen, buffer, 0, 0);
     release_screen();

     rest(20);
}

int main(){

    allegro_init();
    install_keyboard();
    set_color_depth(16);
    set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);

    setupGame();

    while( !key[KEY_ESC]){

           modePlayer();

    }

    return 0;

}

END_OF_MAIN();

and here's the section that breaks; 这是中断的部分;

void movePlayer(){

     tempX = x;
     tempY = y;

     if ( key[KEY_UP] && map[y - 1][x] == 3){
          for ([y - 1][x] == 3; --y){              
              }
              }

     else if( key[KEY_DOWN] && map[y + 1][x] == 3){
          for ([y + 1][x] == 3; ++y){
              }
              }

     else if( key[KEY_RIGHT] && map[y][x + 1] == 3){
          for ([y][x + 1] == 3; ++x){
              }
              }

     else if( key[KEY_LEFT] && map[y][x - 1] == 3){
          for ([y][x - 1] == 3; --x){
              }
              }

it's the for lines it doesn't like. 这是它不喜欢的线。

thanks if you can help. 谢谢您的帮助。

What is going on here? 这里发生了什么?

[y - 1][x] == 3

Did you mean: 你的意思是:

 map[y - 1][x] == 3

The for() statment takes three parts separated by ';' for()语句分为三部分,以“;”分隔

for(<init>;<test>;<post>)
{
}

Any of these three parts can be empty but the ';' 这三个部分中的任何一个都可以为空,但';' must be there. 必须在那里。

You are also missing the object you should be indexing from in the test portion of each for() statement. 您还缺少每个for()语句的测试部分中应从其索引的对象。

for(; map[BLA][BLA] == <VALUE>;<INC>)

This might help: 这可能会有所帮助:

void movePlayer(){

    tempX = x;
    tempY = y;

    if (key[KEY_UP] && map[y - 1][x] == 3)
        for ( ; map[y - 1][x] == 3; --y){              
        }

    else if(key[KEY_DOWN] && map[y + 1][x] == 3)
        for ( ; map[y + 1][x] == 3; ++y){
        }

    else if(key[KEY_RIGHT] && map[y][x + 1] == 3)
        for ( ; map[y][x + 1] == 3; ++x){
        }

    else if(key[KEY_LEFT] && map[y][x - 1] == 3)
        for ( ; map[y][x - 1] == 3; --x){
        }

Your "for" loops are missing a section. 您的“ for”循环缺少一个部分。 Usually there are three parts: an initialization, a condition, and post-iteration operation. 通常包括三个部分:初始化,条件和后迭代操作。 From what I can tell, you have the last two, but no initialization. 据我所知,您有最后两个,但没有初始化。 The compiler is currently interpreting your first "for" loop, for example, as: 编译器当前正在解释您的第一个“ for”循环,例如:

  1. Check 3 against [y-1][x] 对[y-1] [x]进行检查3
  2. While 0 != (result of decrement y)... 而0!=(递减y的结果)...
  3. Do whatever 做任何事

What I think you mean to happen is: 我认为您的意思是:

  1. Assume everything is initialized 假设一切都已初始化
  2. While 3 == [y-1][x]... 而3 == [y-1] [x] ...
  3. Do whatever, and decrement y after each iteration 做任何事情,并在每次迭代后递减y

If so, this should look like: 如果是这样,则应如下所示:

for (; [y-1][x]==3; --y)
{
    // do whatever
}

This applies to all your "for" loops. 这适用于所有“ for”循环。

Another issue is that you aren't using an array variable, but are just using index offsets. 另一个问题是您没有使用数组变量,而只是使用索引偏移量。 Do you mean to say "map[y-1][x]"? 您是说“ map [y-1] [x]”吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM