#include<iostream>
#include<conio.h>
#include<Windows.h>
#include<ctime>
using namespace std;
//-------------------------Screen-------------------------
void clrscr()
{
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
HANDLE hConsoleOut;
COORD Home = { 0, 0 };
DWORD dummy;
hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsoleOut, &csbiInfo);
FillConsoleOutputCharacter(hConsoleOut, ' ', csbiInfo.dwSize.X * csbiInfo.dwSize.Y, Home, &dummy);
csbiInfo.dwCursorPosition.X = 0;
csbiInfo.dwCursorPosition.Y = 0;
SetConsoleCursorPosition(hConsoleOut, csbiInfo.dwCursorPosition);
}
//screen: goto [x,y]
void gotoXY(int column, int line)
{
COORD coord;
coord.X = column;
coord.Y = line;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void TextColor(int color)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
}
//**************************************
struct ToaDo{
int x, y;
};
struct VatCan_1{
ToaDo dot1[7];
int n1;//so dot
};
struct VatCan_2{
ToaDo dot2[7];
int n2;//do cao cua vat can
};
struct VatCan_3{
ToaDo dot3[7];
int n3;//do cao cua vat can
};
struct VatCan_4{
ToaDo dot4[7];
int n4;//do cao cua vat can
};
struct Nguoi
{
ToaDo dot[7];
int n;//so ki tu tao nen nguoi :v
};
void VeDuong(){
for (int i = 0; i < 70; i++){
gotoXY(i, 20);
cout << (char)196;
}
}
void KhoiTao(VatCan_1 &vatCan_1,VatCan_2 &vatCan_2,VatCan_3 &vatCan_3,VatCan_4 &vatCan_4,Nguoi &nguoi){
vatCan_1.dot1[0].x = 100;
vatCan_1.dot1[0].y = 20;
vatCan_1.dot1[1].x = 100;
vatCan_1.dot1[1].y = 19;
/*vatCan_1.dot1[2].x = 100;
vatCan_1.dot1[2].y = 18;*/
vatCan_1.n1 = 2;
vatCan_2.dot2[0].x = 100;
vatCan_2.dot2[0].y = 20;
vatCan_2.dot2[1].x = 100;
vatCan_2.dot2[1].y = 19;
/*vatCan_2.dot2[2].x = 100;
vatCan_2.dot2[2].y = 18;*/
vatCan_2.n2 = 2;
vatCan_3.dot3[0].x = 100;
vatCan_3.dot3[0].y = 20;
vatCan_3.dot3[1].x = 100;
vatCan_3.dot3[1].y = 19;
/*vatCan_3.dot3[2].x = 100;
vatCan_3.dot3[2].y = 18;*/
vatCan_3.n3 = 2;
vatCan_4.dot4[0].x = 100;
vatCan_4.dot4[0].y = 20;
vatCan_4.dot4[1].x = 100;
vatCan_4.dot4[1].y = 19;
/*vatCan_4.dot4[2].x = 100;
vatCan_4.dot4[2].y = 18;*/
vatCan_4.n4 = 2;
nguoi.dot[0].x = 7;
nguoi.dot[0].y = 20;
nguoi.dot[1].x = 7;
nguoi.dot[1].y = 19;
nguoi.dot[2].x = 7;
nguoi.dot[2].y = 18;
nguoi.dot[3].x = 7;
nguoi.dot[3].y = 17;
nguoi.dot[4].x = 7;
nguoi.dot[4].y = 16;
nguoi.n = 5;
}
void HienThi(VatCan_1 &vatCan_1,VatCan_2 &vatCan_2,VatCan_3 &vatCan_3,VatCan_4 &vatCan_4,Nguoi &nguoi,int &dem_1 ){
clrscr();
//diem
gotoXY(60, 9);
if (dem_1 % 100 == 0)
cout << "Diem cua chu chim la: " << dem_1 / 100;
else if (dem_1 % 120 == 0)
cout << "Diem cua chu chim la: " << dem_1 / 120;
else if (dem_1 % 150 == 0)
cout << "Diem cua chu chim la: " << dem_1 / 150;
else if (dem_1 % 170 == 0)
cout << "Diem cua chu chim la: " << dem_1 / 170;
//hien thi em 1
for (int i = 0; i < vatCan_1.n1; i++){
gotoXY(vatCan_1.dot1[i].x, vatCan_1.dot1[i].y);
cout << (char)215;
vatCan_1.dot1[i].x--;
if (vatCan_1.dot1[i].x <= 0){
vatCan_1.dot1[i].x = 100;
}
}
dem_1++;
//hien thi em 2
if (dem_1>=20){
for (int i = 0; i < vatCan_2.n2; i++){
gotoXY(vatCan_2.dot2[i].x, vatCan_2.dot2[i].y);
cout << (char)215;
vatCan_2.dot2[i].x--;
if (vatCan_2.dot2[i].x <= 0){
vatCan_2.dot2[i].x = 100;
}
}
}
//hien thi em 3
if (dem_1 >= 50){
for (int i = 0; i < vatCan_3.n3; i++){
gotoXY(vatCan_3.dot3[i].x, vatCan_3.dot3[i].y);
cout << (char)215;
vatCan_3.dot3[i].x--;
if (vatCan_3.dot3[i].x <= 0){
vatCan_3.dot3[i].x = 100;
}
}
}
//hien thi em 4
if (dem_1 >= 70){
for (int i = 0; i < vatCan_4.n4; i++){
gotoXY(vatCan_4.dot4[i].x, vatCan_4.dot4[i].y);
cout << (char)215;
vatCan_4.dot4[i].x--;
if (vatCan_4.dot4[i].x <= 0){
vatCan_4.dot4[i].x = 100;
}
}
}
//hien thi em nguoi
gotoXY(nguoi.dot[0].x, nguoi.dot[0].y);
cout << (char)178;
gotoXY(nguoi.dot[1].x, nguoi.dot[1].y);
cout << (char)179;
gotoXY(nguoi.dot[2].x, nguoi.dot[2].y);
cout << (char)179;
gotoXY(nguoi.dot[3].x, nguoi.dot[3].y);
cout << (char)179;
gotoXY(nguoi.dot[4].x, nguoi.dot[4].y);
cout << (char)157;
}
void DieuKhien(){
if (_kbhit()){
char key = _getch();
if (key == 'j' || key == 'J'){
gotoXY(7, 20);
cout << " ";
gotoXY(7, 19);
cout << " ";
gotoXY(7, 18);
cout << " ";
gotoXY(7, 17);
cout << " ";
gotoXY(7, 16);
cout << " ";
//clrscr();
gotoXY(7,12);
cout << (char)178;
gotoXY(7,11);
cout << (char)179;
gotoXY(7,10);
cout << (char)179;
gotoXY(7,9);
cout << (char)179;
gotoXY(7,8);
cout << (char)157;
}
Sleep(150);
}
}
int main(){
int dem_1 = 0;
int sleep = 100-time(NULL) % 100;
VatCan_1 vatCan_1;
VatCan_2 vatCan_2;
VatCan_3 vatCan_3;
VatCan_4 vatCan_4;
Nguoi nguoi;
KhoiTao(vatCan_1,vatCan_2,vatCan_3,vatCan_4,nguoi);
while (true)
{
//hien thi
HienThi(vatCan_1,vatCan_2,vatCan_3,vatCan_4,nguoi,dem_1);
//dieu khien
DieuKhien();
//xu ly
Sleep(sleep);
}
return 0;
}
#include<conio.h>
#include<Windows.h>
#include<ctime>
using namespace std;
//-------------------------Screen-------------------------
void clrscr()
{
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
HANDLE hConsoleOut;
COORD Home = { 0, 0 };
DWORD dummy;
hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsoleOut, &csbiInfo);
FillConsoleOutputCharacter(hConsoleOut, ' ', csbiInfo.dwSize.X * csbiInfo.dwSize.Y, Home, &dummy);
csbiInfo.dwCursorPosition.X = 0;
csbiInfo.dwCursorPosition.Y = 0;
SetConsoleCursorPosition(hConsoleOut, csbiInfo.dwCursorPosition);
}
//screen: goto [x,y]
void gotoXY(int column, int line)
{
COORD coord;
coord.X = column;
coord.Y = line;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void TextColor(int color)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color);
}
//**************************************
struct ToaDo{
int x, y;
};
struct VatCan_1{
ToaDo dot1[7];
int n1;//so dot
};
struct VatCan_2{
ToaDo dot2[7];
int n2;//do cao cua vat can
};
struct VatCan_3{
ToaDo dot3[7];
int n3;//do cao cua vat can
};
struct VatCan_4{
ToaDo dot4[7];
int n4;//do cao cua vat can
};
struct Nguoi
{
ToaDo dot[7];
int n;//so ki tu tao nen nguoi :v
};
void VeDuong(){
for (int i = 0; i < 70; i++){
gotoXY(i, 20);
cout << (char)196;
}
}
void KhoiTao(VatCan_1 &vatCan_1,VatCan_2 &vatCan_2,VatCan_3 &vatCan_3,VatCan_4 &vatCan_4,Nguoi &nguoi){
vatCan_1.dot1[0].x = 100;
vatCan_1.dot1[0].y = 20;
vatCan_1.dot1[1].x = 100;
vatCan_1.dot1[1].y = 19;
/*vatCan_1.dot1[2].x = 100;
vatCan_1.dot1[2].y = 18;*/
vatCan_1.n1 = 2;
vatCan_2.dot2[0].x = 100;
vatCan_2.dot2[0].y = 20;
vatCan_2.dot2[1].x = 100;
vatCan_2.dot2[1].y = 19;
/*vatCan_2.dot2[2].x = 100;
vatCan_2.dot2[2].y = 18;*/
vatCan_2.n2 = 2;
vatCan_3.dot3[0].x = 100;
vatCan_3.dot3[0].y = 20;
vatCan_3.dot3[1].x = 100;
vatCan_3.dot3[1].y = 19;
/*vatCan_3.dot3[2].x = 100;
vatCan_3.dot3[2].y = 18;*/
vatCan_3.n3 = 2;
vatCan_4.dot4[0].x = 100;
vatCan_4.dot4[0].y = 20;
vatCan_4.dot4[1].x = 100;
vatCan_4.dot4[1].y = 19;
/*vatCan_4.dot4[2].x = 100;
vatCan_4.dot4[2].y = 18;*/
vatCan_4.n4 = 2;
nguoi.dot[0].x = 7;
nguoi.dot[0].y = 20;
nguoi.dot[1].x = 7;
nguoi.dot[1].y = 19;
nguoi.dot[2].x = 7;
nguoi.dot[2].y = 18;
nguoi.dot[3].x = 7;
nguoi.dot[3].y = 17;
nguoi.dot[4].x = 7;
nguoi.dot[4].y = 16;
nguoi.n = 5;
}
void HienThi(VatCan_1 &vatCan_1,VatCan_2 &vatCan_2,VatCan_3 &vatCan_3,VatCan_4 &vatCan_4,Nguoi &nguoi,int &dem_1 ){
clrscr();
//diem
gotoXY(60, 9);
if (dem_1 % 100 == 0)
cout << "Diem cua chu chim la: " << dem_1 / 100;
else if (dem_1 % 120 == 0)
cout << "Diem cua chu chim la: " << dem_1 / 120;
else if (dem_1 % 150 == 0)
cout << "Diem cua chu chim la: " << dem_1 / 150;
else if (dem_1 % 170 == 0)
cout << "Diem cua chu chim la: " << dem_1 / 170;
//hien thi em 1
for (int i = 0; i < vatCan_1.n1; i++){
gotoXY(vatCan_1.dot1[i].x, vatCan_1.dot1[i].y);
cout << (char)215;
vatCan_1.dot1[i].x--;
if (vatCan_1.dot1[i].x <= 0){
vatCan_1.dot1[i].x = 100;
}
}
dem_1++;
//hien thi em 2
if (dem_1>=20){
for (int i = 0; i < vatCan_2.n2; i++){
gotoXY(vatCan_2.dot2[i].x, vatCan_2.dot2[i].y);
cout << (char)215;
vatCan_2.dot2[i].x--;
if (vatCan_2.dot2[i].x <= 0){
vatCan_2.dot2[i].x = 100;
}
}
}
//hien thi em 3
if (dem_1 >= 50){
for (int i = 0; i < vatCan_3.n3; i++){
gotoXY(vatCan_3.dot3[i].x, vatCan_3.dot3[i].y);
cout << (char)215;
vatCan_3.dot3[i].x--;
if (vatCan_3.dot3[i].x <= 0){
vatCan_3.dot3[i].x = 100;
}
}
}
//hien thi em 4
if (dem_1 >= 70){
for (int i = 0; i < vatCan_4.n4; i++){
gotoXY(vatCan_4.dot4[i].x, vatCan_4.dot4[i].y);
cout << (char)215;
vatCan_4.dot4[i].x--;
if (vatCan_4.dot4[i].x <= 0){
vatCan_4.dot4[i].x = 100;
}
}
}
//hien thi em nguoi
gotoXY(nguoi.dot[0].x, nguoi.dot[0].y);
cout << (char)178;
gotoXY(nguoi.dot[1].x, nguoi.dot[1].y);
cout << (char)179;
gotoXY(nguoi.dot[2].x, nguoi.dot[2].y);
cout << (char)179;
gotoXY(nguoi.dot[3].x, nguoi.dot[3].y);
cout << (char)179;
gotoXY(nguoi.dot[4].x, nguoi.dot[4].y);
cout << (char)157;
}
void DieuKhien(){
if (_kbhit()){
char key = _getch();
if (key == 'j' || key == 'J'){
gotoXY(7, 20);
cout << " ";
gotoXY(7, 19);
cout << " ";
gotoXY(7, 18);
cout << " ";
gotoXY(7, 17);
cout << " ";
gotoXY(7, 16);
cout << " ";
//clrscr();
gotoXY(7,12);
cout << (char)178;
gotoXY(7,11);
cout << (char)179;
gotoXY(7,10);
cout << (char)179;
gotoXY(7,9);
cout << (char)179;
gotoXY(7,8);
cout << (char)157;
}
Sleep(150);
}
}
int main(){
int dem_1 = 0;
int sleep = 100-time(NULL) % 100;
VatCan_1 vatCan_1;
VatCan_2 vatCan_2;
VatCan_3 vatCan_3;
VatCan_4 vatCan_4;
Nguoi nguoi;
KhoiTao(vatCan_1,vatCan_2,vatCan_3,vatCan_4,nguoi);
while (true)
{
//hien thi
HienThi(vatCan_1,vatCan_2,vatCan_3,vatCan_4,nguoi,dem_1);
//dieu khien
DieuKhien();
//xu ly
Sleep(sleep);
}
return 0;
}