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
|
#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <conio.h>
#define KEY_UP 72
#define KEY_LEFT 75
#define KEY_DOWN 80
#define KEY_RIGHT 77
using namespace std;
int x = 1;
int y = 1;
void gotoxy(int x,int y )
{
COORD p = { x, y };
SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), p );
}
/************************************
DRAW MAP
*************************************/
void drawmap(){
char block = 219;
int top = 0;
int left = 0;
int bottom = 0;
int right = 0;
gotoxy(24,24);
cout << block;
while(top < 24){
gotoxy(top,0);
cout << block;
top = top + 1;
}
while(left < 24){
gotoxy(0,left);
cout << block;
left = left + 1;
}
while(bottom < 24){
gotoxy(bottom,24);
cout << block;
bottom = bottom + 1;
}
while(right < 24){
gotoxy(24,right);
right = right + 1;
cout << block;
}
}//end of draw map
/*******************************
DRAW PLAYER
********************************/
void drawplayer(){
char player = 1;
gotoxy(x,y);
cout << player;
}
/********************************************
DROP WATER
*********************************************/
bool water = false;
int waterx;
int watery;
void dropwater(){
char block = 219;
water = true;
waterx = x + 1;
watery = y;
while(water){
gotoxy(waterx,watery);
cout << block;
if(waterx > 0 && watery == 23){
gotoxy(waterx,watery);
cout << block;
waterx --;
}
else if(waterx<23 && watery == 23){
gotoxy(waterx,watery);
cout << block;
waterx++;
}
else if(watery<23){
gotoxy(waterx,watery);
cout << block;
watery++;
}
}
}
/*******************************
GETINPUT
********************************/
void getinput(){
char player = 1;
char input;
input = getch();
switch(input){
case KEY_UP:
if(y == 1){
}
else{
y = y - 1;
gotoxy(x,y);
cout << player;
gotoxy(x,y+1);
cout << " ";
}
break;
case KEY_DOWN:
if(y==23){
}
else{
y = y + 1;
gotoxy(x,y);
cout << player;
gotoxy(x,y-1);
cout << " ";
}
break;
case KEY_LEFT:
if(x == 1){
}
else{
x = x - 1;
gotoxy(x,y);
cout << player;
gotoxy(x+1,y);
cout << " ";
}
break;
case KEY_RIGHT:
if(x==23){
}
else{
x = x + 1;
gotoxy(x,y);
cout << player;
gotoxy(x-1,y);
cout << " ";
}
case 'w':
dropwater();
break;
}
}
int main(int argc, char *argv[])
{
bool done = false;
drawmap();
drawplayer();
while(!done){
getinput();
}
return EXIT_SUCCESS;
}
|