コード例 #1
0
ファイル: StackPackEngine.c プロジェクト: steelwil/Kolumnz
/*----------------------------------------------------------------------------*/
int MovePieceDown(struct GameData* pGameData)
{
	RemovePiece(pGameData, pGameData->m_FallingRow, pGameData->m_FallingCol);	// remove from old position

	if (!PlacePiece(pGameData, pGameData->m_FallingRow+1, pGameData->m_FallingCol))	// try to place in new position
	{		
		PlacePiece(pGameData, pGameData->m_FallingRow, pGameData->m_FallingCol);	// else restore old position
		pGameData->m_FallingRow = -1;
		return 0;
	}
	pGameData->m_FallingRow = (pGameData->m_FallingRow+1)%pGameData->m_Height;
	return 1;
}
コード例 #2
0
ファイル: Game.cpp プロジェクト: kylepollina/Connect-Four
void Game::DoUserInput()
{
	
	if( kbd.LeftIsPressed() && cursorBlock > 0  && !arrowIsPressed ){
		cursorBlock--;
		cursorX -= 114;
		arrowIsPressed = true;
	}

	if( kbd.RightIsPressed() && cursorBlock < 6 && !arrowIsPressed ){
		cursorBlock++;
		cursorX += 114;
		arrowIsPressed = true;
	}

	if( !(kbd.LeftIsPressed() || kbd.RightIsPressed()) ){
		arrowIsPressed = false;
	}

	if( !(kbd.EnterIsPressed() ) ){
		enterIsPressed = false;
	}

	if( kbd.EnterIsPressed() && grid[0][cursorBlock] == EMPTY && !enterIsPressed ){
		PlacePiece();
		enterIsPressed = true;
	}
}
コード例 #3
0
ファイル: StackPackEngine.c プロジェクト: steelwil/Kolumnz
/*----------------------------------------------------------------------------*/
int GameStep(struct GameData* pGameData)
{
	int rt = 1;		/* 0=game over, 1=0K, 2=new piece, 3=new level */
	if (pGameData->m_FallingRow == -1) 
	{
		rt = 2;
		pGameData->m_FallingCol = pGameData->m_Center;
		pGameData->m_FallingPiece = pGameData->m_Preview;
		pGameData->m_BlkRot = 0;
		pGameData->m_BlkNum = pGameData->m_BlkPreviewNum;
		pGameData->m_BlkPreviewNum = (int)(rand()/(double)0x7fffffff*pGameData->m_MaxPieces);
		pGameData->m_Preview = pGameData->m_Shapes[pGameData->m_BlkPreviewNum][pGameData->m_BlkRot];
		pGameData->m_FallingRow = 0;
		if (!PlacePiece(pGameData, pGameData->m_FallingRow, pGameData->m_FallingCol) || pGameData->m_Level == pGameData->m_LastLevel+1)	// try to place
		{
			pGameData->m_GameOver = 1;
			rt = 0;		/* game over */
		}
	}
	else
	{
		if (!MovePieceDown(pGameData))
		{
			pGameData->m_StepDuration = 640-55*pGameData->m_Level;	/* speedInt[m_Level-1]; */
			rt = GameClearFullRows(pGameData);
			CalculateScore(pGameData);
		}
	}
//		Sleep(10000);
	if (pGameData->m_DropCount > 0)
	{
		pGameData->m_DropCount++;
	}
	return rt;
}
コード例 #4
0
ファイル: StackPackEngine.c プロジェクト: steelwil/Kolumnz
/*----------------------------------------------------------------------------*/
int GameRight(struct GameData* pGameData)
{
	if (pGameData->m_FallingRow >= 0)
	{
		RemovePiece(pGameData, pGameData->m_FallingRow, pGameData->m_FallingCol);	// remove from old position

		if (!PlacePiece(pGameData, pGameData->m_FallingRow, pGameData->m_FallingCol+1))	// try to place in new position
		{		
			PlacePiece(pGameData, pGameData->m_FallingRow, pGameData->m_FallingCol);	// else restore old position
			return 0;
		}
		pGameData->m_MoveCount++;
		pGameData->m_FallingCol++;
		return 1;
	}
	return 0;
}
コード例 #5
0
ファイル: Game.cpp プロジェクト: charlie-a-maxwell/Tetris
void Map::MovePiece(int x, int y)
{
    currentX += x;
    if (currentX > width-1)
        currentX = width -1;
    // HERE IS THE PROBLEM.
    // Not any more, sucker!
    if (currentX < -(width / 2.0f))
        currentX = -(width / 2.0f);

    int response = TestCollision(currentX, currentY);
    if (response > 0)
    {
        if (response == 2)
        {
            PlacePiece(currentX, currentY);
        }
        currentX -= x;
    }

    currentY += y;
    if (currentY <= -(height / 2.0f))
        PlacePiece(currentX, currentY-y);

    response = TestCollision(currentX, currentY);
    if (response > 0)
    {
        PlacePiece(currentX, currentY - y);
        currentY -= y;
    }

    if (response > 0 && currentY > (height / 2.0f))
    {
        // Game Over!
        MessageBox(NULL, "Game Over!", "Game Over!", MB_OK);
        g_App->done = true;
    }
}
コード例 #6
0
ファイル: StackPackEngine.c プロジェクト: steelwil/Kolumnz
/*----------------------------------------------------------------------------*/
int GameRotate(struct GameData* pGameData)
{
	unsigned long oldPosition;

	if (pGameData->m_FallingRow >= 0)
	{
		RemovePiece(pGameData, pGameData->m_FallingRow, pGameData->m_FallingCol);	// remove from old position
		oldPosition = pGameData->m_FallingPiece;
		pGameData->m_BlkRot = (pGameData->m_BlkRot+1)%4;					// rotate anti-clockwise
		pGameData->m_FallingPiece = pGameData->m_Shapes[pGameData->m_BlkNum][pGameData->m_BlkRot];

		if (!PlacePiece(pGameData, pGameData->m_FallingRow, pGameData->m_FallingCol))// try to place in new position
		{	
			pGameData->m_BlkRot = (pGameData->m_BlkRot+3)%4;					// rotate anti-clockwise
			pGameData->m_FallingPiece = oldPosition;
			PlacePiece(pGameData, pGameData->m_FallingRow, pGameData->m_FallingCol);	// else restore old position
			return 0;
		}
		pGameData->m_MoveCount++;
		return 1;
	}
	return 0;
}
コード例 #7
0
ファイル: StackPackEngine.c プロジェクト: steelwil/Kolumnz
/*----------------------------------------------------------------------------*/
int AddRows(struct GameData* pGameData, int nRows)
{
	int i,r,c;
	for (i=0; i<nRows; i++)
	{
		// is the top row free?
		if (pGameData->m_FallingRow >= 0)
			RemovePiece(pGameData, pGameData->m_FallingRow, pGameData->m_FallingCol);
		for (c=0; c<pGameData->m_Base; c++)
		{
			if (pGameData->m_Grid[0][c]) 
			{
				return 0;
			}
		}
		// move the whole grid one up
		for (r=0; r<pGameData->m_Height-1; r++)
			for (c=0; c<pGameData->m_Base; c++)
				pGameData->m_Grid[r][c] = pGameData->m_Grid[r+1][c];
		// add random pieces to the bottom
		for (c=0; c<pGameData->m_Base; c++)
			pGameData->m_Grid[pGameData->m_Height-1][c] = rand()%pGameData->m_MaxPieces+1;
		// add about 30% spaces to the rows
		pGameData->m_Grid[pGameData->m_Height-1][rand()%pGameData->m_Base] = 0;
		for (c=0; c<pGameData->m_Base; c++)
			if (rand()%10 < 3)
				pGameData->m_Grid[pGameData->m_Height-1][rand()%pGameData->m_Base] = 0;
		// take care of the falling piece
		if (pGameData->m_FallingRow > 0)
		{
			pGameData->m_FallingRow--;
			GameStep(pGameData);
		}
		if (pGameData->m_FallingRow == 0)
		{
			if (!PlacePiece(pGameData, pGameData->m_FallingRow, pGameData->m_FallingCol))	// try to place
			{
				pGameData->m_GameOver = 1;
				pGameData->m_FallingRow = -1;
				return 0;
			}
		}
	}
	return 1;
}
コード例 #8
0
void DroppedPieceProcess::VOnSuccess()
{
	PlacePiece();
	g_pApp->GetGfxMgr()->RemoveElement(m_pImage);
}