Beispiel #1
0
void init_game() //게임판 초기화
{
	int i, j;
	int x, y;

	nx = ny = 0, count = 0;

	memset(arr_cell, 0, sizeof(arr_cell)); // 배열 초기화

	for (i = 1; i <= 8; i++)
	{
		for (j = 0; j < 2; j++)
		{
			do
			{
				x = make_rand(4), y = make_rand(4); // 두개의 같은 숫자를 난수로 저장
			} while (arr_cell[x][y].Num != 0);
			arr_cell[x][y].Num = i;
		}
	}

	draw_scr(TRUE);
	Sleep(2000);
	system("cls");
	draw_scr(FALSE);
}
Beispiel #2
0
void read_tty(char ch)
{
	int n;
	if(kb_pi >= R*C)
		printf("input buffer full\n");
	if(ch == '\b') {
		if(kb_pi) {
			kb_pi--;
			goto echo;
		}
		else goto no_echo;
	}
	kb_pend[kb_pi] = ch;
	kb_pi++;
	if(ch == '\n') {
		n = write(pipe_in, kb_pend, kb_pi);
		if(n < kb_pi)
			printf("truncation\n");
		kb_pi = 0;
	}
echo:	write_tty_normal(ch);
	draw_scr(cur_top, p_x1, p_y1, p_x2, p_y2);
	refresh_scr(p_x1, p_y1, p_x2, p_y2);
	pend = 0;
	draw_cur();
no_echo:;
}
Beispiel #3
0
int do_window()
{
	WMsg msg;
	static int scroll_off;
	w_recv(ifd, &msg, sizeof(WMsg));
	switch( msg.type )
	{
	case UM_KEY:
		if(!(msg.arg4 & KBS_BRK))
		{
			if((msg.arg4 & KBS_LSH || msg.arg4 & KBS_RSH)) {
				if(msg.arg3 & KB_PGDN) {
					scroll_off += R*C;
					draw_scr(add_mod(cur_top, scroll_off),
						 0, 0, C-1, R-1);
					refresh_scr(0, 0, C-1, R-1);
				} else if(msg.arg3 & KB_PGUP) {
					scroll_off -= R*C;
					draw_scr(add_mod(cur_top, scroll_off),
						 0, 0, C-1, R-1);
					refresh_scr(0, 0, C-1, R-1);
				}
			}
			if(msg.arg2 != 0) {
				if(scroll_off) {
					scroll_off = 0;
					draw_scr(cur_top, 0, 0, C-1, R-1);
					refresh_scr(0, 0, C-1, R-1);
				}
				read_tty(msg.arg2);
			}
		}
		break;
	case UM_EXIT:
		if(destroy_window(hwnd))
			return 1;
		break;
	default:
		break;
	}
	return 0;
}
Beispiel #4
0
void term_init()
{
	int i;
	printf("in\n");
	for(i = 0; i < R*C*NBUF; i++)
	{
		fg[i] = color_table[7];
		bg[i] = color_table[0];
		scr[i] = ' ';
	}
	cur_fg = color_table[7];
	cur_bg = color_table[0];
	draw_scr(0, 0, 0, C-1, R-1);
	refresh_scr(0, 0, C-1, R-1);
}
Beispiel #5
0
static void act_exit(void) {
    static char question[] = "File is modified. Save before quitting? [yn] ";
    if (modified) {
	int c;

	display_moveto (display_rows-1, 0);
	display_clear_to_eol ();
	display_set_colour (COL_MINIBUF);
	display_write_str (question);
	display_refresh();
	do {
#if defined(unix) && !defined(GO32)
	    if (update_required) {
		update();
		display_moveto (display_rows-1, 0);
		display_clear_to_eol ();
		display_set_colour (COL_MINIBUF);
		display_write_str (question);
		display_refresh();
	    }
	    safe_update = TRUE;
#endif
	    c = display_getkey();
#if defined(unix) && !defined(GO32)
	    safe_update = FALSE;
#endif
	    if (c >= 'a' && c <= 'z')
		c += 'A'-'a';
	} while (c != 'Y' && c != 'N' && c != '\007');
	if (c == 'Y') {
	    act_save();
	    if (modified)
		return;		       /* couldn't save, so don't quit */
	    draw_scr();		       /* update the ** on status line! */
	} else if (c == '\007') {
	    return;		       /* don't even quit */
	}
    }
    finished = TRUE;
}
Beispiel #6
0
Datei: e.c Projekt: 8l/ted
void disp_page()
{
int row;
if (batch) return;
clrscr_w();
if (c_comment) {
/* if there are more than 300 lines in a comment, this will fail */
	scan_comment(cursor_row-300,cursor_row+page_len);
}
for(row=page_row;row<page_row+page_len && row < Lines; row++) {
	if (LangType>=0)
		disp_row(row);
	else
		disp_row_raw(row);
}
if (row-page_row < page_len) {
	set_att(0);
	disp_eof(row-page_row);
}
flush_buffer();
draw_scr();
set_att(0);
}
Beispiel #7
0
void write_tty(char *buf, int n)
{
	static int estate;
	static int num, num2;
	static int light, hide;
	static int saved_r, saved_c;
	int i;
	int tmp, tr, tc;
	while(n--) {
		switch(estate) {
		case 0: //normal state
			if(*buf == '\033') {
				estate = 1;
			} else {
				write_tty_normal(*buf);
				estate = estate;
			}
			break;
		case 1: //esc begin
			if(*buf == '[')
				estate = 2;
			else estate = 0;
			break;
		case 2: //meet '['
			if(*buf == 'K') {
				//清除从光标到行尾内容
				estate = 0;
			} else if(*buf == 's') {
				//保存光标位置
				saved_r = add_mod(scr_pos, -cur_top)/C;
				saved_c = add_mod(scr_pos, -cur_top)%C;
				estate = 0;
			} else if(*buf == 'u') {
				//恢复光标位置
				scr_pos = add_mod(cur_top, saved_c+C*saved_r);
				estate = 0;
			} else if(*buf == '?') {
				//隐藏/显示光标
				estate = 6;
			} else if(*buf >= 0 && *buf <= '9') {
				num = *buf - '0';
				estate = 3;
			} else {
				printf("unkown esc seq 1\n");
				estate = 0;
			}
			break;
		case 3: //first arg
			if(*buf == 'm') {
				switch(num) {
				case 0: //关闭所有属性
					light = 0;
					hide = 0;
					cur_fg = color_table[7];
					cur_bg = color_table[0];
					break;
				case 1: //设置高亮
					light = 1;
					break;
				case 4: //下划线
					break;
				case 5: //闪烁
					break;
				case 7: //反显
					tmp = cur_fg;
					cur_fg = cur_bg;
					cur_bg = tmp;
					break;
				case 8: //消隐
					hide = 1;
					break;
				default:
					if(num >= 30 && num <= 37) {
						//前景色
						cur_fg = hide ? cur_bg :
							color_table[num-30+light*8];
					}else if(num >= 40 && num <= 47) {
						//背景色
						cur_bg = color_table[num-40+light*8];
					} else {
						printf("unkown esc seq 2\n");
					}
					break;
				}
				estate = 0;
			} else if(*buf == 'J') {
				if(num == 2) {
					//清屏
					for(i = 0; i < R*C; i++)
					{
						int p = add_mod(i, cur_top);
						scr[p] = ' ';
						fg[p] = color_table[7];
						bg[p] = color_table[0];
					}
					p_x1 = 0; p_y1 = 0;
					p_x2 = C-1; p_y2 = R-1;
					pend = 1;
					estate = 0;
				} else {
					printf("unkown esc seq 3\n");
					estate = 0;
				}
			} else if(*buf == 'A') {
				//上移动
				tr = add_mod(scr_pos, -cur_top)/C;
				tc = add_mod(scr_pos, -cur_top)%C;
				tr -= num;
				if(tr < 0) tr = 0;
				scr_pos = add_mod(cur_top, tc+C*tr);
				estate = 0;
			} else if(*buf == 'B') {
				//下移动
				tr = add_mod(scr_pos, -cur_top)/C;
				tc = add_mod(scr_pos, -cur_top)%C;
				tr += num;
				if(tr >= R) tr = R-1;
				scr_pos = add_mod(cur_top, tc+C*tr);
				estate = 0;
			} else if(*buf == 'C') {
				//左移动
				tr = add_mod(scr_pos, -cur_top)/C;
				tc = add_mod(scr_pos, -cur_top)%C;
				tc -= num;
				if(tc < 0) tc = 0;
				scr_pos = add_mod(cur_top, tc+C*tr);
				estate = 0;
			} else if(*buf == 'D') {
				//右移动
				tr = add_mod(scr_pos, -cur_top)/C;
				tc = add_mod(scr_pos, -cur_top)%C;
				tc += num;
				if(tc >= C) tc = C-1;
				scr_pos = add_mod(cur_top, tc+C*tr);
				estate = 0;
			} else if(*buf == ';') {
				estate = 4;
			} else if(*buf >= '0' && *buf <= '9') {
				num = num*10 + *buf - '0';
				estate = estate;
			}
			break;
		case 4: //meet ;
			if(*buf >= '0' && *buf <= '9') {
				num2 = *buf - '0';
				estate = 5;
			} else {
				printf("unkown esc seq 4\n");
				estate = 0;
			}
			break;
		case 5: //second arg
			if(*buf == 'H') {
				//设置光标
				tr = num;
				tc = num2;
				if(tc >= C) tc = C-1;
				if(tr >= R) tr = R-1;
				scr_pos = add_mod(cur_top, tc+C*tr);
				estate = 0;
			} else if(*buf >= '0' && *buf <= '9') {
				num2 = num2*10 + *buf - '0';
				estate = estate;
			} else {
				printf("unkown esc seq 5\n");
				estate = 0;
			}
			break;
		case 6: //meet ?
			if(*buf >= '0' && *buf <= '9') {
				num2 = *buf - '0';
				estate = 7;
			} else {
				printf("unkown esc seq 6\n");
				estate = 0;
			}
			break;
		case 7:
			if(*buf == 'h') {
				//显示光标
				if(num2 == 25) {
					scr_pos_hide = 0;
				} else printf("unkown esc seq 7\n");
				estate = 0;
			} else if(*buf == 'l') {
				//隐藏光标
				if(num2 == 25) {
					scr_pos_hide = 1;
					printf("cursor hide\n");
				} else printf("unkown esc seq 8\n");
				estate = 0;
			} else if(*buf >= '0' && *buf <= '9') {
				num2 = num2*10 + *buf - '0';
				estate = estate;
			} else {
				printf("unkown esc seq 9\n");
				estate = 0;
			}
			break;
		default:
			printf("esc bug\n");
			exit(1);
			break;
		}
		buf++;
	}
	draw_scr(cur_top, p_x1, p_y1, p_x2, p_y2);
	refresh_scr(p_x1, p_y1, p_x2, p_y2);
	pend = 0;
	draw_cur();
}
Beispiel #8
0
void main(void)
{
	int ch;
	int tx, ty;

	init_rand();
	init_game();

	for (; 1;)
	{
		gotoxy(nx * 5 + 4, ny * 3 + 2);

		ch = getch();
		if (ch == 0xE0) //방향키를 입력받기 위해 한번더 호출
		{
			ch = getch();
			switch (ch) //nx,ny는 화면상의 좌표가 아닌 배열의 위치값
			{
			case LEFT: //왼쪽으로 이동
				if (nx > 0) nx--;
				break;
			case RIGHT:
				if (nx < 3) nx++;
				break;
			case UP:
				if (ny > 0) ny--;
				break;
			case DOWN:
				if (ny < 3) ny++;
				break;
			}
		}
		else
		{
			switch (ch)
			{
			case ESC:
				exit(0);
			case ' ': //공백키가 눌리면 그 위치의 칸을 조사
				if (arr_cell[nx][ny].stat == HIDDEN) //숨김이면
				{
					get_temp_flip(&tx, &ty); //칸의 번호를 조사
					if (tx == -1) //일치하지 않으면
						arr_cell[nx][ny].stat = TEMPFLIP; //숫자를 보여준다
					else
					{
						count++; //시도횟수 증가
						if (arr_cell[tx][ty].Num == arr_cell[nx][ny].Num) //일치하면
						{
							putch('\a');
							arr_cell[tx][ty].stat = FLIP; //완전히 보여준다.
							arr_cell[nx][ny].stat = FLIP;
							if (get_remain() == 0) //남은칸이 없으면
							{
								draw_scr(FALSE);
								gotoxy(26, 22), puts("Good! game restart"); //끝
								Sleep(2000);
								init_game();
							}
						}
						else
						{
							arr_cell[nx][ny].stat = TEMPFLIP; //다른 하나도 보여주고
							draw_scr(FALSE);
							Sleep(1000);
							arr_cell[tx][ty].stat = HIDDEN;
							arr_cell[nx][ny].stat = HIDDEN;
						}
					}
					draw_scr(FALSE);
				}
				break;
			}
		}
	}
}
Beispiel #9
0
static void act_exitsave(void) {
    act_save();
    draw_scr();			       /* update ** on status line */
    act_exit();
}