コード例 #1
0
ファイル: bombs1.cpp プロジェクト: gitrider/wxsj2
// Called when uncovering a cell.
void BombsCanvas::Uncover(int x, int y)
{
    m_game->Unhide(x,y,true);
    RefreshField(x, y, x, y);

    const int gridWidth = m_game->GetWidth();
    const int gridHeight = m_game->GetHeight();

    const bool hasWon = m_game->GetNumRemainingCells() == 0;
    if (m_game->IsBomb(x,y) || hasWon)
    {
        wxBell();
        if (hasWon)
        {
            wxMessageBox(wxT("Nice! You found all the bombs!"),
                wxT("wxWin Bombs"), wxOK|wxCENTRE);
        }
        else // x,y is a bomb
        {
            m_game->Explode(x, y);
        }

        for(x=0; x<gridWidth; x++)
            for(y=0; y<gridHeight; y++)
                m_game->Unhide(x,y,false);

        RefreshField(0, 0, gridWidth-1, gridHeight-1);
    }
    else if (0 == (m_game->Get(x, y) & BG_MASK))
    {
        int left = ( x > 0 ) ? x-1 : 0;
        int right = ( x < gridWidth - 1 )
            ? x+1
            : gridWidth - 1;
        int top = ( y > 0 ) ? y-1 : 0;
        int bottom = ( y < gridHeight - 1 )
            ? y+1
            : gridHeight - 1;

        int i, j;
        for (j=top; j<=bottom; j++)
            for (i=left; i<=right; i++)
                if ( (i != x || j != y) && m_game->IsHidden(i, j)
                    && !m_game->IsMarked(i, j) )
                {
                    Uncover(i, j);
                }
    }
}
コード例 #2
0
ファイル: bombs1.cpp プロジェクト: gitrider/wxsj2
// Called when the canvas receives a mouse event.
void BombsCanvas::OnMouseEvent(wxMouseEvent& event)
{
    const int gridWidth = m_game->GetWidth();
    const int gridHeight = m_game->GetHeight();

    wxCoord fx, fy;
    event.GetPosition(&fx, &fy);
    int x = fx/(m_cellWidth*X_UNIT);
    int y = fy/(m_cellHeight*Y_UNIT);
    if (x<gridWidth && y<gridHeight)
    {
        if ( (event.RightDown() || (event.LeftDown() && event.ShiftDown()))
           && (m_game->IsHidden(x,y)
               || !m_game->GetNumRemainingCells() ) )
        {
            // store previous and current field
            int prevFocusX = m_game->m_gridFocusX;
            int prevFocusY = m_game->m_gridFocusY;
            m_game->m_gridFocusX = x;
            m_game->m_gridFocusY = y;
            RefreshField(prevFocusX, prevFocusY, prevFocusX, prevFocusY);
            m_game->Mark(x, y);
            RefreshField(x, y, x, y);
            return;
        }
        else if (event.LeftDown() && m_game->IsHidden(x,y)
            && !m_game->IsMarked(x,y))
        {
            // store previous and current field
            int prevGridFocusX = m_game->m_gridFocusX;
            int prevGridFocusY = m_game->m_gridFocusY;
            m_game->m_gridFocusX = x;
            m_game->m_gridFocusY = y;
            RefreshField(prevGridFocusX, prevGridFocusY,
                prevGridFocusX, prevGridFocusY);
            Uncover(x, y);
            return;
        }
    }
}
コード例 #3
0
ファイル: statusbr.cpp プロジェクト: czxxjtu/wxPython-1
void wxStatusBarUniv::SetStatusText(const wxString& text, int number)
{
    wxCHECK_RET( number >= 0 && (size_t)number < m_panes.GetCount(),
                 _T("invalid status bar field index in SetStatusText()") );

    if ( text == GetStatusText(number) )
    {
        // nothing changed
        return;
    }

    wxStatusBarBase::SetStatusText(text, number);

    RefreshField(number);
}
コード例 #4
0
ファイル: gameframe.cpp プロジェクト: gotonis/danmake
Field::Field()
{
	animated_count=0;
	droped_count=0;
	back_swap = false;

	EventCallback cb = CLOSURE(this, &Field::JewelClick);
	addEventListener(TouchEvent::TOUCH_DOWN, cb);
	state = fsWaiting;

	setSize(JEWEL_SIZE * FIELD_SIZE, JEWEL_SIZE * FIELD_SIZE);

	FillField(true);
	RefreshField();
}
コード例 #5
0
ファイル: statusbr.cpp プロジェクト: AlexHayton/decoda
void wxStatusBarUniv::SetStatusText(const wxString& text, int number)
{
    wxCHECK_RET( number >= 0 && number < m_nFields,
                 _T("invalid status bar field index in SetStatusText()") );

    if ( text == m_statusText[number] )
    {
        // nothing changed
        return;
    }

    m_statusText[number] = text;

    RefreshField(number);
}
コード例 #6
0
ファイル: gameframe.cpp プロジェクト: gotonis/danmake
void Field::DropEndCallback(Event *ev)
{
	safeSpCast<Jewel>(ev->target)->setState(jsNormal);
	droped_count--;
	if (droped_count==0) 
	{
		if (CheckField()) 
			DropField();
		else
		{
			if (FindSolutions())
				state = fsWaiting;
			else 
				RefreshField();
		}
	}
}
コード例 #7
0
ファイル: bombs1.cpp プロジェクト: gitrider/wxsj2
void BombsCanvas::OnChar(wxKeyEvent& event)
{
    int keyCode = event.GetKeyCode();
    int prevGridFocusX = m_game->m_gridFocusX;
    int prevGridFocusY = m_game->m_gridFocusY;

    const int gridWidth = m_game->GetWidth();
    const int gridHeight = m_game->GetHeight();

    switch(keyCode)
    {

    case WXK_RIGHT:
        m_game->m_gridFocusX++;
        if (m_game->m_gridFocusX >= gridWidth) m_game->m_gridFocusX = 0;
        break;

    case WXK_LEFT:
        m_game->m_gridFocusX--;
        if (m_game->m_gridFocusX<0) m_game->m_gridFocusX = gridWidth-1;
        break;

    case WXK_DOWN:
        m_game->m_gridFocusY++;
        if (m_game->m_gridFocusY >= gridHeight) m_game->m_gridFocusY = 0;
        break;

    case WXK_UP:
        m_game->m_gridFocusY--;
        if (m_game->m_gridFocusY<0) m_game->m_gridFocusY = gridHeight-1;
        break;

    case WXK_RETURN:
        if ( (prevGridFocusX == m_game->m_gridFocusX)
            && (prevGridFocusY == m_game->m_gridFocusY)
            && (m_game->IsHidden(m_game->m_gridFocusX, m_game->m_gridFocusY)) )
        {
            m_game->Mark(m_game->m_gridFocusX, m_game->m_gridFocusY);
            if (!m_game->IsMarked(m_game->m_gridFocusX, m_game->m_gridFocusY))
            {
                Uncover(m_game->m_gridFocusX, m_game->m_gridFocusY);
            }
            RefreshField(m_game->m_gridFocusX, m_game->m_gridFocusY,
                m_game->m_gridFocusX, m_game->m_gridFocusY);
        }
        break;

    default:
        event.Skip();

    }

    if ((prevGridFocusX != m_game->m_gridFocusX)
        || (prevGridFocusY != m_game->m_gridFocusY))
    {
        // cause focused field to be visible after first key hit after launching new game
        if( m_game->m_gridFocusX < 0 ) m_game->m_gridFocusX = 0;
        if( m_game->m_gridFocusY < 0 ) m_game->m_gridFocusY = 0;

        // refresh previous field and focused field
        RefreshField(prevGridFocusX, prevGridFocusY,
            prevGridFocusX, prevGridFocusY);
        RefreshField(m_game->m_gridFocusX, m_game->m_gridFocusY,
            m_game->m_gridFocusX, m_game->m_gridFocusY);
    }
}