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
|
#include <iostream>
#include <conio.h>
#include <windows.h>
#define longcode if (square[1]==" o ") a=1;\
if (square[2]==" o ") a=2;\
if (square[3]==" o ") a=3;\
if (square[4]==" o ")a=4;\
if (square[5]==" o ")a=5;\
if (square[6]==" o ")a=6;\
if (square[7]==" o ")a=7;\
if (square[8]==" o ")a=8;\
if (square[9]==" o ")a=9;\
if (square[10]==" o ")a=10;\
if (square[11]==" o ")a=11;\
if (square[12]==" o ")a=12;\
if (square[13]==" o ")a=13;\
if (square[14]==" o ")a=14;\
if (square[15]==" o ")a=15;\
if (square[16]==" o ")a=16;\
if (square[17]==" o ")a=17;\
if (square[18]==" o ")a=18;\
if (square[19]==" o ")a=19;\
if (square[20]==" o ")a=20;\
if (square[21]==" o ")a=21;\
if (square[22]==" o ")a=22;\
if (square[23]==" o ")a=23;\
if (square[24]==" o ")a=24;\
if (square[25]==" o ")a=25;\
// longcode makes PC memorize what is my current spot in the grid.
//If a equals 23 that means I'm in the 23rd square.
//Code basically works like this:
//I press " d ", that means object is going down the grid .
// Now I set value squareCo, which is coordinate of my current location, to be squareCo+5, because that square is 5 squares away from me (counting to the right).
//To make PC memorize where I am I call the "longcode", which checks if any of the squares are " o ", which mean if I'm in one of the squares.
// If I am, it sets "a" value to the square number, for example, if i'm in 2nd square, that means a will equal to 2.
// I need to use separate variable for that, because loops mess with my squareCo, always making it's value 25, so I use a help, because a doesn't change.
using namespace std;
int main()
{
string square[10000]; // I have no idea what to set in the [] so I always type a high number there
int squareCo=0,a=0,y; // y is basically my button (wasd) , a is coordinate helper
do {square[squareCo]=" . "; squareCo++;} while (squareCo<=30); // I set " . " to every value of square, that means grid will be made of " . "
squareCo=0; // square coordination goes to the beginning , so I can make a new grid
square[1]= " o "; // my current "location"
do {squareCo++; cout << x[squareCo]; if (squareCo%5==0) cout << endl;} while (squareCo<=24); // I make the grid visible
squareCo=0; // again going back to the beginning
cout << "hello." << endl;
square[1]=" . "; // as I know with next press character will move somewhere, I immediately set starting value to " . "
// which means that the character is somewhere else
a=1; // setting my helper to the beginning position too
while (true)
{
char y=_getch(); // waiting for my button press
if ((y=='s') and (a<21)) // as you probably understand, y button press, which lets you move,
// and a<21 means that if you are in 21th square you can't move down anymore.
{ system("CLS"); // a shameful function, I know
if (squareCo==0) square[squareCo+6]=" o "; // if my coordinate was 0 from the start, I will move 6 squares forwards
else if (squareCo>0) square[squareCo+5]=" o "; // else I will move only 5
squareCo=0; // as I have to paint the grid I set this to zero
while (squareCo<=24) // painting the grid
{
squareCo++;
cout << square[squareCo]; if (squareCo%5==0) cout << endl;
} longcode; // checks where I am now and sets "a" value to the same as the square which I'm standing in right now (as for "I'm" I mean the character, which is " o ")
squareCo=a; // because square coordinate was made to 25 by the loop, I make PC "remember" where I'm currently standing with "a" help, because "a" doesn't change.
square[squareCo]=" . "; // as I know I will move somewhere I immediately set my current location to " . ", that means " o " is somewhere else
}
if ((y=='w') and (a>=6))
{ system("CLS");
square[squareCo-5]=" o ";
squareCo=0;
while (squareCo<=24)
{
squareCo++;
cout << square[squareCo]; if (squareCo%5==0) cout << endl;
} longcode;
squareCo=a;
square[squareCo]=" . ";
}
if ((y=='a') and (a!=1) and (a!=6) and (a!=11) and (a!=16) and (a!=21))
{ system("CLS");
square[squareCo-1]=" o ";
squareCo=0;
while (squareCo<=24)
{
squareCo++;
cout << square[squareCo]; if (squareCo%5==0) cout << endl;
} longcode;
squareCo=a;
square[squareCo]=" . ";
}
if ((y=='d') and (a!=5) and (a!=10) and (a!=15) and (a!=20) and (a!=25)) // that means if you are somewhere on the edge, like 10th square, you can't move right anymore.
{ system("CLS");
square[squareCo+1]=" o ";
squareCo=0;
while (squareCo<=24)
{
squareCo++;
cout << square[squareCo]; if (squareCo%5==0) cout << endl;
} longcode;
squareCo=a;
square[squareCo]=" . ";
}
if (a==25) {cout << "YOU WON!"; break;}
}
cin.ignore(); cin.get();
}
|