再发芽的小透明
项目1:简简单单画个圆
#include<windows.h> #include<graphics.h> int main(void) { /*初始化图形窗口*/ initgraph(640, 480); /*确定圆心坐标,以及圆半径*/ circle( 320,240,200); system("pause"); closegraph(); return 0; }
运行结果如下:

压缩包:

[此贴子已经被作者于2022-1-13 22:06编辑过]
#include<graphics.h> #include<Windows.h> int main(void) { /*初始化界面*/ initgraph(640, 480); /*设置背景颜色*/ setbkcolor(RGB(64, 128, 128)); cleardevice(); /*设置画笔颜色*/ setlinecolor(RGB(255, 0, 0)); /*设置画笔样式*/ setlinestyle(PS_SOLID, 10); /*画圆*/ circle(320, 240, 200); /*设置字体颜色*/ settextcolor(RGB(255, 255, 0)); /*设置字体高度、宽度、字体名称*/ settextstyle(100,0,"微软雅黑"); /*输出文本*/ outtextxy(170, 190, "无码高清"); /*划线*/ line(180, 380, 460, 100); system("pause"); closegraph(); return 0; }
#include<graphics.h> #include<Windows.h> int main(void) { initgraph(600, 400); loadimage(0, "bg.jpg"); settextcolor(RGB(255, 255, 0)); settextstyle(25, 0, "微软雅黑"); rectangle(300, 40, 500, 70); outtextxy(305,45,"1.404攻击"); rectangle(300, 75, 500, 105); outtextxy(305, 80, "2.篡改攻击"); rectangle(300, 110, 500, 140); outtextxy(305, 115, "3.攻击次数"); rectangle(300, 145, 500, 175); outtextxy(305, 150, "4.服务器攻击"); rectangle(300, 180, 500, 210); outtextxy(305, 185, "5.推出"); closegraph(); system("pause"); return 0; }
#include<iostream> #include<Windows.h> #include<mmsystem.h> #include<graphics.h> #include<stdio.h> #pragma comment(lib,"winmm.lib") using namespace std; int main(void) { IMAGE image[148]; char filename[128]; cout << "加载中........" << endl; for (int i = 1; i <= 148; i++) { sprintf_s(filename,"E:\\images2\\_%04d_图层-%d.jpg",148-i,i); loadimage(&image[i-1],filename); } initgraph(800, 450); mciSendString("play 极乐净土.mp3 repeat",0,0,0);//重复播放 while (1) { for (int i = 0; i <= 148; i++) { putimage(0, 0, &image[i]); Sleep(75); } } system("pause"); closegraph(); return 0; }
#include<iostream> #include<string> #include<graphics.h> #include<stdio.h> #include<conio.h> #define isValid(pos) pos.y < COLUMN &&pos.y >= 0 &&pos.x < LINE &&pos.x>= 0 #define RATIO 61 #define LINE 9 #define COLUMN 12 #define SCREEN_WIDTH 960 #define SCREEN_HEIGHT 768 #define START_X 100 #define START_Y 150 #define KEY_UP 'w' #define KEY_DOWN 's' #define KEY_LEFT 'a' #define KEY_RIGHT 'd' #define KEY_QUIT 'q' //typedef enum _PROPS pos; using namespace std; int map[9][12]{ {0,0,0,0,0,0,0,0,0,0,0,0}, {0,1,0,1,1,1,1,1,1,1,0,0}, {0,1,4,1,0,2,1,0,2,1,0,0}, {0,1,0,1,0,1,0,0,1,1,1,0}, {0,1,0,2,0,1,1,4,1,1,1,0}, {0,1,1,1,0,3,1,1,1,4,1,0}, {0,1,2,1,1,4,1,1,1,1,1,0}, {0,1,0,0,1,0,1,1,0,0,1,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, }; /* 枚举所用的元素 */ enum _PROPS { WALL, FLOOR, DES, MAN, BOX, HIT, ALL, }; struct _POS { int x; //小人所在的二维数组行 int y;//小人所在的二维数组列 }; struct _POS man; enum _DIRECTION { UP, DOWN, LEFT, RIGHT, }; IMAGE images[ALL]; /* 改变游戏道具并显示出来 输入:line 行下标 columu 列下标 prop:道具类型 */ void changeMap(struct _POS *pos , enum _PROPS props){ map[pos->x][pos->y] = props; putimage(START_Y + RATIO * pos->y, START_X + RATIO * pos->x, &images[props]); } /* 实现控制 */ void gameControl(enum _DIRECTION direct ){ //int x = man.x; //int y = man.y; struct _POS nextpos = man; struct _POS nextnextpos =man ; switch (direct) { case UP: nextpos.x--; nextnextpos.x -= 2; break; case DOWN: nextpos.x++; nextnextpos.x += 2; break; case LEFT: nextpos.y--; nextnextpos.y -= 2; break; case RIGHT: nextpos.y++; nextnextpos.y += 2; break; } //if (direct == UP) { if (isValid(nextpos) && map[nextpos.x][nextpos.y] == FLOOR) { changeMap(&nextpos, MAN);//小人前进一格 changeMap(&man, FLOOR);//人所在的位置换为地板 man= nextpos;//更改人的初始位置坐标 } else if (isValid(nextnextpos) && map[nextpos.x][nextpos.y] == BOX) { if (map[nextnextpos.x][nextnextpos.y]==FLOOR) { changeMap(&nextnextpos, BOX);//箱子下一个位置换为箱子 changeMap(&nextpos,MAN );//箱子所在位置换为人 changeMap(&man, FLOOR);//人所在的位置换为地板 man = nextpos; } else if (map[nextnextpos.x][nextnextpos.y]==DES) { changeMap(&nextnextpos, HIT); changeMap(&nextpos, MAN);//箱子所在位置换为人 changeMap(&man, FLOOR);//人所在的位置换为地板 man = nextpos; } } /**} else if(direct==DOWN){ if ((x +1) < LINE && map[x+1][y] == FLOOR) { changeMap(x + 1, y, MAN);//小人前进一格 man.x = x + 1; changeMap(x, y, FLOOR);//人所在的位置换为地板 } }else if(direct == LEFT){ if ((y-1) >=0 && map[x][y-1] == FLOOR) { changeMap(x , y-1, MAN);//小人前进一格 man.y = y - 1; changeMap(x, y, FLOOR);//人所在的位置换为地板 } } else if (direct == RIGHT) { if ((y + 1) < COLUMN && map[x][y+1] == FLOOR) { changeMap(x , y+1, MAN);//小人前进一格 man.y = y + 1; changeMap(x, y, FLOOR);//人所在的位置换为地板 } }*/ } bool isGameover() { for (int i = 0; i < LINE; i++) { for (int j = 0; j < COLUMN; j++) if (map[i][j] == DES)return false; } return true; } void Thankyou(IMAGE *bg) { putimage(0, 0, bg); setcolor(WHITE); RECT rec = { 0,0,SCREEN_WIDTH,SCREEN_HEIGHT }; settextstyle(20, 0, "宋体"); drawtext(("恭喜您,成为了一个合格的搬箱子老司机"), & rec, DT_CENTER | DT_VCENTER | DT_SINGLELINE); } int main(void) { IMAGE bg_img; initgraph(SCREEN_WIDTH, SCREEN_HEIGHT); loadimage(&bg_img,"blackground.bmp", SCREEN_WIDTH, SCREEN_WIDTH, true); putimage(0, 0, &bg_img); loadimage(&images[WALL], "wall_right.bmp", RATIO, RATIO, true); loadimage(&images[FLOOR], "floor.bmp", RATIO, RATIO, true); loadimage(&images[DES], "des.bmp", RATIO, RATIO, true); loadimage(&images[MAN], "man.bmp", RATIO, RATIO, true); loadimage(&images[BOX], "box.bmp", RATIO, RATIO, true); loadimage(&images[HIT], "box.bmp", RATIO, RATIO, true); for (int i = 0; i < LINE; i++) { for (int j = 0; j < COLUMN; j++) { if (map[i][j] == MAN) { man.x = i; man.y = j; } putimage(START_Y + RATIO *j, START_X + RATIO *i, &images[map[i][j]]); } } bool quit = false; do { if (_kbhit()){ char ch = _getch(); if (ch == KEY_UP) { gameControl(UP); }else if (ch == KEY_DOWN) { gameControl(DOWN); }else if (ch == KEY_LEFT) { gameControl(LEFT); }else if (ch == KEY_RIGHT) { gameControl(RIGHT); }else if(ch == KEY_QUIT) { quit = true; } if (isGameover()) { Thankyou(&bg_img); quit = true; } } Sleep(100); } while (quit==false); system("pause"); closegraph(); return 0; }