1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
#include <iostream>
#define _WIN32_WINNT 0x0500 //Win 2000 or later
#include <conio.h> //By CosminPerRam
#include <stdlib.h>
#include <windows.h>
#include <unistd.h>
#include <string>
#include <ctime> //TODO:
#include <cstdlib> //2)User character to leave a trail in passed cords
//3)Levels
//4)Auto-Move
using namespace std;
short int x, y, xp, yp, av = 0, po = 0, gtv, fmp, fcx, fcy, sps, fcxr, fcyr, rw = 425, rh = 260, ssrw, ssrh, lmv;
string pre, gt;
char ch, p;
int reterr()
{
getch();
system("cls");
cout<<"Fatal Error, application may crash!"<<endl;
return 0;
}
int main()
{
::SendMessage(::GetConsoleWindow(), WM_SYSKEYDOWN, VK_RETURN, 0x20000000);
//presets
HWND console = GetConsoleWindow();
RECT r; //resolution things
GetWindowRect(console, &r);
MoveWindow(console, r.left, r.top, rw, rh, TRUE);
srand(time(0));
//start
cout<<"Welcome to Snake!"<<endl;
cout<<"(You can exit by pressing the ESCAPE button!)"<<endl;
cout<<"Choose the type of gameplay!"<<endl;
cout<<"Level (L) - Free (F): ";
cin >> gt;
system("cls");
if(gt == "level" || gt == "Level" || gt == "L" || gt == "l" || gt == "LEVEL")
{
cout<<"Level-run selected!"<<endl;
gtv += 2;
}
else if(gt == "free" || gt == "Free" || gt == "F" || gt =="f" || gt == "FREE")
{
cout<<"Free-run selected!"<<endl;
gtv += 1;
}
else{reterr();}
getch();
system("cls");
cout<<"Simple (S) - Advanced (A)"<<endl;
cout<<"Choose your start-up setting type: ";
cin >> pre;
if(pre =="s" || pre =="S" || pre =="Simple" || pre =="simple" || pre =="SIMPLE")
{
system("cls");
cout<<"Enter your character: ";
cin >> ch;
p = '+';
fcx= 25;
fcy= 13;
fmp= 10;
if(gtv == 2)
{
fcx= 13;
fcy= 25;
}
system("cls");
}
else if(pre =="a" || pre =="A" || pre =="Advanced" || pre =="advanced" || pre =="ADVANCED")
{
system("cls");
cout<<"Enter your character: ";
cin >> ch;
system("cls");
cout<<"Enter the point character: ";
cin >> p;
system("cls");
cout<<"Value of max points: ";
cin >> fmp;
system("cls");
if(gtv == 1)
{
while(sps == 0)
{
cout<<"How high your last point want to be?(x cord): ";
cin >> fcx;
if(5 >= fcx) {cout<<"Need to be at least !"<<endl;}
if(fcx >= 6) {sps =+ 1;}
if(fcx <= 15){ssrw =+ 1;}
}
sps = 0;
while(sps == 0)
{
cout<<"How high your last point want to be?(y cord): ";
cin >> fcy;
if(5 >= fcy) {cout<<"Need to be at least 6!"<<endl;}
if(fcy >= 6) {sps =+ 1;}
if(fcy <= 15){ssrh =+ 1;}
}
sps = 0;
system("cls");
}
}
else{reterr();}
if(gtv == 2)
{
cout<<"Not developed already!"<<endl;
//continue here m8!
return 0;
}
else if(gtv == 1)
{
rw = fcx * 10.5;
if(ssrw == 1){rw = fcx *20;}
rh = fcy * 18.5;
if(ssrh == 1){rh = fcy *25;}
MoveWindow(console, r.left, r.top, r.right - r.left, r.bottom - r.top, FALSE);
MoveWindow(console, r.left, r.top, rw, rh, FALSE);
fcxr = fcx - 1;
fcyr = fcy - 1;
system("cls");
while(1)
{
while(xp == 0 || yp == 0)
{
xp=rand()%fcxr;
yp=rand()%fcyr;
}
av=getch();
if(av==27)
{
system("cls");
cout<<"Points: "<<po<<endl;
return 0;
}
if(lmv == 0;){ How to do it?}
if(lmv == 1;){}
if(lmv == 2;){}
if(lmv == 3;){}
if(av==72){y = y - 1; lmv = 0;} //UP
if(av==80){y = y + 1; lmv = 1;} //DOWN
if(av==75){x = x - 1; lmv = 2;} //LEFT //keys
if(av==77){x = x + 1; lmv = 3;} //RIGHT
if(x==0){x = 1;} //Protection for border //begin
if(y==0){y = 1;}
if(x==fcx){x = fcxr;} //Protection for border //end
if(y==fcy){y = fcyr;}
system("cls");
COORD coord = {x, y};
SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE), coord);
cout<<ch;
COORD coord2 = {xp, yp};
SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE), coord2);
cout<<p;
if(x == xp && y == yp)
{
po += 1;
xp=rand()%fcxr;
yp=rand()%fcyr;
if(fmp == po)
{
system("cls");
cout<<"Max points ("<<fmp<<") has been reached, congratulations!"<<endl;
return 0;
}
}
}
}
else{reterr();}
return 0;
}
|