天天看點

abap寫的小遊戲 數字移動小遊戲

項目後期維護,沒什麼事情幹,閑着無聊,今天寫了個小遊戲玩玩:

(注:由于代碼不能從客戶那邊帶回來,回家用記事本寫的,注釋也比較少,但是代碼實作的邏輯很簡單,不解釋。。。。。 如有編譯錯誤請諒解,    灰常感謝!!!!)

report ......

selection-screen pushbutton 2(10)  pb11 user-command pb11.

selection-screen pushbutton 12(10) pb12 user-command pb12.

selection-screen pushbutton 22(10) pb13 user-command pb13.

selection-screen skip.

selection-screen pushbutton 2(10)  pb21 user-command pb21.

selection-screen pushbutton 12(10) pb22 user-command pb22.

selection-screen pushbutton 22(10) pb23 user-command pb23.

selection-screen skip.

selection-screen pushbutton 2(10)  pb31 user-command pb31.

selection-screen pushbutton 12(10) pb32 user-command pb32.

selection-screen pushbutton 22(10) pb33 user-command pb33.

selection-screen skip.

selection-screen pushbutton 12(10) pbrt user-command pbrt.

INITIALIZATION.

  "設定畫面的初始值

  pb11 = '2'.

  pb12 = '1'.

  pb13 = '4'.

  pb21 = '7'.

  pb22 = '3'.

  pb23 = '6'.

  pb31 = '8'.

  pb32 = ' '.

  pb33 = '5'.

at selection-screen.

  case sy-ucomm.

    when 'pb11'.

      perform exec_pb11. 

    when 'pb12'.

      perform exec_pb12.

    when 'pb13'.

      perform exec_pb13.

    when 'pb21'.

      perform exec_pb21.

    when 'pb22'.

      perform exec_pb22.

    when 'pb23'.

      perform exec_pb23.

    when 'pb31'.

      perform exec_pb31.

    when 'pb32'.

      perform exec_pb32.

    when 'pb33'.

      perform exec_pb33.

    when 'pbrt'

      perform exec_right_result.

    when

  endcase.

form exec_pb11 .

  check pb11 is not initial.

  perform move_data changing pb11

                             pb12.

  perform move_data changing pb11

                             pb21.

endform.

form exec_pb12 .

  check pb12 is not initial.

  perform move_data changing pb12

                             pb11.

  perform move_data changing pb12

                             pb13.

  perform move_data changing pb12

                             pb22.

endform.

form exec_pb13 .

  check pb13 is not initial.

  perform move_data changing pb13

                             pb12.

  perform move_data changing pb13

                             pb23.

endform.

form exec_pb21 .

  check pb21 is not initial.

  perform move_data changing pb21

                             pb11.

  perform move_data changing pb21

                             pb22.

  perform move_data changing pb21

                             pb31.

endform.

form exec_pb22 .

  check pb22 is not initial.

  perform move_data changing pb22

                             pb12.

  perform move_data changing pb22

                             pb21.

  perform move_data changing pb22

                             pb23.

  perform move_data changing pb22

                             pb32.

endform.

form exec_pb23 .

  check pb23 is not initial.

  perform move_data changing pb23

                             pb13.

  perform move_data changing pb23

                             pb22.

  perform move_data changing pb23

                             pb33.

endform.

form exec_pb31 .

  check pb31 is not initial.

  perform move_data changing pb31

                             pb21.

  perform move_data changing pb31

                             pb32.

endform.

form exec_pb32 .

  check pb32 is not initial.

  perform move_data changing pb32

                             pb22.

  perform move_data changing pb32

                             pb31.

  perform move_data changing pb32

                             pb33.

endform.

form exec_pb33 .

  check pb32 is not initial.

  perform move_data changing pb33

                             pb23.

  perform move_data changing pb33

                             pb32.

endform.

form move_data changing p_pb1 type any

                        p_pb2 type any.

 "實作把點選的那按鈕 移動到臨近的空白按鈕上

  check p_pb1 is not initial

    and p_pb2 is initial.

  p_pb2 = p_pb1.

  clear pb1.

  perform check_right_result.

endform.

form check_right_result.

  if pb11 = '1'

 and pb12 = '2'

 and pb13 = '3'

 and pb21 = '4'

 and pb22 = '5'

 and pb23 = '6'

 and pb31 = '7'

 and pb32 = '8'

 and pb33 = ' '

    message 'Very good !  boys'.

    leave screen.

  endif.

endform.

form exec_right_result.

 "正确結果為:

  pb11 = '1'.

  pb12 = '2'.

  pb13 = '3'.

  pb21 = '4'.

  pb22 = '5'.

  pb23 = '6'.

  pb31 = '7'.

  pb32 = '8'.

  pb33 = ' '.

endform.

繼續閱讀