court.cpp
资源名称:pong.rar [点击查看]
上传用户:szsg028
上传日期:2022-08-01
资源大小:12k
文件大小:3k
源码类别:
GDI/图象编程
开发平台:
Visual C++
- #include "court.h"
- #include <stdio.h>
- court::court()
- {
- m_fontMarcador = CreateFont(130, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Courier");
- m_penMargenes = CreatePen(PS_SOLID, 1, RGB(255, 255, 255));
- m_brushFondo = (HBRUSH)GetStockObject(BLACK_BRUSH);
- m_brushBlanco = (HBRUSH)GetStockObject(WHITE_BRUSH);
- }
- court::~court()
- {
- DeleteObject(m_fontMarcador);
- DeleteObject(m_penMargenes);
- DeleteObject(m_brushFondo);
- DeleteObject(m_brushBlanco);
- }
- void court::draw(HDC hDC)
- {
- HBRUSH hOldBrush;
- HFONT hOldFont;
- HPEN hOldPen;
- COLORREF cOldColor;
- char contador1 = 0;
- char contador2 = 0;
- int i = 0;
- //dibujo el fondo negro
- hOldBrush = (HBRUSH)SelectObject(hDC, m_brushFondo);
- Rectangle(hDC, getX()-getWidth()/2, getY()-getHeight()/2, getWidth(), getHeight());
- //dibujo los puntajes
- hOldFont = (HFONT)SelectObject(hDC, m_fontMarcador);
- cOldColor = SetBkColor(hDC, RGB(0, 0, 0));
- SetTextColor(hDC, RGB(255, 255, 255));
- SetTextAlign(hDC, TA_CENTER | TA_TOP);
- char bufScore1[2];
- sprintf(bufScore1, "%d", getScoreP1());
- TextOut(hDC, (getWidth()/2 - 40), (getMarginTop()-110), (LPCSTR)bufScore1, strlen(bufScore1));
- char bufScore2[2];
- sprintf(bufScore2, "%d", getScoreP2());
- TextOut(hDC, (getWidth()/2 + 34), (getMarginTop()-110), (LPCSTR)bufScore2, strlen(bufScore2));
- //pinto las l韓eas del borde de la cancha
- hOldPen = (HPEN)SelectObject(hDC, m_penMargenes);
- MoveToEx(hDC, 0, getMarginTop(), 0);
- LineTo(hDC, getWidth(), getMarginTop());
- MoveToEx(hDC, 0, getMarginBottom(), 0);
- LineTo(hDC, getWidth(), getMarginBottom());
- //pinto la linea transversal
- SelectObject(hDC, m_brushBlanco);
- while (i <= getMarginBottom())
- {
- Ellipse(hDC, getWidth()/2 - 2, i, getWidth()/2 + 2, i + 4 );
- i += 15;
- }
- //vuelvo a los pens, brushes, fuentes y colores originales
- SetBkColor(hDC, cOldColor);
- SelectObject(hDC, hOldBrush);
- SelectObject(hDC, hOldFont);
- SelectObject(hDC, hOldPen);
- }
- void court::setMargins(int marginLeft, int marginRight, int marginTop, int marginBottom)
- {
- m_iMarginLeft = marginLeft;
- m_iMarginRight = marginRight;
- m_iMarginTop = marginTop;
- m_iMarginBottom = marginBottom;
- }
- void court::setAxisPad1(int valor)
- {
- m_iAxisPad1 = valor;
- }
- void court::setAxisPad2(int valor)
- {
- m_iAxisPad2 = valor;
- }
- void court::resetScores()
- {
- m_iBuffScoreP1 = 0;
- m_iBuffScoreP2 = 0;
- }
- int court::getScoreP1()
- {
- return m_iBuffScoreP1;
- }
- int court::getScoreP2()
- {
- return m_iBuffScoreP2;
- }
- int court::getMarginLeft()
- {
- return m_iMarginLeft;
- }
- int court::getMarginRight()
- {
- return m_iMarginRight;
- }
- int court::getMarginTop()
- {
- return m_iMarginTop;
- }
- int court::getMarginBottom()
- {
- return m_iMarginBottom;
- }
- int court::getAxisPad1()
- {
- return m_iAxisPad1;
- }
- int court::getAxisPad2()
- {
- return m_iAxisPad2;
- }
- void court::P1Scores()
- {
- m_iBuffScoreP1++;
- }
- void court::P2Scores()
- {
- m_iBuffScoreP2++;
- }
- void court::refreshScores()
- {
- m_iScoreP1 = m_iBuffScoreP1;
- m_iScoreP2 = m_iBuffScoreP2;
- }