看板 NKUTEE 關於我們 聯絡資訊
void CLittleMaryDlg::OnBnClickedStart() { Random(); Run(); UpdateData(0); first = 0; } void CLittleMaryDlg::LoadData(void) // 在程式執行時會載入的部份 { int nCount = 0; char* pszFileName = "data.txt"; CFileFind File; BOOL bExist = File.FindFile(pszFileName); if(bExist) // 檔案存在時讀取 { CFile dataFile(pszFileName, CFile::modeRead); CArchive ar(&dataFile, CArchive::load); for(int i=0; i<16; i++) { ar.ReadString(m_data[i]); } dataFile.Close(); } else // 預設資料 { m_data[0] = "資料1"; m_data[1] = "資料2"; m_data[2] = "資料3"; m_data[3] = "資料4"; m_data[4] = "資料5"; m_data[5] = "資料6"; m_data[6] = "資料7"; m_data[7] = "資料8"; m_data[8] = "資料9"; m_data[9] = "資料10"; m_data[10] = "資料11"; m_data[11] = "資料12"; m_data[12] = "資料13"; m_data[13] = "資料14"; m_data[14] = "資料15"; m_data[15] = "資料16"; } // 將 m_data 填滿 for(int i=0; i<16; i++) { if(m_data[i]!="") nCount++; } for(int nFill=0; nFill<16-nCount; nFill++) { m_data[nCount+nFill] = m_data[nFill]; } } void CLittleMaryDlg::Random(void) { srand(time(0)); nRand = rand() % 16; } void CLittleMaryDlg::Run(void) { int nPosition, nGoal; int nResult, nLoop; CString strPast; // 程式部份 if(first) { nRec = 0; strPast = m_data[0]; } srand(time(0)); nLoop = 1 + rand() % 3; nPosition = nRec; strPast = strRec; nGoal = nRand + (16*nLoop); for(nPosition; nPosition<=nGoal; nPosition++) { m_data[nRec] = strPast; nResult = nPosition % 16; nRec = nResult; strPast = m_data[nResult]; m_data[nResult] = "☆ " + m_data[nResult]; UpdateData(0); Sleep(100); } // 記錄上一個的值 nRec = nRand; strRec = strPast; } -- 就這樣,很簡單的程式... 只有短短的幾十行 應該很好懂!? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.240.12.124
michaleeeee:上次給你google找的那個參考有用嗎? 11/06 17:39
michaleeeee:你應該放個執行檔給大家玩 哈哈 要有bug版喔 中大獎 11/06 17:39
pandamilktea:哎喲,我懶得寫那麼多嘛 11/06 21:52