Cześć!!
Jak poruszam snakiem to pokazuje się długość tylko w górę oraz lewo, nie wiem dlaczego nie pokazuje się jak dam w prawo lub dół. Kod:
#include <iostream>
#include <conio.h>
#include <time.h>
#include <cstdlib>
using namespace std;
void wczytaj_plansze_first( int candyx, int candyy);
void plansza(int x[100], int y[100], int candyx, int candyy, int pk);
int steruj(int x[100], int y[100]);
void game_over(int score);
int main() {
int x[100];
int y[100];
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<" Witaj!!\n Aby rozpoczac gre wcisnij enter: ";
getch();
cout<<endl;
int candyx;
int candyy;
system("cls");
cout<<candyx<<" "<<candyy<<endl;
wczytaj_plansze_first( candyx, candyy);
int pk;
pk=0;
x[0]=1;
y[0]=1;
candyx=20;
candyy=20;
for(;;)
{
char znak;
znak=getch();
for(int i=pk;i>=1;i--)/////////////ten fragment tworzy dlugosc snake ale tylko w kierunku gora i lewo////////////////////////////////////////
{
x[i]=x[i-1];
y[i]=y[i-1];
}
if(znak=='w'||znak=='W')y[0]--;
else if(znak=='s'||znak=='S')y[0]++;
else if(znak=='a'||znak=='A')x[0]--;
else if(znak=='d'||znak=='D')x[0]++;
system("cls");
if(x[0]==35||y[0]==41||x[0]==0||y[0]==0)game_over(pk);
if(x[0]==candyx&&y[0]==candyy)
{
srand(time(NULL));
candyx=rand()%34+1;
candyy=rand()%39+1;
pk++;
}
cout<<"Score: "<<pk<<endl;
cout<<candyx<<" "<<candyy<<endl;
cout<<x[0]<<" "<<y[0]<<endl;
plansza(x, y, candyx, candyy, pk);
}
return 0;
}
void wczytaj_plansze_first( int candyx, int candyy)
{
for(int i=0;i<=35;i++)cout<<'#';
cout<<endl;
for(int i=1;i<=40;i++)
{
for(int k=0;k<=35;k++)
{
if(i==1&&k==1)
{
cout<<"S";
}
else if(i==candyy&&k==candyx)cout<<"@";
else
{
if(k==0||k==35)cout<<'#';
else cout<<' ';
}
}
cout<<endl;
}
for(int i=0;i<=35;i++)cout<<'#';
cout<<endl;
}
void plansza(int x[100], int y[100], int candyx, int candyy, int pk)
{
int licznik=0;
for(int i=0;i<=35;i++)
{
cout<<'#';
}
cout<<endl;
for(int i=1;i<=40;i++)
{
for(int k=0;k<=35;k++)
{
if(i==y[licznik]&&k==x[licznik])
{
cout<<"S";
licznik++;
}
else if(i==candyy&&k==candyx)cout<<"@";
else
{
if(k==0)
{
cout<<'#';
}
else if(k==35)
{
cout<<'#';
}
else
{
cout<<' ';
}
}
}
cout<<endl;
}
for(int i=0;i<=35;i++)
{
cout<<'#';
}
cout<<endl;
}
void game_over(int score)
{
system("cls");
cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
cout<<" Game over!!\n Twoj wynik to: "<<score;
cout<<"\n Play again: ";
getch();
system("cls");
main ();
}
Wiem, że w tym jeszcze jest dużo do dopracowania ale na razie chcę to naprawić.