コード例 #1
0
ファイル: GameScreen.cpp プロジェクト: ZwodahS/DiceBattle
GameScreen::DieSprite GameScreen::getAndRemoveDieSprite(sf::Int32 i)
{
    for(std::vector<DieSprite>::iterator it = _diceSprites.begin() ; it != _diceSprites.end() ; ++it)
    {
        if((*it).die.id == i)
        {
            DieSprite ds = *it;
            _diceSprites.erase(it);
            return ds;
        } 
    }
    Die d;
    return makeDie(d);
}
コード例 #2
0
ファイル: Cell.cpp プロジェクト: bkuker/DaemonDice
void Cell::step()
{
	Cell* no = NULL;
	int e,s,u;
	Die* d;
	Lightning* l;
    float t;
	CELL_STATE st;
	std::set<Player*>::iterator i;

	switch (state){
	case CLEAR:
		break;
	case LIGHTNING:
		if (lightning != NULL){
			delete lightning;
			lightning = NULL;
		}
		makeDie();
		state = RISE1;
		time=0;
		break;
    case RISE1:
		for (i = players.begin(); i != players.end(); i++ )
			(*i)->up = true;
		state = RISE2;
        break;
	case RISE2:
		state = OCCUPIED;
        break;
	case OCCUPIED:
        break;
	case ROLLOUT:
		///Move players to next cell
		for (i = players.begin(); i != players.end(); i++ ){
			if ( (*i)->up )
			{
				n(out)->players.insert(*i);
				(*i)->m_pCell = n(out);
				//(*i)->m_v2Position.y = 0.5f;
				//(*i)->m_v2Position.x = 0.5f;
				switch (out){
				case NORTH:
					(*i)->m_v2Position.y = 0;
					break;
				case SOUTH:
					(*i)->m_v2Position.y = 1;
					break;
				case EAST:
					(*i)->m_v2Position.x = 0;
					break;
				case WEST:
					(*i)->m_v2Position.x = 1;
					break;
				}
			}
		}
		players.clear();

		rotate(out);
		die->rotate(out);
		dxs->playSound(snd_roll);
	case PUSHOUT:
		die->rise(1);

		//squish'em
		for (i = n(out)->players.begin(); i != n(out)->players.end(); i++ ){
			if ( !((*i)->up)){
				(*i)->squash();
				addPlayer(*i);
				(*i)->m_pCell = this;
			}
		}
		//Now remove all the players in here from n(out)
		//I know it might make an unneeded call or 2
		for (i = players.begin(); i != players.end(); i++ ){
			n(out)->delPlayer(*i);
		}


		no = n(out);
		//Store neighbor vars
		t = no->time;
		e = no->n_east;
		u = no->n_up;
		s = no->n_south;
		l = no->lightning;
		d = no->die;
		st = no->state;
		
		//set neighbor 
		no->state = OCCUPIED;
		no->n_east = n_east;
		no->n_south = n_south;
		no->n_up = n_up;
		no->die = die;
		no->time = 0;
		no->into = false;
		no->checkMatch = true;
		no->lightning = NULL;
		no->m_pWhoSunk = m_pWhoSunk;

		no->chain = 0;
		chain = 0;
		checkMatch = false;
		m_pWhoSunk = NULL;

		//set my vars
		if ( st == RISE1 || st == RISE2 || st == LIGHTNING){
			state = st;
			die = d;
			lightning = l;
			time = t;
			n_up = u;
			n_east = e;
			n_south = s;
			into = false;
		} else {
			if ( l != NULL )
				delete l;
			if ( d != NULL )
				delete d;
			die = NULL;
			state = CLEAR;
			into = false;
		}
        break;
	case SINK1:
		for (i = players.begin(); i != players.end(); i++ )
			(*i)->up = false;
		state = SINK2;
        break;
	case SINK2:
		delete die;
		die = NULL;
		state = CLEAR;
		m_pWhoSunk = NULL;
		chain = 0;
        break;
	}
	//dxs->debugprintf("Cell %i,%i step() to %i.", x, y, state);
}