Example #1
0
void Field::NewTetromino() {
	downKeyReleased_ = false;

	ResetCounter();
	score_ += level_;
	if (tetromino_) {
		tetromino_->AttachToField();
		CheckLines();
	}
	tetromino_ = nextTetromino_;
	nextTetromino_.reset(new Tetromino(std::uniform_int_distribution<int>(0, 6)(random), *this));

	if (tetromino_) {
		const int xPositions[] = { 5, 6, 4, 7, 3, 8, 2, 9, 1, 10, 0 };
		for(int i = 0; i < 11; ++i)
		{
			tetromino_->SetX(xPositions[i]);
			if(!tetromino_->Collided())
			{
				return;
			}
		}
		tetromino_->SetX(xPositions[0]);
		gameOver_ = true;
		nextTetromino_ = tetromino_;
		counter_ = 10;
	}
}
Example #2
0
    void OnPlayerKilledByCreature(Creature* /*killer*/, Player* killed)
    {
        if (!MultiKillEnable)
            return;

        ResetCounter(killed->GetGUIDLow());
    }
Example #3
0
    void OnPVPKill(Player* killer, Player* killed)
    {
        if (!MultiKillEnable)
            return;

        uint32 killerGuid = killer->GetGUIDLow();
        uint32 killedGuid = killed->GetGUIDLow();

        ResetCounter(killedGuid);

        if (killerGuid == killedGuid)
            return;

        if (MultiKillBattleGround && !killer->InBattleground())
            return;

        time_t now = time(NULL);

        Reward(killer, ++MultiKillPlayer[killerGuid].total, KILL_TYPE_TOTAL);

        if (now - MultiKillPlayer[killerGuid].last > MultiKillTimeBetween)
            MultiKillPlayer[killerGuid].count = 0;

        MultiKillPlayer[killerGuid].last = now;

        if (MultiKillPlayer[killerGuid].count < MultiKillMax)
            MultiKillPlayer[killerGuid].count++;

        if (MultiKillPlayer[killerGuid].count < MultiKillMin)
            return;

        Reward(killer, MultiKillPlayer[killerGuid].count, KILL_TYPE_MULTI);
    }
Example #4
0
void
Generation::Seed(void) {
	AppLog("Seed");
	for (int i=0; i<columns; i++) {
		for (int j=0; j<rows; j++) {
			currentGeneration[i][j] = Osp::Base::Utility::Math::Rand()
			< (Osp::Base::Utility::Math::RAND_VALUE_MAX / 2);
		}
	}
	ResetCounter();
}
Example #5
0
void Field::step() {
	--counter_;
	if (gameOver_ && counter_ <= 0 && !blocks_.empty()) {
		counter_ = 5;
		std::vector<Block>::iterator randomBlock = blocks_.begin() + std::uniform_int_distribution<int>(0, blocks_.size()-1)(random);
		explosions_.push_back(Explosion(*randomBlock, 1));
		blocks_.erase(randomBlock);
	}
	if (!gameOver_) {
		control_->step();
		linesCleared = 0;
		if (counter_ <= 0) {
			ResetCounter();
			if (!tetromino_->MoveDown()) {
				if (delay_) {
					NewTetromino();
					delay_ = false;
				} else {
					counter_ = 30; // Wait 0.3 seconds so that it's possible to move blocks below others
					delay_ = true;
				}
			} else {
				delay_ = false;
			}
		}
		tetromino_->Step();
		if (control_->Check(control::Drop)) {
			tetromino_->drop();
			NewTetromino();
		}
		if (control_->Check(control::Down)) {
			if (downKeyReleased_ && counter_ > 7) {
				counter_ = 7;
			}
		} else {
			downKeyReleased_ = true;
		}
	}

	for (auto& b : blocks_) {
		b.step();
	}

	if ((level_ + 1) * 10 <= lines_) {
		++level_;
	}

	for (auto& e : explosions_) {
		e.Step();
	}
	explosions_.erase(std::remove_if(explosions_.begin(), explosions_.end(), [](const Explosion& e) {
		return e.isFinished();
	}), explosions_.end());
}
Example #6
0
static VALUE method_reset_counter(VALUE self, long counter) {
    if (check_connection(self)) {
        counter = NUM2INT(counter);
        if (valid_counter(counter)) {
            if (ResetCounter(counter) != -1)
                return Qtrue;
        }
        printf("K8055 returned an error.\n");
        return Qfalse;
    }
}
Example #7
0
    uint32_t operator()()
    {
        uint32_t const counter = GetCounter();
        uint32_t const result = m_startIndex + m_base + counter - 2 * (counter / 3) + GetCWNormalizer();
        if (counter + 1 == m_indexPerStrip)
        {
            m_base += m_vertexStride;
            ResetCounter();
        }

        return result;
    }
Example #8
0
 void OnLogin(Player* player)
 {
     ResetCounter(player->GetGUIDLow());
 }
Example #9
0
 void OnPlayerJoinedBattleground(Player* player, Battleground* /*bg*/)
 {
     ResetCounter(player->GetGUIDLow());
 }
Example #10
0
int main (int argc,char *params[]) 
{
	int i,result[3];
	unsigned char d=0;
	int a1=0,a2=0;
	unsigned short c1=0, c2=0;
	unsigned long int start,mstart=0,lastcall=0;

	start = time_msec();

	/*
		Load parameters
		If parameters are valid continue
	*/
	
	if (read_param(argc,params)) 
	{
		/*
			Initialise USB system
			and enable debug mode
		
		if ( debug ) 
			usb_set_debug(2);
		*/
		/*
			Search the device
		*/
		if ( OpenDevice(ipid)<0 ) {
			printf("Could not open the k8055 (port:%d)\nPlease ensure that the device is correctly connected.\n",ipid);
			return (-1);
			
		} else {

			if ( resetcnt1 )
				ResetCounter(1);
			if ( resetcnt2 )
				ResetCounter(2);	
			if ( dbt1 != -1 )
				SetCounterDebounceTime(1,dbt1);
				
			if ( dbt2 != -1 )
				SetCounterDebounceTime(2,dbt1);
				
			mstart = time_msec(); // Measure start
			for (i=0; i<numread; i++) {
				
				if ( delay ) {
					// Wait until next measure
					while ( time_msec()-mstart < i*delay );
				} 
				ReadAllAnalog(&a1,&a2);
				d=ReadAllDigital();
				c1=ReadCounter(1);
				c2=ReadCounter(2);
				lastcall = time_msec();
				printf("%d;%d;%d;%d;%d;%d\n", (int)(lastcall-start),d, (int)a1, (int)a2,c1,c2 );
			}
			
			if (debug && ((ia1!=-1)||(ia2!=-1)||(id8!=-1))) printf("Set ");
			if (ia1!=-1){ result[0]=OutputAnalogChannel(1,ia1);
			if (debug) printf("analog1:%d ",result[0]);}
			if (ia2!=-1){ result[1]=OutputAnalogChannel(2,ia2);
			if (debug) printf("analog2:%d ",result[1]);}
			if (id8!=-1){ result[2]=WriteAllDigital((long)id8);
			if (debug) printf("digital:%d",result[2]);}
			if (debug) printf("\n");		

			CloseDevice();
		}
	}
	return 0;
}
Example #11
0
void CEnvHudCounter::InputResetCounter( inputdata_t &inputdata )
{
	ResetCounter();
	m_OnCounterReset.FireOutput( this, this );
}
Example #12
0
        bool IsValid(vector<vector<char>>& board)
        {	
            for (int row = 0; row < 9; row++)
            {
                ResetCounter();
                for (int col = 0; col < 9; col++)
                {
                    char boardValue = board[col][row];
                    if (boardValue != '.')
                    {
                        if (counter[boardValue - '1'] == 0)
                        {
                            counter[boardValue - '1'] = 1;
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
            }
            for (int col = 0; col < 9; col++)
            {
                ResetCounter();
                for (int row = 0; row < 9; row++)
                {
                    char boardValue = board[col][row];
                    if (boardValue != '.')
                    {
                        if (counter[boardValue - '1'] == 0)
                        {
                            counter[boardValue - '1'] = 1;
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
            }

            for (int blockRow = 0; blockRow < 3; blockRow++)
            {
                for (int blockCol = 0; blockCol < 3; blockCol++)
                {
                    ResetCounter();
                    for (int row = 0; row < 3; row++)
                    {
                        for (int col = 0; col < 3; col++)
                        {
                            char boardValue = board[blockCol * 3 + col][blockRow * 3 + row];
                            if (boardValue != '.')
                            {
                                if (counter[boardValue - '1'] == 0)
                                {
                                    counter[boardValue - '1'] = 1;
                                }
                                else
                                {
                                    return false;
                                }
                            }
                        }
                    }
                }
            }

            return true;
        }