-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjust.cpp
More file actions
55 lines (50 loc) · 1.15 KB
/
just.cpp
File metadata and controls
55 lines (50 loc) · 1.15 KB
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
#include <iostream>
#include <conio.h> // For _getch() on Windows
using namespace std;
const int WIDTH = 10;
const int HEIGHT = 10;
int playerX = 5, playerY = 5;
void draw() {
system("cls"); // Clear screen (Windows-specific)
for (int y = 0; y < HEIGHT; y++) {
for (int x = 0; x < WIDTH; x++) {
if (x == playerX && y == playerY) {
cout << "KRISH "; // Player
} else {
cout << ". "; // Empty space
}
}
cout << endl;
}
}
void input() {
char move = _getch(); // Wait for key input
switch (move) {
case 'w':
case 'W':
if (playerY > 0) playerY--;
break;
case 's':
case 'S':
if (playerY < HEIGHT - 1) playerY++;
break;
case 'a':
case 'A':
if (playerX > 0) playerX--;
break;
case 'd':
case 'D':
if (playerX < WIDTH - 1) playerX++;
break;
case 'q':
case 'Q':
exit(0); // Quit game
}
}
int main() {
while (true) {
draw();
input();
}
return 0;
}