#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
void gotoxy(int x, int y){
COORD pos = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void hide_cursor(void){
CONSOLE_CURSOR_INFO cursorInfo;
cursorInfo.dwSize = 1;
cursorInfo.bVisible = FALSE;
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursorInfo);
}
void start (void){
gotoxy(0, 0);
printf("=== 리모컨 사용 설명서 ===\n");
printf("[w] 전원 ON | [s] 전원 OFF\n");
printf("[a] 채널 UP | [d] 채널 DOWN\n");
printf("[q] 볼륨 UP | [e] 볼륨 DOWN\n");
printf("[f] 채널 직접 입력\n");
printf("[x] 프로그램 종료\n");
printf("==========================\n\n");
}
class RemoteCon {
public:
bool power = false;
int channel = 0;
int volume = 10;
void powerOn() {
if (!power) {
power = true;
printf("[전원 ON] (채널: %d, 볼륨: %d)\n", channel, volume);
} else {
printf("이미 전원이 켜져 있습니다.\n");
}
}
void powerOff() {
if (power) {
power = false;
printf("[전원 OFF] ('w'를 눌러 켜세요)\n");
} else {
printf("이미 전원이 꺼져 있습니다.\n");
}
}
void chnlUp() {
if (!power) return;
if (channel == 999) {
channel = 0;
} else {
channel++;
}
printf("[전원 ON] (채널: %d, 볼륨: %d)\n", channel, volume);
}
void chnlDown() {
if (!power) return;
if (channel == 0) {
channel = 999;
} else {
channel--;
}
printf("[전원 ON] (채널: %d, 볼륨: %d)\n", channel, volume);
}
void volUp() {
if (!power) return;
if (volume < 100) {
volume++;
}
printf("[전원 ON] (채널: %d, 볼륨: %d)\n", channel, volume);
}
void volDown() {
if (!power) return;
if (volume > 0) {
volume--;
}
printf("[전원 ON] (채널: %d, 볼륨: %d)\n", channel, volume);
}
void channelSet() {
if (!power) return;
int chnlSet;
gotoxy(0, 8);
printf("[전원 ON] (채널: %d, 볼륨: %d)\n", channel, volume);
gotoxy(0, 9);
printf("이동할 채널 입력 (0~999): ");
scanf("%d", &chnlSet);
if (chnlSet >= 0 && chnlSet <= 999) {
channel = chnlSet;
system("cls");
start();
gotoxy(0, 8);
printf("[전원 ON] (채널: %d, 볼륨: %d)\n", channel, volume);
} else {
system("cls");
start();
gotoxy(0, 9);
printf("유효하지 않은 채널 번호입니다. (0 ~ 999 사이 입력)\n");
}
}
};
int main() {
RemoteCon remote;
char key;
hide_cursor();
start();
while (1) {
key = _getch();
if (key == 'x' || key == 'X') {
printf("프로그램 종료\n");
break;
}else if (key == 'w' || key == 'W') {
system("cls");
start();
gotoxy(0, 8);
remote.powerOn();
} else if (key == 's' || key == 'S') {
system("cls");
start();
gotoxy(0, 8);
remote.powerOff();
} else if (key == 'a' || key == 'A') {
system("cls");
start();
gotoxy(0, 8);
remote.chnlUp();
} else if (key == 'd' || key == 'D') {
system("cls");
start();
gotoxy(0, 8);
remote.chnlDown();
} else if (key == 'q' || key == 'Q') {
system("cls");
start();
gotoxy(0, 8);
remote.volUp();
} else if (key == 'e' || key == 'E') {
system("cls");
start();
gotoxy(0, 8);
remote.volDown();
} else if (key == 'f' || key == 'F') {
system("cls");
start();
gotoxy(0, 8);
remote.channelSet();
}
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: