SAP 用ABAP写一个小游戏

2023-10-13 16:48:22 浏览数 (1)

直接上代码

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report  ZGAME_LLK
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zgame_llk.
INCLUDE <icon>.
TYPE-POOLS: slis.
TABLES: sscrfields.
CLASS lcl_event_handler DEFINITION DEFERRED.

DATA: lt_icon TYPE TABLE OF icon WITH HEADER LINE.
DATA: go_timer TYPE REF TO cl_gui_timer, "进度条计时器
       go_evt_hndl TYPE REF TO lcl_event_handler,
       twinkle_timer TYPE REF TO cl_gui_timer,   "闪烁计时器
       twinkle_evt_hndl TYPE REF TO lcl_event_handler.
DATA: l_left_time TYPE i VALUE 360, "剩余时间
      l_times TYPE i,                 "用来控制进度条的黑方框数目
      l_start_time TYPE i,            "开始时间
      l_end_time TYPE i,              "结束时间
      l_cost_time TYPE i.             "所用时间
TYPES: BEGIN OF score_line,
  user    LIKE sy-uname,
  time(5) TYPE c,
  hintcount(3) TYPE c,
  reformcount(3) TYPE c,
END OF score_line.
DATA: high_scores TYPE TABLE OF score_line WITH HEADER LINE,
      database_id LIKE indx-srtfd VALUE 'Z0324491X'. " export/import to database ID
*----------------------------------------------------------------------*
*       CLASS lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.
  PUBLIC SECTION.
    METHODS:
    handle_timer FOR EVENT finished OF cl_gui_timer,
    handle_twinkle FOR EVENT finished OF cl_gui_timer.
ENDCLASS. "lcl_event_handler DEFINITION
*&---------------------------------------------------------------------*
*&      CLASS lcl_event_handler IMPLEMENTATION
*&---------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
  METHOD handle_timer."进度条
    CALL METHOD cl_gui_cfw=>set_new_ok_code
      EXPORTING
        new_code = 'RFSH'.
    CALL METHOD go_timer->run "必须重新激活定时器
    EXCEPTIONS
      OTHERS = 9.
  ENDMETHOD.                 "handle_timer

  METHOD handle_twinkle."提示闪烁
    CALL METHOD cl_gui_cfw=>set_new_ok_code
      EXPORTING
        new_code = 'TWNK'.
    CALL METHOD twinkle_timer->run "必须重新激活定时器
    EXCEPTIONS
      OTHERS = 9.
  ENDMETHOD.                 "handle_timer
ENDCLASS. "lcl_event_handler IMPLEMENTATION

DEFINE displ_hsline.
  selection-screen: begin of line.
  selection-screen: comment  38(3) hs1_&1.
  selection-screen: comment 42(14) hs2_&1.
  selection-screen: comment  56(5) hs3_&1.
  selection-screen: comment  64(8) hs4_&1.
  selection-screen: comment  73(8) hs5_&1.
  selection-screen: end of line.
END-OF-DEFINITION.

SELECTION-SCREEN BEGIN OF SCREEN 1001.
*功能按钮
SELECTION-SCREEN PUSHBUTTON 40(6) bt_hint USER-COMMAND bt_hint.
SELECTION-SCREEN COMMENT 70(10) usedtime.
SELECTION-SCREEN PUSHBUTTON 50(6) bt_rfm USER-COMMAND bt_reform.
SELECTION-SCREEN PUSHBUTTON 60(6) bt_rec USER-COMMAND bt_record.
*SELECTION-SCREEN PUSHBUTTON 28(10) refresh USER-COMMAND bt_refresh.
*时间条
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 39(80) progress.
SELECTION-SCREEN END OF LINE.
*图片按钮
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN PUSHBUTTON 38(4) bto01 USER-COMMAND bto01 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 41(4) bto02 USER-COMMAND bto02 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 44(4) btc01 USER-COMMAND btc01 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 47(4) btc02 USER-COMMAND btc02 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 50(4) btc03 USER-COMMAND btc03 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 53(4) btc04 USER-COMMAND btc04 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 56(4) btc05 USER-COMMAND btc05 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 59(4) btc06 USER-COMMAND btc06 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 62(4) btc07 USER-COMMAND btc07 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 65(4) btc08 USER-COMMAND btc08 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 68(4) btc09 USER-COMMAND btc09 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 71(4) btc10 USER-COMMAND btc10 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 74(4) btc11 USER-COMMAND btc11 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 77(4) btc12 USER-COMMAND btc12 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 80(4) bto03 USER-COMMAND bto03 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 83(4) bto04 USER-COMMAND bto04 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON /38(4) bto05 USER-COMMAND bto05 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 83(4) bto06 USER-COMMAND bto06 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON /38(4) btr01 USER-COMMAND btr01 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 44(4) pb001 USER-COMMAND pb001 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 47(4) pb002 USER-COMMAND pb002 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 50(4) pb003 USER-COMMAND pb003 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 53(4) pb004 USER-COMMAND pb004 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 56(4) pb005 USER-COMMAND pb005 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 59(4) pb006 USER-COMMAND pb006 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 62(4) pb007 USER-COMMAND pb007 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 65(4) pb008 USER-COMMAND pb008 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 68(4) pb009 USER-COMMAND pb009 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 71(4) pb010 USER-COMMAND pb010 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 74(4) pb011 USER-COMMAND pb011 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 77(4) pb012 USER-COMMAND pb012 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 83(4) btr13 USER-COMMAND btr13 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON /38(4) btr02 USER-COMMAND btr02 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 44(4) pb013 USER-COMMAND pb013 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 47(4) pb014 USER-COMMAND pb014 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 50(4) pb015 USER-COMMAND pb015 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 53(4) pb016 USER-COMMAND pb016 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 56(4) pb017 USER-COMMAND pb017 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 59(4) pb018 USER-COMMAND pb018 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 62(4) pb019 USER-COMMAND pb019 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 65(4) pb020 USER-COMMAND pb020 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 68(4) pb021 USER-COMMAND pb021 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 71(4) pb022 USER-COMMAND pb022 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 74(4) pb023 USER-COMMAND pb023 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 77(4) pb024 USER-COMMAND pb024 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 83(4) btr14 USER-COMMAND btr14 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON /38(4) btr03 USER-COMMAND btr03 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 44(4) pb025 USER-COMMAND pb025 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 47(4) pb026 USER-COMMAND pb026 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 50(4) pb027 USER-COMMAND pb027 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 53(4) pb028 USER-COMMAND pb028 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 56(4) pb029 USER-COMMAND pb029 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 59(4) pb030 USER-COMMAND pb030 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 62(4) pb031 USER-COMMAND pb031 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 65(4) pb032 USER-COMMAND pb032 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 68(4) pb033 USER-COMMAND pb033 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 71(4) pb034 USER-COMMAND pb034 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 74(4) pb035 USER-COMMAND pb035 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 77(4) pb036 USER-COMMAND pb036 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 83(4) btr15 USER-COMMAND btr15 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON /38(4) btr04 USER-COMMAND btr04 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 44(4) pb037 USER-COMMAND pb037 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 47(4) pb038 USER-COMMAND pb038 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 50(4) pb039 USER-COMMAND pb039 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 53(4) pb040 USER-COMMAND pb040 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 56(4) pb041 USER-COMMAND pb041 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 59(4) pb042 USER-COMMAND pb042 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 62(4) pb043 USER-COMMAND pb043 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 65(4) pb044 USER-COMMAND pb044 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 68(4) pb045 USER-COMMAND pb045 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 71(4) pb046 USER-COMMAND pb046 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 74(4) pb047 USER-COMMAND pb047 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 77(4) pb048 USER-COMMAND pb048 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 83(4) btr16 USER-COMMAND btr16 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON /38(4) btr05 USER-COMMAND btr05 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 44(4) pb049 USER-COMMAND pb049 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 47(4) pb050 USER-COMMAND pb050 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 50(4) pb051 USER-COMMAND pb051 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 53(4) pb052 USER-COMMAND pb052 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 56(4) pb053 USER-COMMAND pb053 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 59(4) pb054 USER-COMMAND pb054 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 62(4) pb055 USER-COMMAND pb055 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 65(4) pb056 USER-COMMAND pb056 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 68(4) pb057 USER-COMMAND pb057 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 71(4) pb058 USER-COMMAND pb058 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 74(4) pb059 USER-COMMAND pb059 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 77(4) pb060 USER-COMMAND pb060 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 83(4) btr17 USER-COMMAND btr17 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON /38(4) btr06 USER-COMMAND btr06 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 44(4) pb061 USER-COMMAND pb061 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 47(4) pb062 USER-COMMAND pb062 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 50(4) pb063 USER-COMMAND pb063 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 53(4) pb064 USER-COMMAND pb064 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 56(4) pb065 USER-COMMAND pb065 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 59(4) pb066 USER-COMMAND pb066 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 62(4) pb067 USER-COMMAND pb067 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 65(4) pb068 USER-COMMAND pb068 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 68(4) pb069 USER-COMMAND pb069 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 71(4) pb070 USER-COMMAND pb070 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 74(4) pb071 USER-COMMAND pb071 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 77(4) pb072 USER-COMMAND pb072 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 83(4) btr18 USER-COMMAND btr18 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON /38(4) btr07 USER-COMMAND btr07 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 44(4) pb073 USER-COMMAND pb073 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 47(4) pb074 USER-COMMAND pb074 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 50(4) pb075 USER-COMMAND pb075 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 53(4) pb076 USER-COMMAND pb076 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 56(4) pb077 USER-COMMAND pb077 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 59(4) pb078 USER-COMMAND pb078 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 62(4) pb079 USER-COMMAND pb079 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 65(4) pb080 USER-COMMAND pb080 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 68(4) pb081 USER-COMMAND pb081 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 71(4) pb082 USER-COMMAND pb082 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 74(4) pb083 USER-COMMAND pb083 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 77(4) pb084 USER-COMMAND pb084 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 83(4) btr19 USER-COMMAND btr19 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON /38(4) btr08 USER-COMMAND btr08 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 44(4) pb085 USER-COMMAND pb085 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 47(4) pb086 USER-COMMAND pb086 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 50(4) pb087 USER-COMMAND pb087 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 53(4) pb088 USER-COMMAND pb088 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 56(4) pb089 USER-COMMAND pb089 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 59(4) pb090 USER-COMMAND pb090 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 62(4) pb091 USER-COMMAND pb091 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 65(4) pb092 USER-COMMAND pb092 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 68(4) pb093 USER-COMMAND pb093 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 71(4) pb094 USER-COMMAND pb094 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 74(4) pb095 USER-COMMAND pb095 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 77(4) pb096 USER-COMMAND pb096 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 83(4) btr20 USER-COMMAND btr20 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON /38(4) btr09 USER-COMMAND btr09 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 44(4) pb097 USER-COMMAND pb097 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 47(4) pb098 USER-COMMAND pb098 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 50(4) pb099 USER-COMMAND pb099 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 53(4) pb100 USER-COMMAND pb100 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 56(4) pb101 USER-COMMAND pb101 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 59(4) pb102 USER-COMMAND pb102 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 62(4) pb103 USER-COMMAND pb103 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 65(4) pb104 USER-COMMAND pb104 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 68(4) pb105 USER-COMMAND pb105 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 71(4) pb106 USER-COMMAND pb106 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 74(4) pb107 USER-COMMAND pb107 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 77(4) pb108 USER-COMMAND pb108 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 83(4) btr21 USER-COMMAND btr21 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON /38(4) btr10 USER-COMMAND btr10 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 44(4) pb109 USER-COMMAND pb109 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 47(4) pb110 USER-COMMAND pb110 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 50(4) pb111 USER-COMMAND pb111 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 53(4) pb112 USER-COMMAND pb112 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 56(4) pb113 USER-COMMAND pb113 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 59(4) pb114 USER-COMMAND pb114 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 62(4) pb115 USER-COMMAND pb115 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 65(4) pb116 USER-COMMAND pb116 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 68(4) pb117 USER-COMMAND pb117 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 71(4) pb118 USER-COMMAND pb118 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 74(4) pb119 USER-COMMAND pb119 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 77(4) pb120 USER-COMMAND pb120 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 83(4) btr22 USER-COMMAND btr22 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON /38(4) btr11 USER-COMMAND btr11 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 44(4) pb121 USER-COMMAND pb121 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 47(4) pb122 USER-COMMAND pb122 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 50(4) pb123 USER-COMMAND pb123 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 53(4) pb124 USER-COMMAND pb124 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 56(4) pb125 USER-COMMAND pb125 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 59(4) pb126 USER-COMMAND pb126 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 62(4) pb127 USER-COMMAND pb127 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 65(4) pb128 USER-COMMAND pb128 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 68(4) pb129 USER-COMMAND pb129 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 71(4) pb130 USER-COMMAND pb130 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 74(4) pb131 USER-COMMAND pb131 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 77(4) pb132 USER-COMMAND pb132 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 83(4) btr23 USER-COMMAND btr23 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON /38(4) btr12 USER-COMMAND btr12 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 44(4) pb133 USER-COMMAND pb133 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 47(4) pb134 USER-COMMAND pb134 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 50(4) pb135 USER-COMMAND pb135 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 53(4) pb136 USER-COMMAND pb136 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 56(4) pb137 USER-COMMAND pb137 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 59(4) pb138 USER-COMMAND pb138 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 62(4) pb139 USER-COMMAND pb139 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 65(4) pb140 USER-COMMAND pb140 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 68(4) pb141 USER-COMMAND pb141 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 71(4) pb142 USER-COMMAND pb142 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 74(4) pb143 USER-COMMAND pb143 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 77(4) pb144 USER-COMMAND pb144 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 83(4) btr24 USER-COMMAND btr24 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON /38(4) bto07 USER-COMMAND bto07 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 83(4) bto08 USER-COMMAND bto08 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON /38(4) bto09 USER-COMMAND bto09 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 41(4) bto10 USER-COMMAND bto10 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 44(4) btc13 USER-COMMAND btc13 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 47(4) btc14 USER-COMMAND btc14 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 50(4) btc15 USER-COMMAND btc15 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 53(4) btc16 USER-COMMAND btc16 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 56(4) btc17 USER-COMMAND btc17 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 59(4) btc18 USER-COMMAND btc18 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 62(4) btc19 USER-COMMAND btc19 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 65(4) btc20 USER-COMMAND btc20 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 68(4) btc21 USER-COMMAND btc21 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 71(4) btc22 USER-COMMAND btc22 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 74(4) btc23 USER-COMMAND btc23 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 77(4) btc24 USER-COMMAND btc24 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 80(4) bto11 USER-COMMAND bto11 VISIBLE LENGTH 2.
SELECTION-SCREEN PUSHBUTTON 83(4) bto12 USER-COMMAND bto12 VISIBLE LENGTH 2.
SELECTION-SCREEN COMMENT /38(80) c_topic.
SELECTION-SCREEN ULINE /38(48) .
displ_hsline 0.
SELECTION-SCREEN ULINE /38(48) .
displ_hsline 1.
displ_hsline 2.
displ_hsline 3.
displ_hsline 4.
displ_hsline 5.
displ_hsline 6.
displ_hsline 7.
displ_hsline 8.
displ_hsline 9.
displ_hsline 10.
displ_hsline 11.
displ_hsline 12.
displ_hsline 13.
displ_hsline 14.
displ_hsline 15.
displ_hsline 16.
displ_hsline 17.
displ_hsline 18.
displ_hsline 19.
displ_hsline 20.
displ_hsline 21.
displ_hsline 22.
displ_hsline 23.
displ_hsline 24.
displ_hsline 25.
displ_hsline 26.
displ_hsline 27.
displ_hsline 28.
displ_hsline 29.
displ_hsline 30.
displ_hsline 31.
displ_hsline 32.
displ_hsline 33.
displ_hsline 34.
displ_hsline 35.
displ_hsline 36.
displ_hsline 37.
displ_hsline 38.
displ_hsline 39.
displ_hsline 40.
displ_hsline 41.
displ_hsline 42.
displ_hsline 43.
displ_hsline 44.
displ_hsline 45.
displ_hsline 46.
displ_hsline 47.
displ_hsline 48.
displ_hsline 49.
displ_hsline 50.
displ_hsline 51.
displ_hsline 52.
displ_hsline 53.
displ_hsline 54.
displ_hsline 55.
displ_hsline 56.
displ_hsline 57.
displ_hsline 58.
displ_hsline 59.
displ_hsline 60.
displ_hsline 61.
displ_hsline 62.
displ_hsline 63.
displ_hsline 64.
displ_hsline 65.
displ_hsline 66.
displ_hsline 67.
displ_hsline 68.
displ_hsline 69.
displ_hsline 70.
displ_hsline 71.
displ_hsline 72.
displ_hsline 73.
displ_hsline 74.
displ_hsline 75.
displ_hsline 76.
displ_hsline 77.
displ_hsline 78.
displ_hsline 79.
displ_hsline 80.
displ_hsline 81.
displ_hsline 82.
displ_hsline 83.
displ_hsline 84.
displ_hsline 85.
displ_hsline 86.
displ_hsline 87.
displ_hsline 88.
displ_hsline 89.
displ_hsline 90.
displ_hsline 91.
displ_hsline 92.
displ_hsline 93.
displ_hsline 94.
displ_hsline 95.
displ_hsline 96.
displ_hsline 97.
displ_hsline 98.
displ_hsline 99.
displ_hsline 100.
displ_hsline 101.
displ_hsline 102.
displ_hsline 103.
displ_hsline 104.
displ_hsline 105.
displ_hsline 106.
displ_hsline 107.
displ_hsline 108.
displ_hsline 109.
displ_hsline 110.
displ_hsline 111.
displ_hsline 112.
displ_hsline 113.
displ_hsline 114.
displ_hsline 115.
displ_hsline 116.
displ_hsline 117.
displ_hsline 118.
displ_hsline 119.
displ_hsline 120.
displ_hsline 121.
displ_hsline 122.
displ_hsline 123.
displ_hsline 124.
displ_hsline 125.
displ_hsline 126.
displ_hsline 127.
displ_hsline 128.
displ_hsline 129.
displ_hsline 130.
displ_hsline 131.
displ_hsline 132.
displ_hsline 133.
displ_hsline 134.
displ_hsline 135.
displ_hsline 136.
displ_hsline 137.
displ_hsline 138.
displ_hsline 139.
displ_hsline 140.
displ_hsline 141.
displ_hsline 142.
displ_hsline 143.
displ_hsline 144.
displ_hsline 145.
displ_hsline 146.
displ_hsline 147.
displ_hsline 148.
displ_hsline 149.
displ_hsline 150.
displ_hsline 151.
displ_hsline 152.
displ_hsline 153.
displ_hsline 154.
displ_hsline 155.
displ_hsline 156.
displ_hsline 157.
displ_hsline 158.
displ_hsline 159.
displ_hsline 160.
displ_hsline 161.
displ_hsline 162.
displ_hsline 163.
displ_hsline 164.
displ_hsline 165.
displ_hsline 166.
displ_hsline 167.
displ_hsline 168.
displ_hsline 169.
displ_hsline 170.
displ_hsline 171.
displ_hsline 172.
displ_hsline 173.
displ_hsline 174.
displ_hsline 175.
displ_hsline 176.
displ_hsline 177.
SELECTION-SCREEN END OF SCREEN 1001.

START-OF-SELECTION.
  CALL SCREEN 1001.

  DATA: l_chars(26) TYPE c VALUE 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.

  DATA: BEGIN OF lt_game OCCURS 0,                            "游戏区域
     value(14) TYPE c,
   END OF lt_game.

  DATA: BEGIN OF lt_number OCCURS 0,                        "1~144
     number TYPE i,
   END OF lt_number.

  DATA: BEGIN OF lt_area OCCURS 0,
     chr(1) TYPE c,
     row TYPE i,
     col TYPE i,
     top TYPE i,
     left TYPE i,
     bottom TYPE i,
     right TYPE i,
   END OF lt_area.

  DATA: BEGIN OF lt_pic OCCURS 0,
     id(4) TYPE c,
   END OF lt_pic.

  DATA: lt_last_area LIKE lt_area OCCURS 0,
         lt_cur_area LIKE lt_area OCCURS 0.

  DATA: randnum TYPE i,     "随机数
        randchr(1) TYPE c,  "随即字母
        linecount TYPE i.   "lt_number的行数

  DATA: last_pb(5) TYPE c,
        cur_pb(5) TYPE c,
        connected(1) TYPE c,
        left_pbs TYPE i VALUE 144,            "剩余个数
        l_pb_chr(1) TYPE c,                   "按钮对应的字母
        l_hint_count(3) TYPE c,               "提示次数
        l_reform_count(3) TYPE c,             "重排次数
        l_dead(1) TYPE c,                     "是否还可以消除
        l_gameover(1) TYPE c.                 "时间耗尽、游戏结束

  DATA: l_hint_pb1(5) TYPE c,                               "提示按钮1
        l_hint_pb2(5) TYPE c,                               "提示按钮2
        l_hint_icon1(4) TYPE c,
        l_hint_icon2(4) TYPE c.

INITIALIZATION.

  bt_hint = '提示'.
  bt_rfm = '重排'.
  bt_rec = '排行榜'.
*  refresh = '刷新图片'.
  btc01 = btc13 = btr01 = btr13 = '1'.
  btc02 = btc14 = btr02 = btr14 = '2'.
  btc03 = btc15 = btr03 = btr15 = '3'.
  btc04 = btc16 = btr04 = btr16 = '4'.
  btc05 = btc17 = btr05 = btr17 = '5'.
  btc06 = btc18 = btr06 = btr18 = '6'.
  btc07 = btc19 = btr07 = btr19 = '7'.
  btc08 = btc20 = btr08 = btr20 = '8'.
  btc09 = btc21 = btr09 = btr21 = '9'.
  btc10 = btc22 = btr10 = btr22 = '10'.
  btc11 = btc23 = btr11 = btr23 = '11'.
  btc12 = btc24 = btr12 = btr24 = '12'.

  c_topic = '================:: HIGH SCORES ::================'.
  hs2_0  = '用户名'.
  hs3_0  = '时间'.
  hs4_0  = '提示次数'.
  hs5_0  = '重排次数'.

  PERFORM high_scores_read.

  PERFORM high_scores_show.

  DO 30 TIMES.
    CONCATENATE progress '█' INTO progress.
  ENDDO.

*  初始化时间
  PERFORM init_timer_progress.

*1.初始化lt_game、lt_number、lt_pic.
  DO 144 TIMES. "为lt_number赋值:1~144
    lt_number-number = sy-index.
    APPEND lt_number.
  ENDDO.

  l_hint_count = '0'.
  l_reform_count = '0'.
  l_gameover = ''.

  DO 14 TIMES.  "初始化lt_game为14个#
    lt_game-value = '##############'.
    APPEND lt_game.
  ENDDO.

  DATA: l_icon_count TYPE i,
        l_get_icon TYPE c.
  SELECT * INTO TABLE lt_icon FROM icon.
  DELETE lt_icon WHERE
    id = icon_green_light OR
    id = icon_yellow_light OR
    id = icon_red_light OR
    id = icon_message_information OR
    id = icon_message_warning OR
    id = icon_message_error OR
    id = icon_message_question OR
    id = icon_message_critical OR
    id = icon_space OR
    id = icon_include_in_selection OR
    id = icon_light_out OR
    id = icon_remove_from_selection OR
    id = icon_wf_workitem_ol OR
    id = icon_new_handling_unit OR
    id = icon_new_handling_if_full OR
    id = icon_set_sum_undo OR
    id = icon_sort_undo OR
    id = icon_bw_process OR
    id = icon_bw_simulate OR
    id = icon_bw_process_cancel OR
    id = icon_bw_simulate_cancel OR
    id = icon_org_unit OR
    id = icon_incomplete OR
    id = icon_aew_project
.

  l_icon_count = LINES( lt_icon[] ).
  REFRESH: lt_pic.
  DO 26 TIMES.
    CLEAR: l_get_icon.
    WHILE l_get_icon = ''.
      CALL FUNCTION 'QF05_RANDOM_INTEGER'
        EXPORTING
          ran_int_max   = l_icon_count
          ran_int_min   = 1
        IMPORTING
          ran_int       = randnum
        EXCEPTIONS
          invalid_input = 1
          OTHERS        = 2.
      READ TABLE lt_icon INDEX randnum.
      READ TABLE lt_pic WITH KEY id = lt_icon-id.
      IF sy-subrc <> 0.
        l_get_icon = 'X'.
        lt_pic-id = lt_icon-id.
        APPEND lt_pic.
      ENDIF.
    ENDWHILE.
  ENDDO.

*2.生成随机数
  DO 72 TIMES. "执行72次,每次生成一个字母,并在lt_number中取出两个随机数字,确定其在lt_game中的位置,放入。
    CALL FUNCTION 'QF05_RANDOM_INTEGER'
      EXPORTING
        ran_int_max   = 26
        ran_int_min   = 1
      IMPORTING
        ran_int       = randnum
      EXCEPTIONS
        invalid_input = 1
        OTHERS        = 2.
    randnum = randnum - 1.
    randchr = l_chars randnum(1).
    DO 2 TIMES.
      DESCRIBE TABLE lt_number LINES linecount.
      CALL FUNCTION 'QF05_RANDOM_INTEGER'
        EXPORTING
          ran_int_max   = linecount
          ran_int_min   = 1
        IMPORTING
          ran_int       = randnum
        EXCEPTIONS
          invalid_input = 1
          OTHERS        = 2.
      PERFORM update_internaltable_and_icon USING randchr.
    ENDDO.
  ENDDO.

*3.检查是否有可以连接的
  PERFORM check_dead.

*4.设置开始时间
  GET RUN TIME FIELD l_start_time.

AT SELECTION-SCREEN.

*时间递减
  IF sy-ucomm = 'RFSH' AND l_left_time > 0.
    l_left_time = l_left_time - 12.
    IF l_left_time = 0.
      CALL METHOD go_timer->free.  "删除定时器
      l_gameover = 'X'.
      MESSAGE '时间已经耗尽,你失败了!' TYPE 'E'.
    ENDIF.
  ENDIF.

  GET RUN TIME FIELD l_end_time.
  l_cost_time = ( l_end_time - l_start_time ) / 1000000.
  usedtime = l_cost_time.
  CONDENSE usedtime NO-GAPS.
  CONCATENATE '已用时' usedtime '秒' INTO usedtime. "更新comment

  IF sy-ucomm = 'TWNK'.
    PERFORM pb_twinkle.
    CALL METHOD twinkle_timer->free.
    FREE twinkle_timer.
  ENDIF.

*更新时间条
  CLEAR progress.
  l_times = l_left_time / 12.
  DO l_times TIMES.
    CONCATENATE progress '█' INTO progress.
  ENDDO.
  l_times = 30 - l_times.
  DO l_times TIMES.
    CONCATENATE progress '口' INTO progress.
  ENDDO.

  CHECK l_gameover = ''.

  IF sscrfields-ucomm = 'BT_HINT'.
    PERFORM get_hint USING 'X'.
  ELSEIF sscrfields-ucomm = 'BT_REFORM'.
    PERFORM reform USING ''.
*  ELSEIF sscrfields-ucomm = 'BT_REFRESH'.
*    PERFORM update_pb_visible.
  ELSEIF sscrfields-ucomm = 'BT_RECORD'.
    PERFORM alv_show_record.
  ENDIF.
  CHECK sscrfields-ucomm CS 'PB'.

*图片按钮事件处理
  IF last_pb IS NOT INITIAL.
    CHECK sscrfields-ucomm NE last_pb.
    cur_pb = sscrfields-ucomm.
    PERFORM get_area TABLES lt_last_area USING last_pb '' ''.
    PERFORM get_area TABLES lt_cur_area USING cur_pb '' ''.
    PERFORM check_connect TABLES lt_last_area lt_cur_area CHANGING connected.
    IF connected EQ 'X'.
      PERFORM clear_pb USING last_pb.
      PERFORM clear_pb USING cur_pb.
      last_pb = ''.
      cur_pb = ''.
    ELSE.
      last_pb = cur_pb.
    ENDIF.
    REFRESH: lt_last_area, lt_cur_area.
  ELSE.
    last_pb = sscrfields-ucomm.
  ENDIF.

AT SELECTION-SCREEN OUTPUT.
  PERFORM update_pb_visible.

*&---------------------------------------------------------------------*
*&      Form  SET_CHAR
*&---------------------------------------------------------------------*
*       在lt_game中设置相应字母,
*       并在lt_number中删除对应行,并更新按钮图片
*----------------------------------------------------------------------*
*      -->P_LT_GAME  text
*      -->P_LT_NUMBER  text
*      -->P_RANDNUM1  text
*----------------------------------------------------------------------*
FORM update_internaltable_and_icon USING p_chr.
  DATA: row TYPE p,
        col TYPE p,
        left TYPE p,
        right TYPE p,
        pbname(5) TYPE c,
        pbnum(3) TYPE c,
        chr_index TYPE i.
  FIELD-SYMBOLS <pbname> TYPE ANY.

  READ TABLE lt_number INDEX randnum.

*修改lt_game
  row = FLOOR( ( lt_number-number - 1 ) / 12 )   2.
  col = ( lt_number-number - 1 )  MOD 12   2.
  left = col - 1.
  right = 14 - col.

  READ TABLE lt_game INDEX row.
  CONCATENATE lt_game-value 0(left) p_chr lt_game-value col(right) INTO lt_game-value.
  MODIFY lt_game INDEX row.

*在lt_number中删除对应行
  DELETE lt_number INDEX randnum.

*更新图片
  pbnum = lt_number-number.
  PERFORM get_pb_name USING pbnum CHANGING pbname.
  ASSIGN (pbname) TO <pbname>.

  FIND p_chr IN SECTION OFFSET 0 OF l_chars
     MATCH OFFSET chr_index.
  chr_index = chr_index   1.
  READ TABLE lt_pic INDEX chr_index.
  IF <pbname> IS ASSIGNED.
    <pbname> = lt_pic-id.
  ENDIF.
ENDFORM. " SET_CHAR
*&---------------------------------------------------------------------*
*&      Form  GET_AREA
*&---------------------------------------------------------------------*
*       根据button或p_row、p_col获取其area
*----------------------------------------------------------------------*
*      -->AREA       text
*      -->PB_UCOMM   text
*----------------------------------------------------------------------*
FORM get_area TABLES area STRUCTURE lt_area USING pb_ucomm p_row p_col.
  DATA: num TYPE p,
        row TYPE p,
        col TYPE p,
        tmprow TYPE p,
        tmpcol TYPE p,
        chr(1) TYPE c.

  IF pb_ucomm NE ''.
    num = pb_ucomm 2(3).
    row = FLOOR( ( num - 1 ) / 12 )   2.
    col = ( num - 1 )  MOD 12   2.
  ELSE.
    row = p_row.
    col = p_col.
  ENDIF.

  READ TABLE lt_game INDEX row.
  tmpcol = col - 1.
  area-chr = lt_game-value tmpcol(1).

  area-row = row.
  area-col = col.

*取Top
  tmprow = row - 1.
  tmpcol = col - 1.
  READ TABLE lt_game INDEX tmprow.
  chr = lt_game-value tmpcol(1).
  WHILE chr EQ '#'.
    IF tmprow = 0.
      EXIT.
    ENDIF.
    tmprow = tmprow - 1.
    READ TABLE lt_game INDEX tmprow.
    chr = lt_game-value tmpcol(1).
  ENDWHILE.
  area-top = tmprow   1.

*取Left
  tmprow = row.
  tmpcol = col - 2.
  READ TABLE lt_game INDEX tmprow.
  chr = lt_game-value tmpcol(1).
  WHILE chr EQ '#'.
    IF tmpcol = 0.
      EXIT.
    ENDIF.
    tmpcol = tmpcol - 1.
    chr = lt_game-value tmpcol(1).
  ENDWHILE.
  IF tmpcol = 0.
    area-left = 1.
  ELSE.
    area-left = tmpcol   2.
  ENDIF.

*取Bottom
  tmprow = row   1.
  tmpcol = col - 1.
  READ TABLE lt_game INDEX tmprow.
  chr = lt_game-value tmpcol(1).
  WHILE chr EQ '#'.
    IF tmprow = 15.
      EXIT.
    ENDIF.
    tmprow = tmprow   1.
    READ TABLE lt_game INDEX tmprow.
    chr = lt_game-value tmpcol(1).
  ENDWHILE.
  area-bottom = tmprow - 1.

*取Right
  tmprow = row.
  tmpcol = col.
  READ TABLE lt_game INDEX tmprow.
  chr = lt_game-value tmpcol(1).
  WHILE chr EQ '#'.
    IF tmpcol = 13.
      EXIT.
    ENDIF.
    tmpcol = tmpcol   1.
    chr = lt_game-value tmpcol(1).
  ENDWHILE.
  IF tmpcol = 13.
    area-right = 14.
  ELSE.
    area-right = tmpcol.
  ENDIF.

  APPEND area.
ENDFORM. "GET_AREA
*&---------------------------------------------------------------------*
*&      Form  check_connected
*&---------------------------------------------------------------------*
*       查看是否可以连接
*----------------------------------------------------------------------*
*      -->LASTPB     text
*      -->CURPB      text
*----------------------------------------------------------------------*
FORM check_connect TABLES lt_area1 STRUCTURE lt_area
                            lt_area2 STRUCTURE lt_area
                   CHANGING connect.
  DATA: tmpnum TYPE i.

  READ TABLE lt_area1 INDEX 1.
  READ TABLE lt_area2 INDEX 1.

  IF lt_area1-chr EQ '#' OR lt_area2-chr EQ '#'.
    connect = ''.
    EXIT.
  ENDIF.

  IF lt_area1-chr NE lt_area2-chr.
    connect = ''.
    EXIT.
  ENDIF.

*相邻情况下的判断
  tmpnum = ABS( lt_area1-row - lt_area2-row )   ABS( lt_area1-col - lt_area2-col ).
  IF tmpnum = 1.
    connect = 'X'.
    EXIT.
  ENDIF.

  DATA: j TYPE i,
         k TYPE i,
         l TYPE i,
         m TYPE i,
         n TYPE i,
         flag_failed(1) TYPE c,
         tmpchr(1) TYPE c.



*不相邻的时候,判断方式一
  j = lt_area1-top.
  WHILE j <= lt_area1-bottom.
    k = lt_area2-top.
    WHILE k <= lt_area2-bottom.
      IF j EQ k.
        READ TABLE lt_game INDEX j.
        IF lt_area1-col < lt_area2-col.
          l = lt_area1-col   1.
          m = lt_area2-col - 1.
          flag_failed = ''.
          WHILE l <= m.
            n = l - 1.
            tmpchr = lt_game-value n(1).
            IF tmpchr NE '#'.
              flag_failed = 'X'.
              EXIT.
            ENDIF.
            l = l   1.
          ENDWHILE.
          IF flag_failed = ''.
            connect = 'X'.
            RETURN.
          ENDIF.
        ELSE.
          l = lt_area2-col   1.
          m = lt_area1-col - 1.
          flag_failed = ''.
          WHILE l <= m.
            n = l - 1.
            tmpchr = lt_game-value n(1).
            IF tmpchr NE '#'.
              flag_failed = 'X'.
              EXIT.
            ENDIF.
            l = l   1.
          ENDWHILE.
          IF flag_failed = ''.
            connect = 'X'.
            RETURN.
          ENDIF.
        ENDIF.
      ENDIF.
      k = k   1.
    ENDWHILE.
    j = j   1.
  ENDWHILE.


*不相邻的时候,判断方式二
  j = lt_area1-left.
  WHILE j <= lt_area1-right.
    k = lt_area2-left.
    WHILE k <= lt_area2-right.
      IF j EQ k.
        IF lt_area1-row < lt_area2-row.
          l = lt_area1-row   1.
          m = lt_area2-row - 1.
          flag_failed = ''.
          WHILE l <= m.
            n = j - 1.
            READ TABLE lt_game INDEX l.
            tmpchr = lt_game-value n(1).
            IF tmpchr NE '#'.
              flag_failed = 'X'.
              EXIT.
            ENDIF.
            l = l   1.
          ENDWHILE.
          IF flag_failed = ''.
            connect = 'X'.
            RETURN.
          ENDIF.
        ELSE.
          l = lt_area2-row   1.
          m = lt_area1-row - 1.
          flag_failed = ''.
          WHILE l <= m.
            n = j - 1.
            READ TABLE lt_game INDEX l.
            tmpchr = lt_game-value n(1).
            IF tmpchr NE '#'.
              flag_failed = 'X'.
              EXIT.
            ENDIF.
            l = l   1.
          ENDWHILE.
          IF flag_failed = ''.
            connect = 'X'.
            RETURN.
          ENDIF.
        ENDIF.
      ENDIF.
      k = k   1.
    ENDWHILE.
    j = j   1.
  ENDWHILE.
  connect = ''.
ENDFORM. "check_connected
*&---------------------------------------------------------------------*
*&      Form  CLEAR_PIC
*&---------------------------------------------------------------------*
*       隐藏按钮,并更新lt_game
*----------------------------------------------------------------------*
*      -->P_LAST_PB  text
*----------------------------------------------------------------------*
FORM clear_pb USING pbname.
  FIELD-SYMBOLS <pbname> TYPE ANY.
  ASSIGN (pbname) TO <pbname>.
  <pbname> = icon_space.

  DATA: row TYPE p,
         col TYPE p,
         left TYPE p,
         right TYPE p,
         modnum TYPE p,
         costtime(4) TYPE c,
         msg(40) TYPE c.

  row = FLOOR( ( pbname 2(3) - 1 ) / 12 )   2.
  col = ( pbname 2(3) - 1 )  MOD 12   2.
  left = col - 1.
  right = 14 - col.

  READ TABLE lt_game INDEX row.
  CONCATENATE lt_game-value 0(left) '#' lt_game-value col(right) INTO lt_game-value.
  MODIFY lt_game INDEX row.

  left_pbs = left_pbs - 1.
  IF left_pbs = 0.
    msg = ''.
    GET RUN TIME FIELD l_end_time.
    l_cost_time = ( l_end_time - l_start_time ) / 1000000   l_reform_count * 20   l_hint_count * 5.
    costtime = l_cost_time.
    CONCATENATE '恭喜你!用时为:' costtime '秒!' INTO msg.
    CONDENSE msg NO-GAPS.
    MESSAGE msg TYPE 'S'.
    PERFORM high_scores_read.
    PERFORM high_scores_update.
    PERFORM high_scores_show.
    EXIT.
  ENDIF.

  modnum = left_pbs MOD 2.
  IF modnum = 0.
    PERFORM check_dead.
  ENDIF.

ENDFORM. " CLEAR_PIC
*&---------------------------------------------------------------------*
*&      Form  get_pb_chr
*&---------------------------------------------------------------------*
*       根据pbname获取其代表的字母
*----------------------------------------------------------------------*
*      -->PBNAME     text
*----------------------------------------------------------------------*
FORM get_pb_chr USING pbname.
  DATA: num TYPE p,
        row TYPE p,
        col TYPE p,
        tmpcol TYPE p.

  num = pbname 2(3).
  row = FLOOR( ( num - 1 ) / 12 )   2.
  col = ( num - 1 )  MOD 12   2.

  READ TABLE lt_game INDEX row.
  tmpcol = col - 1.
  l_pb_chr = lt_game-value tmpcol(1).
ENDFORM. "get_pb_chr


*&---------------------------------------------------------------------*
*&      Form  get_chr
*&---------------------------------------------------------------------*
*       根据p_row、p_col获取相应位置的字母
*----------------------------------------------------------------------*
*      -->P_ROW      text
*      -->P_COL      text
*----------------------------------------------------------------------*
FORM get_chr USING p_row p_col CHANGING p_chr.
  DATA: row TYPE p,
        col TYPE p.
  row = p_row.
  col = p_col - 1.
  READ TABLE lt_game INDEX row.
  p_chr = lt_game-value col(1).
ENDFORM. "get_chr
*&---------------------------------------------------------------------*
*&      Form  GET_HINT
*&---------------------------------------------------------------------*
*       获取提示。
*       若成功,则hintcount每次加一。
*       如果没有可供消除的,更新l_dead为'X'。
*----------------------------------------------------------------------*
*      -->HINTCOUNT  text
*      -->RESULT     text
*----------------------------------------------------------------------*
FORM get_hint USING flag_show_msg. "
  DATA: row1 TYPE p VALUE 2,
        col1 TYPE p VALUE 2,
        row2 TYPE p,
        col2 TYPE p,
        crow1(2) TYPE c,
        ccol1(2) TYPE c,
        crow2(2) TYPE c,
        ccol2(2) TYPE c,
        area1 LIKE lt_area OCCURS 0,
        area2 LIKE lt_area OCCURS 0,
        can_connect(1) TYPE c,
        msg(40) TYPE c,
        chr1(1) TYPE c,
        chr2(1) TYPE c.

  WHILE row1 <= 13.
    WHILE col1 <= 13.
      PERFORM get_chr USING row1 col1 CHANGING chr1.
      IF chr1 NE '#'.
        IF col1 = 13 .
          IF row1 = 13.
            l_dead = 'X'.
            RETURN.
          ELSE.
            row2 = row1   1.
            col2 = 2.
          ENDIF.
        ELSE.
          row2 = row1.
          col2 = col1   1.
        ENDIF.
        WHILE row2 <= 13.
          WHILE col2 <= 13.
            PERFORM get_chr USING row2 col2 CHANGING chr2.
            IF chr2 EQ chr1.
              REFRESH: area1, area2.
              PERFORM get_area TABLES area1 USING '' row1 col1.
              PERFORM get_area TABLES area2 USING '' row2 col2.
              PERFORM check_connect TABLES area1 area2 CHANGING can_connect.
              IF can_connect = 'X'.
                IF flag_show_msg EQ 'X'.
                  crow1 = row1 - 1.
                  ccol1 = col1 - 1.
                  crow2 = row2 - 1.
                  ccol2 = col2 - 1.
                  l_hint_count = l_hint_count   1.
                  CONCATENATE '第' l_hint_count '次提示:第' crow1 '行第'
                    ccol1 '列----第' crow2 '行第' ccol2 '列' ',耗时增加5秒!' INTO msg.
                  CONDENSE msg NO-GAPS.
                  MESSAGE msg TYPE 'S'.
                  "闪烁
                  DATA: pbnum(3) TYPE c.
                  l_hint_pb1 = l_hint_pb1 = ''.
                  pbnum = ( crow1 - 1 ) * 12   ccol1.
                  PERFORM get_pb_name USING pbnum CHANGING l_hint_pb1.
                  pbnum = ( crow2 - 1 ) * 12   ccol2.
                  PERFORM get_pb_name USING pbnum CHANGING l_hint_pb2.
                  IF l_hint_icon1 EQ ''.
                    PERFORM pb_twinkle.
                    PERFORM init_timer_twinkle.
                  ENDIF.
                ENDIF.
                l_dead = ''.
                RETURN.
              ENDIF.
            ENDIF.
            col2 = col2   1.
          ENDWHILE.
          row2 = row2   1.
          col2 = 2.
        ENDWHILE.
      ENDIF.
      col1 = col1   1.
    ENDWHILE.
    row1 = row1   1.
    col1 = 2.
  ENDWHILE.
  l_dead = 'X'.
ENDFORM. "GET_HINT


*&---------------------------------------------------------------------*
*&      Form  reform
*&---------------------------------------------------------------------*
*       重排
*----------------------------------------------------------------------*
FORM reform USING p_flag. "系统自动重拍时,不累计重排次数
  DATA: BEGIN OF ft_chars OCCURS 0,
    chr(1) TYPE c,
  END OF ft_chars.
  DATA: f_counts TYPE i,
        j TYPE i VALUE 2,
        k TYPE i VALUE 1,
        msg(40) TYPE c.

*所有剩余的字母放入fm_chars.
  WHILE j <= 13.
    READ TABLE lt_game INDEX j.
    WHILE k <= 12.
      IF lt_game-value k(1) NE '#'.
        ft_chars-chr = lt_game-value k(1).
        APPEND ft_chars.
      ENDIF.
      k = k   1.
    ENDWHILE.
    j = j   1.
    k = 1.
  ENDWHILE.

*初始化lt_game以及lt_number.
  REFRESH: lt_game, lt_number.
  DO 14 TIMES.  "初始化lt_game为14个#
    lt_game-value = '##############'.
    APPEND lt_game.
  ENDDO.
  DO 144 TIMES. "为lt_number赋值:1~144
    lt_number-number = sy-index.
    APPEND lt_number.
  ENDDO.

*随机将数据放入lt_game
  LOOP AT ft_chars.
    DESCRIBE TABLE lt_number LINES linecount.
    CALL FUNCTION 'QF05_RANDOM_INTEGER'
      EXPORTING
        ran_int_max   = linecount
        ran_int_min   = 1
      IMPORTING
        ran_int       = randnum
      EXCEPTIONS
        invalid_input = 1
        OTHERS        = 2.
    PERFORM update_internaltable_and_icon USING ft_chars-chr.
  ENDLOOP.

  PERFORM update_pb_visible.

  IF p_flag = ''.
    l_reform_count = l_reform_count   1.
    msg = l_reform_count.
    CONCATENATE '第' msg '次重排,耗时增加20秒!' INTO msg.
    CONDENSE msg NO-GAPS.
    MESSAGE msg TYPE 'S'.
  ENDIF.
ENDFORM. "reform
*&---------------------------------------------------------------------*
*&      Form  check_dead
*&---------------------------------------------------------------------*
*       检查是否还有可以消除的,如果没有,自动执行重排直至有可以消除的为止
*----------------------------------------------------------------------*
FORM check_dead.
  PERFORM get_hint USING ''.
  WHILE l_dead EQ 'X'.
    MESSAGE '没有可以消除的图片,自动进行重排' TYPE 'S'.
    PERFORM reform USING 'X'.
    PERFORM get_hint USING ''.
  ENDWHILE.
ENDFORM. "check_dead
*&---------------------------------------------------------------------*
*&      Form  Update_pb_visible
*&---------------------------------------------------------------------*
*       重排后,刷新按钮的可见性
*----------------------------------------------------------------------*
FORM update_pb_visible.
  LOOP AT SCREEN.
    CHECK screen-name 0(2) EQ 'PB'.
    PERFORM get_pb_chr USING screen-name.
    IF l_pb_chr EQ '#'.
      screen-invisible = '1'.
    ELSE.
      screen-invisible = '0'.
    ENDIF.
    MODIFY SCREEN.
  ENDLOOP.
ENDFORM. "Update_pb_visible
*&---------------------------------------------------------------------*
*&      Form  init_timer_progress
*&---------------------------------------------------------------------*
*       初始化进度条计时器
*----------------------------------------------------------------------*
FORM init_timer_progress.
  CHECK go_timer IS INITIAL.
  CREATE OBJECT go_timer
    EXCEPTIONS
      OTHERS = 9.
  CREATE OBJECT go_evt_hndl.
  SET HANDLER go_evt_hndl->handle_timer FOR go_timer.
  go_timer->interval = 12.                                  "设置间隔为6秒
  CALL METHOD go_timer->run "激活定时器
  EXCEPTIONS
    OTHERS = 9.
ENDFORM. " init_timer_progress
*&---------------------------------------------------------------------*
*&      Form  init_timer_twinkle
*&---------------------------------------------------------------------*
*       初始化闪烁计时器
*----------------------------------------------------------------------*
FORM init_timer_twinkle.
  CREATE OBJECT twinkle_timer
    EXCEPTIONS
      OTHERS = 9.
  CREATE OBJECT twinkle_evt_hndl.
  SET HANDLER twinkle_evt_hndl->handle_twinkle FOR twinkle_timer.
  twinkle_timer->interval = 1.                              "设置间隔为1秒
  CALL METHOD twinkle_timer->run "激活定时器
  EXCEPTIONS
    OTHERS = 9.
ENDFORM. "init_timer_twinkle
*&---------------------------------------------------------------------*
*&      Form  high_scores_read
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM high_scores_read.
  REFRESH high_scores.
  IMPORT lines = high_scores[] FROM DATABASE indx(st) ID database_id.
ENDFORM. "high_scores_read
*&---------------------------------------------------------------------*
*&      Form  high_scores_show
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM high_scores_show.
  DATA: s(7) TYPE c, line(3) TYPE c.
  FIELD-SYMBOLS: <fs0> TYPE c,
                 <fs1> TYPE c,
                 <fs2> TYPE c,
                 <fs3> TYPE c,
                 <fs4> TYPE c.

  DO 177 TIMES.
    line = sy-index.
    CONDENSE line NO-GAPS.
    CONCATENATE 'hs1_' line INTO s.
    ASSIGN (s) TO <fs0>.
    CONCATENATE 'hs2_' line INTO s.
    ASSIGN (s) TO <fs1>.
    CONCATENATE 'hs3_' line INTO s.
    ASSIGN (s) TO <fs2>.
    CONCATENATE 'hs4_' line INTO s.
    ASSIGN (s) TO <fs3>.
    CONCATENATE 'hs5_' line INTO s.
    ASSIGN (s) TO <fs4>.
    READ TABLE high_scores INDEX sy-index.
    IF high_scores-user = 'AC-LSUN'.
      high_scores-user = '************'.
    ENDIF.
    IF sy-subrc EQ 0.
      <fs0> = line.
      <fs1> = high_scores-user.
      <fs2> = high_scores-time.
      <fs3> = high_scores-hintcount.
      <fs4> = high_scores-reformcount.
      CONDENSE <fs3> NO-GAPS.
      CONDENSE <fs4> NO-GAPS.
      IF <fs1> <> '' AND <fs3> = ''.
        <fs3> = '0'.
      ENDIF.
      IF <fs1> <> '' AND <fs4> = ''.
        <fs4> = '0'.
      ENDIF.
    ELSE.
      CLEAR: <fs0>, <fs1>, <fs2>, <fs3>.
      EXIT.
    ENDIF.
  ENDDO.
ENDFORM. "high_scores_show
*&---------------------------------------------------------------------*
*&      Form  high_scores_update
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM high_scores_update.
  high_scores-user = sy-uname.
  WRITE l_cost_time TO high_scores-time RIGHT-JUSTIFIED.
  WRITE l_hint_count TO high_scores-hintcount.
  WRITE l_reform_count TO high_scores-reformcount.
  APPEND high_scores.
  SORT high_scores BY time user hintcount reformcount.
*  LOOP AT high_scores FROM 11.
*    DELETE high_scores INDEX sy-tabix.
*  ENDLOOP.
  EXPORT lines = high_scores[] TO DATABASE indx(st) ID database_id.
ENDFORM. "high_scores_update
*&---------------------------------------------------------------------*
*&      Form  PB_TWINKLE
*&---------------------------------------------------------------------*
*       闪烁
*----------------------------------------------------------------------*
*      -->P_CROW1  text
*      -->P_CCOL1  text
*      -->P_CROW2  text
*      -->P_CCOL2  text
*----------------------------------------------------------------------*
FORM pb_twinkle.
  FIELD-SYMBOLS: <pbname1> TYPE ANY,
                 <pbname2> TYPE ANY.

  ASSIGN (l_hint_pb1) TO <pbname1>.
  ASSIGN (l_hint_pb2) TO <pbname2>.
  IF <pbname1> NE icon_space.
    l_hint_icon1 = <pbname1>.
    <pbname1> = icon_space.
  ELSE.
    <pbname1> = l_hint_icon1.
    l_hint_icon1 = ''.
  ENDIF.
  IF <pbname2> NE icon_space.
    l_hint_icon2 = <pbname2>.
    <pbname2> = icon_space.
  ELSE.
    <pbname2> = l_hint_icon2.
    l_hint_icon1 = ''.
  ENDIF.
ENDFORM. " PB_TWINKLE
*&---------------------------------------------------------------------*
*&      Form  get_pb_name
*&---------------------------------------------------------------------*
*       根据pushbutton的编号获取其名字
*----------------------------------------------------------------------*
*      -->P_PBNUM    text
*      -->P_PBNAME   text
*----------------------------------------------------------------------*
FORM get_pb_name USING p_pbnum CHANGING p_pbname.
  DATA: pbnum(3) TYPE c.
  pbnum = p_pbnum.
  CONDENSE pbnum NO-GAPS.
  IF STRLEN( pbnum ) EQ 1.
    CONCATENATE 'PB00' pbnum INTO p_pbname.
  ELSEIF STRLEN( pbnum ) EQ 2.
    CONCATENATE 'PB0' pbnum INTO p_pbname.
  ELSE.
    CONCATENATE 'PB' pbnum INTO p_pbname.
  ENDIF.
ENDFORM. "get_pb_name
*&---------------------------------------------------------------------*
*&      Form  ALV_SHOW_RECORD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM alv_show_record .
  DATA: ls_layout TYPE slis_layout_alv.
  DATA: lt_fieldcat TYPE slis_t_fieldcat_alv,
        ls_fieldcat TYPE slis_fieldcat_alv.
  DATA: BEGIN OF lt_data OCCURS 0.
  DATA: num TYPE i.
  INCLUDE TYPE score_line.
  DATA: END OF lt_data.
  ls_layout-zebra = 'X'.
  ls_layout-colwidth_optimize = 'X'.

  DEFINE append_fieldcat.
    ls_fieldcat-fieldname = &1.
    ls_fieldcat-seltext_l = &2.
    ls_fieldcat-seltext_m = &2.
    ls_fieldcat-seltext_s = &2.
    append ls_fieldcat to lt_fieldcat.
  END-OF-DEFINITION.

  append_fieldcat 'NUM' '排名' .
  append_fieldcat 'USER' 'User' .
  append_fieldcat 'TIME' '时间' .
  append_fieldcat 'HINTCOUNT' '提示次数' .
  append_fieldcat 'REFORMCOUNT' '重排次数' .

  PERFORM high_scores_read.

  LOOP AT high_scores.
    MOVE-CORRESPONDING high_scores TO lt_data.
    lt_data-num = sy-tabix.
    IF lt_data-user = 'AC-LSUN'.
      lt_data-user = '************'.
    ENDIF.
    APPEND lt_data.
  ENDLOOP.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
*      i_callback_program = sy-repid
      is_layout          = ls_layout
      it_fieldcat        = lt_fieldcat
      i_grid_title       = '排行榜'
    TABLES
      t_outtab           = lt_data[]
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.
ENDFORM.                    " ALV_SHOW_RECORD

0 人点赞