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
|
#include <iostream>
#include <conio.h>
using namespace std;
void Cursor(int, int);
int main() {
char snake[100][100];
char move;
int x, y, Xmax, Ymax, S1, S2, a1, a2, a;
//Imax = width
Xmax = 50;
//Jmax= height
Ymax = 22;
S1 = 10;
S2 = 10;
//Initializing the 2D Array
for (y = Ymax - 1; y >= 0; y--) {
for (x = 0; x < Xmax; x++) {
snake[x][y] = '±';
}
}
//Update the 2D Array
for (y = Ymax - 2; y >= 1; y--) {
for (x = 1; x < Xmax - 1; x++) {
snake[x][y] = ' ';
}
}
//Snake[S1][s2] = '±';
//Printing the 2D Array
for (y = Ymax - 1; y >= 0; y--) {
for (x = 0; x < Xmax; x++) {
cout << snake[x][y];
}
cout << endl;
}
cout << "\n\nWhere would you like to move (a, s, d, w)?";
Cursor(S1, (Ymax - 1) - S2);
cout << 's';
Cursor(43, 24);
do {
move = _getch();
if(move == 'a' && snake[S1 - 1][S2] == ' ') {
Cursor(S1, (Ymax - 1) - S2);
cout << ' ';
S1--;
Cursor(S1, (Ymax - 1) - S2);
cout << 's';
}
else if (move == 's' && snake[S1][S2 - 1] == ' ') {
Cursor(S1, (Ymax - 1) - S2);
cout << ' ';
S2--;
Cursor(S1, (Ymax - 1) - S2);
cout << 's';
}
else if (move == 'd' && snake[S1 + 1][S2] == ' ') {
Cursor(S1, (Ymax - 1) - S2);
cout << ' ';
S1++;
Cursor(S1, (Ymax - 1) - S2);
cout << 's';
}
else if (move == 'w' && snake[S1][S2 + 1] == ' ') {
Cursor(S1, (Ymax - 1) - S2);
cout << ' ';
S2++;
Cursor(S1, (Ymax - 1) - S2);
cout << 's';
}
Cursor(43, 24);
} while (move == 'a' || move == 's' || move == 'd' || move == 'w');
char exit;
cout << "\n\nPlease press a key and <enter> to exit";
cin >> exit;
return 0;
}
#include <Windows.h>
void Cursor(int x, int y) {
COORD Cord;
Cord.X = x;
Cord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Cord);
}
|