Hello guys,
Snake just hates me,I just cannot create it in any way, how it can it possible? Anyone can help me? I'm mad...
Code:
#include <cstdlib>#include <Windows.h>
#include <iostream>
#include <ctime>
#include <conio.h>
using namespace std;
void setcolor(unsigned char color)
{
HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hcon,color);
}
void sp(int spalva)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), spalva);
}
void s()
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
}
class Lithuania
{
protected:
double Scoore;
int rad,FailRandm,x, y,a,b,i,SnakeLength = 2,previous;
char Ibiza [2400], key;
bool down ,left,right,up ;
public:
Lithuania()
{
Scoore = 0 ;
x = 1560;
y = 1400;
down = 0 ;
left = 0 ;
right = 0 ;
up = 0 ;
previous = 0;
i = 0;
}
void clearscreen ();
void ToGetRandomApple();
void CheckRight ();
void CheckLeft ();
void ConstSnake ();
void Keyboard ();
void MoveLogic ();
void Keyboard2 ();
}jaja;
int main()
{
jaja.ConstSnake();
}
void Lithuania ::ToGetRandomApple()
{
if(x < 0 || x > 4800 ){cout << endl << "\n\nGame Over!";cout << "You earned:" << Scoore/125;cin.ignore();}
if(Ibiza[rad] == Ibiza[x]){
Scoore += 2;
SnakeLength++;
if( left == true )
{
x--;
}
else if( down == true )
{
x+=80;
}
else if( up == true )
{
x-=80;
}
else if( right == true )
{
x++;
}
rad = rand()%48;
FailRandm = rand()&48;
rad*=FailRandm;
}}
void Lithuania ::ConstSnake()
{
srand((unsigned)time(0));
system("color 19");
rad = rand() % 2400+1;
do{
cout << "Dollers=" << Scoore/125 << " " <<endl;
cout << "LEFT=" << left << endl << "DOWN=" << down << endl << "UP=" << up << endl << "RIGHT=" << right;
cout << "Previous=" << previous << endl<<endl;
jaja.ToGetRandomApple();
setcolor(15);
for(i = 0 ; i < 2400 ; i++)
{
if(x == y)
{
cout << "LOL NOOB";
cin.ignore();
}
if(x != i && y != i && rad != i)
{
cout << Ibiza[i];
}
else if(i == x)
{
Ibiza[i] = 219;
sp(240);
cout << Ibiza[i] ;
}
else if(i == rad)
{
Ibiza[rad] = 1;
cout << Ibiza[i];
}
else
{
sp(240);
Ibiza[i] = 173;
cout << Ibiza[i] ;
}
s();
}
jaja.Keyboard ();
jaja.MoveLogic();
jaja.clearscreen ();
}
while(true);
}
void Lithuania::clearscreen()
{
HANDLE hOut;
COORD Position;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
Position.X = 0;
Position.Y = 0;
SetConsoleCursorPosition(hOut, Position);
}
void Lithuania::Keyboard()
{
if(kbhit()){
key = getch();
jaja.Keyboard2();
cout << y;
switch( key )
{
case 'd':
{
if (left == 0) {
left = 0, up = 0, down = 0,
right = 1;
}
break;
}
case 'w':
{
if (down == 0) {
left = 0, down = 0, right = 0,
up = 1;
}
break;
}
case 'a':
{
if (right == 0) {
down = 0, up = 0, right = 0,
left = 1;
}
break;
}
case 's':
{
if (up == 0) {
left = 0, up = 0, right = 0,
down = 1;
}
break;
}
}
}
}
void Lithuania::MoveLogic()
{
if(left == 1 && right == 0)
{
if(previous == 2)
{
x--;
if(x !=y-SnakeLength)
{
y+=80;
}
else y--;
}
else if(previous == 4)
{
x--;
if(x !=y-SnakeLength)
{
y-=80;
}
else y--;
}
else if(previous == 1)
{
x--;
y--;
}
}
else if(left == 0 && right == 1)
{
if(previous == 2)
{
x++;
if(x!=y+SnakeLength)
{
y+=80;
}
else y++;
}
else if(previous == 4)
{
x++;
if(x!=y+SnakeLength)
{
y-=80;
}
else y++;
}
else if(previous == 3)
{
x++;
y++;
}
}
else if(down == 1 && right == 0)
{
if(previous == 2)
{
x+=80;
y+=80;
}
else if(previous == 3)
{
x+=80;
if(x!=y+SnakeLength * 80)
{
y++;
}
else y+=80;
}
else if(previous == 1)
{
x+=80;
if(x!=y+SnakeLength * 80)
{
y--;
}
else y+=80;
}
}
else if(up == 1 && right == 0)
{
if(previous == 3)
{
x-=80;
if(x!=y-80*SnakeLength)
{
y++;
}
else y-=80;
}
else if(previous == 4)
{
x-=80;
y-=80;
}
else if(previous == 1)
{
x-=80;
if(x!=y-80*SnakeLength)
{
y--;
}
else y-=80;
}
}
}
void Lithuania::Keyboard2()
{
if( left == true )
{
previous = 1;
}
else if( down == true )
{
previous = 2;
}
else if( up == true )
{
previous = 4;
}
else if( right == true )
{
previous = 3;
}
else {;}
}