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

📄 draw.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
	return((13 - col + (col <= 6 ? 1 : 0)) * TriWidth						+ (TriWidth - CircDiam) / 2);}erasepiece(point, color, oldnum)int point, color, oldnum; /* oldnum is original # of piece on point */{	int tri_index, height, xcor, ycor, c, top, overlap;	/* first, determine correct index into Triangle array for the */	/* color and orientation we want */	if (point % 2 == 0)		tri_index = 2;	else		tri_index = 0;	if (isonbot(point))		tri_index++;	/* next, figure out what height on the triangle we should copy from */	/* also, save the height value for when we rop the buffer later */	if (oldnum > 10)		height = 2 * OVERLAP + (oldnum - 11) * CircDiam;	else if (oldnum > 5)		height = OVERLAP + (oldnum - 6) * CircDiam;	else		height = (oldnum - 1) * CircDiam;	if (isonbot(point) || (point == BAR && color == computercolor)				|| (point == HOME && color == humancolor)) {		ycor = brdrect.r_height - height - CircDiam;		height = TriHeight - height - CircDiam;		top = 0;	} else {		ycor = height;		top = 1;	}	/* now, white out the buffer */	pr_rop(EraseBuf, 0, 0, TriWidth, CircDiam, PIX_SRC, 0, 0, 0);	/* next, draw the right piece of a triangle into the buffer */	if (point != BAR && point != HOME)		pr_rop(EraseBuf, 0, 0, TriWidth, CircDiam, PIX_SRC,				Triangle[tri_index], 0, height);	/* if this piece is next to a left edge of the board, the */	/* vertical line must be drawn in too */	if (point == 12 || point == 13 || point == 6 || point == 19					|| point == BAR || point == HOME)		pr_vector(EraseBuf, 0, 0, 0, CircDiam, PIX_SRC, 1);	/* now, draw in previously hidden circles if necessary */	xcor = (TriWidth - CircDiam) / 2;	if (oldnum > 10) {		overlap = (top ? 1 : 2) * OVERLAP;		addhiddenpieces(EraseBuf, xcor, color, overlap, oldnum, top);	}	if (oldnum > 5) {		overlap = (top ? 2 : 1) * OVERLAP;		addhiddenpieces(EraseBuf, xcor, color, overlap, oldnum, top);	}	/* finally, compute the x coordinate for ropping in buffer and */	/* do the rop */	if (point == BAR)		xcor = 7 * TriWidth;	else if (point == HOME)		xcor = 14 * TriWidth;	else {		if (isontop(point))			c = point - 12;		else			c = 13 - point;		if (c > 6)			c++;		xcor = c * TriWidth;	}	pw_write(brdwin, xcor, ycor, TriWidth, CircDiam, PIX_SRC,							EraseBuf, 0, 0);	if (oldnum == 15 && point != HOME && point != BAR)		drawdice(BOTH, NOFLASH);	/* since dice get chopped */}addhiddenpieces(pr, xcor, color, overlap, num, top)struct pixrect *pr;int xcor, color;int overlap;int num;			/* old number of pieces on point */int top;{	if ((num != 15 && num != 10) || !top)	/* piece below */		drawhiddenpieceat(pr, xcor, overlap, CircDiam,					CircDiam - overlap, color, 0, 0);	if ((num != 15 && num != 10) || top)	/* piece above */		drawhiddenpieceat(pr, xcor, 0, CircDiam, overlap, color, 0,							CircDiam - overlap);}/* The following procedure must be EXACTLY analogous to drawpieceat() */drawhiddenpieceat(pr, dx, dy, w, h, color, sx, sy)struct pixrect *pr;int dx, dy, w, h, color, sx, sy;{	pr_stencil(pr, dx, dy, w, h, PIX_SRC | PIX_COLOR(color == BLACK), Disk, sx, sy, 0, 0, 0);	if (color == WHITE)	/* must circle the white piece in black */		pr_rop(pr, dx, dy, w, h, PIX_SRC | PIX_DST, Circle, sx, sy);	else		/* and black Pieces in white */		pr_stencil(pr, dx, dy, w, h, PIX_SRC, Circle, sx, sy, 0, 0, 0);}drawpiece(point, color, oldnum)int point, color, oldnum;{	int height, xcor;	xcor = leftcoor(point);	if (oldnum > 9)		height = 2 * OVERLAP + (oldnum - 10) * CircDiam;	else if (oldnum > 4)		height = OVERLAP + (oldnum - 5) * CircDiam;	else		height = oldnum * CircDiam;	if (isonbot(point) || (point == BAR && color == computercolor)					|| (point == HOME && color == humancolor))		height = brdrect.r_height - height - CircDiam;	drawpieceat(xcor, height, color);}drawdice(who, flash)int who, flash;{	int xcor, ycor, d0, d1, color, numdice;	if (who == BOTH) {		drawdice(HUMAN, flash);		drawdice(COMPUTER, flash);		return;	}	if (who == HUMAN) {		d0 = humandieroll[0] & NUMMASK;		d1 = humandieroll[1] & NUMMASK;		color = humancolor;		xcor = 3 * TriWidth;		numdice = numhdice;	} else {		d0 = computerdieroll[0];		d1 = computerdieroll[1];		color = computercolor;		xcor = 10 * TriWidth;		numdice = numcdice;	}	ycor = TriHeight + (brdrect.r_height - 2 * TriHeight - 32) / 2;	pw_writebackground(brdwin, xcor, ycor, 80, 32, PIX_SRC);	if (numdice == 0)		return;	if (numdice == 1)		xcor += 24;	if (flash == FLASH) {		displaydie(xcor, ycor, d0, color, PIX_NOT(PIX_SRC));		if (numdice == 2)			displaydie(xcor+48, ycor, d1, color, PIX_NOT(PIX_SRC));		select(0, 0, 0, 0, &flashdelay);	}	displaydie(xcor, ycor, d0, color, PIX_SRC);	if (numdice == 2)		displaydie(xcor+48, ycor, d1, color, PIX_SRC);}displaydie(x, y, num, color, op)int x, y, num, color, op;{	if (color)		pw_write(brdwin, x, y, 32, 32, PIX_NOT(op), dice[num-1], 0, 0);	else		pw_write(brdwin, x, y, 32, 32, op, dice[num-1], 0, 0);}drawcube(){	int turnindex, numindex, gval, xcor, ycor;	switch (lastdoubled) {	case HUMAN:		turnindex = 1;		break;	case COMPUTER:		turnindex = 0;		break;	case NOBODY:		return;	}	numindex = 0;	for (gval = gamevalue; gval > 2; gval /= 2, numindex++)		;        xcor = 7 * TriWidth + (TriWidth - 48) / 2;        ycor = brdrect.r_height / 2 - 24;	pw_write(brdwin, xcor, ycor, 48, 48, PIX_SRC, dblecubes[numindex][turnindex], 0, 0);}clearcube(){	int xcor, ycor;        xcor = 7 * TriWidth + (TriWidth - 48) / 2;        ycor = brdrect.r_height / 2 - 24;	pw_write(brdwin, xcor, ycor, 48, 48, PIX_SRC, NULL, 0, 0);	pw_vector(brdwin, 7 * TriWidth, ycor, 7 * TriWidth, ycor + 48, PIX_SRC, 1);	pw_vector(brdwin, 8 * TriWidth, ycor, 8 * TriWidth, ycor + 48, PIX_SRC, 1);}drawoutline(x, y)int x, y;{	x -= CircDiam / 2;	y -= CircDiam / 2;	pw_write(brdwin, x, y, CircDiam, CircDiam, PIX_SRC ^ PIX_DST,		Circle, 0, 0);}getpoint(x, y)		/* given coords on screen, determine board point */int x, y;{	if (!rect_includespoint(&brdrect, x, y))		return(OUTOFBOUNDS);	x /= TriWidth;	if (x < 1)		/* click was off the playing board */		return(OUTOFBOUNDS);	if (x == 7)		return(BAR);	if (x >= 14)		return(HOME);	if (y <= TriHeight + 2 * OVERLAP)	/* top half of board */		return(x + 12 - (x > 7 ? 1 : 0));	else if (y >= brdrect.r_height - TriHeight - 2 * OVERLAP)		return(13 - x + (x > 7 ? 1 : 0));	/* bottom */	else		return(OUTOFBOUNDS);	/* click was in between top & bot */}drawscore(who)int who;{	int score, height, x;	char numbuf[6], *text;	if (who == BOTH) {		drawscore(HUMAN);		drawscore(COMPUTER);	}	pw_vector(brdwin, 0, brdrect.r_height / 2, TriWidth,					brdrect.r_height / 2, PIX_SRC, 1);	if (who == HUMAN) {		height = 0;		text = humanname;		score = humanscore;	} else {		height = brdrect.r_height / 2;		text = "Computer";		score = computerscore;	}	height += ((brdrect.r_height / 2) - ((strlen(text) + 2)					* msgfont->pf_defaultsize.y))					/ 2 - msgfont->pf_char['n'].pc_home.y;	x = (TriWidth - msgfont->pf_defaultsize.x) / 2;	while (*text) {		pw_char(brdwin, x, height, PIX_SRC, msgfont, *text++);		height += msgfont->pf_defaultsize.y;	}	height += msgfont->pf_defaultsize.y;	if (score < 10)		sprintf(numbuf, " %d ", score);	else if (score < 100)		sprintf(numbuf, " %d", score);	else		sprintf(numbuf, "%d", score);	x = (TriWidth - strlen(numbuf) * msgfont->pf_defaultsize.x) / 2;	pw_text(brdwin, x, height, PIX_SRC, msgfont, numbuf);}

⌨️ 快捷键说明

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