troubleshooting Question

Visual C++, MFC

Avatar of larry84
larry84 asked on
Visual Basic.NETVisual C++.NETSystem Programming
7 Comments1 Solution1121 ViewsLast Modified:
I am programming a game on a SDI. The display consists of three rectangles, a small rectangle in a larger rectangle within a larger rectangle. These rectangles are connected by 4 lines, 2 vertical, 2 horizintal, similar to a cross being placed on the rectangles except the cross doesn't show inside the inner rectangle. On each rectangle I can place either an x or an o at 8 different positions, on all the corners and half way between the corners. The object of the game is that there are two players, each places a piece on the display in alternate goes. Each player gets 6 pieces, if a player gets 3 of his pieces in a row he can remove one of the components pieces.

The problem I have is that I can display all 12 pieces but after all 12 pieces are placed I need to move pieces already placed.
// E4gameView.cpp : implementation of the CE4gameView class
//
 
#include "stdafx.h"
#include "E4game.h"
 
#include "E4gameDoc.h"
#include "E4gameView.h"
 
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
 
/////////////////////////////////////////////////////////////////////////////
// CE4gameView
 
IMPLEMENT_DYNCREATE(CE4gameView, CView)
 
BEGIN_MESSAGE_MAP(CE4gameView, CView)
	//{{AFX_MSG_MAP(CE4gameView)
	ON_WM_LBUTTONDOWN()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
 
/////////////////////////////////////////////////////////////////////////////
// CE4gameView construction/destruction
 
CE4gameView::CE4gameView()
{
	// TODO: add construction code here
 
	
    for (int i=0; i<7; i++) {
	for (int j=0; j<7; j++) {
	int x=(i*70)+10;
	int y=-(j*70)-10;
	m_rect[i][j].SetRect(x,y,x +60, y - 60);
	m_rect[i][j].NormalizeRect();
	}
	}
}
 
CE4gameView::~CE4gameView()
{
}
 
BOOL CE4gameView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs
 
	return CView::PreCreateWindow(cs);
}
 
/////////////////////////////////////////////////////////////////////////////
// CE4gameView drawing
 
void CE4gameView::OnDraw(CDC* pDC)
{
	CE4gameDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	pDC->SetMapMode (MM_LOENGLISH);
	//
	CRect rect;
	//
	// TODO: add draw code for native data here
	//
    CPen pen (PS_SOLID,5,RGB(0,0,255));
	CPen* pOldPen = pDC->SelectObject (&pen);
 
	pDC->MoveTo (30,-30);
	pDC->LineTo (30,-460);
    pDC->LineTo (460,-460);     //Big rect
    pDC->LineTo (460,-30);
    pDC->LineTo (30,-30);
 
    pDC->MoveTo (110,-110);
	pDC->LineTo (110,-390);
    pDC->LineTo (390,-390);    //Middle rect
    pDC->LineTo (390,-110);
    pDC->LineTo (110,-110);
 
    pDC->MoveTo (180,-180);
	pDC->LineTo (180,-320);
    pDC->LineTo (320,-320);     //Small rect
    pDC->LineTo (320,-180);
    pDC->LineTo (180,-180);
 
    pDC->MoveTo (30,-250);
	pDC->LineTo (180,-250);
 
    pDC->MoveTo (250,-30);
	pDC->LineTo (250,-180);
 
    pDC->MoveTo (320,-250);
	pDC->LineTo (460,-250);
 
    pDC->MoveTo (250,-320);
	pDC->LineTo (250,-460);
 
 
 
 
 
	pDC->SelectObject (pOldPen);
}
 
/////////////////////////////////////////////////////////////////////////////
// CE4gameView printing
 
BOOL CE4gameView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}
 
void CE4gameView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}
 
void CE4gameView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}
 
/////////////////////////////////////////////////////////////////////////////
// CE4gameView diagnostics
 
#ifdef _DEBUG
void CE4gameView::AssertValid() const
{
	CView::AssertValid();
}
 
void CE4gameView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}
 
CE4gameDoc* CE4gameView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CE4gameDoc)));
	return (CE4gameDoc*)m_pDocument;
}
#endif //_DEBUG
 
/////////////////////////////////////////////////////////////////////////////
// CE4gameView message handlers
 
void CE4gameView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
    //
    //
	CE4gameDoc*pDoc=GetDocument();
	//
	CClientDC dc (this);
	dc.SetMapMode (MM_LOENGLISH);
	dc.DPtoLP (&point);
	//
	//
	BOOL bQuit = FALSE;
	for (int i=0; i<7 && !bQuit; i++){
	for (int j=0; j<7 && !bQuit; j++){
	if (m_rect[i][j].PtInRect (point)){
    if(pDoc->GetSquare(i,j) ==0) {
    if (pDoc->Isitp1Turn()) {
						pDoc->Addpiece1 (i,j);
						Drawp1 (&dc, &m_rect[i][j]);
					}
					else{
						pDoc->Addpiece2 (i,j);
						Drawp2 (&dc, &m_rect[i][j]);
				}
				}
				bQuit = TRUE;
				
			}
		}
	}
 
	
	CView::OnLButtonDown(nFlags, point);
}
 
void CE4gameView::Drawp1(CDC *pDC, CRect *pRect)
{
    CE4gameDoc* pDoc = GetDocument();
    //
	//make a local copy of the rectangle and shrink it.
	//
	CRect rect;
	rect.CopyRect (pRect);
	rect.DeflateRect (1,1);
	//
	//create a red pen and use it to draw an x.
	//
	CPen pen (PS_SOLID,4,RGB(255,0,0));
	CPen* pOldPen = pDC->SelectObject (&pen);
	pDC->MoveTo (rect.left, rect.top);
	pDC->LineTo (rect.right, rect.bottom);
	pDC->MoveTo (rect.left, rect.bottom);
	pDC->LineTo (rect.right, rect.top);
	pDC->SelectObject (pOldPen);
 
	
 
    
}
 
void CE4gameView::Drawp2(CDC *pDC, CRect *pRect)
{
    CE4gameDoc* pDoc = GetDocument();
    //
	//make a local copy of the rectangle and shrink it
	//
    CRect rect;
	rect.CopyRect (pRect);
	rect.DeflateRect (1,1);
	//
	//Create a blue pen and use it to draw an O.
	//
	CPen pen (PS_SOLID, 4,RGB (0,255,0));
	CPen* pOldPen = pDC->SelectObject (&pen);
	pDC->SelectStockObject (NULL_BRUSH);
	pDC->Ellipse (rect);
	pDC->SelectObject (pOldPen);
 
    int count= pDoc->Getcount();
 
    if (count >=12){
    AfxMessageBox ("Move Piece");
    pDoc->OnNewDocument();
	
	}
 
}
ASKER CERTIFIED SOLUTION
alb66

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros