C++ Snake programmieren, aber wie?

Hallo, ich schreibe gerade an einem Spiel(Snake) in c++. Ich weiß aber nicht wie ich die punkte einfüge die die schlange dann einsammeln kann, wie ich die Schlange länger mache und wie ich die kollision zwischen schlangenkopf und schlangenkörper integriere.

Hier mein bisheriger code:

include <conio.h> include <Windows.h> include

using namespace std;

const int rechts = 'd'; const int links = 'a'; const int hoch = 'w'; const int runter = 's'; const int prechts = 0x4d; //Hexadezimale codes der Pfeiltasten const int plinks = 0x4b; const int phoch = 0x48; const int prunter = 0x50;

void Bewegung(int, int);

int main() { bool ende = false; int x = 12; //x Koordniate (erst definition = Startpunkt) int < = 10; //y Koordniate (erst definition = Startpunkt) int richtung = 1; int punkt = 0;

cout << "Punkte " << punkte << endl; cout <<"XXXXXXXXXXXXXXXXXXXXXXXXX"<<endl; for(int i = 1; i < 24; i++) { cout << "X X"<<endl; } cout <<"XXXXXXXXXXXXXXXXXXXXXXXXX"<<endl;

do { Bewegung(x, y); cout << "o";

if(kbhit()) { int taste = getch(); if(!taste || taste == 0xe0)) taste = getch();

if(taste == hoch && richtung != 2 || taste == phoch && richtung != 2) { richtung = 1; --y; }

else if(taste == runter && richtung != 1 || taste == prunter && richtung != 1) { richtung = 2; ++y; }

else if(taste == rechts && richtung != 4 || taste == prechts && richtung != 4) { richtung = 3; ++x; }

else if(taste == links && richtung != 3 || taste == plinks && richtung != 3)

else { continue; }

Sleep(150); }

else if(!kbhit()) { if(richtung == 1) { --y; } if(richtung == 2) { ++y; } if(richtung == 3) { ++x; } if(richtung == 4) { --x; } Sleep(150); }

system("cls");

if( x <= 0 || x >= 24 || x <= 1 || y >= 25) { cout << "Game Over!" << endl << endl; cout << "Du hast " << punkte << " Punkte erreicht" << endl << endl; system("pause"); return 0; }

cout << "Punkte " << punkte << endl; cout <<"XXXXXXXXXXXXXXXXXXXXXXXXX"<<endl; for(int i = 1; i < 24; i++) { cout << "X X"<<endl; } cout <<"XXXXXXXXXXXXXXXXXXXXXXXXX"<<endl;

}while(true);

return 0; }

void Bewegung(int b, int h) { COORD punkt; punkt.X = b; punkt.Y = h; SetConsoleCursorPosition(GetStdHandle(STDOUTPUTHANDLE), punkt); }

...zur Frage

Da die Formatierung durch das Kopieren auf diese Seite verloren gegangen ist, gibt es hier nochmal einen Link zum formatierten sourcecode:

http://pastebin.com/JRvXZ321

...zur Antwort
Weitere Inhalte können nur Nutzer sehen, die bei uns eingeloggt sind.