Em đang tập lập trình game ạ, Em không set được con trỏ “*” điều khiển lên xuống để chọn menu mà không dùng lệnh xóa màn hình. Anh chị có hàm nào xóa kí tự vừa nhập mà không sử dụng lệnh xóa màn hình không ạ. Em cảm ơn
#include<iostream>
#include<conio.h>
#include<windows.h>
#include<time.h>
#include<string.h>
#include "console.h"
#define chieudai 80
#define chieurong 25
using namespace std;
enum TrangThai{UP,DOWN,LEFT,RIGHT};
struct chuyendong {
int x, y;
char s[5];
TrangThai tt;
};
void dieukhien(chuyendong &cd)
{
if (kbhit())
{
char key = getch();
if (key == 'A' || key == 'a')
{
cd.tt = LEFT;
cd.x--;
}
else if (key == 'D' || key == 'd')
{
cd.tt = RIGHT;
cd.x++;
}
else if (key == 'W' || key == 'w')
{
cd.tt = UP;
cd.y--;
}
else if (key == 'S' || key == 's')
{
cd.tt = DOWN;
cd.y++;
}
}
}
void Xulichambien(chuyendong &cd)
{
if (cd.x <= 0)
cd.tt = RIGHT;
else if (cd.x >= chieudai - strlen(cd.s))
cd.tt = LEFT;
else if (cd.y <= 0)
cd.tt = DOWN;
else if (cd.y >= chieurong - 1)
cd.tt = UP;
}
int main()
{
int menu;
chuyendong A;
cout << ">>CHAO MUNG BAN DEN VOI TRO CHOI CUA TOI<<" << endl;
cout << " BAT DAU" << endl;
cout << " KET THUC" << endl;
strcpy(A.s, "*");
A.x = 0;
A.y = 1;
while (1)
{
clrscr();
gotoXY(A.x, A.y);
cout << A.s;
dieukhien(A);
}
switch (menu)
{
case 1:
if (strlen(A.s) == A.y)
break;
case 2:
system("Pause");
return 0;
}
strcpy(A.s, "Hello");
A.x = 0;
A.y = 0;
while(1)
{
clrscr();
gotoXY(A.x, A.y);
cout << A.s;
//xu li cham bien
Xulichambien(A);
//dieu khien
dieukhien(A);
Sleep(100);
}
return 0;
}