線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2221
推到 Plurk!
推到 Facebook!

賓果遊戲問題

尚未結案
Mosquito
一般會員


發表:4
回覆:5
積分:1
註冊:2005-01-04

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-01-05 02:18:05 IP:59.104.xxx.xxx 未訂閱
目前的問題出在  /*計算連線數*/ 按下第6次按鈕,還沒有第2條連線 但是Memo卻會顯示有2條連線成功 想不透哪裡邏輯出問題 以下是相關的程式碼:
int temp=0;
int times = 0 ;
int numbercheck = 0 ;
int count=0;    void TForm1::cleartime()
{
   times = 0;
}
void TForm1::score_count()
{
          if (times==5)
         {
           count  ;
           cleartime();
          switch (count)
          {
            case 1:
                 score->Lines->Clear();
                 score->Lines->Append("目 前 連 線 數 一");
                 break;
            case 2:
                 score->Lines->Clear();
                 score->Lines->Append("目 前 連 線 數 二");
                 break;
            case 3:
                 score->Lines->Clear();
                 score->Lines->Append("目 前 連 線 數 三");
                 break;
            case 4:
                 score->Lines->Clear();
                 score->Lines->Append("目 前 連 線 數 四");
                 break;
            case 5:
                 score->Lines->Clear();
                 score->Lines->Append("目 前 連 線 數 五");
                 temp=1;
                 break;
           }
       }
     else
        {
         cleartime();
        }
}
-----------------------------------------------------------------------
void __fastcall TForm1::startnumberClick(TObject *Sender)
{
   /*圈選標記*/
       for ( int i = 1; i <=25; i   )
       {
          TEdit *edit = dynamic_cast(FindComponent("Edit"   IntToStr(i)));
          if ( number->Text == edit->Text )
         {
            edit->Color = clRed;
            number->Text = "";
         }
       }
   /*計算連線數*/
    if(temp != 1 )
    {
       for ( int line1 = 1 ; line1<=5 ; line1   )
       {
          TEdit *edit = dynamic_cast(FindComponent("Edit"   IntToStr(line1)));
          if ( edit->Color == clRed )
          {
            times  ;
          }
        }
          score_count ();           for ( int line2 = 6 ; line2<=10 ; line2   )
       {
          TEdit *edit = dynamic_cast(FindComponent("Edit"   IntToStr(line2)));
          if ( edit->Color == clRed )
          {
            times  ;
          } 
       }
         score_count ();           for ( int line3 = 11 ; line3<=15 ; line3   )
       {
          TEdit *edit = dynamic_cast(FindComponent("Edit"   IntToStr(line3)));
          if ( edit->Color == clRed )
          {
            times  ;
          }    
       }
        score_count ();           for ( int line4 = 16 ; line4<=20 ; line4   )
       {
          TEdit *edit = dynamic_cast(FindComponent("Edit"   IntToStr(line4)));
          if ( edit->Color == clRed )
          {
            times  ;
          }
       }
   score_count ();       for ( int line5 = 21 ; line5<=25 ; line5   )
   {
      TEdit *edit = dynamic_cast(FindComponent("Edit"   IntToStr(line5)));
      if ( edit->Color == clRed )
      {
        times  ;
      }
   }
   score_count ();
}    }
程式大概模型 ★代表Edit ★★★★★ 1~5 ★★★★★ 6~10 ★★★★★ 11~15 ★★★★★ 16~20 ★★★★★ 21~25 發表人 - Mosquito 於 2005/01/05 02:23:56 發表人 - Mosquito 於 2005/01/05 02:26:02 發表人 - Mosquito 於 2005/01/06 00:12:27
fffhghgjh
一般會員


發表:2
回覆:33
積分:17
註冊:2004-12-23

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-01-05 13:47:27 IP:61.220.xxx.xxx 未訂閱
看了一下貼的程式 發現程式的邏輯上有問題 在score_count中 都先把count清為零 這樣最多只有一條會連線 應當把count放到外部變數 最後再一起判斷連線數  
int count=0;
void TForm1::score_count()
{
    if (times==5)
    {
        count  ;
    }
    cleartime();
}
//再多一個判斷連線數
void TForm1::checkmatchnumber()
{
          switch (count)
          {
            case 1:
                 score->Lines->Clear();
                 score->Lines->Append("目 前 連 線 數 一");
                 break;
            case 2:
                 score->Lines->Clear();
                 score->Lines->Append("目 前 連 線 數 二");
                 break;
            case 3:
                 score->Lines->Clear();
                 score->Lines->Append("目 前 連 線 數 三");
                 break;
            case 4:
                 score->Lines->Clear();
                 score->Lines->Append("目 前 連 線 數 四");
                 break;
            case 5:
                 score->Lines->Clear();
                 score->Lines->Append("目 前 連 線 數 五");
                 temp=1;
                 break;
           }
} 
 
試試看吧 發表人 - fffhghgjh 於 2005/01/05 13:50:00
Mosquito
一般會員


發表:4
回覆:5
積分:1
註冊:2005-01-04

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-01-06 00:13:48 IP:211.74.xxx.xxx 未訂閱
感謝 fffhghgjh 的回答,解決了一個小邏輯錯誤 但是還有另一個邏輯錯誤想不透
fffhghgjh
一般會員


發表:2
回覆:33
積分:17
註冊:2004-12-23

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-01-06 09:56:24 IP:61.220.xxx.xxx 未訂閱
在你每次判斷連線數按鈕之前 void __fastcall TForm1::startnumberClick(TObject *Sender) { count=0;//這要先設定為0 /*圈選標記*/ for ( int i = 1; i <=25; i ) ‧ ‧ ‧ } 這樣在每次按鈕判斷才回重新計算 不然count會累積
系統時間:2024-03-28 17:24:04
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!