void resetGame(char *playerHand, char *dealerHand, char *deck,int *playerScore,int *dealerScore, int *deckPointer, bool *checkForWinner) {
    shuffle(deck);
    drawHand(dealerHand, deck, deckPointer);
    drawHand(playerHand,deck, deckPointer);
    *checkForWinner = false;
    *playerScore = *dealerScore = 0;
}
Example #2
0
void Clock::draw() const
{
  float colorRed[3] = {1.0, 0.0, 0.0};
  float colorWhite[3] = {1.0, 1.0, 1.0};
  float colorBlack[3] = {0.0, 0.0, 0.0};
  const time_t now = time(0);
  tm *convertedTime = localtime(&now);
  int hours = convertedTime->tm_hour % 12;
  int minutes = convertedTime->tm_min;
  float hourAngles = 90 - (hours + minutes / 60.0) * (360 / 12);
  float minuteAngles = 90 - minutes * (360 / 60);

  // Draw clock border
  drawCircle(colorRed, 10.0, GL_LINE_LOOP, radius);

  // Draw clock face
  drawCircle(colorWhite, 1.0, GL_TRIANGLE_FAN, radius * 0.97);

  // Draw clock numbers
  drawNumbers(colorBlack, GLUT_BITMAP_TIMES_ROMAN_24);

  // Draw hour hand
  drawHand(hourAngles, colorBlack, 10.0);

  // Draw minute hand
  drawHand(minuteAngles, colorBlack, 3.5);
}
Example #3
0
void Clock::plotHands() {
	_clockHandHour = calcHand(_oldHourAngle, 14, kColorYellow);
	_clockHandMinute = calcHand(_oldMinute * 6, 17, kColorYellow);
	drawHand(_clockHandHour, kColorBrown);
	drawHand(_clockHandMinute, kColorBrown);

	_clockHandHour = calcHand(_hourAngle, 14, kColorBrown);
	_clockHandMinute = calcHand(_minute * 6, 17, kColorBrown);
	drawHand(_clockHandHour, kColorYellow);
	drawHand(_clockHandMinute, kColorYellow);
}
Example #4
0
void testCardDeal()
{
    Player p1, p2;
    p1.name = "Player 1";
    p2.name = "Player 2";
    
    Card deck[DECK_SIZE];
    
    initDeck(deck);
    
    cout << "-------- TESTING CARD FUNCTIONS ---------" << endl;
    
    cout << "--- ORIGINAL SORTED DECK ---" << endl << endl;
    displayDeck(deck);
    
    cout << endl << "--- SHUFFLED DECK ---" << endl << endl;
    shuffleCards(deck, DECK_SIZE);
    displayDeck(deck);
    
    drawHand(deck, p1);
    drawHand(deck, p2);
    
    cout << endl << "--- PLAYER HANDS ---" << endl << endl;
    displayHand(p1);
    cout << endl << endl;
    displayHand(p2);
    cout << endl << endl;
    
    
    
    tossCardFromHand(p1.hand[2], p1);
    tossCardFromHand(p2.hand[2], p2);
    
    cout << endl << "--- PLAYER HANDS ---" << endl << endl;
    displayHand(p1);
    cout << endl << endl;
    displayHand(p2);
    cout << endl << endl;
    
    drawCard(deck, p1);
    drawCard(deck, p2);
    
    
    cout << endl << "--- PLAYER HANDS ---" << endl << endl;
    displayHand(p1);
    cout << endl << endl;
    displayHand(p2);
    cout << endl << endl;
}
/*!
  \brief Draw the needle

  A clock has no single needle but three hands instead. drawNeedle
  translates value() into directions for the hands and calls
  drawHand().

  \param painter Painter
  \param center Center of the clock
  \param radius Maximum length for the hands
  \param dir Dummy, not used.
  \param colorGroup ColorGroup

  \sa drawHand()
*/
void QwtAnalogClock::drawNeedle( QPainter *painter, const QPointF &center,
                                 double radius, double dir, QPalette::ColorGroup colorGroup ) const
{
    Q_UNUSED( dir );

    if ( isValid() )
    {
        const double hours = value() / ( 60.0 * 60.0 );
        const double minutes = ( value() - ( int )hours * 60.0 * 60.0 ) / 60.0;
        const double seconds = value() - ( int )hours * 60.0 * 60.0
                               - ( int )minutes * 60.0;

        double angle[NHands];
        angle[HourHand] = 360.0 * hours / 12.0;
        angle[MinuteHand] = 360.0 * minutes / 60.0;
        angle[SecondHand] = 360.0 * seconds / 60.0;

        for ( int hand = 0; hand < NHands; hand++ )
        {
            double d = angle[hand];
            if ( direction() == Clockwise )
                d = 360.0 - d;

            d -= origin();

            drawHand( painter, ( Hand )hand, center, radius, d, colorGroup );
        }
    }
}
void GoofyLeapImageGallery::draw()
{
  ofPushMatrix();
  ofTranslate(ofGetWindowWidth()*.5, ofGetWindowHeight()*.5);
  ofScale(scaleFactor, scaleFactor);
  ofPushMatrix();
  ofTranslate(-ofGetWindowWidth()*.5, -ofGetWindowHeight()*.5);
  if(!isMoving)
    ofTranslate(mainOffsetX, 0);
  else
  {
    ofTranslate(tweenMainImage.update(), 0);
  }
  if(prevImage)
    drawImage(-ofGetWindowWidth(),prevImage);
  if(actualImage)
    drawImage(0,actualImage);
  if(nextImage)
    drawImage(ofGetWindowWidth(),nextImage);
  ofPopMatrix();
  ofPopMatrix();
  
  //glEnable(GL_DEPTH_TEST);
  glEnable(GL_NORMALIZE);
  drawHand();
  
  //glDisable(GL_DEPTH_TEST);
  glDisable(GL_NORMALIZE);
  ofDrawBitmapString(ofToString(actualImageCount+1) + "/" + ofToString(urlImages.size()), ofVec2f(20,20));
}
Example #7
0
void Person::drawArm()
{
	glPushMatrix();
		glPushMatrix();
			glScalef(.25,2.5,0);
			glCallList(squareIndex);
		glPopMatrix();
		glTranslatef(15,0,0);
		drawHand();
	glPopMatrix();
}//end drawArm
//--------------------------------------------------------------
void LeapVisualizer::drawFrame(ofxLeapMotion & leap){
	
	// If hand(s) exist in the frame,
	// Get the vector of Hands from ofxLeap.
	vector <Hand> hands = leap.getLeapHands();
	if (hands.size() > 0) {
		
		// For each hand,
		for (int h=0; h<hands.size(); h++){
			
			// Get the current hand
			Hand & hand = hands[h];
			drawHand (hand,leap);
		}
	}
}
Example #9
0
// Draw all hands
//--------------------------------------------------------------
void ofxHandGenerator::drawHands() {
	for(int i = 0;  i < max_hands; ++i)
		drawHand(i);
}
Example #10
0
void Player::endTurn() {
    // empty remaining hand into discard then draw a new hand
    discard_pile.insert(discard_pile.begin(), hand.begin(), hand.end()); // TODO test
    hand.clear();
    drawHand();
}
Example #11
0
int Darts::throwDart(int dartNum, int computer) {
	Events &events = *_vm->_events;
	Screen &screen = *_vm->_screen;
	int height;
	int horiz;
	Common::Point targetPos;
	Common::String temp;

	/* clear keyboard buffer */
	events.clearEvents();

	erasePowerBars();
	screen.print(Common::Point(_dartInfo.left, _dartInfo.top), 0, "%s # %d", FIXED(Dart), dartNum);

	drawDartsLeft(dartNum, computer);

	if (!computer) {
		screen.print(Common::Point(_dartInfo.left, _dartInfo.top + _spacing), 0, "%s", FIXED(HitAKey));
		screen.print(Common::Point(_dartInfo.left, _dartInfo.top + _spacing * 2), 0, "%s", FIXED(ToStart));
	}

	if (!computer) {
		// Wait for a hit
		while (!dartHit())
			;
	} else {
		events.wait(1);
	}

	drawDartsLeft(dartNum + 1, computer);
	screen._backBuffer2.blitFrom(screen._backBuffer1, Common::Point(_dartInfo.left, _dartInfo.top - 1),
		Common::Rect(_dartInfo.left, _dartInfo.top - 1, _dartInfo.right, _dartInfo.bottom - 1));
	screen.blitFrom(screen._backBuffer1, Common::Point(_dartInfo.left, _dartInfo.top - 1),
		Common::Rect(_dartInfo.left, _dartInfo.top - 1, _dartInfo.right, _dartInfo.bottom - 1));

	if (computer) {
		getComputerNumber(computer - 1, targetPos);
	} else {
		// Keyboard control
		targetPos = Common::Point(0, 0);
	}

	horiz = drawHand(targetPos.x, computer);
	height = doPowerBar(Common::Point(DART_BAR_VX, DART_HEIGHT_Y), DART_COLOR_FORE, targetPos.y, 1);

	// Invert height
	height = 101 - height;

	// Copy power bars to the secondary back buffer
	screen._backBuffer2.blitFrom(screen._backBuffer1, Common::Point(DART_BAR_VX - 1, DART_HEIGHT_Y - 1),
		Common::Rect(DART_BAR_VX - 1, DART_HEIGHT_Y - 1, DART_BAR_VX - 1 + 10, 
		DART_HEIGHT_Y - 1 + DART_BAR_SIZE + 2));

	Common::Point dartPos(DARTBOARD_TOTALLEFT + horiz*DARTBOARD_TOTALX / 100,
		DARTBOARD_TOTALTOP + height * DARTBOARD_TOTALY / 100);
	
	dartPos.x += 2 - _vm->getRandomNumber(4);
	dartPos.y += 2 - _vm->getRandomNumber(4);

	drawDartThrow(dartPos, computer);
	return dartScore(dartPos);
}
Example #12
0
void Clock::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option, const QRect &rect)
{
    Q_UNUSED(option)

    // compute hand angles
    const qreal minutes = 6.0 * m_time.minute() - 180;
    const qreal hours = 30.0 * m_time.hour() - 180 +
                        ((m_time.minute() / 59.0) * 30.0);
    qreal seconds = 0;
    if (m_showSecondHand) {
        static const double anglePerSec = 6;
        seconds = anglePerSec * m_time.second() - 180;

        if (m_fancyHands) {
            if (!m_secondHandUpdateTimer) {
                m_secondHandUpdateTimer = new QTimer(this);
                connect(m_secondHandUpdateTimer, SIGNAL(timeout()), this, SLOT(moveSecondHand()));
            }

            if (m_animateSeconds && !m_secondHandUpdateTimer->isActive()) {
                //kDebug() << "starting second hand movement";
                m_secondHandUpdateTimer->start(50);
                m_animationStart = QTime::currentTime().msec();
            } else {
                static const int runTime = 500;
                static const double m = 1; // Mass
                static const double b = 1; // Drag coefficient
                static const double k = 1.5; // Spring constant
                static const double PI = 3.141592653589793; // the universe is irrational
                static const double gamma = b / (2 * m); // Dampening constant
                static const double omega0 = sqrt(k / m);
                static const double omega1 = sqrt(omega0 * omega0 - gamma * gamma);
                const double elapsed = QTime::currentTime().msec() - m_animationStart;
                const double t = (4 * PI) * (elapsed / runTime);
                const double val = 1 + exp(-gamma * t) * -cos(omega1 * t);

                if (elapsed > runTime) {
                    m_secondHandUpdateTimer->stop();
                    m_animateSeconds = false;
                } else {
                    seconds += -anglePerSec + (anglePerSec * val);
                }
            }
        } else {
            if (!m_secondHandUpdateTimer) {
                m_secondHandUpdateTimer = new QTimer(this);
                connect(m_secondHandUpdateTimer, SIGNAL(timeout()), this, SLOT(moveSecondHand()));
            }

            if (m_animationStart != seconds && !m_secondHandUpdateTimer->isActive()) {
                m_secondHandUpdateTimer->start(50);
                m_animationStart = seconds; //we don't want to have a second animation if there is a external update (wallpaper etc).
                seconds += 1;
            } else {
                m_secondHandUpdateTimer->stop();
            }
        }
    }

    if (contentsRect().size().toSize() != m_theme->size()) {
        invalidateCache();
    }

    // paint face and glass cache
    QRect faceRect = m_faceCache.rect();
    if (m_repaintCache == RepaintAll) {
        m_faceCache.fill(Qt::transparent);
        m_glassCache.fill(Qt::transparent);

        QPainter facePainter(&m_faceCache);
        QPainter glassPainter(&m_glassCache);
        facePainter.setRenderHint(QPainter::SmoothPixmapTransform);
        glassPainter.setRenderHint(QPainter::SmoothPixmapTransform);

        m_theme->paint(&facePainter, faceRect, "ClockFace");

        glassPainter.save();
        QRectF elementRect = QRectF(QPointF(0, 0), m_theme->elementSize("HandCenterScrew"));
        glassPainter.translate(faceRect.width() / 2 - elementRect.width() / 2, faceRect.height() / 2 - elementRect.height() / 2);
        m_theme->paint(&glassPainter, elementRect, "HandCenterScrew");
        glassPainter.restore();

        m_theme->paint(&glassPainter, faceRect, "Glass");

        // get vertical translation, see drawHand() for more details
        m_verticalTranslation = m_theme->elementRect("ClockFace").center().y();
    }

    // paint hour and minute hands cache
    if (m_repaintCache == RepaintHands || m_repaintCache == RepaintAll) {
        m_handsCache.fill(Qt::transparent);

        QPainter handsPainter(&m_handsCache);
        handsPainter.drawPixmap(faceRect, m_faceCache, faceRect);
        handsPainter.setRenderHint(QPainter::SmoothPixmapTransform);

        drawHand(&handsPainter, faceRect, m_verticalTranslation, hours, "Hour");
        drawHand(&handsPainter, faceRect, m_verticalTranslation, minutes, "Minute");
    }

    // reset repaint cache flag
    m_repaintCache = RepaintNone;

    // paint caches and second hand
    QRect targetRect = faceRect;
    if (targetRect.width() < rect.width()) {
        targetRect.moveLeft((rect.width() - targetRect.width()) / 2);
    }
    targetRect.translate(rect.topLeft());

    p->drawPixmap(targetRect, m_handsCache, faceRect);
    if (m_showSecondHand) {
        p->setRenderHint(QPainter::SmoothPixmapTransform);
        drawHand(p, targetRect, m_verticalTranslation, seconds, "Second");
    }
    p->drawPixmap(targetRect, m_glassCache, faceRect);

    // optionally paint the time string
    if (m_showingTimezone) {
        QString time = prettyTimezone();

        if (!time.isEmpty()) {
            QRect textRect = tzRect(time);
            tzFrame()->paintFrame(p, textRect, QRect(QPoint(0, 0), textRect.size()));

            qreal left, top, right, bottom;
            tzFrame()->getMargins(left, top, right, bottom);

            p->setPen(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor));
            p->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
            p->drawText(textRect.adjusted(left, 0, -right, 0), Qt::AlignCenter, time);
        }
    }
}
void loop() {
    static char deck[DECK_SIZE];
    static char dealerHand[HAND_SIZE];
    static char hand[HAND_SIZE];
    static int deckPointer = 0;

    static int playerScore = 0;
    static int dealerScore = 0;
    static bool first = true;
    static bool checkForWinner = false;


    if(first) {
        generateDeck(deck);
        drawHand(hand,deck, &deckPointer);
        drawHand(dealerHand, deck, &deckPointer);
        playerScore = computeScore(hand);

        if(playerScore == BLACKJACK) {
            printGameResult("Blackjack!", playerScore);
            resetGame(hand, dealerHand, deck, &playerScore, &dealerScore, &deckPointer, &checkForWinner);
        }
        first = false;
    }

    if(sensorValue != analogRead(A0)) {
        sensorValue = analogRead(A0);
        Button button = (Button) getButton();

        switch (button) {
            case UP_BTN:
                playerScore = hit(hand,deck, &deckPointer);
                break;
            case DOWN_BTN:
                dealerScore = stay(dealerHand,deck, &deckPointer);
                checkForWinner = true;
                break;
            case LEFT_BTN:
                break;
            case RIGHT_BTN:
                break;
            case SELECT_BTN:
                resetGame(hand,dealerHand,deck,&playerScore,&dealerScore,&deckPointer,&checkForWinner);
                break;
            default:
                break;
        }
    }

    printCards(hand,1,0, false);

    if(computeScore(hand) == BLACKJACK) {
        printGameResult("Win!", playerScore);
        resetGame(hand,dealerHand,deck,&playerScore,&dealerScore,&deckPointer,&checkForWinner);

    } else if(computeScore(hand) == BUST) {
        printGameResult("Bust!", computeScoreNoBust(hand));
        resetGame(hand,dealerHand,deck,&playerScore,&dealerScore,&deckPointer,&checkForWinner);
    }

    if(checkForWinner) {
        printCards(dealerHand, 0,0,false);
        if(computeScore(hand) > computeScore(dealerHand)) {
            printGameResult("Win!", computeScore(hand));
        } else if(computeScore(hand) == computeScore(dealerHand)) {
            printGameResult("Tie.", computeScore(hand));
        } else {
            printGameResult("Lose.", computeScore(hand));
        }

        resetGame(hand,dealerHand,deck,&playerScore,&dealerScore,&deckPointer,&checkForWinner);
    } else {
        printCards(dealerHand,0,0,true);
    }

    computeScore(hand) > 9 ? lcd.setCursor(14,1) : lcd.setCursor(15,1);
    lcd.print(computeScore(hand));
    delay(100);
}
bool UKinect::pollInteraction()
{
	NUI_USER_INFO user;
	NUI_INTERACTION_FRAME Interaction_Frame;
	hr = interactionStream->GetNextFrame( 0, &Interaction_Frame );
	if (FAILED(hr))
	{
		cerr << hex << hr <<endl;
		cerr <<"[UKinect] WARNING: Interaction pool." << endl;
		return false;
	}

	for (int i = 0 ; i < NUI_SKELETON_COUNT; ++i)
	{
		user = Interaction_Frame.UserInfos[i];
		if (user.SkeletonTrackingId != 0) break;
	}

	NUI_HANDPOINTER_INFO handLeft = user.HandPointerInfos[0];
	NUI_HANDPOINTER_INFO handRight = user.HandPointerInfos[1];
	NUI_HANDPOINTER_STATE stateLeft  = (NUI_HANDPOINTER_STATE)handLeft.State;
	NUI_HANDPOINTER_STATE stateRight  = (NUI_HANDPOINTER_STATE)handRight.State;

	interID=user.SkeletonTrackingId;

	interLeftTracked= (bool)(stateLeft & NUI_HANDPOINTER_STATE_TRACKED);
	interLeftActive= (bool)(stateLeft & NUI_HANDPOINTER_STATE_PRESSED);
	interLeftInteractive= (bool)(stateLeft & NUI_HANDPOINTER_STATE_ACTIVE); 
	interLeftPressed= (bool)(stateLeft & NUI_HANDPOINTER_STATE_INTERACTIVE);

	interRightTracked=(bool)(stateRight & NUI_HANDPOINTER_STATE_TRACKED);
	interRightActive=(bool)(stateRight & NUI_HANDPOINTER_STATE_PRESSED);
	interRightInteractive=(bool)(stateRight & NUI_HANDPOINTER_STATE_ACTIVE);
	interRightPressed= (bool)(stateRight & NUI_HANDPOINTER_STATE_INTERACTIVE); 

	if (stateLeft!= NUI_HANDPOINTER_STATE_NOT_TRACKED)
	{
		interLeftX = handLeft.X;
		interLeftY = -handLeft.Y;
		interLeftRawX = handLeft.RawX;
		interLeftRawY = -handLeft.RawY;
		interLeftRawZ = handLeft.RawZ;
		interLeftPress = handLeft.PressExtent;
		if (handLeft.HandEventType>0) interLeftEvent = handLeft.HandEventType;
		//interLeftEvent = handLeft.HandEventType;
	}

	if (stateLeft!= NUI_HANDPOINTER_STATE_NOT_TRACKED)
	{
		interRightX = handRight.X;
		interRightY = -handRight.Y;
		interRightRawX = handRight.RawX;
		interRightRawY = -handRight.RawY;
		interRightRawZ = handRight.RawZ;
		interRightPress = handRight.PressExtent;
		if (handRight.HandEventType>0) interRightEvent = handRight.HandEventType;
		//interRightEvent = handRight.HandEventType;
	}

	if (interVisualization) {

		DWORD t_width, t_height;
		NuiImageResolutionToSize((NUI_IMAGE_RESOLUTION)colorResolution.as<int>(), t_width, t_height);

		if 
			((color)&&(interVisualizationOnColor.as<int>())) interCVMat=colorCVMat.clone(); // use color image as a background if color function enabled
		else
			interCVMat=Mat(Size(static_cast<int>(t_width), static_cast<int>(t_height)), CV_8UC3, CV_RGB( 0, 0, 0 ));

		if (stateLeft!= NUI_HANDPOINTER_STATE_NOT_TRACKED)
		{
			drawHand(user.SkeletonTrackingId,11,interRightEvent.as<int>(),interRightPressed.as<bool>(), interRightInteractive.as<bool>(), interRightPress.as<double>());
		}

		if (stateLeft!= NUI_HANDPOINTER_STATE_NOT_TRACKED)
		{
			drawHand(user.SkeletonTrackingId,7,interLeftEvent.as<int>(),interLeftPressed.as<bool>(),interLeftInteractive.as<bool>(),interLeftPress.as<double>());
		}

		interBin.image.width = interCVMat.cols;
		interBin.image.height = interCVMat.rows;
		interBin.image.size = interCVMat.cols * skeletonCVMat.rows * 3;
		interBin.image.data = interCVMat.data;
		interImage=interBin;

	}

	return true;
}