⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 game3.c

📁 DOS游戏界面的设计
💻 C
📖 第 1 页 / 共 2 页
字号:
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,BUTTON_COLOR_DARK);
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR_LIGHT);
			Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR);
			if(win->active==ACTIVE)
				Blit_String(win->top.x+2,win->top.y+1,win->color,win->word,1);
			else
				Blit_String(win->top.x+2,win->top.y+1,NOACTIVE_COLOR,win->word,1);
			break;
		}
		case BUTTON_PRESS:
		{
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,BUTTON_COLOR_LIGHT);
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR_DARK);
			Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR);
			Blit_String(win->top.x+2,win->top.y+1,win->color,win->word,1);
			break;
		}
		case BUTTON_CLOSE:
		{
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,BUTTON_COLOR_DARK);
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR_LIGHT);
			Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR);
			if(win->active==ACTIVE)
			{
				Bline(win->top.x+2,win->top.y+2,win->top.x+win->move.x-2,win->top.y+win->move.y-2,win->color);
				Bline(win->top.x+win->move.x-2,win->top.y+2,win->top.x+2,win->top.y+win->move.y-2,win->color);
			}
			else
			{
				Bline(win->top.x+2,win->top.y+2,win->top.x+win->move.x-2,win->top.y+win->move.y-2,NOACTIVE_COLOR);
				Bline(win->top.x+win->move.x-2,win->top.y+2,win->top.x+2,win->top.y+win->move.y-2,NOACTIVE_COLOR);
			}
			break;
		}
		case BUTTON_CLOSE_PRESS:
		{
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,BUTTON_COLOR_LIGHT);
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR_DARK);
			Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR);
			Bline(win->top.x+2,win->top.y+2,win->top.x+win->move.x-2,win->top.y+win->move.y-2,win->color);
			Bline(win->top.x+win->move.x-2,win->top.y+2,win->top.x+2,win->top.y+win->move.y-2,win->color);
			break;
		}
		case BUTTON_SMALL:
		{
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,BUTTON_COLOR_DARK);
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR_LIGHT);
			Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR);
			if(win->active==ACTIVE)
				H_Line(win->top.x+2,win->top.x+win->move.x-2,win->top.y+win->move.y-2,win->color);
			else
				H_Line(win->top.x+2,win->top.x+win->move.x-2,win->top.y+win->move.y-2,NOACTIVE_COLOR);
			break;
		}
		case BUTTON_SMALL_PRESS:
		{
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,BUTTON_COLOR_LIGHT);
			Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR_DARK);
			Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR);
			H_Line(win->top.x+2,win->top.x+win->move.x-2,win->top.y+win->move.y-2,win->color);
			break;
		}
		default:break;
	}
}

void Object_Init(windows_ptr ptr,int kind,int x,int y,int move_x,int move_y,char *word,int color,int bk_color,int status,char *hotkey,int bk_flag,void (far *windows),int active)
{
	ptr->kind=kind;
	ptr->top.x=x;
	ptr->top.y=y;
	ptr->move.x=move_x;
	ptr->move.y=move_y;
	ptr->word=word;
	ptr->color=color;
	ptr->bk_color=bk_color;
	ptr->status=status;
	ptr->hotkey=hotkey;
	ptr->windows=windows;
	ptr->bk_flag=bk_flag;
	if(bk_flag==1)
		ptr->background=(char far *)malloc( (move_x+1)* (move_y+1)+1);
	ptr->active=active;
}


void Behind_Button(windows_ptr win)
{

char far *work_back;
int work_offset=0,offset,y;


work_back = win->background;


offset = (win->top.y << 8) + (win->top.y << 6) + win->top.x;

for (y=0; y<BUTTON_Y; y++)
    {

    _fmemmove((void far *)&work_back[work_offset],
	     (void far *)&video_buffer[offset],
	     BUTTON_X);


    offset      += SCREEN_WIDTH;
    work_offset += BUTTON_X;

    }

}

void Erase_Button(windows_ptr win)
{

char far *work_back;
int work_offset=0,offset,y;


work_back = win->background;


offset = (win->top.y << 8) + (win->top.y << 6) + win->top.x;

for (y=0; y<BUTTON_Y; y++)
    {

    _fmemmove((void far *)&video_buffer[offset],
	     (void far *)&work_back[work_offset],
	     BUTTON_X);


    offset      += SCREEN_WIDTH;
    work_offset += BUTTON_X;

    }

}
void Behind_Object(windows_ptr win)
{

char far *work_back;
int work_offset=0,offset,y;


work_back = win->background;


offset = (win->top.y << 8) + (win->top.y << 6) + win->top.x;

for (y=0; y<win->move.y+1; y++)
    {

    _fmemmove((void far *)&work_back[work_offset],
	     (void far *)&video_buffer[offset],
	     win->move.x+1);


    offset      += SCREEN_WIDTH;
    work_offset += win->move.x+1;

    }

}

void Erase_Object(windows_ptr win)
{

char far *work_back;
int work_offset=0,offset,y;


work_back = win->background;


offset = (win->top.y << 8) + (win->top.y << 6) + win->top.x;

for (y=0; y<win->move.y+1; y++)
    {

    _fmemmove((void far *)&video_buffer[offset],
	     (void far *)&work_back[work_offset],
	     win->move.x+1);


    offset      += SCREEN_WIDTH;
    work_offset += win->move.x+1;

    }

}

void Object_Delete(windows_ptr win)
{

	int index;

	if(win->bk_flag==1)
		free(win->background);
	free(&win);
}

void Free_Object(void)
{
	windows_ptr restore;
	restore=head;
	if(restore->bk_flag==1)
	{
		Erase_Object(restore);
	}
	Object_Delete(restore);
	do{
		restore=restore->next;
		if(restore->bk_flag==1)
		{
			Erase_Object(restore);
		}
		Object_Delete(restore);
	}while(restore->next!=NULL);
	head=NULL;

}


void win(windows_ptr win)
{
//	printf("\n\n\n\n\nwindows fuction is in use\n");
}

void clo(windows_ptr win)
{
	win->kind=BUTTON_CLOSE_PRESS;
	Draw_Windows(win);
	Delay(5);
	win->kind=BUTTON_CLOSE;
	Draw_Windows(win);
	Delay(5);
	Free_Object();
	Set_Video_Mode(TEXT_MODE);
	exit(1);
}

void game(int xmouse,int ymouse)
{
	int color=YELLOW,key=0;
	Squeeze_Mouse(MOUSE_HIDE,0,0,0);
	Fill_Rectangle(xa*16,ya*10,xa*16+15,ya*10+9,color);
	if(xmouse<xa*16&&xa>0)
	{
		Fill_Rectangle(xa*16,ya*10,xa*16+15,ya*10+9,BLACK);
		xa=xa-1;
		Fill_Rectangle(xa*16,ya*10,xa*16+15,ya*10+9,color);
	}
	else if(xmouse>xa*16&&xa<19)
	{
		Fill_Rectangle(xa*16,ya*10,xa*16+15,ya*10+9,BLACK);
		xa=xa+1;
		Fill_Rectangle(xa*16,ya*10,xa*16+15,ya*10+9,color);
	}
	if(ymouse<ya*16&&ya>0)
	{
		Fill_Rectangle(xa*16,ya*10,xa*16+15,ya*10+9,BLACK);
		ya=ya-1;
		Fill_Rectangle(xa*16,ya*10,xa*16+15,ya*10+9,color);
	}
	else if(ymouse>ya*16&&ya<19)
	{
		Fill_Rectangle(xa*16,ya*10,xa*16+15,ya*10+9,BLACK);
		ya=ya+1;
		Fill_Rectangle(xa*16,ya*10,xa*16+15,ya*10+9,color);
	}
	Squeeze_Mouse(MOUSE_SHOW,0,0,0);
}


void bt1(windows_ptr win)
{
	int x,y,fcolor;
	long i;
	win->kind=BUTTON_PRESS;
	Draw_Windows(win);
	Delay(5);
	win->kind=BUTTON;
	Draw_Windows(win);
	Free_Object();
	xa=0;
	ya=0;
	gameflag=1;
}

void Read_From_File(char flag,FILE *stream,int *word)
{
	int i,j=0,k=0;
	char *buf;
	if ((stream = fopen(stream, "r+b")) == NULL)
	{
		fprintf(stderr, "Cannot open output file.\n");
		return 1;
	}
	for(i=0;!feof(stream);i++)
	{
		fread(buf,1, 1, stream);
		if(buf[0]==flag)
		{
			fseek(stream,k, SEEK_SET);
			fread(buf,i-k+1,1,stream);
			buf[i-k]='\x0';
			word[j]=atoi(buf);
			j++;
			k=i+1;
		}
	}
	fclose(stream);
}


void loa(windows_ptr win)
{
	int x,y,fcolor;
	long i;
	int *word=malloc(sizeof(int)*2);
	win->kind=BUTTON_PRESS;
	Draw_Windows(win);
	Delay(5);
	win->kind=BUTTON;
	Draw_Windows(win);
	Free_Object();
	Read_From_File(flag,stream,word);
	xa=word[0];
	ya=word[1];
	gameflag=1;
}

void Write_To_File(char flag,FILE *stream,int *word)
{
	const char *xy;
	int i=0;
	if ((stream = fopen(stream, "w+b")) == NULL)
	{
		fprintf(stderr, "Cannot open output file.\n");
		return 1;
	}
	while(word[i]!=-1)
	{
	itoa(word[i],xy,10);
	fwrite(xy,strlen(xy), 1, stream);
	fwrite(",",1, 1, stream);
	i++;
	}
	fclose(stream);
}


void sav(windows_ptr win)
{
	int x,y,fcolor;
	long i;
	int *word=malloc(sizeof(int)*2);
	win->kind=BUTTON_PRESS;
	Draw_Windows(win);
	Delay(5);
	win->kind=BUTTON;
	Draw_Windows(win);
	Free_Object();
	word[0]=xa;
	word[1]=ya;
	word[2]=-1;
	Write_To_File(flag,stream,word);
}

void bt2(windows_ptr win)
{
	win->kind=BUTTON_PRESS;
	Draw_Windows(win);
	Delay(5);
	win->kind=BUTTON;
	Draw_Windows(win);
	Delay(5);
	Free_Object();
	Set_Video_Mode(TEXT_MODE);
	exit(1);
}

void sma(windows_ptr win)
{
	win->kind=BUTTON_SMALL_PRESS;
	Draw_Windows(win);
	Delay(5);
	win->kind=BUTTON_SMALL;
	Draw_Windows(win);
	Free_Object();
}

void men(windows_ptr win)
{
	windows_ptr restore;
	win->kind=BUTTON_PRESS;
	Draw_Windows(win);
	Delay(5);
	win->kind=BUTTON;
	Draw_Windows(win);
	if(win->status==MIN)
	{
		now=(struct windows *)malloc(sizeof(struct windows));
		Object_Init(now,BUTTON,WINDOWS_X+2,WINDOWS_Y-BUTTON_Y*4,BUTTON_X-1,BUTTON_Y-1,"new",0,24,0,"",1,bt1,ACTIVE);
		now->father=win;
		Behind_Object(now);
		Draw_Windows(now);
		last->next=now;
		pre=now;
		now=(struct windows *)malloc(sizeof(struct windows));
		Object_Init(now,BUTTON,WINDOWS_X+2,WINDOWS_Y-BUTTON_Y*3,BUTTON_X-1,BUTTON_Y-1,"save",0,24,0,"",1,sav,ACTIVE);
		now->father=win;
		Behind_Object(now);
		Draw_Windows(now);
		pre->next=now;
		pre=now;
		now=(struct windows *)malloc(sizeof(struct windows));
		Object_Init(now,BUTTON,WINDOWS_X+2,WINDOWS_Y-BUTTON_Y*2,BUTTON_X-1,BUTTON_Y-1,"load",0,24,0,"",1,loa,ACTIVE);
		now->father=win;
		Behind_Object(now);
		Draw_Windows(now);
		pre->next=now;
		pre=now;
		now=(struct windows *)malloc(sizeof(struct windows));
		Object_Init(now,BUTTON,WINDOWS_X+2,WINDOWS_Y-BUTTON_Y,BUTTON_X-1,BUTTON_Y-1,"exit",0,24,0,"",1,bt2,ACTIVE);
		now->father=win;
		Behind_Object(now);
		Draw_Windows(now);
//		getch();
//		Erase_Button(now);
//		getch();
		pre->next=now;
		pre=now;
		pre->next=NULL;

		win->status=MAX;
		menuflag=MAX;
	}
	else if(win->status==MAX)
	{
		restore=head;
		do{
			restore=restore->next;
			if(restore->bk_flag==1)
			{
				Erase_Object(restore);
				Object_Delete(restore);
			}
		}while(restore->next!=NULL);
		last->next=NULL;
		win->status=MIN;
		menuflag=MIN;
	}
}

void Build_Object()
{
	now=pre=(struct windows *)malloc(sizeof(struct windows));
	Object_Init(now,BAR,WINDOWS_X,WINDOWS_Y,WINDOWS_X_MOVE,WINDOWS_Y_MOVE,"Move Rectangle",0,24,0,"",1,win,ACTIVE);
	Behind_Object(now);
	win_now=now;
	Draw_Windows(now);
	head=now;
	now=(struct windows *)malloc(sizeof(struct windows));
	Object_Init(now,BUTTON,WINDOWS_X+2,WINDOWS_Y+2,BUTTON_X-1,BUTTON_Y-1,"Star",0,24,MIN,"",0,men,ACTIVE);
	Draw_Windows(now);
	pre->next=now;
	pre=now;
	now=(struct windows *)malloc(sizeof(struct windows));
	Object_Init(now,BUTTON_SMALL,WINDOWS_X+WINDOWS_X_MOVE-(BUTTON_XY+2)*2,WINDOWS_Y+2,BUTTON_XY-1,BUTTON_XY-1,"",0,24,MAX,"",0,sma,ACTIVE);
	Draw_Windows(now);
	pre->next=now;
	pre=now;
	now=(struct windows *)malloc(sizeof(struct windows));
	Object_Init(now,BUTTON_CLOSE,WINDOWS_X+WINDOWS_X_MOVE-BUTTON_XY-2,WINDOWS_Y+2,BUTTON_XY-1,BUTTON_XY-1,"",0,24,0,"",0,clo,ACTIVE);
	Draw_Windows(now);
	pre->next=now;
	pre=now;
	pre->next=NULL;
	last=pre;

}

void Judge_Object(void)
{
	int xmouse,ymouse,btnmouse;
	static int btn=-1;
	windows_ptr test;
	Squeeze_Mouse(MOUSE_MOTION_REL,&xmouse,&ymouse,&btnmouse);
	if(ymouse==199&&head==NULL)
	{
		gameflag=0;
		Squeeze_Mouse(MOUSE_HIDE,0,0,0);
		Build_Object();
		Squeeze_Mouse(MOUSE_SHOW,0,0,0);
	}
	if(ymouse<=185&&menuflag!=MAX&&head!=NULL)
	{
		Squeeze_Mouse(MOUSE_HIDE,0,0,0);
		Free_Object();
		Squeeze_Mouse(MOUSE_SHOW,0,0,0);
	}
	Squeeze_Mouse(MOUSE_BUTT_POS,&xmouse,&ymouse,&btnmouse);
	if(btnmouse==btn)
		return;
	else
		btn=btnmouse;
	xmouse=xmouse/2;
	ymouse=ymouse;
	if(btnmouse==1)
	{
		if(head!=NULL)
		{
		test=head;
		if((xmouse>=test->top.x&&xmouse<=test->top.x+test->move.x)&&
		(ymouse>=test->top.y&&ymouse<=test->top.y+test->move.y))
		{
			Squeeze_Mouse(MOUSE_HIDE,0,0,0);
			if(test->active==ACTIVE)
				test->windows(test);
			Squeeze_Mouse(MOUSE_SHOW,0,0,0);
		}
		do{
			test=test->next;
			if((xmouse>=test->top.x&&xmouse<=test->top.x+test->move.x)&&
			(ymouse>=test->top.y&&ymouse<=test->top.y+test->move.y))
			{
				Squeeze_Mouse(MOUSE_HIDE,0,0,0);
				if(test->active==ACTIVE)
					test->windows(test);
				Squeeze_Mouse(MOUSE_SHOW,0,0,0);
			}
		}while(test->next!=NULL);
		}
		if(gameflag==1)
			game(xmouse,ymouse);
	}
}

void main(void)
{
	windows_ptr test;
	Set_Video_Mode(VGA256);
	Build_Object();
	Squeeze_Mouse(MOUSE_RESET,0,0,0);
	mscurson(handcurs);

	while(1){
		Judge_Object();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -