Пример #1
0
int main(int argc ,char **argv){
 SDL_Init(SDL_INIT_VIDEO);
 Window *frame = createWindow(SCREEN_WIDTH,SCREEN_HEIGHT,"Snakeing!");
 Game *game = createGame(frame);
 SDL_Event event;
 int flag = 1 ;
 while (flag){
   if ( !displayGame(game) ) {
     flag=0; 
     break;
    }  
   SDL_PollEvent(&event);
   SDL_Delay(80);
    if (event.type == SDL_QUIT){
       flag = 0;
       break;
      } 
    else if (event.type == SDL_KEYDOWN) {
        handleEvent(game,event); 
       }
  } 
 printf("Your Score is : %i\n",getGameScore(game));
 destroyGame(game); 
 game = NULL;
 destroyWindow(frame); 
 frame = NULL;
 SDL_Quit();
 return 0;
}
Пример #2
0
/* 
 * Loads the file header data from the item selected in the directory display
 */
void MainWindow::slot_displayFileHeader(const QModelIndex & topLeft, const QModelIndex & /*bottomRight*/ )
{
	GameLoaded = NULL;
	SGFloaded = QString();
	ui.displayBoard->clearData();

	ui.File_WhitePlayer->setText("");
	ui.File_BlackPlayer->setText("");
	ui.File_Date->setText("");
	ui.File_Handicap->setText("");
	ui.File_Result->setText("");
	ui.File_Komi->setText("");
	ui.File_Size->setText("");

	QVariant v = topLeft.data(QDirModel::FilePathRole);
	//qDebug( "Selected item : %s" ,v.toString().toLatin1().constData());

	if (model->isDir(topLeft))
	{
		ui.button_loadGame->setDisabled(true);
		return ;
	}
	//qDebug( "Selected file : %s \n" ,model->filePath(topLeft).toLatin1().constData());

	fileLoaded = model->filePath(topLeft);
	SGFloaded = MW_SGFparser->loadFile(fileLoaded);
	
	if (SGFloaded == NULL)
	{
		ui.button_loadGame->setDisabled(true);
		return ;
	}

	ui.button_loadGame->setEnabled(true);
	
	GameLoaded = MW_SGFparser->initGame(SGFloaded, fileLoaded);
	GameLoaded->gameMode = modeNormal;
	if (GameLoaded)
	{
		QString komi, hcp, sz;
		komi.setNum(GameLoaded->komi);	
		hcp.setNum(GameLoaded->handicap);
		sz.setNum(GameLoaded->board_size);

		ui.File_WhitePlayer->setText(GameLoaded->white_name);
		ui.File_BlackPlayer->setText(GameLoaded->black_name);
		ui.File_Date->setText(GameLoaded->date);
		ui.File_Handicap->setText(hcp);
		ui.File_Result->setText(GameLoaded->result);
		ui.File_Komi->setText(komi);
		ui.File_Size->setText(sz);

		displayGame();
	}	

}
Пример #3
0
void TowersOfHanoi::moveDisk(char orgPeg, char destPeg) {
#ifdef RAW_PROFILING
	RawProfiling::RawProfiling::TowersOfHanoi_moveDisk_counter++;
	RawProfiling::RawProfiling theProfiling(RawProfiling::RawProfiling::TowersOfHanoi_moveDisk_chronograph);
#endif
	int topDisk = pegs_[orgPeg  - 'A'].back();
	pegs_[orgPeg  - 'A'].pop_back();
	pegs_[destPeg - 'A'].push_back(topDisk);
	displayGame();
}
Пример #4
0
void gameloop(struct game *state)
{

  printf("gameloop: current board '%s' with player %c\n",state->board,state->player);

  displayGame(state);

  if(gameover(state) == 1) {
	return;
  }

  makePlayerMove(state,getPlayerMove(state));

  displayGame(state);

  if(gameover(state) == 1) {
	return;
  }

  makeComputerMove(state);

  gameloop(state);

}
Пример #5
0
void GuiGame::handleOpponentBoardClick(int index)
{
	if(not _myTurn.load())
	{
		displayMessage("You must wait your turn!");
		return;
	}
	// clicking on opponent if selection is null doesn't do anything
	if(_currentSelfSelection == NoSelection)
		return;
	_currentOpponentSelection = index;
	int selfSelection{_currentSelfSelection};
	unselectSelfCard();
	attackWithCreature(selfSelection, false, _currentOpponentSelection);
	displayGame();
}
void respondToGPIOInput()
{
	const int PUSH_BUTTONS_CENTER = 0x01;
    const int PUSH_BUTTONS_RIGHT  = 0x02;
    const int PUSH_BUTTONS_LEFT   = 0x08;
    const int PUSH_BUTTONS_UP     = 0x10;
    const int PUSH_BUTTONS_DOWN   = 0x04;

	int buttonState = XGpio_DiscreteRead(&gpPB, 1);

	if (buttonState & PUSH_BUTTONS_LEFT)
		tank_moveTankLeft();
	else if (buttonState & PUSH_BUTTONS_RIGHT)
		tank_moveTankRight();

	if (buttonState & PUSH_BUTTONS_UP)
		tank_fireBullet();

	if (buttonState & PUSH_BUTTONS_CENTER)
		sound_volumeUp();
	else if (buttonState & PUSH_BUTTONS_DOWN)
		sound_volumeDown();

	int x = mouse_getXMovement();
	tank_moveTank(x / TANK_MOUSE_DIVIDER);
	if(mouse_getMouseButtons() == MOUSE_LEFT_BUTTON)
		tank_fireBullet();

	// switches
	const int SWITCH_LD6 = 0x40;
	const int SWITCH_LD5 = 0x20;
	int oldSwitchState = switchState;
	switchState = XGpio_DiscreteRead(&gpswitches, 1);

	if ((switchState & SWITCH_LD5) != (oldSwitchState & SWITCH_LD5)) { // switch changed position
		if (switchState & SWITCH_LD5)
			displayScreenCapture();
		else
			displayGame();

	}
	if ((switchState & SWITCH_LD6) && !(oldSwitchState & SWITCH_LD6)) { // switch flipped up
		captureScreen();
	}
}
Пример #7
0
int main()
{
    int bins[5];
    int turns = 1;;
    int i = 0;
    for(i = 0; i < 5; i++)
    {
        bins[i] = 7;
    }
    int matchesRemoved;
    int binNumber;
    while(checkGameEnd(bins, 5) == false)
    {
        displayGame(bins, 5);
        if(turns % 2 == 0)
        {
            printf("It is Player 2's turn\n");
        }
        else
        {
            printf("It is Player 1's turn\n");
        }
        printf("What bin do you want to remove matches from? (1-5)\n");
        scanf(" %d", &binNumber);
        binNumber -= 1;
        printf("How many matches do you want to remove? (1-7)\n");
        scanf(" %d", &matchesRemoved);
        if(removeMatches(binNumber, matchesRemoved, bins, 5) == false)
        {
            printf("Try again, please enter a legal move.\n");
            turns -= 1;
        }
        turns++;
    }
    if(turns % 2 == 0)
    {
        printf("Player 2 wins!\n");
    }
    else
    {
        printf("Player 1 wins!\n");
    }
}
Пример #8
0
void GuiGame::processWindowEvents()
{
	sf::Event event;
	while(_context.window->pollEvent(event))
	{
		assert(std::this_thread::get_id() == _ownerId);
		if(_displayRequest.load())
		{
			displayGame();
			_displayRequest.store(false);
		}
		while(not _pendingMessages.empty())
		{
			displayGameInfo(_pendingMessages.front());
			_pendingMessages.pop();
		}
		if(event.type == sf::Event::Closed)
			quit();
		else
			_context.gui->handleEvent(event);
	}
}
Пример #9
0
void Game::gameLoop()
{
    sf::Clock myClock;
    const int TICKS_PER_SECOND = 50;
    const int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
    const int MAX_FRAMESKIP = 10;

    sf::Int32 nextGameTick = myClock.getElapsedTime().asMilliseconds();
    int loops;

    while(window.isOpen())
    {
        loops = 0;

        sf::Event event;
        while(window.pollEvent(event))
        {
            if(event.type == sf::Event::Closed)
            {
                window.close();
            }
        }

        while(myClock.getElapsedTime().asMilliseconds() > nextGameTick && loops < MAX_FRAMESKIP)
        {
            //handleUserInput();
            update();
            //checkCollisions();

            //time stuff
            nextGameTick+=SKIP_TICKS;
            loops++;
        }

        window.clear();
        displayGame();
        window.display();
    }
}
Пример #10
0
void TSGame::run()
{
    mainWindow.create(sf::VideoMode{800,600}, "TriangleSuper", sf::Style::Titlebar | sf::Style::Close);
    mainWindow.setMouseCursorVisible(false);
    gameMenu.initialize(mainWindow, mainFont);
    while(mainWindow.isOpen())
    {
        handleEvents();
        mainWindow.clear();
        mainWindow.draw(player);

        if(gameStatus)
            displayMenu();

        else if(!gameStatus)
           displayGame();

        stars.Update();
        mainWindow.draw(stars.getSystem());
        mainWindow.display();
        sf::sleep(sf::milliseconds((1.f/fpsLimit)*1000.f - gameClock.restart().asMicroseconds()/1000.f));
    }
}
Пример #11
0
void GuiGame::displayHandCards()
{
	static auto availableWidth{_cardsLayoutWidth * 3.f / 4.f};
	auto cardHeight{_selfHandPanel->getSize().y};

	// Clear the panel
	_selfHandPanel->removeAllWidgets();
	_selfHand.clear();

	// do not use an iterator-for loop since i is a used counter variable
	const float distanceBetweenCards{(availableWidth/(static_cast<float>(_selfHandCards.size()) - 1.f)).getValue()};
	for(unsigned i{0U}; i < _selfHandCards.size(); ++i)
	{
		const auto cardData{_context.client->getCardData(_selfHandCards.at(i).id)};
		const auto widthPosition{static_cast<float>(i) * distanceBetweenCards};
		// create a new card
		_selfHand.push_back(std::make_shared<CardWidget>(cardData));
		// Have it sized according to the panel
		_selfHand.back()->setSize(_cardsLayoutWidth / 4.f, cardHeight);
		// Place it one the panel
		_selfHand.back()->setPosition({widthPosition, 0.f});

		////////// Set up callbacks

		// If card is pressed, use the card
		_selfHand.back()->connect("MousePressed", [this, i]()
		{
			useCard(i);
			displayGame();
		});
		// When the mouse enters on the card area
		connectBigCardDisplay(_selfHand.back(), cardData);
		// Add the card to the panel
		_selfHandPanel->add(_selfHand.back());
	}
}
Пример #12
0
void GuiGame::removeClickableCallbacks()
{
	_activeCallbacks = false;
	displayGame();
}
Пример #13
0
GuiGame::GuiGame(Context& context):
	AbstractGame{*context.client},
	_context{context},
	_decksListBox{std::make_shared<tgui::ListBox>()},
	_decksChosen{false},
	_display{false},
	_width{tgui::bindWidth(*_context.gui)},
	_height{tgui::bindHeight(*_context.gui)},
	_selfHandPanel{std::make_shared<tgui::Panel>()},
	// Self info labels
	_selfInfoLayout{std::make_shared<tgui::VerticalLayout>()},
	_selfHealthLabel{std::make_shared<tgui::Label>()},
	_selfEnergyLabel{std::make_shared<tgui::Label>()},
	_selfDeckSizeLabel{std::make_shared<tgui::Label>()},
	_selfGraveyardSizeLabel{std::make_shared<tgui::Label>()},
	_gameInfoLabel{std::make_shared<tgui::Label>()},
	_endTurnButton{std::make_shared<tgui::Button>()},
	_attackOpponentButton{std::make_shared<tgui::Button>()},
	// Opponent info layout
	_oppoInfoLayout{std::make_shared<tgui::VerticalLayout>()},
	_oppoHealthLabel{std::make_shared<tgui::Label>()},
	_oppoHandSizeLabel{std::make_shared<tgui::Label>()},
	_cardsLayoutWidth{_width/1.4f},
	_isBigCardOnBoard{false},
	_opponentBoardPanel{std::make_shared<tgui::Panel>()},
	_selfBoardPanel{std::make_shared<tgui::Panel>()},
	_currentSelfSelection{NoSelection},
	_currentOpponentSelection{NoSelection},
	_activeCallbacks{true},
	_displayRequest{false},
	_ownerId{std::this_thread::get_id()}
{
	// end turn button
	_endTurnButton->setText("End turn");
	_endTurnButton->connect("Pressed", [this]()
	{
		endTurn();
		_endTurnButton->disable();
		displayGame();
	});

	float heightWidget{_height.getValue()};

	// have the grid sized so that we can align perfectly 4 cards in it
	auto cardWidth{_cardsLayoutWidth / 4.f};
	auto cardHeight{cardWidth * (CardGui::getSize().y / static_cast<float>(CardGui::getSize().x))};
	_selfHandPanel->setSize(_cardsLayoutWidth, cardHeight);
	// remove the self hand panel
	heightWidget -= _selfHandPanel->getSize().y + 10;
	_selfHandPanel->setPosition({(_width - _cardsLayoutWidth) / 2.f, heightWidget});
	_context.gui->add(_selfHandPanel);

	// Self info labels
	_selfHealthLabel->setTextColor(sf::Color(200, 0, 0));  // Dark red
	_selfHealthLabel->setTextSize(15);
	_selfEnergyLabel->setTextColor(sf::Color(0, 0, 200));  // Dark blue
	_selfEnergyLabel->setTextSize(15);
	_selfDeckSizeLabel->setTextSize(15);
	_selfGraveyardSizeLabel->setTextSize(15);
	// The text of these labels is set in displayGame
	_selfInfoLayout->add(_selfHealthLabel);
	_selfInfoLayout->add(_selfEnergyLabel);
	_selfInfoLayout->add(_selfDeckSizeLabel);
	_selfInfoLayout->add(_selfGraveyardSizeLabel);
	_selfInfoLayout->add(_endTurnButton);
	_selfInfoLayout->setSize((_width - _cardsLayoutWidth) / 2.f - 10.f, tgui::bindHeight(_selfHandPanel));
	_selfInfoLayout->setPosition(tgui::bindRight(_selfHandPanel) + 5.f, tgui::bindTop(_selfHandPanel));
	_context.gui->add(_selfInfoLayout);

	// default behaviour of button is to be disabled (re-enabled at the beginning of each turn)
	_endTurnButton->disable();

	// Oponnent info labels
	_oppoHealthLabel->setTextColor(sf::Color(200, 0, 0));  // Dark red
	_oppoHealthLabel->setTextSize(15);
	_oppoHandSizeLabel->setTextSize(15);
	// The text of these labels is set in displayGame
	_oppoInfoLayout->add(_oppoHealthLabel);
	_oppoInfoLayout->add(_oppoHandSizeLabel);
	_oppoInfoLayout->setSize((_width - _cardsLayoutWidth) / 2.f - 10.f, tgui::bindHeight(_selfHandPanel));
	_oppoInfoLayout->setPosition(5.f, tgui::bindTop(_selfHandPanel));
	_context.gui->add(_oppoInfoLayout);

	// self board
	_selfBoardPanel->setBackgroundColor(sf::Color(50, 50, 50));
	_selfBoardPanel->setSize(_width, 180);
	// remove the self board panel
	heightWidget -= _selfBoardPanel->getSize().y + 20;

	// game messages
	_gameInfoLabel->setPosition((_width - tgui::bindWidth(_gameInfoLabel))/2.f, tgui::bindBottom(_selfBoardPanel));
	_context.gui->add(_gameInfoLabel);

	_selfBoardPanel->setPosition({0.f, heightWidget});
	_context.gui->add(_selfBoardPanel);

	// opponent board
	_opponentBoardPanel->setBackgroundColor(sf::Color(100, 100, 100));
	_opponentBoardPanel->setSize(_width, 180);
	// remove the opponent board panel
	heightWidget -= _opponentBoardPanel->getSize().y + 20;
	_opponentBoardPanel->setPosition({0.f, heightWidget});
	_context.gui->add(_opponentBoardPanel);

	// Place the button to attack directly the opponent
	_attackOpponentButton->setText("Attack opponent");
	_attackOpponentButton->setSize(_width * 3.f / 4.f, _opponentBoardPanel->getPosition().y - 10);
	_attackOpponentButton->setPosition(_width / 8.f, 5);
	_attackOpponentButton->connect("Pressed", [this]()
	{
		int selfSelection{_currentSelfSelection};
		unselectSelfCard();
		attackWithCreature(selfSelection, true, NoSelection);
		displayGame();
	});
	_context.gui->add(_attackOpponentButton);
}