Zeichen an gewisser Stelle überprüfen



  • Wie soll man dann helfen



  • indem man mier sagt wo ich was genau da einfügen muss, vielleicht war da immer mein fehler



  • Du fragst nach einem Verfahren wie man etwas grundlegendes in C macht.

    Wie sollen wir wissen wo du was machen möchtest. am ehesten bieten sich logischerweise die Stellen an an denen die printf stehen, denn du möchstet ja prüfen ob da und was da schon steht.
    Um zu wissen ob da schon was steht solltest du dir ein einem Feld (2.dimensional) merken wo sich etwas befindet und bevor du neue Zeichen schreibst diese Stellen mit dem Verfahren von loki1985 überprüfen.



  • hier mal der gesammte code:

    #include <stdlib.h>
    #include <stdio.h>
    #include <conio.h>
    #include <dos.h>
    #include <time.h>
    
    int mywait(int tmx){
    struct time t, tneu;
    int loop;
    
    for (loop=0; loop<tmx; loop++){
    gettime(&t);
    gettime(&tneu);
    while (t.ti_hund == tneu.ti_hund) gettime(&tneu);}}
    
    void picer();
    void figures();
    
    int figur1  (int, int);    //block
    
    int figur2  (int, int);    //linie
    int figur2b (int, int);
    
    int figur3  (int, int);    //Zet1
    int figur3b (int, int);
    
    int figur4  (int, int);    //Zet2
    int figur4b (int, int);
    
    int figur5  (int, int);    //EL1
    int figur5b (int, int);
    int figur5c (int, int);
    int figur5d (int, int);
    
    int figur6  (int, int);    //EL2
    int figur6b (int, int);
    int figur6c (int, int);
    int figur6d (int, int);
    
    int figur7  (int, int);    //Tee
    int figur7b (int, int);
    int figur7c (int, int);
    int figur7d (int, int);
    
    //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
    
    char pic[23][23]={
    {" .................... "},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯"}};
    
    void picer  ()
    
    {
    int loop;
    int leep;
    
    for (loop=0; loop < 23; loop++)
       {
        for (leep=0; leep < 23; leep++)
           { gotoxy(32+loop,leep+1);
    	printf("%s",& pic[leep][loop]);
            }
    
        }
    }
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////////
    
    int figur1(int fx, int fy)
    
    {
     char moveto;
    
     //fx=42;
     //fy=2;
    
     gotoxy(fx,fy);
    
    while (moveto != '2')
         {
          moveto = getch();
    
          gotoxy(fx,fy)   ; printf ("  ");
          gotoxy(fx,fy+1) ; printf ("  ");
    
          if (moveto == '4' && fx >= 34)
            {fx=fx--;}
          if (moveto == '6' && fx <= 50)
            {fx=fx++;}
    
          gotoxy(fx,fy)   ; printf ("");
          gotoxy(fx,fy+1) ; printf ("");
    
          gotoxy(fx,fy);
         }
    return(0);
    }
    
    ////////////////////////////////////////////////////////// Figur 3: Zet1
    int figur3(int fx, int fy)
    
    {
    
    int xscan;
    int yscan;
    
     char moveto;
    
     //fx=42;
     //fy=2;
    
     gotoxy(fx,fy);
    
    	while (moveto != '2')
    		{
    
        		  moveto = getch();
    
    		  gotoxy(fx  ,fy )   ; printf ("..");
    		  gotoxy(fx+1,fy+1)  ; printf  ("..");
    
    		  xscan = fx - 1;
                      yscan = fy - 1;
    
       		     if (moveto == '4' && fx >= 34)
    		       {fx=fx--;}
    
                         if (fx+2 != '0')
    			{
                            }
    
    		     if (moveto == '6' && fx <= 49)
    		       {fx=fx++;}
    
    		     if (moveto == '5' && fy <= 20)
    		       {fy=fy++;}
    
       		   gotoxy(fx  ,fy )   ; printf ("##");
    		   gotoxy(fx+1,fy+1)  ; printf  ("##");
    		   gotoxy(fx+1,fy);
    
    		  if (moveto == '8' && fx <= 50 && fy <= 21)
    			{
    			 gotoxy(fx  ,fy)    ; printf  ("..");
    			 gotoxy(fx+1,fy+1)  ; printf   ("..");
    
    		         gotoxy(fx+1,fy-1)    ; printf  ("#");
    			 gotoxy(fx ,fy)  ; printf ("##");
    			 gotoxy(fx ,fy+1)  ; printf ("#");
    
    			 figur3b(fx,fy);    
    		}
    
    	if (moveto == '8' )
    	  {
    	   fx = 42;
               fy =  2;
    	   gotoxy(fx,fy);
    	   figur3(fx,fy);
    	  }
         }
    return(0);
    }
    
    /////////////////////////////////////
    int figur3b(int fx, int fy)
    
    {
    
     char moveto;
    
     //fx=42;
     //fy=2;
    
     gotoxy(fx,fy);
    
    	while (moveto != '2')
    		{
    
        		  moveto = getch();
    
    			 gotoxy(fx+1,fy-1)    ; printf  (".");
      		         gotoxy(fx  ,fy)      ; printf ("..");
    			 gotoxy(fx  ,fy+1)  ; printf (".");
    
       		   if (moveto == '4' && fx >= 34)
       		     {fx=fx--;}
       		   if (moveto == '6' && fx <= 50)
       		     {fx=fx++;}
    		   if (moveto == '5' && fy <= 20)
    		     {fy=fy++;}
    
    		         gotoxy(fx+1,fy-1)    ; printf  ("#");
      		         gotoxy(fx  ,fy)  ; printf ("##");
    			 gotoxy(fx  ,fy+1)  ; printf ("#");
    
       		   gotoxy(fx+1,fy);
    
        		  if (moveto == '8' && fx <= 50)
    			{
    			 gotoxy(fx+1,fy-1)      ; printf  (".");
      		         gotoxy(fx,fy)  ; printf ("..");
    			 gotoxy(fx  ,fy+1)    ; printf (".");
    
    			 gotoxy(fx  ,fy)    ; printf  ("##");
    			 gotoxy(fx+1,fy+1)  ; printf   ("##");
    
    			 figur3(fx,fy);
    		}
    
         }
    return(0);
    }
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////
    int main (void)
    
    {
    picer();
    figur3(42,2);
    
    return (0);
    
    }
    /Copyright by PDS2/
    

    so, das ganze ist im Turbo C++ 3.1 Compiler von Borland gemacht, schaus dir einfach mal an. Das Problem von mir liegt darin: Wenn in dem char pic* nicht ein punkt sondern mitlerweile ein # ist, dann soll der nen neuen baustein bringen, jedoch überschreibt der die alten zeichen, was du sicher schon lange gemerkt hast 😉

    Wäre echt super wenn du mir sagst wie ich das hin bekomm das das dann abfrägt ob da mitlerweile ein anderer Stein liegt und den dann nicht wieder überschreibt. sollte das dringend schnell fertig bekommen

    THX



  • ?¿?



  • weiß keiner weiter?



  • ist doch simpel.

    du fragst ja schon in deinem post "ist punk BLA ein WASAUCHIMMER".

    also wenn du zum beispiel überprüfen willst ob punk x1 y4 ein '.' ist, heisst der code:

    if(pic[1][4] == '.') {// so, ergebnis ist wahr, weitermachen}
    

    ganz ehrlich, schau dir lieber nochmal ein paar tutorials an.



  • wenn das so simple wäre würde ich net fragen, denn das tut dummerweise so net 😞



  • Warum bist du so unhöflich?

    Was heißt das tut nicht?

    In welcher Zeile passiert welcher Fehler?

    Wie wärs denn mal mit nem Debugger.

    Notfalls in dem man an den Stellen sn denen was passiert in ein file einträgt was passiert. Auf dem Bildschirm ausgeben macht bei dir keinen Sinn, da sonst deine Graphik zerstört wird.



  • Entweder

    a) Du machst keine direkte Ausgabe sondern bufferst immer alles und gibts es dann über eine Funktion aus. Das wäre eh viel besser weil du dann keine Nicht-Standard-Funktionen benötigst (gotoxy). Dann kannst du in deinem eigenem Buffer "nachlesen".

    b) http://www.tutorials.de/tutorials210263.html&highlight=zeichen+konsole

    muh



  • Master-of-Scare schrieb:

    wenn das so simple wäre würde ich net fragen, denn das tut dummerweise so net 😞

    es ist aber so simpel.

    anstatt rumzumeckern dass es nicht geht solltest du versuchen, es einzubauen.

    abgesehen davon: besorg dir tutorials und lerne. wenn dir die basics fehlen wirst du nämlich sehr bald wieder vor einem ähnlich simplen problem stehen....



  • sorry wenn ich unfreundlich war, mein problem ist das ich wegen dem mist seit knapp 4 wochen net mehr weiter komme da das nicht tut wie es normal tun sollte. ich weiß wo ich das einfügen müsste, was leider net wirklich geht. denk mal das liegt daran das wenn ein neuer stein kommt die neuen veränderten zeichen eben nicht im array gespeichert sind sondern immer noch die standartdeklaration, oder?



  • kA... aber ein guter anfang wäre, das beispiel einzubauen, den neuen code posten und eine exakte beschreibung des problems und/oder fehlers dazuzuschreiben. es macht nämlich keinen bock deinen code groß studieren zu müssen um den sinn und das problem zu kapieren.....



  • hab alles soweit hin bekommen, nur noch ne kurze frage:

    wenn ich in ner datei zb

    fghj
    jhgf

    habe, und ich will jetzt genau in der zweiten zeile an der stelle des g ein anderes symbol hinsetzen (g überschreiben) wie mach ich das, das nur diese stelle überschrieben wird?



  • Ich habe den code mal schnell überflogen und kann nirgends finden das das 2dim array pic irgendwo upgedated wird. was du in diesem fall wirklich brauchst ist eine funktion wie getxy() die dir zurückgibt welches zeichen an einer bestimmten stelle am Bildschirm steht. Keine Ahnung ob es so etwas in der library die du da verwendest überhaupt gib. und ausserdem ist der code so aufgebaut dass du diese abfrage an vielen vielen stellen einbauen müsstest. Am besten ist du überlegst dir ein neues konzept für dieses spiel.
    Kurt



  • hi kurt, ist auch nicht mehr der aktuelle code, muss nur wissen wie ich an die stelle in ner datei komme ohne das der rest überschrieben wird



  • wenn du in zeile 2 das 3. zeichen zu # haben willst, machst du einfach arrayname[1][2] = '#'..... (oder umgekehrt, bin mir bei mehrdimensionalen arrays nicht sicher)

    merke dass die stellennummer in arrays mit 0 anfangen, nicht mit 1.....



  • hi, also neues problem, hab das mal so hin bekommen:

    #include <stdlib.h>
    #include <stdio.h>
    #include <conio.h>
    #include <dos.h>
    #include <time.h>
    
    int mywait(int tmx){
    struct time t, tneu;
    int loop;
    
    for (loop=0; loop<tmx; loop++){
    gettime(&t);
    gettime(&tneu);
    while (t.ti_hund == tneu.ti_hund) gettime(&tneu);}}
    
    void picer();
    void figures();
    
    int figur1  (int, int);    //block
    
    int figur2  (int, int);    //linie
    int figur2b (int, int);
    
    int figur3  (int, int);    //Zet1
    int figur3b (int, int);
    
    int figur4  (int, int);    //Zet2
    int figur4b (int, int);
    
    int figur5  (int, int);    //EL1
    int figur5b (int, int);
    int figur5c (int, int);
    int figur5d (int, int);
    
    int figur6  (int, int);    //EL2
    int figur6b (int, int);
    int figur6c (int, int);
    int figur6d (int, int);
    
    int figur7  (int, int);    //Tee
    int figur7b (int, int);
    int figur7c (int, int);
    int figur7d (int, int);
    
    //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
    
    char pic[23][23]={
    {" .................... "},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"|....................|"},
    {"¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯"}};
    
    void picer  ()
    
    {
    int loop;
    int leep;
    
    for (loop=0; loop < 23; loop++)
       {
        for (leep=0; leep < 23; leep++)
           { gotoxy(32+loop,leep+1);
    	printf("%s",& pic[leep][loop]);
            }
    
        }
    }
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////////
    
    int figur1(int fx, int fy)
    
    {
     char moveto;
    
     //fx=42;
     //fy=2;
    
     gotoxy(fx,fy);
    
    while (moveto != '2')
         {
          moveto = getch();
    
          gotoxy(fx,fy)   ; printf ("  ");
          gotoxy(fx,fy+1) ; printf ("  ");
    
          if (moveto == '4' && fx >= 34)
            {fx=fx--;}
          if (moveto == '6' && fx <= 50)
            {fx=fx++;}
    
          gotoxy(fx,fy)   ; printf ("");
          gotoxy(fx,fy+1) ; printf ("");
    
          gotoxy(fx,fy);
         }
    return(0);
    }
    
    ////////////////////////////////////////////////////////// Figur 3: Zet1
    int figur3(int fx, int fy)
    
    {
    
    int xscan;
    int yscan;
    
     char moveto;
    
     //fx=42;
     //fy=2;
    
     gotoxy(fx,fy);
    
    	while (moveto != '2')
    		{
    
        		  moveto = getch();
    
    		  gotoxy(fx  ,fy )   ; printf ("..");
    		  gotoxy(fx+1,fy+1)  ; printf  ("..");
    		  pic[fx][fy]='..';
    		  pic[fx+1][fy+1]='..';
    
    		  xscan = fx;
                      yscan = fy;
    
    		     if(pic[fx-2][fy]=='.')
                         {
       		     if (moveto == '4' && fx >= 34)
    		       {fx=fx--;}
                         }
                         if (fx+2 != '0')
    			{
                            }
    
    		     if (moveto == '6' && fx <= 49)
    		       {fx=fx++;}
    
    		     if (moveto == '5' && fy <= 20)
    		       {fy=fy++;}
    
    		   pic[fx][fy]='##';
    		   pic[fx+1][fy+1]='##';
       		   gotoxy(fx  ,fy )   ; printf ("##");
       		   gotoxy(fx+1,fy+1)  ; printf  ("##");
    
    		   gotoxy(fx+1,fy);
    
    		  if (moveto == '8' && fx <= 50 && fy <= 21)
    			{
    			 gotoxy(fx  ,fy)    ; printf  ("..");
    			 gotoxy(fx+1,fy+1)  ; printf   ("..");
    
    		         gotoxy(fx+1,fy-1)    ; printf  ("#");
    			 gotoxy(fx ,fy)  ; printf ("##");
    			 gotoxy(fx ,fy+1)  ; printf ("#");
    
    			 figur3b(fx,fy);    
    		}
    
    	if (moveto == '8' )
    	  {
    	   fx = 42;
               fy =  2;
    	   gotoxy(fx,fy);
    	   figur3(fx,fy);
    	  }
         }
    return(0);
    }
    
    /////////////////////////////////////
    int figur3b(int fx, int fy)
    
    {
    
     char moveto;
    
     //fx=42;
     //fy=2;
    
     gotoxy(fx,fy);
    
    	while (moveto != '2')
    		{
    
        		  moveto = getch();
    
    			 gotoxy(fx+1,fy-1)    ; printf  (".");
      		         gotoxy(fx  ,fy)      ; printf ("..");
    			 gotoxy(fx  ,fy+1)  ; printf (".");
    
       		   if (moveto == '4' && fx >= 34)
       		     {fx=fx--;}
       		   if (moveto == '6' && fx <= 50)
       		     {fx=fx++;}
    		   if (moveto == '5' && fy <= 20)
    		     {fy=fy++;}
    
    		         gotoxy(fx+1,fy-1)    ; printf  ("#");
      		         gotoxy(fx  ,fy)  ; printf ("##");
    			 gotoxy(fx  ,fy+1)  ; printf ("#");
    
       		   gotoxy(fx+1,fy);
    
        		  if (moveto == '8' && fx <= 50)
    			{
    			 gotoxy(fx+1,fy-1)      ; printf  (".");
      		         gotoxy(fx,fy)  ; printf ("..");
    			 gotoxy(fx  ,fy+1)    ; printf (".");
    
    			 gotoxy(fx  ,fy)    ; printf  ("##");
    			 gotoxy(fx+1,fy+1)  ; printf   ("##");
    
    			 figur3(fx,fy);
    		}
    
         }
    return(0);
    }
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////
    int main (void)
    
    {
    picer();
    figur3(42,2);
    
    return (0);
    
    }
    

    So, nun das Problem, wenn man das öffnet, die figur geht nicht mehr nach links, weiß jemand wieso? muss hierran eigentlich liegen, oder?:

    if(pic[fx-2][fy]=='.')
                         {
       		     if (moveto == '4' && fx >= 34)
    		       {fx=fx--;}
                         }
                         if (fx+2 != '0')
    			{
                            }
    
    		     if (moveto == '6' && fx <= 49)
    		       {fx=fx++;}
    
    		     if (moveto == '5' && fy <= 20)
    		       {fy=fy++;}
    
    		   pic[fx][fy]='##';
    		   pic[fx+1][fy+1]='##';
       		   gotoxy(fx  ,fy )   ; printf ("##");
       		   gotoxy(fx+1,fy+1)  ; printf  ("##");
    
    		   gotoxy(fx+1,fy);
    
    		  if (moveto == '8' && fx <= 50 && fy <= 21)
    			{
    			 gotoxy(fx  ,fy)    ; printf  ("..");
    			 gotoxy(fx+1,fy+1)  ; printf   ("..");
    
    		         gotoxy(fx+1,fy-1)    ; printf  ("#");
    .....
    


  • Tja, wohl pech gehabt



  • keiner nen rat`?


Anmelden zum Antworten