Wo ist Fehler?



  • CStoll (off) schrieb:

    Schneida_M schrieb:

    void menu()
    {
    st: clrscr();
      //...
      for(;;)
      {
        opt=getch();
        if(opt=='G'||opt=='g') { del++; if(del==21) del=3; goto st; }
        //..
      }
    }
    

    *mal etwas gekürzt* Da hast du ein goto 😉

    Ok, ich nehm alles zurück und behaupte das Gegenteil 🤡

    Außerdem wird das jetzt mal gescheit formatiert...



  • Also ich habe den Quellcode noch etwas geändert:

    #include <graphics.h>
    #include <iostream.h>
    #include <stdlib.h>
    #include <string.h>
    #include <stdio.h>
    #include <conio.h>
    #include <comm.h>
    #include <dos.h>
    
    int y1,y2,
        xb,yb,
        xb_dir=1,yb_dir=1,
        del=10,
        lvl=4,mode,
        ast=0,
        ric,ric1;
    int xb1,yb1,
        xb_dir1,yb_dir1,
        twoball=0,
        score1=0,score2=0,scoremax=5;
        long k=1;
    
    void drawball(int i,int j,int c1,int c2);
    void drawbrick1(int i,int c);
    void drawbrick2(int i,int c);
    void drawborder();
    void graphinit();
    void display();
    void start();
    void menu();
    void move();
    void ai1();
    void ai2();
    void win();
    
    int main()
    {
       menu();
       start();
       move();
       return 0;
    }
    
    void graphinit()
    {
       int driver=DETECT,mode;
       initgraph(&driver,&mode,"C:\BC31\bgi");
    }
    
    void menu()
    {
       char opt;
       _setcursortype(_NOCURSOR);
       st: clrscr();
    
       gotoxy(31,5);
       textcolor(9);
       cprintf("P I N G - P O N G");
    
       gotoxy(33,9);
       textcolor(12);
       cprintf("S");
       gotoxy(34,9);
       textcolor(10);
       cprintf("ingle Player");
    
       gotoxy(34,12);
       textcolor(12);
       cprintf("M");
       gotoxy(35,12);
       textcolor(10);
       cprintf("ultiplayer");
    
       gotoxy(32,18);
       textcolor(12);
       cprintf("G");
       gotoxy(33,18);
       textcolor(10);
       cprintf("ame speed: %d",del);
    
       gotoxy(37,24);
       textcolor(12);
       cprintf("Q");
       gotoxy(38,24);
       textcolor(10);
       cprintf("uit");
    
       for( ; ; )
       {
          opt=getch();
          if(opt=='G'||opt=='g')
          {
             del++;
             if(del==21)
                del=3;
             goto st;
          }
    
          if(opt=='Q'||opt=='q')
          {
             clrscr();
             cout<<" Bye!";
             delay(500);
             exit(0);
          }
    
          if(opt=='s'||opt=='S')
          {
             mode=1;
             dif();
             return;
          }
    
          if(opt=='m'||opt=='M')
          {
             mode=2;
             return;
          }
       }
    }
    
    void start()
    {
       int j;
       randomize();
       j=random(100);
       yb_dir=-1;
       yb_dir1=1;
    
       if(j%2==0)
       {
          xb_dir=1;
          xb_dir1=-1;
       }
       else
       {
          xb_dir=-1;
          xb_dir1=1;
       }
    
       graphinit();
       drawborder();
    
       xb=320;
       yb=400;
       xb1=320;
       yb1=80;
       y1=y2=200;
    
       drawbrick1(y1,2); drawbrick2(y2,2);
    
       drawball(xb,yb,4,1);
    }
    
    void drawborder()
    {
       setcolor(1);
       rectangle(5,4,635,476);
    }
    
    void drawbrick1(int i,int c)
    {
       int brick1[10]={634,i,634,i+100,611,i+100,611,i,634,i};
    
       setcolor(c);
       setfillstyle(7,c);
       fillpoly(4,brick1);
    }
    
    void drawbrick2(int i,int c)
    {
       int brick2[10]={6,i,28,i,28,i+100,6,i+100,6,i};
    
       setcolor(c);
       setfillstyle(8,c);
       fillpoly(4,brick2);
    }
    
    void win()
    {
       if((xb<24&&xb_dir==-1&&xb>15)&&!ric)
       {
          score1++;
          ric=1;
          if(scoremax)
             if(score1==scoremax)
             {
                gotoxy(33,15);
                cout<<"Player 1 wins!";
                delay(2000);
                exit(0);
             }
       }
       if((xb>611&&xb_dir==1&&xb<616)&&!ric)
       {
          score2++;
          ric=1;
    
          if(scoremax)
             if(score2==scoremax)
             {
                gotoxy(33,15);
                cout<<"Player 2 wins!";
                delay(2000);
                exit(0);
             }
       }
       if((xb1<24&&xb_dir1==-1&&xb>15)&&!ric1)
       {
          score1++;
          ric1=1;
    
          if(scoremax)
             if(score1==scoremax)
             {
                gotoxy(33,15);
                cout<<"Player 1 wins!";
                delay(2000);
                exit(0);
             }
       }
       if((xb1>611&&xb_dir1==1&&xb1<616)&&!ric1)
       {
          score2++;
          ric1=1;
    
          if(scoremax)
             if(score2==scoremax)
             {
                gotoxy(33,15);
                cout<<"Player 2 wins!";
                delay(2000);
                exit(0);
             }
       }
    }
    
    void move()
    {
       char a;
    
       while(a!=ESC)
       {
          a=0;
          if(kbhit())
          {
             a=getch();
             if(a==UP&&y1>15)
             {
                drawbrick1(y1+1,0);
                y1-=10;
                drawbrick1(y1,2);
             }
             if(a==DOWN&&y1<365)
             {
                drawbrick1(y1,0);
                y1+=10;
                drawbrick1(y1,2);
             }
             if(mode==2)
             {
                if(a=='w'&&y2>15)
                {
                   drawbrick2(y2+1,0);
                   y2-=10;
                   drawbrick2(y2,2);
                }
                if(a=='s'&&y2<365)
                {
                   drawbrick2(y2,0);
                   y2+=10;
                   drawbrick2(y2,2);
                }
             }
          }
          drawball(xb,yb,0,0);
    
          if(twoball)
             drawball(xb1,yb1,0,0);
    
          xb+=xb_dir*5;
          yb+=yb_dir*3;
    
          if(twoball)
          {
             xb1+=xb_dir1*4;
             yb1+=yb_dir1*2;
          }
    
          drawball(xb,yb,4,1);
    
          if(twoball)
             drawball(xb1,yb1,14,9);
    
          win();
    
          if(k%lvl==0)
             if(mode!=2)
                ai1();
    
          if(ast)
             if(k%ast==0)
                ai2();
    
          k++;
    
          if(ric)
             ric++;
    
          if(ric>110)
             ric=0;
    
          if(ric1)
             ric1++;
    
          if(ric1>110)
             ric1=0;
    
          delay(del);
    
          if(yb>462||yb<18)
          {
             sound(1500);
             delay(1);
             nosound();
             yb_dir*=-1;
          }
          if(xb>619||xb<21||(xb==40&&(yb-y2<100&&yb-y2>0))|| (xb==600&&(yb-y1<100&&yb-y1>0)))
          {
             xb_dir*=-1;
          }
       }
    }
    
    void ai1()
    {
       if(yb>y2+25&&xb<320&&xb_dir==-1&&y2<365)
       {
          drawbrick2(y2,0);
          y2+=10;
          drawbrick2(y2,2);
       }
       if(yb<y2+25&&xb<320&&xb_dir==-1&&y2>15)
       {
          drawbrick2(y2+1,0);
          y2-=10;
          drawbrick2(y2,2);
       }
       if(xb_dir==1)
       {
          if(y2+50>240)
          {
             drawbrick2(y2+1,0);
             y2-=10;
             drawbrick2(y2,2);
          }
    	  if((y2+50)<23 cool);
    	  {
             drawbrick2(y2,0);
             y2+=10;
             drawbrick2(y2,2);
          }
       }
    }
    
    void ai2()
    {
       if(yb>y1+50 && xb>320 && xb_dir==1&&y1<365)
       {
          drawbrick1(y1,0);
          y1+=10;
          drawbrick1(y1,2);
       }
       if(yb<y1+50 && xb>320 && xb_dir==1&&y1>15)
       {
          drawbrick1(y1+1,0);
          y1-=10;
          drawbrick1(y1,2);
       }
    }
    
    ;
    

    Folgende Fehlermeldungen:

    ╔═[■]══════════════════════════════ Message ═════════════════════════════2═[↑]═╗
    ║ Compiling ..\..\DOKUME~1\MICHAEL\DESKTOP\PINGPONG.CPP: ▲
    ║•E~1\MICHAEL\DESKTOP\PINGPONG.CPP 111: Function 'dif' should have a prototype ▒
    ║ Error ..\..\DOKUME~1\MICHAEL\DESKTOP\PINGPONG.CPP 363: If statement missing )▒

    Zeile
    E~1\MICHAEL\DESKTOP\PINGPONG.CPP 111: Function 'dif' should have a prototype

    if(opt=='s'||opt=='S')
          {
             mode=1;
             dif();
             return;
          }
    

    Zeile
    Error ..\..\DOKUME~1\MICHAEL\DESKTOP\PINGPONG.CPP 363: If statement missing )

    if((y2+50)<23 cool);
    	  {
             drawbrick2(y2,0);
             y2+=10;
             drawbrick2(y2,2);
          }
    


  • die funktion dif() gibts nicht
    guck dir das if an. da hat sich ein smiley eingeschlichen und den code zerstoert.



  • Danke jetzt zeigt er keine Fehlermeldungen mehr an!
    Dafür steht jetzt wenn ich das Programm in meinen Compiler (Borland 3.1) ausführen will folgender Error:

    Can't run a Windows EXE file

    ..\..\SOUNDER.EXE

    Wie kann ich den beheben?



  • schmeiss borland in die tonne und nimm was ordentliches. sorry, aber so ist das leben.



  • Und welchen Compiler würdest du mir empfehlen (ausser Bloodsheet der gefällt mir nich)?



  • fuer windows nimm gcc fuer win32 oder mingw (da ist gcc auch drin).
    als editor probiere mal code::blocks.



  • Habe mir jetzt Code:Blocks mit GNU zugelegt!
    Code:Blocks gibt folgende Errors aus:

    C:/Programme/CodeBlocks/include/graphics.h:254: error: far' does not name a type C:/Programme/CodeBlocks/include/graphics.h:256: error:far' does not name a type
    C:/Programme/CodeBlocks/include/graphics.h:257: error: far' does not name a type C:/Programme/CodeBlocks/include/graphics.h:259: error:far' does not name a type

    C:/Programme/CodeBlocks/include/graphics.h:260: error: far' does not name a type C:/Programme/CodeBlocks/include/graphics.h:261: error:far' does not name a type
    C:/Programme/CodeBlocks/include/graphics.h:262: error: `far' does not name a type

    C:/Programme/CodeBlocks/include/graphics.h:263: error: far' does not name a type C:/Programme/CodeBlocks/include/graphics.h:264: error:far' does not name a type
    C:/Programme/CodeBlocks/include/graphics.h:265: error: `far' does not name a type

    C:/Programme/CodeBlocks/include/graphics.h:267: error: far' does not name a type C:/Programme/CodeBlocks/include/graphics.h:268: error:far' does not name a type

    C:/Programme/CodeBlocks/include/graphics.h:269: error: far' does not name a type C:/Programme/CodeBlocks/include/graphics.h:270: error:far' does not name a type
    C:/Programme/CodeBlocks/include/graphics.h:271: error: far' does not name a type C:/Programme/CodeBlocks/include/graphics.h:272: error:far' does not name a type
    C:/Programme/CodeBlocks/include/graphics.h:273: error: `far' does not name a type

    C:/Programme/CodeBlocks/include/graphics.h:274: error: expected init-declarator before '*' token

    C:/Programme/CodeBlocks/include/graphics.h:274: error: expected ,' or;' before '*' token

    :/Programme/CodeBlocks/include/graphics.h:275: error: expected init-declarator before "cdecl"

    C:/Programme/CodeBlocks/include/graphics.h:275: error: expected ,' or;' before
    "cdecl"

    C:/Programme/CodeBlocks/include/graphics.h:276: error: far' does not name a type C:/Programme/CodeBlocks/include/graphics.h:277: error:far' does not name a type
    C:/Programme/CodeBlocks/include/graphics.h:278: error: far' does not name a type C:/Programme/CodeBlocks/include/graphics.h:279: error:far' does not name a type
    C:/Programme/CodeBlocks/include/graphics.h:281: error: far' does not name a type C:/Programme/CodeBlocks/include/graphics.h:282: error:far' does not name a type
    C:/Programme/CodeBlocks/include/graphics.h:283: error: far' does not name a type C:/Programme/CodeBlocks/include/graphics.h:284: error:far' does not name a type
    C:/Programme/CodeBlocks/include/graphics.h:285: error: `far' does not name a type

    C:/Programme/CodeBlocks/include/graphics.h:286: error: expected init-declarator before "cdecl"

    C:/Programme/CodeBlocks/include/graphics.h:286: error: expected ,' or;' before "cdecl"

    C:/Programme/CodeBlocks/include/graphics.h:287: error: far' does not name a type C:/Programme/CodeBlocks/include/graphics.h:289: error:far' does not name a type
    C:/Programme/CodeBlocks/include/graphics.h:290: error: far' does not name a type C:/Programme/CodeBlocks/include/graphics.h:291: error:far' does not name a type
    C:/Programme/CodeBlocks/include/graphics.h:292: error: far' does not name a type C:/Programme/CodeBlocks/include/graphics.h:293: error:far' does not name a type
    C:/Programme/CodeBlocks/include/graphics.h:294: error: far' does not name a type C:/Programme/CodeBlocks/include/graphics.h:295: error:far' does not name a type
    C:/Programme/CodeBlocks/include/graphics.h:296: error: `far' does not name a type

    C:/Programme/CodeBlocks/include/graphics.h:297: error: expected init-declarator before "cdecl"

    C:/Programme/CodeBlocks/include/graphics.h:297: error: expected ,' or;' before "cdecl"

    C:/Programme/CodeBlocks/include/graphics.h:298: error: `far' does not name a type

    C:/Programme/CodeBlocks/include/graphics.h:299: error: expected init-declarator before '*' token

    C:/Programme/CodeBlocks/include/graphics.h:299: error: expected ,' or;' before '*' token

    C:/Programme/CodeBlocks/include/graphics.h:300: error: far' does not name a type C:/Programme/CodeBlocks/include/graphics.h:301: error:far' does not name a type
    C:/Programme/CodeBlocks/include/graphics.h:302: error: far' does not name a type C:/Programme/CodeBlocks/include/graphics.h:305: error:far' does not name a type

    Was bedeuten die Errors und wie behebe ich sie?



  • Schneida_M schrieb:

    Was bedeuten die Errors und wie behebe ich sie?

    Das bedeutet dass du "graphics.h" von deinem alten compiler verwendest. Du kannst nicht einfach irgendwelche header und libraries von verschiedenen compilern hin und her kopieren.
    Kurt



  • Das kommt daher wenn man den Borland vorschnell in die Tonne schmeisst, ohne zu bedenken, dass man die ganze Zeit Borland-spezifische Header/Libs benutzt. *rofl*



  • Gibt es die Möglickeit diese LIB unter meinen Compiler einzufügen?



  • Schneida_M schrieb:

    Gibt es die Möglickeit diese LIB unter meinen Compiler einzufügen?

    Such mal in deinem Borland-Verzeichnis nach der graphics.h und der graphics.lib.
    Vermutlich wirst du auch das ganze BGI-Verzeichnis brauchen.



  • Danke werd ich dan gleich mal probieren!
    Für Code:Blocks gibt es ja auch einen Borland Compiler!
    Wird dadurch das Problem gelöst?


Anmelden zum Antworten