📄 dlgscore.cpp
字号:
// DlgScore.cpp : implementation file
//
#include "stdafx.h"
#include "JL.h"
#include "JLDoc.h"
#include "DlgScore.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CJLDoc * AfxGetDocument();
class CScore : public CObject
{
public:
int gameNumber;
int steps;
CTime tmStart, tmEnd;
enum { gameInit = 0, gamePassed, gameGiveUp, gameDead } gameStatus;
};
static const char * statusStr[4] = {"未玩","通过","放弃","挂了"};
static const char * fmts = "%H:%M:%S";
/////////////////////////////////////////////////////////////////////////////
// CDlgScore dialog
CDlgScore::CDlgScore(CWnd* pParent /*=NULL*/)
: CDialog(CDlgScore::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgScore)
//}}AFX_DATA_INIT
}
CDlgScore::~CDlgScore()
{
while(!m_score.IsEmpty()) {
CScore *pScore = (CScore*)m_score.RemoveHead();
delete pScore;
}
}
void CDlgScore::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgScore)
DDX_Control(pDX, IDLC_SCORE_INFO, m_lcScoreInfo);
DDX_Control(pDX, IDLC_SCORE, m_lcScore);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgScore, CDialog)
//{{AFX_MSG_MAP(CDlgScore)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgScore message handlers
BOOL CDlgScore::OnInitDialog()
{
CDialog::OnInitDialog();
//每局的信息
m_lcScore.SetBkColor(RGB(0,128,0));
m_lcScore.SetTextBkColor(RGB(0,128,0));
int charWid = m_lcScore.GetStringWidth("9");
m_lcScore.InsertColumn(0,"牌局",LVCFMT_LEFT,charWid * (5+2));
m_lcScore.InsertColumn(1,"步数",LVCFMT_LEFT,charWid * (4+2));
m_lcScore.InsertColumn(2,"状态",LVCFMT_LEFT,charWid * (4+2));
m_lcScore.InsertColumn(3,"耗时",LVCFMT_LEFT,charWid * (8+2));
m_lcScore.InsertColumn(4,"时间",LVCFMT_LEFT,charWid * (20+2));
int nTotal = 0;
int nPassed = 0;
int nGiveUp = 0;
int nDead = 0;
int nStepsPassed = 0;
CString s;
int i = 0;
for (POSITION pos = m_score.GetTailPosition(); pos != NULL; ++i )
{
//最后一局还没有解,所以状态不必显示
if(pos == m_score.GetHeadPosition()) break;
CScore *p = (CScore*)m_score.GetPrev(pos);
s.Format("%d",p->gameNumber);
m_lcScore.InsertItem(i,s);
s.Format("%d",p->steps);
m_lcScore.SetItemText(i,1,s);
m_lcScore.SetItemText(i,2,
statusStr[p->gameStatus]);
CTimeSpan ts = p->tmEnd - p->tmStart;
s.Format("%2dm%2ds",ts.GetMinutes(),ts.GetSeconds());
m_lcScore.SetItemText(i,3,s);
m_lcScore.SetItemText(i,4,
p->tmStart.Format(fmts) + "/" + p->tmEnd.Format(fmts));
++nTotal;
if(p->gameStatus == CScore::gamePassed) {
++nPassed;
nStepsPassed += p->steps;
}
else if(p->gameStatus == CScore::gameGiveUp) {
++nGiveUp;
}
else if(p->gameStatus == CScore::gameDead) {
++nDead;
}
}
//统计战况
m_lcScoreInfo.SetBkColor(RGB(0,128,0));
m_lcScoreInfo.SetTextBkColor(RGB(0,128,0));
m_lcScoreInfo.InsertColumn(0,"项目",LVCFMT_LEFT,charWid * 10);
m_lcScoreInfo.InsertColumn(1,"统计",LVCFMT_LEFT,charWid * 12);
m_lcScoreInfo.InsertItem(0,"总计(局)");
m_lcScoreInfo.InsertItem(1,"通过(局)");
m_lcScoreInfo.InsertItem(2,"胜率" );
m_lcScoreInfo.InsertItem(3,"玩通一局");
m_lcScoreInfo.InsertItem(4,"放弃(局)");
m_lcScoreInfo.InsertItem(5,"挂了(局)");
s.Format("%d",nTotal);
m_lcScoreInfo.SetItemText(0,1,s);
s.Format("%d",nPassed);
m_lcScoreInfo.SetItemText(1,1,s);
if(nTotal > 0){
s.Format("%3.1f%%",100.*nPassed/nTotal);
m_lcScoreInfo.SetItemText(2,1,s);
}
if(nPassed > 0){
s.Format("平均%3.1f步",float(nStepsPassed)/nPassed);
m_lcScoreInfo.SetItemText(3,1,s);
}
s.Format("%d",nGiveUp);
m_lcScoreInfo.SetItemText(4,1,s);
s.Format("%d",nDead);
m_lcScoreInfo.SetItemText(5,1,s);
return TRUE;
}
//更新战况
void CDlgScore::UpdateScore()
{
if(m_score.IsEmpty()) return;
CScore *p = (CScore*)m_score.GetHead();
p->tmEnd = CTime::GetCurrentTime();
//十五秒以内解开的局认为是使用了自动解答的帮助,将不予记录
if((p->tmEnd - p->tmStart).GetTotalSeconds() < 15) {
m_score.RemoveHead();
delete p;
return;
}
CJLDoc *pDoc = AfxGetDocument();
p->gameStatus =
pDoc->GameOver() ? CScore::gamePassed :
pDoc->m_Hints.IsEmpty() ? CScore::gameDead :
CScore::gameGiveUp;
p->steps = pDoc->m_pOps->GetCount();
}
void CDlgScore::InitScore()
{
CScore *p = new CScore;
ASSERT(p);
m_score.AddHead(p);
CJLDoc *pDoc = AfxGetDocument();
p->gameNumber = pDoc->m_nCurGameNumber;
p->tmStart = CTime::GetCurrentTime();
}
//看看此局是否曾经玩过
bool CDlgScore::IsOldGameNumber(int gameNum)
{
for(POSITION pos = m_score.GetHeadPosition(); pos != NULL; )
if(gameNum == ((CScore*)m_score.GetNext(pos))->gameNumber)
return true;
return false;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -