<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Snake]]></title><description><![CDATA[<p>Hi Leute!<br />
ich hab folgendes Problem:<br />
ich will als kleines Programm 'Snake' schreiben. ich habe schon so eine ungefähre Ahnung wie das funktionieren soll. allerdings macht der computer nicht was ich will sondern irgendwas. schaut euch bitte den code an und sagt mir was ich falsch gemacht haben könnte. Danke!!<br />
(ich denke mal nicht, dass ich die #include befehle dazupacken muss <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> )</p>
<pre><code>int main()
{
    char position[15][15];
    char richtung;
    int irichtung[225]={4};
    int f_x=0, f_y=0;
    int pos_s_x[225]={0}, pos_s_y[225]={0};
    int zs_pos_s_x[225], zs_pos_s_y[225];
    int score=1;
    bool tot;
    bool fressen_vorhanden=false;
    srand(time(NULL));
    for(int k=0; k&lt;15; k++)
    {
            for(int l=0; l&lt;15; l++)
            {
                    position[l][k]=' ';
            }
    }
    position[0][0]='S';

    while(!tot)
    {
         system(&quot;cls&quot;);
         for(int i=0; i&lt;15; i++)
         {
                for(int j=0; j&lt;15; j++)
                {
                        cout&lt;&lt;position[j][i];        
                }
                cout&lt;&lt;'|'&lt;&lt;endl;
         }
         cout&lt;&lt;&quot;----------------&quot;&lt;&lt;endl;
         cout&lt;&lt;endl&lt;&lt;irichtung[1]&lt;&lt;' '&lt;&lt;pos_s_x[1]&lt;&lt;' '&lt;&lt;pos_s_y[1];
         if(position[f_x][f_y]=='S')
         {
                score++;
                switch(irichtung[score-1])                          
                {
                       case 1:
                            pos_s_x[score]=pos_s_x[score-1];
                            pos_s_y[score]=pos_s_y[score-1]-1; 
                            break;

                       case 2:
                            pos_s_x[score]=pos_s_x[score-1]-1;
                            pos_s_y[score]=pos_s_y[score-1];
                            break;

                       case 3:
                            pos_s_x[score]=pos_s_x[score-1];
                            pos_s_y[score]=pos_s_y[score-1]+1;
                            break;

                       case 4:
                            pos_s_x[score]=pos_s_x[score-1]+1;
                            pos_s_y[score]=pos_s_y[score-1];
                            break;                  
                }
                fressen_vorhanden=false;
         }
         if(!fressen_vorhanden)
         {
                f_x=rand()%15+1;
                f_y=rand()%15+1;
                for(int p=0; p&lt;score; p++)
                {
                if(f_x!=pos_s_x[p]&amp;&amp;f_y!=pos_s_y[p])
                {
                      fressen_vorhanden=true;   
                      position[f_x][f_y]='o';
                }      
                }             
         }
         Sleep(100); 
         if(kbhit())
         {
                richtung=getch();
                switch(richtung)
                {
                       case 'w':
                            if(irichtung[1]!=3){irichtung[1]=1;}
                            break;

                       case 'a':
                            if(irichtung[1]!=4){irichtung[1]=2;}
                            break;                

                       case 's':
                            if(irichtung[1]!=1){irichtung[1]=3;}
                            break;

                       case 'd':
                            if(irichtung[1]!=2){irichtung[1]=4;}
                            break;
                }
         }
         for(int o=0; o&lt;score; o++)
         {
         switch(irichtung[o])
         {
                case 1:
                     position[pos_s_x[o&rsqb;&rsqb;[pos_s_y[o&rsqb;&rsqb;=' ';
                     pos_s_y[o]=(pos_s_y[o]-1)%15;
                     position[pos_s_x[o&rsqb;&rsqb;[pos_s_y[o&rsqb;&rsqb;='S';
                     break;

                case 2:
                     position[pos_s_x[o&rsqb;&rsqb;[pos_s_y[o&rsqb;&rsqb;=' ';
                     pos_s_x[o]=(pos_s_x[o]-1);
                     if(pos_s_x[o]&lt;0){pos_s_x[o]=14;}
                     position[pos_s_x[o&rsqb;&rsqb;[pos_s_y[o&rsqb;&rsqb;='S';
                     break;

                case 3:
                     position[pos_s_x[o&rsqb;&rsqb;[pos_s_y[o&rsqb;&rsqb;=' ';
                     pos_s_y[o]=(pos_s_y[o]+1)%15;
                     position[pos_s_x[o&rsqb;&rsqb;[pos_s_y[o&rsqb;&rsqb;='S';
                     break;

                case 4:
                     position[pos_s_x[o&rsqb;&rsqb;[pos_s_y[o&rsqb;&rsqb;=' ';
                     pos_s_x[o]=(pos_s_x[o]+1)%15;
                     position[pos_s_x[o&rsqb;&rsqb;[pos_s_y[o&rsqb;&rsqb;='S';
                     break;          

         }
         }
         for(int p=score; p&gt;=0; p--)
         {
                 irichtung[p]=irichtung[p-1];
         }

    }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/304190/snake</link><generator>RSS for Node</generator><lastBuildDate>Mon, 10 Aug 2026 00:49:50 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/304190.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 31 May 2012 14:12:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Snake on Thu, 31 May 2012 14:12:22 GMT]]></title><description><![CDATA[<p>Hi Leute!<br />
ich hab folgendes Problem:<br />
ich will als kleines Programm 'Snake' schreiben. ich habe schon so eine ungefähre Ahnung wie das funktionieren soll. allerdings macht der computer nicht was ich will sondern irgendwas. schaut euch bitte den code an und sagt mir was ich falsch gemacht haben könnte. Danke!!<br />
(ich denke mal nicht, dass ich die #include befehle dazupacken muss <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> )</p>
<pre><code>int main()
{
    char position[15][15];
    char richtung;
    int irichtung[225]={4};
    int f_x=0, f_y=0;
    int pos_s_x[225]={0}, pos_s_y[225]={0};
    int zs_pos_s_x[225], zs_pos_s_y[225];
    int score=1;
    bool tot;
    bool fressen_vorhanden=false;
    srand(time(NULL));
    for(int k=0; k&lt;15; k++)
    {
            for(int l=0; l&lt;15; l++)
            {
                    position[l][k]=' ';
            }
    }
    position[0][0]='S';

    while(!tot)
    {
         system(&quot;cls&quot;);
         for(int i=0; i&lt;15; i++)
         {
                for(int j=0; j&lt;15; j++)
                {
                        cout&lt;&lt;position[j][i];        
                }
                cout&lt;&lt;'|'&lt;&lt;endl;
         }
         cout&lt;&lt;&quot;----------------&quot;&lt;&lt;endl;
         cout&lt;&lt;endl&lt;&lt;irichtung[1]&lt;&lt;' '&lt;&lt;pos_s_x[1]&lt;&lt;' '&lt;&lt;pos_s_y[1];
         if(position[f_x][f_y]=='S')
         {
                score++;
                switch(irichtung[score-1])                          
                {
                       case 1:
                            pos_s_x[score]=pos_s_x[score-1];
                            pos_s_y[score]=pos_s_y[score-1]-1; 
                            break;

                       case 2:
                            pos_s_x[score]=pos_s_x[score-1]-1;
                            pos_s_y[score]=pos_s_y[score-1];
                            break;

                       case 3:
                            pos_s_x[score]=pos_s_x[score-1];
                            pos_s_y[score]=pos_s_y[score-1]+1;
                            break;

                       case 4:
                            pos_s_x[score]=pos_s_x[score-1]+1;
                            pos_s_y[score]=pos_s_y[score-1];
                            break;                  
                }
                fressen_vorhanden=false;
         }
         if(!fressen_vorhanden)
         {
                f_x=rand()%15+1;
                f_y=rand()%15+1;
                for(int p=0; p&lt;score; p++)
                {
                if(f_x!=pos_s_x[p]&amp;&amp;f_y!=pos_s_y[p])
                {
                      fressen_vorhanden=true;   
                      position[f_x][f_y]='o';
                }      
                }             
         }
         Sleep(100); 
         if(kbhit())
         {
                richtung=getch();
                switch(richtung)
                {
                       case 'w':
                            if(irichtung[1]!=3){irichtung[1]=1;}
                            break;

                       case 'a':
                            if(irichtung[1]!=4){irichtung[1]=2;}
                            break;                

                       case 's':
                            if(irichtung[1]!=1){irichtung[1]=3;}
                            break;

                       case 'd':
                            if(irichtung[1]!=2){irichtung[1]=4;}
                            break;
                }
         }
         for(int o=0; o&lt;score; o++)
         {
         switch(irichtung[o])
         {
                case 1:
                     position[pos_s_x[o&rsqb;&rsqb;[pos_s_y[o&rsqb;&rsqb;=' ';
                     pos_s_y[o]=(pos_s_y[o]-1)%15;
                     position[pos_s_x[o&rsqb;&rsqb;[pos_s_y[o&rsqb;&rsqb;='S';
                     break;

                case 2:
                     position[pos_s_x[o&rsqb;&rsqb;[pos_s_y[o&rsqb;&rsqb;=' ';
                     pos_s_x[o]=(pos_s_x[o]-1);
                     if(pos_s_x[o]&lt;0){pos_s_x[o]=14;}
                     position[pos_s_x[o&rsqb;&rsqb;[pos_s_y[o&rsqb;&rsqb;='S';
                     break;

                case 3:
                     position[pos_s_x[o&rsqb;&rsqb;[pos_s_y[o&rsqb;&rsqb;=' ';
                     pos_s_y[o]=(pos_s_y[o]+1)%15;
                     position[pos_s_x[o&rsqb;&rsqb;[pos_s_y[o&rsqb;&rsqb;='S';
                     break;

                case 4:
                     position[pos_s_x[o&rsqb;&rsqb;[pos_s_y[o&rsqb;&rsqb;=' ';
                     pos_s_x[o]=(pos_s_x[o]+1)%15;
                     position[pos_s_x[o&rsqb;&rsqb;[pos_s_y[o&rsqb;&rsqb;='S';
                     break;          

         }
         }
         for(int p=score; p&gt;=0; p--)
         {
                 irichtung[p]=irichtung[p-1];
         }

    }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2217784</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2217784</guid><dc:creator><![CDATA[Clundsch]]></dc:creator><pubDate>Thu, 31 May 2012 14:12:22 GMT</pubDate></item><item><title><![CDATA[Reply to Snake on Thu, 31 May 2012 14:22:00 GMT]]></title><description><![CDATA[<p>also im moment fehlen mir natürlich noch der code, wie man stirbt, aber ich will erst mal eine zusammenhängende schlange hinbekommen (da liegt mein problem)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2217788</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2217788</guid><dc:creator><![CDATA[Clundsch]]></dc:creator><pubDate>Thu, 31 May 2012 14:22:00 GMT</pubDate></item><item><title><![CDATA[Reply to Snake on Thu, 31 May 2012 14:23:52 GMT]]></title><description><![CDATA[<p>Clundsch schrieb:</p>
<blockquote>
<p>Hi Leute!<br />
ich hab folgendes Problem:<br />
ich will als kleines Programm 'Snake' schreiben. ich habe schon so eine ungefähre Ahnung wie das funktionieren soll. allerdings macht der computer nicht was ich will sondern irgendwas. schaut euch bitte den code an und sagt mir was ich falsch gemacht haben könnte. Danke!!</p>
</blockquote>
<p>Soso. &quot;Irgendwas&quot; macht er. Meinst du, wir können was damit anfangen? Lies dir bitte mal die als wichtig gekennzeichneten Threads hier im Forum durch oder die Links in meiner Signatur, da erfährst du, wie man beantwortbare Fragen stellt.</p>
<blockquote>
<p>(ich denke mal nicht, dass ich die #include befehle dazupacken muss <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> )</p>
</blockquote>
<p>Doch, jede Menge. srand, system, cout, Sleep, khbit. Alles keine Schlusselwörter, sondern Funktionen/Objekte aus einer Bibliothek. Im Falle von Sleep und khbit nicht einmal die Standardbibliothek.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2217789</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2217789</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 31 May 2012 14:23:52 GMT</pubDate></item><item><title><![CDATA[Reply to Snake on Thu, 31 May 2012 14:28:43 GMT]]></title><description><![CDATA[<p>erstmal danke für die schnelle antwort. und ja ich weiß, dass ich es blöd erklärt habe. also hier meine problemschilderung:<br />
1. Fehler: Die 'Schlange' bewegt sich nicht automatisch, wie sie es eigentlich sollte.<br />
2. Fehler: sobald ich ein teilchen 'fresse' erscheint nicht hinter dem letzten schlangenglied ein neues, sondern irgendwo in der obersten zeile.</p>
<p>hoffe das war gut genug geschildert.<br />
hier der header:</p>
<pre><code>#include &lt;iostream&gt;
#include &lt;windows.h&gt;
#include &lt;cstdlib&gt;
#include &lt;conio.h&gt;
#include &lt;time.h&gt;
using namespace std;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2217794</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2217794</guid><dc:creator><![CDATA[Clundsch]]></dc:creator><pubDate>Thu, 31 May 2012 14:28:43 GMT</pubDate></item><item><title><![CDATA[Reply to Snake on Fri, 01 Jun 2012 11:41:45 GMT]]></title><description><![CDATA[<p>Problem gelöst, trotzdem danke für die eine Antwort <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2218090</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2218090</guid><dc:creator><![CDATA[Clundsch]]></dc:creator><pubDate>Fri, 01 Jun 2012 11:41:45 GMT</pubDate></item></channel></rss>