Beispiel #1
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->chatTimeout = true;
    this->connected = false;
    this->currColorId = 2; // czarny
    this->lastColorButton = ui->blackPushButton;
    this->graphicsScene = new QGraphicsScene();
    ui->graphicsView->setScene(graphicsScene);
    this->currentPen.setColor(QColor("black"));


    connect(ui->graphicsView,SIGNAL(drawPoint(QPoint)),this,SLOT(drawPoint(QPoint)));
    connect(ui->graphicsView,SIGNAL(drawLineTo(QPoint)),this,SLOT(drawLineTo(QPoint)));

    connect(ui->clearPushButton,SIGNAL(clicked()),this,SLOT(clearView()));
    connect(ui->redPushButton,SIGNAL(clicked()),this,SLOT(switchColor()));
    connect(ui->greenPushButton,SIGNAL(clicked()),this,SLOT(switchColor()));
    connect(ui->blackPushButton,SIGNAL(clicked()),this,SLOT(switchColor()));
    connect(ui->sendMessagePushButton,SIGNAL(clicked()),this,SLOT(sendMessage()));
    connect(ui->chatLineEdit,SIGNAL(returnPressed()),this,SLOT(sendMessage()));

    this->socket = new KalSocket();
    this->chatTimer = new QTimer();

    connect(socket,SIGNAL(connected()),this,SLOT(connectionSuccess()));
    connect(socket,SIGNAL(error(QAbstractSocket::SocketError)),
            this,SLOT(displayError(QAbstractSocket::SocketError)));
    connect(socket,SIGNAL(pointsReceived(int,int,int,KalSocket::DrawType)),
            this,SLOT(pointsReceived(int,int,int,KalSocket::DrawType)));
    connect(socket,SIGNAL(clear()),graphicsScene,SLOT(clear()));
    connect(socket,SIGNAL(someoneLoggedIn(QString)),this,SLOT(someoneLoggedIn(QString)));
    connect(socket,SIGNAL(chatMessage(QString,QString)),this,SLOT(addMessage(QString,QString)));
    connect(socket,SIGNAL(nicknames(QList<QString>)),this,SLOT(getNicknames(QList<QString>)));
    connect(socket,SIGNAL(logout(QString)),this,SLOT(someoneLoggedOut(QString)));
    connect(socket,SIGNAL(drawStart(QString)),this,SLOT(drawStart(QString)));
    connect(socket,SIGNAL(gotSettings(ServerSettings)),this,SLOT(getSettings(ServerSettings)));
    connect(socket,SIGNAL(errorMessage(QString)),this,SLOT(showMessage(QString)));

    connect(ui->wantDrawCheckBox,SIGNAL(toggled(bool)),this,SLOT(wantDrawToggled(bool)));

    // actiony z menu: Polaczenie
    connect(ui->actionPo_cz,SIGNAL(triggered()),this,SLOT(connectWindowExec())); // laczymy sie
    connect(ui->actionRoz_cz,SIGNAL(triggered()),this,SLOT(disconnect())); // rozlaczamy sie
    connect(ui->actionZako_cz,SIGNAL(triggered()),this,SLOT(close())); // koniec programu

    // timer
    connect(chatTimer,SIGNAL(timeout()),this,SLOT(timeout()));
    connect(ui->progressBar,SIGNAL(full()),this,SLOT(drawTimeout()));

    // inne
    this->disableActions(false); // Polacz - aktywne, Rozlacz - nieaktywne
}
Beispiel #2
0
void CController::run() {
    board::CBoard board;
    auto currentColor = board::ESquare::WHITE;
    std::vector<int> captures = board.squaresWithCapture(currentColor);
    std::vector<int> moves = board.squaresWithMove(currentColor);
    while (not captures.empty() || not moves.empty()) {
        ui_->show(board, currentColor);
        auto * currentPlayer = players_.find(currentColor)->second.get();

        const std::vector<int> possible = captures.empty() ? moves : captures;
        const auto move = currentPlayer->play(board, possible, *ui_);

        if (move == std::pair<int, int>(0, 0))
            break;

        if (not board.isValid(move.first) || not board.isValid(move.second)) {
            ui_->showInvalidMove(move);
            continue;
        }

        const auto dests = board.possibleDestinationsFrom(move.first);
        if (std::find(dests.begin(), dests.end(), move.second) == dests.end()) {
            ui_->showInvalidMove(move);
            continue;
        }

        if (not captures.empty()) {
            if (std::find(captures.begin(), captures.end(), move.first) == captures.end()) {
                ui_->showInvalidMove(move);
                continue;
            }
        } else {
            if (std::find(moves.begin(), moves.end(), move.first) == moves.end()) {
                ui_->showInvalidMove(move);
                continue;
            }
        }
        board.executeMove(move.first, move.second);

        if (not captures.empty() && board.hasCapture(move.second)) {
            captures = std::vector<int> {move.second};
        } else {
            currentColor = switchColor(currentColor);

            captures = board.squaresWithCapture(currentColor);
            moves = board.squaresWithMove(currentColor);
        }
    }

    ui_->show(board);
    currentColor = switchColor(currentColor);

    ui_->announceWinner(currentColor);

}
void HeartBeat::listen()
{
	float a = audio.eq.spectrum[1] - 70;
	
	if (a < 0) a = 0;
	
	float ratio = a / 950 * maxBrightness;
	
	for (int n=0;n<8;n++)
	{
		fLEDs.entry(n)->me->brightness = ratio;
	}
	
	if (lastValue == 0)
	{
		if (a != 0)
		{
			switchColor();
		}
	}
	
	lastValue = a;
	
//	float b = audio.eq.spectrum[5] - 100;
//	float ratioB = b / 900 * maxBrightness;
//	foos.entry(0)->me->fLEDs.entry(0)->me->brightness = ratioB;
}
void RGBElement::setB(byte value, bool force) {
    m_Bnext = value;
    m_sync = force;
    if(force)
    {
        switchColor();
        writeB();
    }
}
void PluginWindow::init(QString element)
{
	GameElement::ElementType elemType;
	if (element == "white") {
		elemType = GameElement::TypeWhite;
	} else {
		elemType = GameElement::TypeBlack;
	}
	// Инициируем модель доски
	if (bmodel == NULL) {
		bmodel = new BoardModel(this);
		connect(bmodel, SIGNAL(changeGameStatus(GameModel::GameStatus)), this, SLOT(changeGameStatus(GameModel::GameStatus)));
		connect(bmodel, SIGNAL(setupElement(int, int)), this, SLOT(setupElement(int, int)));
		connect(bmodel, SIGNAL(lose()), this, SLOT(setLose()), Qt::QueuedConnection);
		connect(bmodel, SIGNAL(draw()), this, SLOT(setDraw()), Qt::QueuedConnection);
		connect(bmodel, SIGNAL(switchColor()), this, SIGNAL(switchColor()));
		connect(bmodel, SIGNAL(doPopup(const QString)), this, SIGNAL(doPopup(const QString)));
	}
void RGBElement::setRGB(byte R, byte G, byte B, bool force)
{
    if((m_Ract != R)||(m_Gact != G)||(m_Bact !=B))
    {
        m_Rnext = R;
        m_Gnext = G;
        m_Bnext = B;
        m_sync = force;
    }
    if(force) {
        switchColor();
        writeRGB();
    }
}
void RGBElement::update()
{
    /*
     * WAIT FOR NEXT WAIT TIME /
     */
    /*
     * IF COLOR CHANGE PRINT STATUS
     */
    if(!isReady())
    {
        if(m_fade)
        {
            fadeColor();
        }
        else
        {
            switchColor();
        }
        writeRGB();
    }
    if(m_sync||(m_play && (millis()> m_nextWait)))
    {
        m_nextWait = millis()+ (m_wTime * 1000);
        stateMaschine();
        if(m_state > 3)
        {
            m_sync = false;
        }
    }
    else if(!m_play)
    {
        /*
         * SAVE WAIT TIME STATE
         *  ADD DURATION QUICKFIX
         */
        if(m_nextWait > millis())
        {
            int diff = m_nextWait - millis();
            m_nextWait += diff;
        }
    }
}
Beispiel #8
0
/******************************************************************************
  * version:    1.0
  * author:     link
  * date:       2016.01.20
  * brief:      点击按钮,发送颜色信息
******************************************************************************/
void w_Colr::buttonJudge(int id)
{
    emit switchColor(id);
    emit switchWindow(W_CONF);
}
Beispiel #9
0
void edgeColoringSimple(Shape &shape, double angleThreshold, unsigned long long seed) {
    double crossThreshold = sin(angleThreshold);
    std::vector<int> corners;
    for (std::vector<Contour>::iterator contour = shape.contours.begin(); contour != shape.contours.end(); ++contour) {
        // Identify corners
        corners.clear();
        if (!contour->edges.empty()) {
            Vector2 prevDirection = (*(contour->edges.end()-1))->direction(1);
            int index = 0;
            for (std::vector<EdgeHolder>::const_iterator edge = contour->edges.begin(); edge != contour->edges.end(); ++edge, ++index) {
                if (isCorner(prevDirection.normalize(), (*edge)->direction(0).normalize(), crossThreshold))
                    corners.push_back(index);
                prevDirection = (*edge)->direction(1);
            }
        }

        // Smooth contour
        if (corners.empty())
            for (std::vector<EdgeHolder>::iterator edge = contour->edges.begin(); edge != contour->edges.end(); ++edge)
                (*edge)->color = WHITE;
        // "Teardrop" case
        else if (corners.size() == 1) {
            EdgeColor colors[3] = { WHITE, WHITE };
            switchColor(colors[0], seed);
            switchColor(colors[2] = colors[0], seed);
            int corner = corners[0];
            if (contour->edges.size() >= 3) {
                int m = contour->edges.size();
                for (int i = 0; i < m; ++i)
                    contour->edges[(corner+i)%m]->color = (colors+1)[int(3+2.875*i/(m-1)-1.4375+.5)-3];
            } else if (contour->edges.size() >= 1) {
                // Less than three edge segments for three colors => edges must be split
                EdgeSegment *parts[7] = { };
                contour->edges[0]->splitInThirds(parts[0+3*corner], parts[1+3*corner], parts[2+3*corner]);
                if (contour->edges.size() >= 2) {
                    contour->edges[1]->splitInThirds(parts[3-3*corner], parts[4-3*corner], parts[5-3*corner]);
                    parts[0]->color = parts[1]->color = colors[0];
                    parts[2]->color = parts[3]->color = colors[1];
                    parts[4]->color = parts[5]->color = colors[2];
                } else {
                    parts[0]->color = colors[0];
                    parts[1]->color = colors[1];
                    parts[2]->color = colors[2];
                }
                contour->edges.clear();
                for (int i = 0; parts[i]; ++i)
                    contour->edges.push_back(EdgeHolder(parts[i]));
            }
        }
        // Multiple corners
        else {
            int cornerCount = corners.size();
            int spline = 0;
            int start = corners[0];
            int m = contour->edges.size();
            EdgeColor color = WHITE;
            switchColor(color, seed);
            EdgeColor initialColor = color;
            for (int i = 0; i < m; ++i) {
                int index = (start+i)%m;
                if (spline+1 < cornerCount && corners[spline+1] == index) {
                    ++spline;
                    switchColor(color, seed, EdgeColor((spline == cornerCount-1)*initialColor));
                }
                contour->edges[index]->color = color;
            }
        }
    }
}