代码
REPORT ZLM_GAME5.
*&---------------------------------------------------------------------*
* to install tetris:
* 1) create program and place all this text in it.
* 2) create standart screen 100 and insert this part
*------------------------------------------------------------*
* process before output.
* module status_0100.
*
* process after input.
* module exx at exit-command.
* module user_command_0100.
*------------------------------------------------------------*
* 3) create gui-status status_0 and insert
* 3.1) free functional keys
*------------------------------------------------------------*
* f5 pf21 drop (f5)
* f6 pf22 left (f6)
* f7 pf23 rotate(f7)
* f8 pf24 right (f8)
* shift-f1 pf25 return
* shift-f6 pf26 down
*------------------------------------------------------------*
* 3.2) buttons
*------------------------------------------------------------*
* pf21 pf22 pf23 pf24
* drop (f5) left (f6) rotate(f7) right (f8)
*------------------------------------------------------------*
* 3.3) and as usual standart functions ;-)
* back up exit
*------------------------------------------------------------*
* 4) activate it and enjoy! ;-)
* 5) if you want to try delays less then one second,
* create functional module like this, and comment/uncomment
* calls and recieves in the forms "f_call_rfc_wait" and "f_task_end".
*------------------------------------------------------------*
* function z_nbcsh_delay .
* *"------------------------------------------------------------
* *" importing
* *" value(delay) type f default 1
* *"------------------------------------------------------------
* wait up to delay seconds.
* endfunction.
*------------------------------------------------------------*
*REPORT zit001.
DATA count TYPE i.
DATA scores TYPE i.
TYPES: BEGIN OF outtype ,
line TYPE char20,
END OF outtype.
DATA outtab TYPE outtype OCCURS 1 WITH HEADER LINE.
*---------------------------------------------------------------------*
DATA: stakan TYPE c OCCURS 0,
stakan_fig LIKE stakan,
stakan_fig_old LIKE stakan,
stakan_zad LIKE stakan.
DATA: sz, st, sf,
data0,
data1,
data2,
data3,
data4,
data5,
data6,
data7,
data8,
data9.
DATA: err, fl_new.
DATA: row TYPE i, col TYPE i.
DATA: st_width TYPE i VALUE 12, st_height TYPE i VALUE 20.
TYPES: BEGIN OF figure,
* CUR_POS TYPE I,
* START_POS TYPE I,
name(10),
width TYPE i,
height TYPE i,
* NEXTFIG TYPE FIGURE,
body1 TYPE i,
body2 TYPE i,
body3 TYPE i,
body4 TYPE i,
old_body1 TYPE i,
old_body2 TYPE i,
old_body3 TYPE i,
old_body4 TYPE i,
END OF figure.
DATA: square TYPE figure,
line1 TYPE figure,
line2 TYPE figure,
lzz1 TYPE figure,
lzz2 TYPE figure,
rzz1 TYPE figure,
rzz2 TYPE figure,
tri1 TYPE figure,
tri2 TYPE figure,
tri3 TYPE figure,
tri4 TYPE figure,
lgg1 TYPE figure,
lgg2 TYPE figure,
lgg3 TYPE figure,
lgg4 TYPE figure,
rgg1 TYPE figure,
rgg2 TYPE figure,
rgg3 TYPE figure,
rgg4 TYPE figure
.
DATA cur_fig TYPE figure.
START-OF-SELECTION.
PERFORM init_figures."初始化方块子程序
PERFORM init_stakan."初始化图形界面子程序
PERFORM put_next_fig."下一个方块子程序
SET PF-STATUS 'STATUS_0'.
CALL SCREEN 100.
AT USER-COMMAND.
CASE sy-ucomm.
WHEN 'BACK' OR 'UP' OR 'EXIT'.
LEAVE PROGRAM.
* PERFORM F_READ_DATA.
* IS_SELFIELD-REFRESH = "X".
* SET USER-COMMAND "&OPT". " OPTIMIZE COLUMNS WIDTH
ENDCASE.
*DROP
AT PF21."DROP方块一下到底SHIFT F6
CLEAR: err, count.
DO.
PERFORM fig_move USING 'DOWN' CHANGING err."参数值ERR带回碰撞检测值
IF err EQ 'X'.
EXIT.
ENDIF.
* ADD 1 TO COUNT."原程序DROP有加分,没?梦胰サ袅?
ENDDO.
* ADD COUNT TO SCORES."计分
PERFORM out."屏幕输出
PERFORM f_call_rfc_wait."定时刷新
AT PF22. "F6 LEFT左
PERFORM fig_move USING 'LEFT' CHANGING err."调用方块移动子程序
PERFORM out."屏幕显示
PERFORM f_call_rfc_wait."方块自动下落刷新,这里设时间为1秒
AT PF23. "F7 ROTATE转
PERFORM fig_rotate."图形旋转
PERFORM out.
PERFORM f_call_rfc_wait.
AT PF24. "F8 RIGHT右
PERFORM fig_move USING 'RIGHT' CHANGING err.
PERFORM out.
PERFORM f_call_rfc_wait.
AT PF25." RETURN "SHIFT F1
* SET USER-COMMAND "PF21".
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'PF21'.
LEAVE LIST-PROCESSING.
AT PF26. "F5 DOWN缓下
PERFORM fig_move USING 'DOWN' CHANGING err.
PERFORM out.
IF err = 'X'."如果方块到底了,则
PERFORM fig_append."出现新的方块
PERFORM check_full_line."检查消去行
PERFORM put_next_fig."选出下个方块
ENDIF.
PERFORM f_call_rfc_wait.
*---------------------------------------------------------------------*
* FORM OUT *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM out.
DATA outstring(100).
DATA: lc TYPE i, otstup TYPE i.
DATA stakan_out LIKE stakan.
DATA so(2).
otstup = st_width * 4."
stakan_out[] = stakan[].
MODIFY stakan_out FROM 'X' INDEX cur_fig-body1."把方块添加到图形内表中
MODIFY stakan_out FROM 'X' INDEX cur_fig-body2.
MODIFY stakan_out FROM 'X' INDEX cur_fig-body3.
MODIFY stakan_out FROM 'X' INDEX cur_fig-body4.
CLEAR outstring.
WRITE AT 8 'SCORE:'."显示得分
WRITE scores LEFT-JUSTIFIED."20位的数字选择左对齐,不然前面都是空
LOOP AT stakan_out INTO st.
*