Example #1
0
void GameBoard::initialize(const CardList& cards)
{
	CardList columnCards;
	columnCards.reserve(6);

	const int k_numColumnsInFirstGroup = 4;
	const int k_numColumnsInSecondGroup = 6;
	const int k_numCardsInColumnFisrtGroup = 5;
	const int k_numCardsInColumnSecondGroup = 4;

	for(int i = 0; i < k_numColumnsInFirstGroup; i++)
	{
		CardList::const_iterator it_from = cards.begin() + i * k_numCardsInColumnFisrtGroup;
		CardList::const_iterator it_to = cards.begin() + (i + 1) * k_numCardsInColumnFisrtGroup;

		columnCards.insert(columnCards.begin(), it_from, it_to);
		m_cardColumns[i].initialize(columnCards);

		columnCards.clear();
	}
	
	const int k_totalCardsInFirstGroup = 20; //k_numColumnsInFirstGroup * k_numCardsInColumnFisrtGroup;
	for(int i = 0; i < k_numColumnsInSecondGroup; i++)
	{
		CardList::const_iterator it_from = cards.begin() + k_totalCardsInFirstGroup + i * k_numCardsInColumnSecondGroup;
		CardList::const_iterator it_to = cards.begin() + k_totalCardsInFirstGroup + (i + 1) * k_numCardsInColumnSecondGroup;

		columnCards.insert(columnCards.begin(), it_from, it_to);
		m_cardColumns[k_numColumnsInFirstGroup + i].initialize(columnCards);

		columnCards.clear();
	}

	m_cardDeck.initialize(SpiderGame::k_seriesToPass);
	m_buildedStackDeck.reset();
	m_scoreBoard.reset();	
}
Example #2
0
void main()
{
    Game game = Game();
    CardList cards;
	//Player playerOne;
    BeastCubeManager beastCube(&game);
	Hand gameHand(0);
	//Hand::playerOneCards = (CardFactory::getCards(5));
	//Hand::playerTwoCards = (CardFactory::getCards(4));
	//Hand::convertToMenu(1, Hand::playerOneCards);
    Hand::drawHand();
	Menu m(Hand::handBuffer, &gAssets, Hand::playerOneHand);
	m.anchor(0);

    //Make beasts    
    for(int cube = 1; cube < CubeSet::connected().count(); ++cube) {
        LOG("###---Player %i---\n", cube);

        //CardList c = (CardFactory::getCards(2));  
        CardFactory::getCards(&cards, 2);

        for(int i = 0; i < cards.count(); i++)
        {
            LOG("###Card for beast creation: %i %i\n", cards[i].type, cards[i].power);
        }
         
        Card beastCards[] = {cards.pop_back(), cards.pop_back()};
        Beast m = BeastFactory::createBeast(beastCards, 2);

        LOG("###Beast created:\n Type: %i\n Attack:%i\n Health:%i\n Resolve:%i\n Anger:%i\n\n",
                m.type, m.attack, m.health, m.resolve, m.anger);

        beastCube.init(cube, m);     
        cards.clear();
    }

	struct MenuEvent e;
    uint8_t item;
    int target = 0;


    while(1)
	{
        System::paint();
		
	while (m.pollEvent(&e)) {
		if(game.newTurn)
		{
		    //LOG("New turn!\n");
            //Hand::drawCard(game.activePlayerIndex + 1);
			//if(game.activePlayerIndex == 0)
			//	m.init(Hand::handBuffer, &gAssets, Hand::playerOneHand);
			//else
			//	m.init(Hand::handBuffer, &gAssets, Hand::playerTwoHand);
            Hand::drawHand();
			game.newTurn = false;
		}
            switch (e.type) {

                case MENU_ITEM_PRESS:
            //        // Game Buddy is not clickable, so don't do anything on press
            //        if (e.item >= 3) {
            //            // Prevent the default action
            //            continue;
            //        } else {
            //            m.anchor(e.item);
            //        }
            //        if (e.item == 4) {
            //            static unsigned randomIcon = 0;
            //            randomIcon = (randomIcon + 1) % e.item;
            //            m.replaceIcon(e.item, Hand::playerOneHand[randomIcon].icon, Hand::playerOneHand[randomIcon].label);
            //        }
                    if(target != 0)
                    {
						Card c;
						c = Hand::playerOneCards[e.item];
                        game.cardAction(&beastCube.beasts[target], &c);
                        beastCube.refresh(target);

                        game.newTurn = true;
                    }
                    break;

                case MENU_EXIT:
                    // this is not possible when pollEvent is used as the condition to the while loop.
                    // NOTE: this event should never have its default handler skipped.
                    ASSERT(false);
                    break;

                case MENU_NEIGHBOR_ADD:
                    //LOG("found cube %d on side %d of menu (neighbor's %d side)\n",
                         //e.neighbor.neighbor, e.neighbor.masterSide, e.neighbor.neighborSide);
                    target = e.neighbor.neighbor;
                    break;

                case MENU_NEIGHBOR_REMOVE:
                    //LOG("lost cube %d on side %d of menu (neighbor's %d side)\n",
                    //     e.neighbor.neighbor, e.neighbor.masterSide, e.neighbor.neighborSide);

                    if(e.neighbor.neighbor == target)
                    {
                        target = 0;
                    }
                    break;

                case MENU_ITEM_ARRIVE:
                    LOG("arriving at menu item %d\n", e.item);
                    Hand::currentCardIndex = item = e.item;
                    break;

                case MENU_ITEM_DEPART:
                    //LOG("departing from menu item %d, scrolling %s\n", item, e.direction > 0 ? "forward" : "backward");
                    break;

                case MENU_PREPAINT:
                    // do your implementation-specific drawing here
                    // NOTE: this event should never have its default handler skipped.
                    break;

                case MENU_UNEVENTFUL:
                    // this should never happen. if it does, it can/should be ignored.
                    ASSERT(false);
                    break;
            }

            m.performDefault();
        }

        // Handle the exit event (so we can re-enter the same Menu)
        ASSERT(e.type == MENU_EXIT);
        m.performDefault();

        //LOG("Selected Game: %d\n", e.item);
	}
}
/// \todo Split up into smaller testing units
TEST_F( libRocketDataGridTest, DataSourceModel )
{
  // Disable assertion handling prompts for these tests (just report instead)
  // nom::set_assertion_handler(log_assert_handler, nullptr);
  // Disable assertion handling prompts for these tests and ignore the report
  // nom::set_assertion_handler(null_assert_handler, nullptr);

  // Buffer objects used for verifying storage model results
  nom::StringList row;
  nom::StringList cols;
  cols.push_back( "name" );
  cols.push_back( "num" );

  this->model.reset( new CardsPageDataSource("cards_db") );

  // Baseline sanity tests

  EXPECT_TRUE( this->model != nullptr );

  EXPECT_EQ( "cards", this->model->table_name() )
  << "Table name string should be the default initialized value.";

  EXPECT_EQ( true, this->model->empty() )
  << "Resulting storage size should be empty (zero).";

  // NOM_LOG_INFO( NOM_LOG_CATEGORY_TEST, this->model->dump() );

  // Creation tests

  CardList cards;
  cards.push_back( Card( 0, "Geezard", 999 ) );
  EXPECT_EQ( 1, this->model->append_cards( cards ) )
  << "Resulting storage size should be one item.";

  EXPECT_EQ( 2, this->model->append_card( Card( 89, "testme", 22 ) ) )
  << "Resulting storage size should be two items.";

  // Overwrite 'testme' card
  EXPECT_EQ( 2, this->model->insert_card( 1, Card( 1, "Fungar", 777 ) ) )
  << "Resulting storage size should remain two.";

  EXPECT_EQ( false, this->model->empty() )
  << "Storage should not be empty.";

  // NOM_LOG_INFO( NOM_LOG_CATEGORY_TEST, this->model->dump() );

  // Destruction tests

  // Destroy 'Fungar' card
  EXPECT_EQ( 1, this->model->erase_card( 1 ) )
  << "Resulting storage size should be one.";

  // ...and verify the results
  row.clear();
  this->model->row(row, 0, cols );
  EXPECT_EQ( "Geezard", row.at(0) );
  EXPECT_EQ( "999", row.at(1) );

  cards.clear();
  cards.push_back( Card( 2, "Bite Bug", 2 ) );
  cards.push_back( Card( 3, "Red Bat", 5 ) );
  cards.push_back( Card( 89, "Diablos", 666 ) );

  // Overwrite all but the first card in the model, shifting said first card to
  // the end of the container.
  EXPECT_EQ( 4, this->model->insert_cards( 0, cards ) )
  << "Resulting storage size should be four items.";

  // Ensure that the first card is at the end of the container
  row.clear();
  this->model->row( row, this->model->num_rows() - 1, cols );
  EXPECT_EQ( "Geezard", row.at(0) );
  EXPECT_EQ( "999", row.at(1) );
  // NOM_LOG_INFO( NOM_LOG_CATEGORY_TEST, this->model->dump() );

  // Destroy all but 'Geezard' card
  EXPECT_EQ( 1, this->model->erase_cards( 0, 3 ) )
  << "The Geezard card should be the only item remaining.";

  // ...and verify the results
  row.clear();
  this->model->row(row, 0, cols );
  EXPECT_EQ( "Geezard", row.at(0) );
  EXPECT_EQ( "999", row.at(1) );

  this->model->erase_cards();
  EXPECT_EQ( true, this->model->empty() )
  << "Resulting storage size should be emptied (zero).";

  row.clear();
  this->model->erase_cards();

  NOM_LOG_INFO( NOM_LOG_CATEGORY_TEST, this->model->dump() );
}