Exemplo n.º 1
0
void Display_tty::one_die (const Die& d) const
{
  switch (d.type ())
    {
    case GREEN:
      std::cout << green;
      break;
    case YELLOW:
      std::cout << yellow;
      break;
    case RED:
      std::cout << red;
      break;
    default:
      std::cout << white << "Apocalypse die: ";
    }
  switch (d.value ())
    {
    case BRAIN:
      std::cout << "[     BRAIN     ]";
      break;
    case RUNNING:
      std::cout << "[ STILL RUNNING ]";
      break;
    case SHOTGUN:
      std::cout << "[    SHOTGUN    ]";
      break;
    default:
      std::cout << "[  APOCALYPSE   ]";
    }
  std::cout << white << std::endl;
}
Exemplo n.º 2
0
		int* faceValue()
		{
			arrayPointer = &result[0];
			result[0] = dieOne.faceValue();
			result[1] = dieTwo.faceValue();
			return arrayPointer;
		}
Exemplo n.º 3
0
void Block_manager_parent::init(Ssd* new_ssd, FtlParent* new_ftl, IOScheduler* new_sched, Garbage_Collector* new_gc, Wear_Leveling_Strategy* new_wl, Migrator* new_migrator) {
    ssd = new_ssd;
    ftl = new_ftl;
    scheduler = new_sched;

    for (uint i = 0; i < SSD_SIZE; i++) {
        Package* package = ssd->get_package(i);
        for (uint j = 0; j < PACKAGE_SIZE; j++) {
            Die* die = package->get_die(j);
            for (uint t = 0; t < DIE_SIZE; t++) {
                Plane* plane = die->get_plane(t);
                for (uint b = 0; b < PLANE_SIZE; b++) {
                    Block* block = plane->get_block(b);
                    free_blocks[i][j][0].push_back(Address(block->get_physical_address(), PAGE));
                    all_blocks.push_back(block);
                }
            }
            Address pointer = free_blocks[i][j][0].back();
            free_block_pointers[i][j] = pointer;
            Free_Space_Per_LUN_Meter::mark_new_space(pointer, 0);
            free_blocks[i][j][0].pop_back();
        }
    }
    wl = new_wl;
    gc = new_gc;
    migrator = new_migrator;
}
Exemplo n.º 4
0
	void Game::RollForGame(GameResult* resultTracking) {
		Die* die = instance->player->GetDieFromBag();

		// Add die to the table
		gameTable->AddDieToTable(die);

		// Get Result
		int result = die->GetDieRoll();

		// Record Die Result
		resultTracking->AddDieResult(result);

		// Check Win Condition
		if (Utility::IsPrimeNumber(resultTracking->GetCurrentGameScore()) == true) {
			instance->GameWin(resultTracking);			
			return;
		}
		else if (instance->player->GetRemainingNumberOfDieInBag() == 0) {
			instance->GameLose(resultTracking);
			return;
		}
		else {
			RollForGame(resultTracking);
		}
	}
Exemplo n.º 5
0
item_ptr Item::Generate() {
    Die die = {1, ITEM_RANGED + 1, -1};
    uint cat = DieRoll::Roll(die);

    item_ptr item;

    switch(cat) {
        case ITEM_ARMOUR:
            die.Set(1, sizeof(armourTemplates)/sizeof(armourTemplates[0]), -1);
            item = std::make_shared<Armour>(armourTemplates[DieRoll::Roll(die)]);
            break;

        case ITEM_WEAPON:
            die.Set(1, sizeof(weaponTemplates)/sizeof(weaponTemplates[0]), -1);
            item = std::make_shared<Weapon>(weaponTemplates[DieRoll::Roll(die)]);
            break;

        case ITEM_RANGED:
            die.Set(1, sizeof(rangedTemplates)/sizeof(rangedTemplates[0]), -1);
            item = std::make_shared<Ranged>(rangedTemplates[DieRoll::Roll(die)]);
            break;

        default:
            item = std::make_shared<Item>("Nothing", 255, 255, 0);
    }

    return item;
}
Exemplo n.º 6
0
//READ THE COMMENT BELOW
//DO NOT REMOVE THIS FUNCTION
//READ THE COMMENT ABOVE
void Player::takeTurn(Board &game){
  int d1, d2;
  Die dice;
  dice.roll();
  cout<<"\nPlayer "<<turnControl<<endl;
  cout<<"Player Balance: "<<balance<<endl;
  diceTotal = dice.getTotal();
  update(game,diceTotal);
  displayDice(dice.d1, dice.d2);
  game.spaceManager(this);
  }
Exemplo n.º 7
0
/*********************************************************************
** Function:         defense_roll()
** Description:      Makes the appropriate type of die and rolls it
**                   the appropriate number of times
** Parameters:       None
** Pre-Conditions:   Creature must have data members set
** Post-Conditions:  Prints result of each roll and returns the total
**                   of all rolls (if multiple)
********************************************************************/
int Creature::defense_roll()
{
	int total_roll = 0, roll = 0;
	Die* die = new Die(this->defense_dice_sides);

	for (int i = 0; i < this->defense_dice_count; i++)
	{
		roll = die->roll();
		total_roll += roll;
		std::cout << this->type_name << " rolls defense die: d" << defense_dice_sides << " for " << roll << "\n";
	}
	std::cout << "Total defense roll: " << total_roll << "\n";
	delete die;
	return total_roll;
}
Exemplo n.º 8
0
		int Round() {
			Die1.RollDie(); Die2.RollDie();
			Score = Score + Die1.getValue() + Die2.getValue();
			if(Score == 5 || Score == 15 || Score == 25 || Score == 35) {
				if(Money < 5000) {
					Money = 0;
				}
				else {
					Money = Money - 5000;
				}
			}
			if(Score == 10 || Score == 20 || Score == 30 || Score == 40) {
				Money += 10000;
			}
			return Score;
		}
Exemplo n.º 9
0
	Die* DiceBag::GetRandomDieFromBag() {
		unsigned int count = this->GetNumberOfRemainingDie();
		
		unsigned int index = 0;
		if(count > 1) index = Utility::GetRandomNumber(0, count - 1);
		else if (count == 1) index = 0;
		
		Die* returnValue = dice.Export((int)index);

		// Basic Error Check 
		if (returnValue == nullptr)
			cout << "Null Retrun Value" << endl;

		this->UpdateBagCount(returnValue->GetType(), -1);
		
 		return returnValue;
	}
Exemplo n.º 10
0
/* I modified Die to make it possible to a const Die reference */
void IOutputer::printDice(const Die& d) const
{
    /* We just assume the die has 6 sides. No way of finding out. */
    int dieValue = d.getDieValue();
    for (int i = 0; i < 5; i++)
    {
        cout << IOutputer::msDices[dieValue-1][i] << endl;
    }
}
Exemplo n.º 11
0
int main()
{
	//frame setup
	system("title Dice Game");
	system("mode con: cols=63 lines=20");
	system("color 27");
	
	
	//animation array, this was shorteded to var "a" for easy use
	int a[20][2] = {{5,9},{7,7},{9,4},{11,2},{13,2},
					{15,4},{17,6},{19,9},{21,8},{23,7},
					{25,6},{27,5},{29,4},{31,5},{33,6},
					{35,7},{37,8},{39,9},{41,9},{42,9}};
	
	
	//var setup
	Renderer renderer;
	Die die;
	int dice1;
	int dice2;
	int yourScore = 0;
	int dealerScore = 0;
	int input;
	bool even;
	srand(5);
	
	
	//Start Game Here
	cout<< "Note:\n -Number displays work best if you pick less than 10 iterations\n -For best effect dont resize window\n-------------------------------------------------------------";
	cout<< "\nHow Many times do you want to play? ";
	cin >> input;
	cout << "\nEven or odd (0 or 1)? ";
	cin >> even;
	for(int j = 0; j < input; j ++){
		for(int i = 0; i < 20; i ++){
			//clear renderer
			renderer.clear();
			//display roll number
			char rollnum[8] = {'R','o','l','l',' ',(char)(j + 49),':','\0'};
			renderer.write(5,1,rollnum,7);
			//die #1 display
			die.roll();
			switch(dice1 = die.getValue()){
				case 1:
					renderer.draw(a[i][0],a[i][1]," ----- |     ||  O  ||     | ----- ",7,7*5);
					break;
				case 2:
					renderer.draw(a[i][0],a[i][1]," ----- |O    ||     ||    O| ----- ",7,7*5);
					break;
				case 3:
					renderer.draw(a[i][0],a[i][1]," ----- |O    ||  O  ||    O| ----- ",7,7*5);
					break;
				case 4:
					renderer.draw(a[i][0],a[i][1]," ----- |O   O||     ||O   O| ----- ",7,7*5);
					break;
				case 5:
					renderer.draw(a[i][0],a[i][1]," ----- |O   O||  O  ||O   O| ----- ",7,7*5);
					break;
				case 6:
					renderer.draw(a[i][0],a[i][1]," ----- |O   O||O   O||O   O| ----- ",7,7*5);
					break;
			};
			//die #2 display
			die.roll();
			switch(dice2 = die.getValue()){
				case 1:
					renderer.draw(a[i][0]+8,a[i][1]," ----- |     ||  O  ||     | ----- ",7,7*5);
					break;
				case 2:
					renderer.draw(a[i][0]+8,a[i][1]," ----- |O    ||     ||    O| ----- ",7,7*5);
					break;
				case 3:
					renderer.draw(a[i][0]+8,a[i][1]," ----- |O    ||  O  ||    O| ----- ",7,7*5);
					break;
				case 4:
					renderer.draw(a[i][0]+8,a[i][1]," ----- |O   O||     ||O   O| ----- ",7,7*5);
					break;
				case 5:
					renderer.draw(a[i][0]+8,a[i][1]," ----- |O   O||  O  ||O   O| ----- ",7,7*5);
					break;
				case 6:
					renderer.draw(a[i][0]+8,a[i][1]," ----- |O   O||O   O||O   O| ----- ",7,7*5);
					break;
			};
			//render frame
			renderer.render();
			//sleep for a sec then move on to the next frame
			usleep(100000);
		}
		//this if desides who wins the roll
	 	if(even ? (dice1+dice2)%2 == 1 : (dice1+dice2)%2 == 0){
	 		cout<<"\nYou Win!\n";
	 		yourScore ++;
		}else{
			cout << "\nDealer Wins!\n";
			dealerScore ++;
		}
		system("pause");
	}
	//clear renderer
	renderer.clear();
	//end game cstring setup
	char you[30] = {'Y','o','u','r',' ','f','i','n','a','l',' ','s','c','o','r','e',' ','i','s',' ',(char)(yourScore + 48),' ','p','o','i','n','t','s','.','\0'};
	char deal[34] = {'D','e','a','l','e','r',(char)96,'s',' ','f','i','n','a','l',' ','s','c','o','r','e',' ','i','s',' ',(char)(dealerScore + 48),' ','p','o','i','n','t','s','.','\0'};
	char win[9] =  {'Y','o','u',' ','W','i','n','!','\0'};
	char loss[9] =  {'Y','o','u',' ','L','o','s','t','\0'}; 
	//setup and display end game message
	if(yourScore <= dealerScore)
			renderer.write(28,9,loss,8);
	else 
			renderer.write(28,9,win,8);
	renderer.write(16,4,you,29);
	renderer.write(14,6,deal,33);
	renderer.render();
return 0;
}
Exemplo n.º 12
0
		void roll()
		{
			dieOne.roll();
			dieTwo.roll();
		}
Exemplo n.º 13
0
/**
 \param obj object that has been clicked/selected by the user

 userSelect handles is called whenever a user selects a new object
 either by mouse click, or by keyboard marking.

 this function governs the gameplay!

 userSelect checks if there is already a selected object,
 what kind of object this is
 and what is the corresponding action, for example
 move a die, deselect the currently selected object
 of select a new object and disregard the old selection
 */
void GameWidget::userSelect(Model* obj) {
  //FIXME: this function is currently only working with mouse interaction
  KBX::Logger log("userSelect");
  if ( !this->_game->finished()) {
    // dynamically select clicked object
    Die* die = dynamic_cast< Die* >(obj);
    Tile* tile = dynamic_cast< Tile* >(obj);
    Path* path = dynamic_cast< Path* >(obj);

    bool pathIsTempObj = false;
    if (die) {
      if (die->getPlayColor() == this->_game->getNext()) {
        this->_clearDieSelection();
        // die of current player: render paths, i.e. move possibilities
        std::list< Move > moves = this->_game->possibleMoves(die->getId());
        log.info(stringprintf("# of possible moves: %d", moves.size()));
        for (std::list< Move >::iterator mv = moves.begin(); mv != moves.end(); mv++) {
          log.info(
              stringprintf("possible move [dx, dy, firstX]: %d, %d, %s", mv->rel.dx, mv->rel.dy,
                  mv->rel.firstX ? "true" : "false"));
          this->_paths.push_back(this->_scene->add(new Path(this->_scene, die->getPosition(), *mv)));
        }
        this->_selectedDie = die;
      } else {
        if (this->_selectedDie) {
          // die of other player: get tile below die and treat with 'tile-code' below
          tile = die->getTile();
        }
      }
    }
    if (tile) {
      if (this->_selectedDie) {
        int oldX = this->_game->getDie(this->_selectedDie->getId()).x();
        int oldY = this->_game->getDie(this->_selectedDie->getId()).y();
        // check if selected die can move to this field. if yes: move (or draw remaining paths)
        std::list< Move > moves = this->_game->possibleMoves(this->_selectedDie->getId());
        std::list< Move > filteredMoves;
        for (std::list< Move >::iterator mv = moves.begin(); mv != moves.end(); mv++) {
          if ((mv->rel.dx + oldX == tile->getX()) && (mv->rel.dy + oldY == tile->getY())) {
            // move lands on selected tile
            filteredMoves.push_back( *mv);
          }
        }
        if (filteredMoves.size() == 1) {
          // only one move possible: perform move directly
          path = new Path(this->_scene, this->_selectedDie->getPosition(), filteredMoves.front());
          pathIsTempObj = true;
        } else if (filteredMoves.size() == 2) {
          // clear old paths, but keep selected die
          Die* sel = this->_selectedDie;
          this->_clearDieSelection();
          this->_selectedDie = sel;
          // two moves possible: draw paths
          this->_paths.push_back(this->_scene->add(new Path(this->_scene, sel->getPosition(), filteredMoves.front())));
          this->_paths.push_back(this->_scene->add(new Path(this->_scene, sel->getPosition(), filteredMoves.back())));
        } else {
          // no move possible: just clear selection
          this->_clearDieSelection();
        }
      }
    }
    if (path) {
      // if the game is paused, we do not accept user moves;
      if(!this->paused()){
        // move die along this path
        Move mv = path->getMove();
        this->_performMove(mv);
        if (pathIsTempObj && (path != NULL)) {
          delete path;
        }
      }
    }
  }
}
Exemplo n.º 14
0
void Level::Generate() {

    // allocate memory for levels
    Tile** new_map = new Tile* [_h];
    Tile** flooded_map = new Tile* [_h];
    for(uint i = 0; i < _h; i++) {
        new_map[i] = new Tile [_w];
        flooded_map[i] = new Tile [_w];
    }

    while(1) {
        // randomly fill starting level
        for(uint y = 1; y < _h -1; y++) {
            for(uint x = 1; x < _w; x++) {
                _map[y][x] = tiles[randpick()];
            }
        }

        // fill temp level with walls
        for(uint y = 0; y < _h; y++) {
            for(uint x = 0; x < _w; x++) {
                new_map[y][x] = tiles[MAP_WALL];
            }
        }

        // ensure the level has outer walls
        for(uint y = 0; y < _h; y++) {
            _map[y][0] = _map[y][_w-1] = tiles[MAP_WALL];
        }
        for(uint x = 0; x < _w; x++) {
            _map[0][x] = _map[_h-1][x] = tiles[MAP_WALL];
        }

        // run cellular autonoma algorithm
        for(uint y = 1; y < _h - 1; y++) {
            for(uint x = 1; x < _w - 1; x++) {
                int adjcount_r1 = 0,
                    adjcount_r2 = 0;

                for(int i = -1; i <= 1; i++) {
                    for(int j = -1; j <= 1; j++) {
                        if(_map[y+i][x+j].type != MAP_FLOOR) adjcount_r1++;
                    }
                }

                for(uint i = y - 2; i <= y + 2; i++) {
                    for(uint j = x - 2; j <= x + 2; j++) {
                        if(abs(i-y) == 2 && abs(j-x) == 2) continue;
                        if(i >= _h || j >= _w) continue;
                        if(_map[i][j].type != MAP_FLOOR) adjcount_r2++;
                    }
                }

                // select new tile for this position
                if(adjcount_r1 >= _r1_cutoff || adjcount_r2 <= _r2_cutoff) {
                    new_map[y][x] = tiles[MAP_WALL];
                }
                else {
                    new_map[y][x] = tiles[MAP_FLOOR];
                }
            }
        }

        // flood map from random floor cell
        int rnd_x, rnd_y;
        while(1) {
            rnd_x = rand() % _w;
            rnd_y = rand() % _h;

            if(new_map[rnd_y][rnd_x].type == MAP_FLOOR) break;
        }

        for(uint y = 0; y < _h; y++) {
            for(uint x = 0; x < _w; x++) {
                flooded_map[y][x] = tiles[MAP_WALL];
            }
        }

        floodmap(new_map, flooded_map, rnd_x, rnd_y);

        // ensure that at least 1/2 of the map is floor
        uint floorcount = 0;
        for(uint y = 0; y < _h; y++) {
            for(uint x = 0; x < _w; x++) {
                if(flooded_map[y][x].type == MAP_FLOOR) floorcount++;
            }
        }

        if(floorcount > (_w*_h)/2) break;
    }

    // place stairs
    int rnd_x, rnd_y;
    while(1) {
        rnd_x = rand() % _w;
        rnd_y = rand() % _h;

        if(flooded_map[rnd_y][rnd_x].type == MAP_FLOOR) {
            flooded_map[rnd_y][rnd_x] = tiles[MAP_STAIR_DOWN];
            _stairDown.x = rnd_x;
            _stairDown.y = rnd_y;
            break;
        }
    }
    while(1) {
        rnd_x = rand() % _w;
        rnd_y = rand() % _h;

        if(flooded_map[rnd_y][rnd_x].type == MAP_FLOOR) {
            flooded_map[rnd_y][rnd_x] = tiles[MAP_STAIR_UP];
            _stairUp.x = rnd_x;
            _stairUp.y = rnd_y;
            break;
        }
    }

    // replace map with new one
    for(uint y = 1; y < _h - 1; y++) {
        for(uint x = 1; x < _w -1; x++) {
            _map[y][x] = flooded_map[y][x];
        }
    }

    // free memory used up by temporary maps
    for(uint i = 0; i < _h; i++) {
        delete [] new_map[i];
        delete [] flooded_map[i];
    }
    delete [] new_map;
    delete [] flooded_map;

    // scatter items around level
    for(uint i = 0; i < LEVEL_HEIGHT / 2; i++) {
        Die tmp = {1, _h-1, 0};
        uint y = DieRoll::Roll(tmp);
        tmp.Set(1, _w-1, 0);
        uint x = DieRoll::Roll(tmp);

        if(_map[y][x].type == MAP_FLOOR) _map[y][x].items.push_back(Item::Generate());
    }
}
Exemplo n.º 15
0
void IfNode::run(ExecutionNode *previous)
{
    m_previousNode = previous;
    if(NULL==previous)
    {
        return;
    }
    ExecutionNode* previousLoop = previous;
    ExecutionNode* nextNode = NULL;
    bool runNext = (NULL==m_nextNode) ? false : true;
    Result* previousResult = previous->getResult();
    m_result = previousResult;

    if(NULL!=m_result)
    {
        qreal value = previousResult->getResult(Result::SCALAR).toReal();

        if(NULL!=m_validator)
        {
            DiceResult* previousDiceResult = dynamic_cast<DiceResult*>(previousResult);
            if(NULL!=previousDiceResult)
            {
                QList<Die*> diceList=previousDiceResult->getResultList();
                if(m_conditionType == OnEach)
                {
                    for(Die* dice : diceList)
                    {
                        if(m_validator->hasValid(dice,true,true))
                        {
                            nextNode = (NULL==m_true) ? NULL: m_true->getCopy();
                        }
                        else
                        {
                            nextNode = (NULL==m_false) ? NULL: m_false->getCopy();
                        }
                        if(NULL!=nextNode)
                        {
                            if(NULL==previousLoop->getNextNode())
                            {
                                previousLoop->setNextNode(nextNode);
                            }
                            if(NULL==m_nextNode)
                            {
                                m_nextNode = nextNode;
                            }
                            nextNode->run(previousLoop);
                            previousLoop = getLeafNode(nextNode);
                        }
                    }
                }
                else
                {
                    bool trueForAll=true;
                    bool falseForAll=true;

                    bool oneIsTrue=false;
                    bool oneIsFalse=false;

                    for(Die* dice : diceList)
                    {
                        bool result = m_validator->hasValid(dice,true,true);
                        qDebug() << result << m_conditionType;
                        trueForAll = trueForAll ? result : false;
                        falseForAll = falseForAll ? result : false;

                        oneIsTrue = (oneIsTrue==false) ? result : true;
                        oneIsFalse = (oneIsFalse==false) ? result : true;
                    }
                    if(m_conditionType==OneOfThem)
                    {
                        if(oneIsTrue)
                        {
                            nextNode = (NULL==m_true) ? NULL: m_true->getCopy();
                        }
                        else if(oneIsFalse)
                        {
                             nextNode = (NULL==m_false) ? NULL: m_false->getCopy();
                        }
                    }
                    else if(m_conditionType==AllOfThem)
                    {
                        if(trueForAll)
                        {
                            nextNode = (NULL==m_true) ? NULL: m_true->getCopy();
                        }
                        else if(falseForAll)
                        {
                             nextNode = (NULL==m_false) ? NULL: m_false->getCopy();
                        }
                    }


                    if(NULL!=nextNode)
                    {
                        if(NULL==m_nextNode)
                        {
                            m_nextNode = nextNode;
                        }
                        nextNode->run(previousLoop);
                        previousLoop = getLeafNode(nextNode);
                    }
                }
            }
            else
            {
                Die* dice = new Die();
                dice->setValue(value);
                dice->setFaces(value);
                if(m_validator->hasValid(dice,true,true))
                {
                        nextNode=m_true;
                }
                else
                {
                        nextNode=m_false;
                }
                if(NULL!=nextNode)
                {
                    if(NULL==m_nextNode)
                    {
                        m_nextNode = nextNode;
                    }
                    nextNode->run(previousLoop);
                    previousLoop = getLeafNode(nextNode);
                }
            }
        }
    }

    if((NULL!=m_nextNode)&&(runNext))
    {
        m_nextNode->run(previousLoop);
    }
}