Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <iostream>
- #include <graphics.h>
- #include <math.h>
- #include <time.h>
- void Face(){
- moveto(0,0);
- initwindow(800,800);
- setcolor(15);
- rectangle (50, 50, 750, 750);
- }
- int Fi(int x,int y, int color) {
- setfillstyle (1,4);
- setcolor(color);
- line(x-25,y-10,x+20,y-10);
- line(x-25,y+10,x+20,y+10);
- line(x-25,y-10,x-25,y+10);
- line(x+20,y-10,x+35,y);
- line(x+20,y+10,x+35,y);
- line(x-25,y-10,x-35,y-25);
- line(x-25,y+10,x-35,y+25);
- line(x,y-10,x-35,y-25);
- line(x,y+10,x-35,y+25);
- circle(x+5,y,5);
- }
- int KeyMoving(int x,int y,int xOld, int yOld, int color) {
- int code;
- Face();
- outtextxy (0,0,"E-up D-rigth");
- outtextxy (0,20,"S-left X-down");
- while(1){
- Fi(xOld,yOld,0);
- Fi(x,y,color);
- delay(1);
- if (kbhit()) {
- code=getch();
- switch(code) {
- case 75: {xOld=x; yOld=y; x-=5;}; break; // âëåâî S
- case 77: {xOld=x; yOld=y; x+=5;}; break; // âïðàâî D
- case 72: {yOld=y; xOld=x; y-=5;}; break; // ââåðõ E
- case 80: {yOld=y; xOld=x; y+=5;}; break; // âíèç X
- case 27: closegraph(); return 0;
- }
- }
- if ((x>=715)||(x<=85)||(y>=725)||(y<=75))
- while(1)
- {
- delay(1);
- if(kbhit())
- if(getch()==27)
- {
- closegraph();
- return 0;
- }
- }
- }
- }
- int FreeMoving(int x, int y, int xOld, int yOld, int color) {
- Face();
- int code=0;
- while(1) {
- while( (x<715) && (y<725) ) {
- delay(1);
- xOld=x; x+=1;
- yOld=y; y+=1;
- Fi(xOld,yOld,0);
- Fi(x,y,color);
- if(kbhit()){
- code=getch();
- if(code==27) {
- closegraph();
- return 0;
- }
- }
- }
- while( (x!=400) && (y!=400) ) {
- delay(1);
- xOld=x; x-=1;
- yOld=y; y-=1;
- Fi(xOld,yOld,0);
- Fi(x,y,color);
- if(kbhit()){
- code=getch();
- if(code==27) {
- closegraph();
- return 0;
- }
- }
- }
- while( (x<715) && (y>75) ) {
- delay(1);
- xOld=x; x+=1;
- yOld=y; y-=1;
- Fi(xOld,yOld,0);
- Fi(x,y,color);
- if(kbhit()){
- code=getch();
- if(code==27) {
- closegraph();
- return 0;
- }
- }
- }
- while( (x!=400) && (y!=400) ) {
- delay(1);
- xOld=x; x-=1;
- yOld=y; y+=1;
- Fi(xOld,yOld,0);
- Fi(x,y,color);
- if(kbhit()){
- code=getch();
- if(code==27) {
- closegraph();
- return 0;
- }
- }
- }
- while( (x>85) && (y>75) ) {
- delay(1);
- xOld=x; x-=1;
- yOld=y; y-=1;
- Fi(xOld,yOld,0);
- Fi(x,y,color);
- if(kbhit()){
- code=getch();
- if(code==27) {
- closegraph();
- return 0;
- }
- }
- }
- while( (x!=400) && (y!=400) ) {
- delay(1);
- xOld=x; x+=1;
- yOld=y; y+=1;
- Fi(xOld,yOld,0);
- Fi(x,y,color);
- if(kbhit()){
- code=getch();
- if(code==27) {
- closegraph();
- return 0;
- }
- }
- }
- while( (x>85) && (y<725) ) {
- delay(1);
- xOld=x; x-=1;
- yOld=y; y+=1;
- Fi(xOld,yOld,0);
- Fi(x,y,color);
- if(kbhit()){
- code=getch();
- if(code==27) {
- closegraph();
- return 0;
- }
- }
- }
- while( (x!=400) && (y!=400) ) {
- delay(1);
- xOld=x; x+=1;
- yOld=y; y-=1;
- Fi(xOld,yOld,0);
- Fi(x,y,color);
- if(kbhit()){
- code=getch();
- if(code==27) {
- closegraph();
- return 0;
- }
- }
- }
- }
- }
- int main()
- {
- printf("Hello\n");
- srand(time(NULL));
- int x=400,y=400;
- int xOld=400,yOld=400;
- int color=2,code,num;
- printf("Press number for choice \n1. Free Move\n2. Key Move\n3. Exit\n\n\n");
- while(1){
- check:
- scanf("%d",&num);
- switch(num) {
- case 1: FreeMoving(x,y,xOld,yOld,color); break;
- case 2: KeyMoving(x,y,xOld,yOld,color); break;
- case 3: system("CLS"); return 0;
- default: printf("Error!\nRepeat:\n"); goto check;
- }
- printf("Lets go again?\n");
- }
- getch();
- closegraph();
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement