full code gần 200 dòng :))
thông cảm :))
-------------------------------------
#include <iostream>
#include <string.h>
#include <conio.h>
#include <windows.h>
#include <iomanip>
using namespace std;
int n;
int **a, x, y, countt=0;
char ct;
void setcolor(word color)
{
handle hconsoleoutput;
hconsoleoutput = getstdhandle(std_output_handle);
console_screen_buffer_info screen_buffer_info;
getconsolescreenbufferinfo(hconsoleoutput, &screen_buffer_info);
word wattributes = screen_buffer_info.wattributes;
color &= 0x000f;
wattributes &= 0xfff0;
wattributes |= color;
setconsoletextattribute(hconsoleoutput, wattributes);
}
void setbgcolor(word color)
{
handle hconsoleoutput;
hconsoleoutput = getstdhandle(std_output_handle);
console_screen_buffer_info screen_buffer_info;
getconsolescreenbufferinfo(hconsoleoutput, &screen_buffer_info);
word wattributes = screen_buffer_info.wattributes;
color &= 0x000f;
color <<= 4;
wattributes &= 0xff0f;
wattributes |= color;
setconsoletextattribute(hconsoleoutput, wattributes);
}
void oouutt()
{
cout << "\n game cuif for k54cb \n";
cout <<endl<<endl<< " "<< countt << endl<< endl;
for (int i=0; i<n; i++)
{
cout << " ";
setcolor(4);
cout << '.'; for (int z=1; z<=n; z++) cout << " __ ."; cout << endl;
cout << ' '; for (z=1; z<=n; z++) cout << " "; cout << endl;
cout << " ";cout << "|";
for (int j=0; j<n; j++)
{
cout << ' ';
setcolor(2);
if (!a[i][j])
{
setbgcolor(4);
cout << " ";
setbgcolor(0);
}
else
cout << setw(2) << a[i][j];
setcolor(4);
cout << " |";
}
cout << endl;
}
cout << " ";
cout << '.'; for (int z=1; z<=n; z++) cout << " __ ."; cout << endl;
setcolor(6);
}
void khoi_tao()
{
int r=0;
a=new int*[n];
for (int i=0; i<n; i++)
{
a[i]=new int[n];
for (int j=0; j<n; j++)
a[i][j]=r++;
}
x=0; y=0;
}
void dichuyen(int &x, int &y, int h)
{
countt++;
if (h==1)
{
if (x>0)
{
swap(a[x-1][y],a[x][y]);
x--;
}
}
else if (h==2)
{
if (y<n-1)
{
swap(a[x][y+1],a[x][y]);
y++;
}
}
else if (h==3)
{
if (x<n-1)
{
swap(a[x+1][y],a[x][y]);
x++;
}
}
else if (h==4)
{
if (y>0)
{
swap(a[x][y-1],a[x][y]);
y--;
}
}
}
void makerand(int n)
{
for (int i=0; i<n; i++)
{
int e=rand()%4+1;
dichuyen(x,y,e);
oouutt();
sleep(3);
system("cls");
}
countt=0;
}
bool check_end()
{
int t=0;
for (int i=0; i<n; i++)
{
for (int j=0; j<n; j++)
{
if (a[i][j]!=t) return false;
t++;
}
}
return true;
}
void control()
{
while (1)
{
ct=getch();
if (ct==-32)
ct=getch();
if (ct==72)
dichuyen(x,y,1);
else if (ct==77)
dichuyen(x,y,2);
else if (ct==80)
dichuyen(x,y,3);
else if (ct==75)
dichuyen(x,y,4);
else continue;
if (check_end())
{
cout << "\a\a";
return;
}
system("cls"); //trumtinhoc :>>
oouutt();
}
}
void menu()
{
oouutt();
cout << "\n\n\n nhan phim bat ki de bat dau";
char a;
a=getch();
makerand(abs((int)a));
}
int main()
{
system("color 6");
cout << "level: ";
cin >> n;
khoi_tao();
menu();
oouutt();
control();
system("cls");
oouutt();
cout << "\n\n win !!! ^^ trumtinhoc-hoidap247.com \n";
getch();
return 0;
}
Tin học, tiếng Anh: informatics, tiếng Pháp: informatique, là một ngành khoa học chuyên nghiên cứu quá trình tự động hóa việc tổ chức, lưu trữ, xử lý và truyền dẫn thông tin của một hệ thống máy tính cụ thể hoặc trừu tượng (ảo). Với cách hiểu hiện nay, tin học bao hàm tất cả các nghiên cứu và kỹ thuật có liên quan đến việc mô phỏng, biến đổi và tái tạo thông tin.
Nguồn : Wikipedia - Bách khoa toàn thưLớp 8 - Năm thứ ba ở cấp trung học cơ sở, học tập bắt đầu nặng dần, sang năm lại là năm cuối cấp áp lực lớn dần nhưng các em vẫn phải chú ý sức khỏe nhé!
Nguồn : ADMIN :))Xem thêm tại https://loigiaisgk.com/cau-hoi or https://giaibtsgk.com/cau-hoi
Copyright © 2021 HOCTAPSGK