コード例 #1
0
ファイル: Player.cpp プロジェクト: b055/Tron
//possible moves for a player somewhere in the middle of the sphere
std::vector<std::vector< int> > Player::middleMoves()
{
    std::vector<std::vector< int> > result;
    //if(debug){
    //	std::cout<<"starting middle moves\n";
    //	std::cout<<" here we are\n";
    //}


    //normal y's
    //if(debug)
    //	std::cout<<"getting normal y's\n";
    std::vector<int> up = upMove(y);
    if(!up.empty()) {
        result.push_back(up);
    }
    std::vector<int> down = downMove(y);
    if(!down.empty())
        result.push_back(down);

    if(x==29)//right edge
    {
        //std::cout<<"right edge\n";
        if((*grid)[y][0]==0)//can wrap around the right
        {
            std::vector<int> right = rightMove(-1);
            if(!right.empty())
                result.push_back(right);
        }
        //add left
        std::vector<int> left = leftMove(x);
        if(!left.empty())
            result.push_back(left);
    }
    else if(x==0)//left edge
    {
        //std::cout<<"left edge\n";
        if((*grid)[y][29]==0) { //can wrap around the left
            std::vector<int> left = leftMove(30);
            if(!left.empty())
                result.push_back(left);
        }
        //add right
        std::vector<int> right  = rightMove(x);
        if(!right.empty())
            result.push_back(right);
    }
    else
    {   //normal x's
        std::vector<int> left =leftMove(x);
        if(!left.empty())
            result.push_back(left);
        std::vector<int> right  = rightMove(x);
        if(!right.empty())
            result.push_back(right);
    }
    return result;
}
コード例 #2
0
ファイル: main.c プロジェクト: nirenxiaoxiao/2048_linux_c
int moveDir(char dir)
{
	storeNow();
	switch(dir)
	{
	case 'a': leftMove();	break;
	case 'd': rightMove();	break;
	case 's': downMove();	break;
	case 'w': upMove();	break;
	case 'b': backMove();break;	
	}	
	if(moveFlag)
	{
		if(backTo == boardOneBefore)
			backTo = boardTwoBefore;
		else
			backTo = boardOneBefore;	
	}
}
コード例 #3
0
ファイル: Rotator.cpp プロジェクト: Bastnt/RushMyCube
//--------------------------------------------------------------
void Rotator::update(){
	if(_redCircle->isFinished()) {
		_wiimote->SetRumble(false);
		launchDemo();
	}

	_greenCircle->isFinished();

	float elapsedTime = ofGetElapsedTimef();
	//-------------------------------------------------------------------------------------------------------------------
	// WIIMOTE CONTROLS (HORIZONTAL POSITION)
	//-------------------------------------------------------------------------------------------------------------------

	if(_wiimote->pressed(1, _wiimote->Button.One())) {
		if(!_demo->isActive())
			launchDemo();
		else {
			_demo->stop();
			_whiteCircle->stop();
		}
	}

	if(!_demo->isActive()) {
		if(_wiimote->pressed(0, _wiimote->Button.Two())) {
			if(_cursor.X==_sequence[_progression].X && _cursor.Y==_sequence[_progression].Y) {
				//good move
				_greenCircle->start(ANIMATION_LENGTH, _cursor.X, _cursor.Y);
				_progression++;
			}
			else {
				//bad move (loser!)
				_greenCircle->start(ANIMATION_LENGTH,_sequence[_progression].X, _sequence[_progression].Y);
				_redCircle->start(ANIMATION_LENGTH,_cursor.X, _cursor.Y);
				_progression=0;
				_wiimote->SetRumble(true);
			}
		}
	}
		
	if(!_demo->isActive()) {
		if(_wiimote->pressed(2, _wiimote->Button.Up()))
			leftMove();
		if(_wiimote->pressed(3, _wiimote->Button.Down()))
			rightMove();
		if(_wiimote->pressed(4, _wiimote->Button.Left()))
			upMove();
		if(_wiimote->pressed(5, _wiimote->Button.Right()))
			downMove();
	}

	if(ofGetElapsedTimeMillis() - _rotateTime > 8)
	{
		_rotateTime = ofGetElapsedTimeMillis();
		_rotation += 0.05 + 0.01*_level;
		if(_rotation>=360) _rotation=0.0;
	}

	//-------------------------------------------------------------------------------------------------------------------
	// BACKGROUND GRADIENT COLOR
	//-------------------------------------------------------------------------------------------------------------------
	gradientTransition(6.0-0.5*_level);
	
	//-------------------------------------------------------------------------------------------------------------------
	// DEMO (BEGINS WITH AN INTERVAL)
	//-------------------------------------------------------------------------------------------------------------------
	_demo->isFinished();
	_whiteCircle->isFinished();
	if(_demo->newTop()) {
		_whiteCircle->start(DEMO_ANIMATION_LENGTH, _sequence[_demoIndex].X, _sequence[_demoIndex].Y);
		_demoIndex++;
	}
}