Ejemplo n.º 1
0
Archivo: c++.cpp Proyecto: mkut/aoj
int main()
{
	int n;
	while(cin >> n, n != 0)
	{
		bitset<1000> used;
		vector<int> vp(n), vq(n), vr(n), vb(n);
		for(int i = 0; i < n; i++)
		{
			cin >> vp[i] >> vq[i] >> vr[i] >> vb[i];
			if(vr[i] != 0) used[vr[i]-1] = true;
			if(vb[i] != 0) used[vb[i]-1] = true;
		}
		Stick* root;
		for(int i = 0; i < 1000; i++)
		{
			if(!used[i])
			{
				root = new Stick(vp[i], vq[i], vr[i], vb[i], vp, vq, vr, vb);
				break;
			}
		}
		cout << root->weight() << endl;
		delete root;
	}
	return 0;
}
Ejemplo n.º 2
0
Archivo: c++.cpp Proyecto: mkut/aoj
	int weight()
	{
		int wr = r == NULL ? 1 : r->weight();
		int wb = b == NULL ? 1 : b->weight();
		int _lcm = lcm(wr * p, wb * q);
		return _lcm / p + _lcm / q;
	}
Ejemplo n.º 3
0
Stick * Stick::createWithFrameName( std::string strBottomFrameName, std::string strStickFrameName )
{
	Stick *pRet = new Stick();
	if (pRet && pRet->init(strBottomFrameName, strStickFrameName))
	{ 
		pRet->autorelease();
		return pRet;
	} 
	else
	{ 
		delete pRet; 
		pRet = NULL; 
		return NULL;
	}
}
Ejemplo n.º 4
0
//do_zap: Perform a zap with a wand
bool do_zap()
{
    Coord delta;
    if (!get_dir(&delta))
        return false;

    Item *item = get_item("zap with", STICK);
    if (!item)
        return false;

    Stick* stick = dynamic_cast<Stick*>(item);
    Weapon* weapon = dynamic_cast<Weapon*>(item);
    if (!(stick || (weapon && weapon->is_vorpalized() && weapon->charges()))) {
        //mdk: zapping with non-stick doesn't count as turn
        msg("you can't zap with that!");
        return false;
    }

    // Handle the special case of a vorpalized weapon
    if (weapon) {
        game->screen().play_sound("zap");
        if (weapon->zap_vorpalized_weapon(delta)) {
            weapon->use_charge();
        }
        return true;
    }

    // Zap the appropriate stick
    if (stick->charges() == 0) {
        msg("nothing happens");
    }
    else{
        game->screen().play_sound("zap");
        if (stick->Zap(delta)) {
            stick->use_charge();
        }
    }

    return true;
}
Ejemplo n.º 5
0
int main(){
	/*VARIABLES*/
		/*shell variables*/
	bool done=false;
	bool render=false;

		/*project variables*/
	Player* player = NULL;
	Stick* stick = NULL;
	ALLEGRO_BITMAP* playerImg=NULL;
	ALLEGRO_BITMAP* stickImg=NULL;
	// =====================

	/*ALLEGRO_VARIABLES*/

	ALLEGRO_DISPLAY* display = NULL;
	ALLEGRO_EVENT_QUEUE* eq = NULL;
	ALLEGRO_TIMER* timer = NULL;
	ALLEGRO_FONT* font18 = NULL;

	// =====================

	/*ALLEGRO_INIT*/
	if(!al_init())
		return -1;
	display = al_create_display(WIDTH,HEIGHT);
	if(!display)
		return -1;

	// ======================

	/*ADDON_INSTALL*/

	al_install_keyboard();
	al_init_image_addon();
	al_init_font_addon(); // font before ttf always
	al_init_ttf_addon();
	al_init_primitives_addon();

	// ======================

	/*PROJECT_INIT*/
	srand(time(NULL));
	font18 = al_load_font("assets/FreeMonoBold.ttf",18,0);
	playerImg=al_load_bitmap("assets/player.png");
	stickImg=al_load_bitmap("assets/stick.png");
	al_convert_mask_to_alpha(playerImg,al_map_rgb(255,0,255));
	player = new Player();
	player->init(playerImg);

	stick = new Stick();
	stick->initImg(stickImg);
	stick->init(rand()%(WIDTH-32),rand()%(HEIGHT-32),0,0,0,0,32,32);
	// ======================


	/* TIMER AND START_UP */

	eq = al_create_event_queue();
	timer = al_create_timer(1.0/60);
	al_start_timer(timer);


	/* register events */

	al_register_event_source(eq,al_get_timer_event_source(timer));
	al_register_event_source(eq,al_get_keyboard_event_source());
	al_register_event_source(eq,al_get_display_event_source(display));


	// ======================

	/* THE LOOP */
	while(!done){
		ALLEGRO_EVENT ev;
		al_wait_for_event(eq,&ev);

		switch(ev.type){

		case ALLEGRO_EVENT_KEY_DOWN:

			switch(ev.keyboard.keycode){
			case ALLEGRO_KEY_ESCAPE:
				done = true;
				break;
			case ALLEGRO_KEY_UP:
				keys[UP]=true;
				break;
			case ALLEGRO_KEY_DOWN:
				keys[DOWN]=true;
				break;
			case ALLEGRO_KEY_LEFT:
				keys[LEFT]=true;
				break;
			case ALLEGRO_KEY_RIGHT:
				keys[RIGHT]=true;
				break;
			case ALLEGRO_KEY_SPACE:
				keys[SPACE]=true;
				break;
			}

			break;

		case ALLEGRO_EVENT_KEY_UP:

			switch(ev.keyboard.keycode){
				case ALLEGRO_KEY_ESCAPE:
					done = true;
					break;
				case ALLEGRO_KEY_UP:
					keys[UP]=false;
					break;
				case ALLEGRO_KEY_DOWN:
					keys[DOWN]=false;
					break;
				case ALLEGRO_KEY_LEFT:
					keys[LEFT]=false;
					break;
				case ALLEGRO_KEY_RIGHT:
					keys[RIGHT]=false;
					break;
				case ALLEGRO_KEY_SPACE:
					keys[SPACE]=false;
					break;
				}
			break;

		case ALLEGRO_EVENT_DISPLAY_CLOSE:
			done=true;
			break;

		/*UPDATE*/
		case ALLEGRO_EVENT_TIMER:
			render = true;
			if(keys[UP]){
				player->moveUp();
				// force one direction movement No diagonal movement
				keys[RIGHT]=false;
				keys[LEFT]=false;
			}else if(keys[DOWN]){
				player->moveDown();
				// force one direction movement No diagonal movement
				keys[RIGHT]=false;
				keys[LEFT]=false;
			}else
			// we should rest the animation for the player here
			player->restAnimation(1);

			if(keys[LEFT]){
				player->moveLeft();
				// force one direction movement No diagonal movement
				keys[UP]=false;
				keys[DOWN]=false;
			}else if(keys[RIGHT]){
				player->moveRight();
				// force one direction movement No diagonal movement
				keys[UP]=false;
				keys[DOWN]=false;
			}else
			// and rest it it here also.
			player->restAnimation(0);

			player->update();
			stick->update();
			if(stick->checkCollision(player)){
				stick->collided(player);
				stick->init(rand()%(WIDTH-32),rand()%(HEIGHT-32),0,0,0,0,32,32);
			}
			break;
		// ==================
		}

		/*RENDER*/
		if(render && al_is_event_queue_empty(eq)){
			render = false;
			// do rendering here
			player->render();
			stick->render();
			al_draw_textf(font18, al_map_rgb(255, 0, 255), 5, 5, 0, "Score: %i",player->getScore());
			al_flip_display();
			al_clear_to_color(al_map_rgb(0,0,0));
		}
		// ==================
	}

	// ======================



	/*DESTROY*/
	al_destroy_display(display);
	al_destroy_timer(timer);
	al_destroy_event_queue(eq);
	al_destroy_font(font18);
	al_destroy_bitmap(playerImg);
	al_destroy_bitmap(stickImg);
	delete player;
	delete stick;
	return 0;
}