void displayInfo(int board[4][4], int move_score[4], MoveDirection move)
{
	displayBoard(board);
	displayScore(move_score);
	displayMove(move);
	printf("-------------------------\n");
}
void		SDL::moveAndFlip(Player *player, direction dir)
{
  player->move(dir);
  if (!this->_gameOver)
    displayScore(player);
  SDL_Flip(this->_screen);
  SDL_Delay(this->_speed);
}
Exemple #3
0
void *create_bomb(void *arg) {
    Block *bomb;
    bomb = (Block *) arg;
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
    pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
    pthread_mutex_lock(&mutex);
    addThread(pthread_self());
    pthread_mutex_unlock(&mutex);
    while(bomb->row <= bomb->screen_height) {
        if(bomb->row == bomb->screen_height - 1) {
            pthread_mutex_lock(&mutex);
            if(bomb->col >= bomb->block->start && bomb->col <= bomb->block->end) {
                increaseScore();
                displayScore();
            } else {
                flash();
                decreaseScore(score);
                displayScore();
            }
            delete_bomb(bomb);
            pthread_mutex_unlock(&mutex);
            break;
        }
        pthread_mutex_lock(&mutex);
        SET_COLOR_BLUE;
        move(bomb->row, bomb->col);
        delch();
        insch(' ');
        (bomb->row)++;
        SET_COLOR_RED;
        pthread_mutex_unlock(&mutex);
        refresh();
        pthread_testcancel();
        napms(150);
    }

    pthread_mutex_lock(&mutex);
    bomb->cols[bomb->col] = 0;
    removeThread(pthread_self());
    pthread_mutex_unlock(&mutex);

    free(bomb);
    pthread_exit((void *) 0);
}
Exemple #4
0
void select_long_click_handler(ClickRecognizerRef recognizer, Window *window) {
  (void)recognizer;
  (void)window;

  team ^= 1;
  current = getScore(team);
  score(12);
  displayScore();
  keyIndex = 8;
}
void MainWindow::resetGame() {
    score = 0;
    level = 1;
    numberOfRobots = MIN_ROBOTS;
    gameState = GameState(numberOfRobots);
    gameState.draw(scene);
    displayScore();
    displayLevel();
    gameOver = false;
    gameOverWindow.hide();
}
Exemple #6
0
int flashImageIsDisplayed(void) {
  if(flashImage) {
    flashImage = 0;
    current = getScore(team);
    layer_set_hidden(&image_container.layer.layer, true);
    layer_set_hidden(&scoreBoard, false);
    layer_set_hidden(&buttonsLayer, false);
    displayScore();
    return 1;
  }
  return 0;
}
Exemple #7
0
void select_single_click_handler(ClickRecognizerRef recognizer, Window *window) {
  (void)recognizer;
  (void)window;

  if(flashImageIsDisplayed()) return;

  layer_set_hidden(&inputLayer.layer, true);

  if(keyIndex == 0) keyIndex = 8;
  score(keyIndex);
  displayScore();
  keyIndex = 8;
}
Exemple #8
0
void runAStep(struct Ball* ball, int posYJ1, int posYJ2, struct Score* score)
{
    if(colideRWall(*ball) == 1)
    {
        if (colideRaquette(posYJ1, *ball))
        {
            changeDirection(ball);
            ball->varY = ((ball->coord.y - posYJ1) - 20)/2.3;
            mouve(ball);
        }
        else 
        {
            score->J2++;
            displayScore(*score);
            initBall(ball);
        }
    }
    else if(colideRWall(*ball) == 2)
    {
        if (colideRaquette(posYJ2, *ball))
        {
            changeDirection(ball);
            ball->varY = ((ball->coord.y - posYJ2) - 20)/2.3;
            mouve(ball);
        }
        else
        {
            score->J1++;
            displayScore(*score);
            initBall(ball);
        }
    }
    else
    {
        if (colideWall(*ball) > 0)
            ball->varY =  - ball->varY;
        mouve(ball);
    }
}
/*
 * Process results of viable move
 */
void MainWindow::processMove(bool waiting) {
    gameState.moveRobots();
    score += gameState.countCollisions() * (POINTS_PER_ROBOT +
                                            (waiting ? WAIT_BONUS : 0));
    gameState.draw(scene);
    displayScore();

    if (!gameState.anyRobotsLeft()) { // won level
        numberOfRobots = std::min(MAX_ROBOTS, numberOfRobots + ROBOTS_INC);
        gameState = GameState(numberOfRobots);
        gameState.draw(scene);
        ++level;
        displayLevel();
    } else if (gameState.heroDead()) { // game over
        gameOver = true;
        gameOverWindow.show();
    }
}
Exemple #10
0
void Game::playGame()
{
    resizeConsole(x_max+1,y_max+1);//game size
    screen.clear();
    drawBoundary();

    while(!dead)
    {
        displayScore();

        if(!paused)
        {
            snake.clear(screen);
            snake.move();
            snake.draw(screen);

            food.draw(screen);

            Sleep(100-speed);


            if(snake.hit(x_min,x_max,y_min,y_max))
            {
                dead = true;
            }
            else if(snake.getHead().equals(food))
            {
                snake.grow();
                generateFood();
                harder();
            }
        }

        if(kbhit())
        {
            getKeys();
        }

    }
    //endgame();
    updateUser();
}
void GameOverLayer::displayContent()
{
    // effect node
    auto root = Node::create();
    this->addChild(root, 0, rootNodeTag);
    if (root) {
        root->setPosition(Vec2(100, -400));
        root->setRotation(-30);
        auto move = MoveTo::create(0.5f, Vec2::ZERO);
        auto rotate = RotateTo::create(0.5f, 0);
        auto easeRotate = EaseBackOut::create(rotate);
        
        root->runAction(move);
        root->runAction(easeRotate);
    }
    
    // content
    auto size = Size(660, 380);
    auto contentLayer = LayerColor::create(Color4B::WHITE, size.width, size.height);
    contentLayer->setPosition(Vec2(VisibleRect::center().x - size.width / 2, VisibleRect::center().y - size.height / 2));
    root->addChild(contentLayer, 1);
    
    displayScore(contentLayer);
    
    // title
    auto titleLabel = Label::createWithTTF(FC_NUMBER_TITLE, "game over");
    if (titleLabel) {
        titleLabel->setTextColor(C4_LIGHT_GREEN);
        titleLabel->enableOutline(C4_DARK_GREEN);
        titleLabel->setAnchorPoint(Vec2(0.5, 1));
        titleLabel->setPosition(VisibleRect::center() - contentLayer->getPosition() + Vec2(0, 190));
        contentLayer->addChild(titleLabel);
    }
    
    auto restartBtn = displayRestartBtn();
    auto gameCenterBtn = displayGameCenterBtn();
    
    auto menu = Menu::create(restartBtn, gameCenterBtn, nullptr);
    menu->setPosition(VisibleRect::center() - contentLayer->getPosition());
    contentLayer->addChild(menu);
}
bool ColumnsGame::paint(Image& backBuffer)
{
	PlayField.paint(backBuffer);

	if(iGameState!=COLUMNS_GAME_PAUSE){
		gameLogic();
		Pit.paint(backBuffer);
		activeStone.paint(backBuffer);
	}	else {
		static float iRadius=30.0f;		// Display Pause Logo
		static int a=0;
		int iRotSpeed=3;
		int xc=sin(a*(3.14f/180.0f))*iRadius;
		int yh=cos(a*(3.14f/180.0f))*50;
		a+=iRotSpeed;
		imgElements.setSrcRect(Rect(0,304,128,32));
		imgElements.show(backBuffer, 230+xc,225-abs(yh/2),165,yh,IMAGE_BLTMODE_ADD);
	}

	if (iGameState==COLUMNS_GAME_OVER)
	{
		static float iRadius=30.0f;		// Display Game Over Logo
		static int a=0;
		int iRotSpeed=3;
		int xc=sin(a*(3.14f/180.0f))*iRadius;
		int yh=cos(a*(3.14f/180.0f))*50;
		a+=iRotSpeed;
		iRadius-=iRotSpeed*(30.0f/720.0f);
		imgElements.setSrcRect(Rect(225,5,165,50));
		imgElements.show(backBuffer, 230+xc,225-abs(yh/2),165,yh,IMAGE_BLTMODE_ADD);
		if (a>720)
		{
			a=0;
			iRadius=30.0f;
			iGameState=COLUMNS_GAME_OUT;
		}
	}
	// Displaying Score...
	displayScore(backBuffer);
	return true;
}
Exemple #13
0
void Game::gameLoop()
{
	sf::Event currentEvent;
	mainWindow_.pollEvent(currentEvent);


	switch (gameState_)
	{
	case Game::ShowingMenu:
	{
		gameObjectManager_.drawAll(mainWindow_);
		showMenu();
		mainWindow_.display();
		break;
	}
	case Game::Playing:
	{
		mainWindow_.clear(sf::Color(100, 100, 100));

		gameObjectManager_.updateAll();
		gameObjectManager_.drawAll(mainWindow_);
		sf::RectangleShape bar(sf::Vector2f(1024, 20));
		bar.setPosition(0, 280);
		bar.setFillColor(sf::Color(0, 0, 0));
		mainWindow_.draw(bar);

		displayScore();
		mainWindow_.display();
		if (currentEvent.type == sf::Event::Closed) gameState_ = Game::Exiting;
		break;
	}
	case Game::Finished:
	{
		displayText();
		mainWindow_.display();
		break;
	}
	}
}
bool SelectLevel::init()
{
	if (!CCLayer::init())
	{
		return false;
	}
	this->setTouchEnabled(true);
	userDefault->setIntegerForKey("max_level", 7);
	winSize = CCDirector::sharedDirector()->getVisibleSize();
	
	CCSprite *back = CCSprite::createWithTexture(IMAGEPOOL->textureForKey("/pic/back.png"));
	back->setPosition(ccp(30, winSize.height - 30));
	back->setScale(0.7f);
	this->addChild(back, 1);

	readData();

	displayLevels();

	displayScore();

	//背景滚动
	CCSprite *m_pBackGround1 = CCSprite::create("/pic/background.png");    // STR_BACKGROUND是图片的路径
	CCSprite *m_pBackGround2 = CCSprite::create("/pic/background.png");    // 加载背景
	CCAssert(m_pBackGround1 && m_pBackGround2, "");
	CCSize size = CCDirector::sharedDirector()->getWinSize();
	CCRect rcBounding = m_pBackGround1->boundingBox();
	m_pBackGround1->setPosition(ccp(rcBounding.size.width / 2, size.height / 2));    // 设置在屏幕中间
	m_pBackGround2->setPosition(ccp(rcBounding.size.width * 3 / 2, size.height / 2));// 设置精灵2连接在精灵1的后面
	this->addChild(m_pBackGround1, 0, 100);    // 0
	this->addChild(m_pBackGround2, 0, 200);

	scheduleUpdate();


	return true;
}
Exemple #15
0
int main(void) {
    // int pid = getpid();
    // printf("PID = %d\n", pid);
    // getchar();

    initscr();
    cbreak();
    noecho();
    keypad(stdscr, TRUE);

    int scr_width, scr_height;
    getmaxyx(stdscr, scr_height, scr_width);
    int columns[scr_width];
    int arr_index;
    for(arr_index = 0; arr_index < scr_width; ++arr_index)
        columns[arr_index] = 0;

    start_color();

    assume_default_colors(COLOR_WHITE, COLOR_WHITE);

    init_pair(1, COLOR_RED, COLOR_RED);
    init_pair(2, COLOR_WHITE, COLOR_WHITE);
    init_pair(3, COLOR_BLUE, COLOR_BLUE);
    init_pair(4, COLOR_BLACK, COLOR_WHITE);
    init_pair(5, COLOR_BLACK, COLOR_BLACK);

    int block_start = 1;
    int block_end = block_start + 20;
    int block_row = scr_height - 1;

    int index;

    SET_COLOR_RED;
    for(index = block_start; index < 20; ++index) {
        move(block_row, index);
        delch();
        insch(' ');
    }

    SET_COLOR_BLACK;
    for(index = 0; index <= scr_width; ++index) {
        move(1, index);
        delch();
        insch(' ');
    }

    // hide cursor. doesn't work?.
    curs_set(0);
    refresh();
    // pthread_attr_t attr;

    pthread_mutex_init(&mutex, NULL);

    Block *block = malloc(sizeof(Block)); // freed by another thread
    block->start = 1;
    block->end = (block->start) + 20;
    block->row = scr_height - 1;
    block->screen_height = scr_height;
    block->screen_width = scr_width;
    block->cols = columns;

    // initialize score information
    score.bombs_caught = 0;
    score.bombs_missed = 0;
    score.points = 0;
    displayScore();

    speed = 1000; // 1 second

    pthread_t block_thread;
    threadPool.tid = block_thread;
    threadPool.next = NULL;
    pthread_create(&block_thread, NULL, blockMovement, (void *) block);

    pthread_t timer_thread;
    pthread_create(&timer_thread, NULL, changeSpeed, (void *) 0);
    addThread(timer_thread);

    pthread_t bomb_thread;
    pthread_create(&bomb_thread, NULL, drop_bombs, (void *) block);
    addThread(bomb_thread);
    // void *status;
    // wait for the user to press q to actually quit
    pthread_join(block_thread, NULL);
    // free(score);
    pthread_mutex_destroy(&mutex);
    pthread_exit(NULL);
}
Exemple #16
0
void loop(){ //main game loop
  gameLoop();
  displayScore();
  setup();
}
Exemple #17
0
int main(void)
{

    // variable declarations
    int userGuess; int computerForecast; int score; int lastGuess; int secondMostRecentGuess; int thirdMostRecentGuess; int turn_counter;
    int move_table[2][2][2][2] = {{{{0}}}}; // FOUR DIMENSIONAL ARRAY OMG


    score = 0;
    userGuess = 0;
    lastGuess = 0; // most recent
    secondMostRecentGuess = 0; // second most recent
    thirdMostRecentGuess = 0; // third most recent
    turn_counter = 0;

    // print header
    printf("Program #1: 0 or 1 number guessing game \nAuthor: Wynn Drahorad\nLab: Tues 9am\nInstructions:\nFor each move the computer will forecast what it thinks you will enter.\nWhen prompted you then enter 0 or 1.  The computer forecast and your\ninput will be compared.  If the computer got it right, the score is\ndecremented.  If the computer got it wrong, the score is incremented.\nThe score starts at 0.  If it reaches -10 the computer wins.\nIf it reaches 10, the human wins!  Good luck, you'll need it!");


    /* start game */

    // start game loop
    while ( score < 10 && score > -10 ) {
        // set computerForecast to most probable, using move table after turn 2
        if (turn_counter > 2) {
            computerForecast = findMostProbable(move_table, lastGuess, secondMostRecentGuess, thirdMostRecentGuess);
        } else {
            computerForecast = getRand();
        }

        // display score to user
        displayScore(score);

        // prompt user to guess 0 or 1
        do {
            userGuess = getUserGuess();
        } while (userGuess == -1); // handle inputs other than 1 or 0

        if (turn_counter > 2) {
            // add new userGuess data to prediction table
            ++move_table[lastGuess][secondMostRecentGuess][thirdMostRecentGuess][userGuess];

            printMoveTable(move_table); // uncomment this line if you want to see the move_table
        }

        if (userGuess == computerForecast) {
            --score;
        } else {
            ++score;
        }



        // store lastGuess user guesses, shift older guesses
        thirdMostRecentGuess = secondMostRecentGuess;
        secondMostRecentGuess = lastGuess;
        lastGuess = userGuess;
        ++turn_counter;
    }

    if (score > 10) {
        printf("How did you win? Congratulations! (... But seriously how?)\n");
    } else {
        printf("Sorry, you lost!\n");
    }

    return 0; // to appease the C gods
}