예제 #1
0
void CFBTeam::switchHilightPlayer()
{
    CC_ASSERT(isDefending());
    m_hilightPlayerId++;
    if (m_hilightPlayerId >= getPlayerNumber())
    {
        m_hilightPlayerId = 1;
    }
}
예제 #2
0
파일: gameData.cpp 프로젝트: hue11/myTest
int GameData::getScore(int index)
{
    if(index > getPlayerNumber() || index < 0)
    {
        return 0;
    }
    
    std::list<Player>::iterator it = playerList.begin();
    
    
    for(int i = 0; i != index; i++)
    {
        it++;
    }
    
    return it->getTotalScore();
}
예제 #3
0
void GameData::decodeScore_Packet(sf::Packet & packet)
{
    //structure :
    //(# of player) -> for each player[(size of scoreList)->(scoreList)]

    int playerNumber;
    packet >> playerNumber;
    if(playerNumber != getPlayerNumber())
    {
        std::cout << "PlayerNum Error...the value is " << playerNumber << std::endl;
        RebuildPlayer(playerNumber);
    }

    for(Player &player : playerList)
    {
        //get the size first
        int size;
        packet >> size;

        //get that player's scoreList
        std::vector<int>& holdList = player.getScoreList();

        //clear the list
        holdList.clear();

        for(int i = 0; i < size; i++)
        {
            int value;
            packet >> value;
            holdList.push_back(value);
        }
    }

    //set the basic texture path of each player
    std::string texture_path[] = { "Texture/box_blue_1_", "Texture/box_red_1_", "Texture/box_green_1_", "Texture/box_yellow_1_" };
    int numPlayer = 0;
    for (Player &player : playerList)
    {
        player.setTexturePath(texture_path[numPlayer]);
        numPlayer++;
    }

    playerList_it = playerList.begin();

    isCreated = true;
}
예제 #4
0
//retrieves user specified scores
void retrieveScores(int score_keep[][NUM_PLAYERS], int game_count)
{
    int game = 0, player = 0;
    bool doAgain = true;
    
    while (doAgain)
    {
        //gets game number to view
        cout << endl << "What game would you like to view?" << endl;
        game = getValidGameNumber(game_count)-1;
        
        //gets player number to view
        cout << "What player would you like to view (you can view all by entering 0)?" << endl;
        player = getPlayerNumber()-1;
        
        //prints all player scores if user entered 0
        if (player == -1)
        {
            int i = 0;
            while ((score_keep[game][i] != -1) && (i < 20))
            {
                cout << "Player " << (i+1) << ": " << score_keep[game][i] << endl;
                i++;
            }
        }
        //prints specified player's score
        else
        {
            if (score_keep[game][player] == -1)
                cout << "There weren't this many players. Try again in the loop." << endl;
            else
            {
                cout << "Game " << (game+1) << endl;
                cout << "Player " << (player+1) << ": " << score_keep[game][player] << endl;
            }
        }
        
        //prompts the user if they would like to retrieve another score
        cout << "Would you like to view another game (y/n)?" << endl;
        doAgain = getValidChoice();
    }
    return;
}
예제 #5
0
void CFBMatch::syncTeam()
{
    auto team = m_teamsInMatch[(int)SIDE::SELF];
    
    vector<float> v;
    int num = team->getPlayerNumber();
    
    for (int i = 0; i < num; ++i)
    {
        auto player = team->getPlayer(i);
        auto& pos = player->getPosition();
        v.push_back(pos.x);
        v.push_back(pos.y);
        auto& vec = player->getMovingVector();
        v.push_back(vec.x);
        v.push_back(vec.y);
    }
    
    m_proxy->sendTeamPosition(v, team->isAttacking() ? team->getHilightPlayerId() : -1, (unsigned int)team->getSide());
}
예제 #6
0
void CFBMatch::teamPositionAck(int side, const vector<float>& p, int ballPlayerId, unsigned int timeStamp)
{
    auto team = m_teams[side];
    
    int size = team->getPlayerNumber();
    
    if (timeStamp == 0)     // timeStamp为0表示暂停时候的强制同步
    {
        for (int i = 0; i < size; ++i)
        {
            Point pos(p[i * 4], p[i * 4 + 1]);
            Point vec(p[i * 4 + 2], p[i * 4 + 3]);
            auto player = team->getPlayer(i);
            
            player->loseBall();
            player->setPosition(pos);
            player->setMovingVector(vec);
        }
        
        if (ballPlayerId != -1)
        {
            team->getPlayer(ballPlayerId)->gainBall();
        }
    }
    else
    {
        float dt = m_proxy->getDeltaTime(timeStamp);
        
        for (int i = 0; i < size; ++i)
        {
            Point pos(p[i * 4], p[i * 4 + 1]);
            Point vec(p[i * 4 + 2], p[i * 4 + 3]);
            auto player = team->getPlayer(i);

            player->moveFromTo(pos, vec, dt, m_SYNC_TIME);
        }
        
        CC_ASSERT(team == m_teamsInMatch[(int)SIDE::OPP]);
        m_syncTime[(int)SIDE::OPP] = m_SYNC_TIME;
    }
}
예제 #7
0
sf::Packet& GameData::fillScore_Packet(sf::Packet & packet)
{
    //structure :
    //(# of player) -> for each player[(size of scoreList)->(scoreList)]

    //send the amount of player
    packet << getPlayerNumber();

    for(Player &player : playerList)
    {
        //get that player's scoreList
        std::vector<int> holdList = player.getScoreList();
        //send the size first
        packet << static_cast<int>(holdList.size());
        //send the scoreList
        for(int & num : holdList)
        {
            packet << num;
        }
    }
    return packet;
}
void ComponentUserControllable::setupInputHandlers()
{
	const int playerNumber = getPlayerNumber();

	ASSERT(input,           "Have not yet received input subsystem!");
	ASSERT(playerNumber>=0, "Have not received updated player number!");

	const int joystickNumber = playerNumber;


	handleGamePadBtnR_down = input->registerJoyButtonPressHandler(joystickNumber, XPAD_BTN_R, bind(&ComponentUserControllable::onKeyPressChargeUp, this));
	handleGamePadBtnR_up = input->registerJoyButtonUpHandler(joystickNumber, XPAD_BTN_R, bind(&ComponentUserControllable::onKeyPressAttack, this));
	handleGamePadBtnL_down = input->registerJoyButtonPressHandler(joystickNumber, XPAD_BTN_L, bind(&ComponentUserControllable::onKeyPressChargeUp, this));
	handleGamePadBtnL_up = input->registerJoyButtonUpHandler(joystickNumber, XPAD_BTN_L, bind(&ComponentUserControllable::onKeyPressAttack, this));
	handleGamePadBtnY = input->registerJoyButtonPressHandler(joystickNumber, XPAD_BTN_Y, bind(&ComponentUserControllable::onKeyPressUse, this));
	handleGamePadAxisX = input->registerJoyAxisMotionHandler(joystickNumber, XPAD_AXIS_X, bind(&ComponentUserControllable::onJoystickAxisX, this, _1));
	handleGamePadAxisY = input->registerJoyAxisMotionHandler(joystickNumber, XPAD_AXIS_Y, bind(&ComponentUserControllable::onJoystickAxisY, this, _1));
	handleGamePadAxisXRot = input->registerJoyAxisMotionHandler(joystickNumber, XPAD_AXIS_XROT, bind(&ComponentUserControllable::onJoystickAxisXRot, this, _1));
	handleGamePadAxisYRot = input->registerJoyAxisMotionHandler(joystickNumber, XPAD_AXIS_YROT, bind(&ComponentUserControllable::onJoystickAxisYRot, this, _1));

	if(joystickNumber == 0)
	{
		handleKeyboardF = input->registerKeyPressHandler(SDLK_f, bind(&ComponentUserControllable::onKeyPressSuicide, this));
		handleKeyboardE = input->registerKeyPressHandler(SDLK_e, bind(&ComponentUserControllable::onKeyPressUse, this));
		handleKeyboardSpace_down = input->registerKeyPressHandler(SDLK_SPACE, bind(&ComponentUserControllable::onKeyPressChargeUp, this));
		handleKeyboardSpace_up = input->registerKeyUpHandler(SDLK_SPACE, bind(&ComponentUserControllable::onKeyPressAttack, this));

		handleKeyboardW = input->registerKeyDownHandler(SDLK_w, bind(&ComponentUserControllable::onKeyDownFwd, this));
		handleKeyboardS = input->registerKeyDownHandler(SDLK_s, bind(&ComponentUserControllable::onKeyDownRev, this));
		handleKeyboardA = input->registerKeyDownHandler(SDLK_a, bind(&ComponentUserControllable::onKeyDownLeft, this));
		handleKeyboardD = input->registerKeyDownHandler(SDLK_d, bind(&ComponentUserControllable::onKeyDownRight, this));

		handleMouseMove = input->registerMouseMoveHandler(bind(&ComponentUserControllable::onMouseMove, this, _1, _2));
		handleMouseRightClick = input->registerMouseDownRightHandler(bind(&ComponentUserControllable::onMouseDownRight, this, _1, _2));
		handleMouseLeftDown = input->registerMouseDownLeftHandler(bind(&ComponentUserControllable::onMouseDownLeft, this, _1, _2));
		handleMouseLeftUp = input->registerMouseUpLeftHandler(bind(&ComponentUserControllable::onMouseUpLeft, this, _1, _2));
	}
}
예제 #9
0
void CFBMatch::update(float dt)
{
    m_proxy->update(dt);
    switch (m_matchStep)
    {
        case FBDefs::MATCH_STEP::WAIT_START:
            break;
        case FBDefs::MATCH_STEP::COUNT_DOWN:
        {
            int delta = (int)(m_startTime - m_proxy->getTime());
            if (delta <= 0)
            {
                m_matchStep = FBDefs::MATCH_STEP::MATCHING;
            }
            break;
        }
        case FBDefs::MATCH_STEP::MATCHING:
        {
            if (!m_isPause)
            {
                m_teamsInMatch[(int)SIDE::SELF]->update(dt);
                m_teamsInMatch[(int)SIDE::OPP]->update(dt);
            }
            
            if (m_currentInstruction != nullptr)
            {
                m_currentInstruction->update(dt);
            }
            
            for (int i = 0; i < (int)SIDE::NONE; ++i)
            {
                if (m_syncTime[i] < 0)
                {
                    if (i == (int)SIDE::SELF)
                    {
                        auto hilightPlayer = m_teamsInMatch[(int)SIDE::SELF]->getHilightPlayer();
                        hilightPlayer->setMovingVector(m_vecFromUser);
                        m_teamsInMatch[(int)SIDE::SELF]->think();
                        syncTeam();
                        m_syncTime[i] = m_SYNC_TIME;
                    }
                    else
                    {
                        auto oppTeam = m_teamsInMatch[(int)SIDE::OPP];
                        int num = oppTeam->getPlayerNumber();
                        for (int i = 0; i < num; ++i)
                        {
                            oppTeam->getPlayer(i)->setMovingVector(0, 0);
                        }
                    }
                }
                
                m_syncTime[i] -= dt;
            }
            break;
        }
        case FBDefs::MATCH_STEP::PLAY_ANIM:
        {
            break;
        }
        default:
            break;
    }
}
예제 #10
0
QString SnakePart::decodePart()
{
    QString name;

    // Player
    if (getPlayerNumber() == 0)
    {
        name = QLatin1String( "tron1-" );
    }
    else if (getPlayerNumber() == 1)
    {
        name = QLatin1String( "tron2-" );
    }

    // Heads (or tails)
    if (getPartType() == SnakePartType::Head)
    {
        if (getPartTop() && getPartLeft() && getPartRight())
        {
            name += QLatin1String( "head-north" );
        }
        else if (getPartBottom() && getPartLeft() && getPartRight())
        {
            name += QLatin1String( "head-south" );
        }
        else if (getPartTop() && getPartBottom() && getPartLeft())
        {
            name += QLatin1String( "head-west" );
        }
        else if (getPartTop() && getPartBottom() && getPartRight())
        {
            name += QLatin1String( "head-east" );
        }
    }
    else if (getPartType() == SnakePartType::Hole)
    {
        if (getPartTop() && getPartLeft() && getPartRight())
        {
            name += QLatin1String( "tail-south" );
        }
        else if (getPartBottom() && getPartLeft() && getPartRight())
        {
            name += QLatin1String( "tail-north" );
        }
        else if (getPartTop() && getPartBottom() && getPartLeft())
        {
            name += QLatin1String( "tail-east" );
        }
        else if (getPartTop() && getPartBottom() && getPartRight())
        {
            name += QLatin1String( "tail-west" );
        }
    }
    else if (getPartType() == SnakePartType::Tail)
    {
        if (getPartTop() && getPartLeft() && getPartRight())
        {
            name += QLatin1String( "tail-south2" );
        }
        else if (getPartBottom() && getPartLeft() && getPartRight())
        {
            name += QLatin1String( "tail-north2" );
        }
        else if (getPartTop() && getPartBottom() && getPartLeft())
        {
            name += QLatin1String( "tail-east2" );
        }
        else if (getPartTop() && getPartBottom() && getPartRight())
        {
            name += QLatin1String( "tail-west2" );
        }
    }
    else if (getPartType() == SnakePartType::Body)
    {
        // Bodys
        if (getPartTop() && getPartBottom())
        {
            name += QLatin1String( "body-h" );
        }
        else if (getPartLeft() && getPartRight())
        {
            name += QLatin1String( "body-v" );
        }
        else if (getPartLeft() && getPartTop())
        {
            name += QLatin1String( "body-nw" );
        }
        else if (getPartTop() && getPartRight())
        {
            name += QLatin1String( "body-ne" );
        }
        else if (getPartLeft() && getPartBottom())
        {
            name += QLatin1String( "body-sw" );
        }
        else if (getPartBottom() && getPartRight())
        {
            name += QLatin1String( "body-se" );
        }
    }

    return name;
}