#include #include #include #include #include using namespace std; int main(int argc, char *argv[]) { // ohnoes >_< it's the variables n stuff :O struct gridtiles { char location; int event; }; const int gridmaxx= 20; const int gridmaxy = 30; const int background = 176; const int player = 254; int movement; bool win; short newlocx = 4 , newlocy = 4; double random; bool winlocationset = false; srand (time(0)); //random seed gridtiles grid[gridmaxx][gridmaxy]; //make grid //prepare grid while (winlocationset == false) //loop until a win loaction has been set { for (short xgridindex = 0; xgridindex <= (gridmaxx - 1); xgridindex++) // loop for every x { for (short ygridindex = 0; ygridindex <= (gridmaxy - 1); ygridindex++) // loop for every y { grid[xgridindex][ygridindex].location = background; //draw a background tile random = static_cast (rand()) / RAND_MAX; //get a random number if (random >= 0.9 && winlocationset == false) // check if this is the winloaction { grid[xgridindex][ygridindex].event = 1; //set the win location winlocationset = true; // let the loop know the location has been set } else grid[xgridindex][ygridindex].event = 0; //this is not the winlocation } } } //show grid for (short xgridindex = 0; xgridindex <= (gridmaxx - 1); xgridindex++) // loop for every x { cout << " "; //move the grid away form the side of teh console for (short ygridindex = 0; ygridindex <= (gridmaxy - 1); ygridindex++) // loop for every y { if (xgridindex == newlocx && ygridindex == newlocy) //check to see if this location is my location grid[xgridindex][ygridindex].location = player; //draw me (the player symbol) else grid[xgridindex][ygridindex].location = background; //draw a background //show location cout << grid[xgridindex][ygridindex].location; //show the grid x } cout << endl; //show the grid y } //get direction do //loop to keep moving untill i win { cout << "W = up, A = left, S = down and D = right, Q is quit\n\n"; //some info ;) movement = getch() ; //get a key stroke if (movement == 'w')//119) //going up? (w) newlocx--; else if (movement == 'a')//97) //goin left? (a) newlocy--; else if(movement == 's')//115) //goin down? (s) newlocx++; else if(movement == 'd')//100)//goin right? (d) newlocy++; //check if your not going of the grid if (newlocx > (gridmaxx - 1)) newlocx--; else if (newlocx < 0) newlocx++; else if (newlocy > (gridmaxy - 1)) newlocy--; else if (newlocy < 0) newlocy++; system("cls"); //less pain in the eyes //change location for (short xgridindex = 0; xgridindex <= (gridmaxx - 1); xgridindex++) // loop for every x { cout << " "; //move the grid away form the side of teh console for (short ygridindex = 0; ygridindex <= (gridmaxy - 1); ygridindex++) // loop for every y { if (xgridindex == newlocx && ygridindex == newlocy) //check to see if this location is my location { grid[xgridindex][ygridindex].location = player; //draw a player symbol if (grid[xgridindex][ygridindex].event == 1) //did i win? win = true ; //i won! } else grid[xgridindex][ygridindex].location = background; // draw a background //show location cout << grid[xgridindex][ygridindex].location; //show the grid x } cout << endl; //show the grid y } cout << endl << "Event: " << grid[newlocx][newlocy].event << endl; //show wich event happend if (win) break; // i won now gimme my prize >_< } while (movement != 'q'); // yes you can quit without finishing :/ cout << "you won\n\n"; //zeh price! system("PAUSE"); //lets atleast show wtf happend return EXIT_SUCCESS; //caps is cruise control for cool? }