示例#1
0
文件: main.c 项目: wcybxzj/shangguan
int main(int argc, const char *argv[])
{
	int ret;
	char ch;
	
	srand(time(NULL));
	ret = fb_open();
	key_init();	
	draw_back();
	draw_grid();
	signal(SIGALRM, sig_handler);
	alarm(1);

	while (1) {
		ch = getchar();
		switch (ch) {
			case 'a':
				if(canleft(pos_x, pos_y, cur_type, arr)) {
					draw_type(pos_x, pos_y, cur_type, BACK);
					pos_x--;
				}
				break;
			case 'd':
				if(canright(pos_x, pos_y, cur_type, arr)) {
					draw_type(pos_x, pos_y, cur_type, BACK);
					pos_x++;
				}
				break;	
			case 's':
				if(candown(pos_x, pos_y, cur_type, arr)) {
					draw_type(pos_x, pos_y, cur_type, BACK);
					pos_y++;
				}
				break;
			case 'w':
				if(canchange(pos_x,pos_y,cur_type,arr)) {
					draw_type(pos_x, pos_y, cur_type, BACK);
					type_chg(&cur_type);
				}
				break;
			default :
				break;
		}
		draw_type(pos_x, pos_y, cur_type, COLOR);
		draw_grid();
		if(!candown(pos_x, pos_y, cur_type, arr)) {
			draw_flag(pos_x, pos_y, cur_type, arr);
			if(gameover(arr)) {
				exit(0);
			}
			deleteone(arr);
			pos_x = XNUM/2; pos_y = 0;
			cur_type = rand()%14;
		}
	}

	fb_close();

	return 0;
}
template<typename T, typename KEY> void RBTree<T, KEY>::deleteone(KEY Key)
{
    if (pRoot)
    {
        //std::cout << "Deleting: " << Key << std::endl;
        if (!isRed(pRoot->pLeft))
            pRoot->color = RED;
        pRoot = deleteone(pRoot, Key);
        if (pRoot)
            pRoot->color = BLACK;
    }
}
template<typename T, typename KEY> RBTNode<T, KEY> *RBTree<T, KEY>::deleteone(RBTNode<T, KEY> *h, KEY Key)
{
    // Delete a node.
    // However will be not sure Key exists in the tree. Check if the Key exists before deleting.
    if (Key < h->key)
    {
        if (!isRed(h->pLeft) && !isRed(h->pLeft->pLeft))
            h = MoveRedLeft(h);
        h->pLeft = deleteone(h->pLeft, Key);
    }
    else{
        if (isRed(h->pLeft))
            h = RotateRight(h);
        if ((Key == h->key) && !(h->pRight) )
        {
            //std::cout << "Delete one specified node: " << h->key << ", value: " << h->value << std::endl;
            delete h;
            return NULL;
        }
        if (!isRed(h->pRight) && !isRed(h->pRight->pLeft))
            h = MoveRedRight(h);
        if (Key == h->key)
        {
            //std::cout << "To delete " << h->key << ", delete subtree's min node" << std::endl;
            RBTNode<T, KEY> *temp = getmin(h->pRight);
            h->value = temp->value;
            h->key = temp->key;
            h->pRight = deletemin(h->pRight);
        }
        else
            h->pRight = deleteone(h->pRight, Key);
    }
    if (isRed(h->pRight))
        h = RotateLeft(h);
    return h;
}
示例#4
0
文件: main.c 项目: wcybxzj/shangguan
void sig_handler(int s)
{
	alarm(1);
	if(candown(pos_x, pos_y, cur_type, arr)) {
		draw_type(pos_x, pos_y, cur_type, BACK);
		pos_y++;
		draw_type(pos_x, pos_y, cur_type, COLOR);
		draw_grid();
	}else {
		draw_flag(pos_x, pos_y, cur_type, arr);
		if(gameover(arr)) {
			exit(0);
		}
		deleteone(arr);
		pos_x = XNUM/2; pos_y = 0;
		cur_type = rand()%14;
	}
}