*&---------------------------------------------------------------------*
*& Report ZTEST_BUTTON_GAME *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
report ZTEST_button_game .
include <icon>.
tables : sscrfields.
*** internal table for storing the list of icons temporarily
data : begin of i_icons occurs 1000,
id like icon-id,
end of i_icons.
*** internal table for storing the 32 icons/pictures
data : begin of i_iconlist occurs 32,
id like icon-id,
end of i_iconlist.
*** internal table for storing the icons in the 64 positions
data : begin of i_layout occurs 0,
row(1) type n,
col(1) type n,
id like icon-id,
end of i_layout.
*** data declaration
data : w_layout like i_layout.
data : ran_no type i.
data : len type i.
data : subrc like sy-subrc.
data : count type i.
data : name(10).
data : flg_one.
data : flg_two.
data : icon_one like icon-id.
data : icon_two like icon-id.
data : b_one(5).
data : b_two(5).
data : current_ucomm like sscrfields-ucomm.
field-symbols : <fs> type any.
**** selection-screen declaration.
*** keeping the button names and its user-command same will
*** make things easier later....
selection-screen begin of block b1 with frame no intervals.
selection-screen skip 1.
selection-screen pushbutton /2(4) pb11 user-command pb11.
selection-screen pushbutton 9(4) pb12 user-command pb12.
selection-screen pushbutton 16(4) pb13 user-command pb13.
selection-screen pushbutton 23(4) pb14 user-command pb14.
selection-screen pushbutton 30(4) pb15 user-command pb15.
selection-screen pushbutton 37(4) pb16 user-command pb16.
selection-screen pushbutton 44(4) pb17 user-command pb17.
selection-screen pushbutton 51(4) pb18 user-command pb18.
selection-screen skip 1.
selection-screen pushbutton /2(4) pb21 user-command pb21.
selection-screen pushbutton 9(4) pb22 user-command pb22.
selection-screen pushbutton 16(4) pb23 user-command pb23.
selection-screen pushbutton 23(4) pb24 user-command pb24.
selection-screen pushbutton 30(4) pb25 user-command pb25.
selection-screen pushbutton 37(4) pb26 user-command pb26.
selection-screen pushbutton 44(4) pb27 user-command pb27.
selection-screen pushbutton 51(4) pb28 user-command pb28.
selection-screen skip 1.
selection-screen pushbutton /2(4) pb31 user-command pb31.
selection-screen pushbutton 9(4) pb32 user-command pb32.
selection-screen pushbutton 16(4) pb33 user-command pb33.
selection-screen pushbutton 23(4) pb34 user-command pb34.
selection-screen pushbutton 30(4) pb35 user-command pb35.
selection-screen pushbutton 37(4) pb36 user-command pb36.
selection-screen pushbutton 44(4) pb37 user-command pb37.
selection-screen pushbutton 51(4) pb38 user-command pb38.
selection-screen skip 1.
selection-screen pushbutton /2(4) pb41 user-command pb41.
selection-screen pushbutton 9(4) pb42 user-command pb42.
selection-screen pushbutton 16(4) pb43 user-command pb43.
selection-screen pushbutton 23(4) pb44 user-command pb44.
selection-screen pushbutton 30(4) pb45 user-command pb45.
selection-screen pushbutton 37(4) pb46 user-command pb46.
selection-screen pushbutton 44(4) pb47 user-command pb47.
selection-screen pushbutton 51(4) pb48 user-command pb48.
selection-screen skip 1.
selection-screen pushbutton /2(4) pb51 user-command pb51.
selection-screen pushbutton 9(4) pb52 user-command pb52.
selection-screen pushbutton 16(4) pb53 user-command pb53.
selection-screen pushbutton 23(4) pb54 user-command pb54.
selection-screen pushbutton 30(4) pb55 user-command pb55.
selection-screen pushbutton 37(4) pb56 user-command pb56.
selection-screen pushbutton 44(4) pb57 user-command pb57.
selection-screen pushbutton 51(4) pb58 user-command pb58.
selection-screen skip 1.
selection-screen pushbutton /2(4) pb61 user-command pb61.
selection-screen pushbutton 9(4) pb62 user-command pb62.
selection-screen pushbutton 16(4) pb63 user-command pb63.
selection-screen pushbutton 23(4) pb64 user-command pb64.
selection-screen pushbutton 30(4) pb65 user-command pb65.
selection-screen pushbutton 37(4) pb66 user-command pb66.
selection-screen pushbutton 44(4) pb67 user-command pb67.
selection-screen pushbutton 51(4) pb68 user-command pb68.
selection-screen skip 1.
selection-screen pushbutton /2(4) pb71 user-command pb71.
selection-screen pushbutton 9(4) pb72 user-command pb72.
selection-screen pushbutton 16(4) pb73 user-command pb73.
selection-screen pushbutton 23(4) pb74 user-command pb74.
selection-screen pushbutton 30(4) pb75 user-command pb75.
selection-screen pushbutton 37(4) pb76 user-command pb76.
selection-screen pushbutton 44(4) pb77 user-command pb77.
selection-screen pushbutton 51(4) pb78 user-command pb78.
selection-screen skip 1.
selection-screen pushbutton /2(4) pb81 user-command pb81.
selection-screen pushbutton 9(4) pb82 user-command pb82.
selection-screen pushbutton 16(4) pb83 user-command pb83.
selection-screen pushbutton 23(4) pb84 user-command pb84.
selection-screen pushbutton 30(4) pb85 user-command pb85.
selection-screen pushbutton 37(4) pb86 user-command pb86.
selection-screen pushbutton 44(4) pb87 user-command pb87.
selection-screen pushbutton 51(4) pb88 user-command pb88.
selection-screen skip 1.
selection-screen begin of line.
selection-screen comment 2(15) no_tries.
parameters : p_tries type i modif id hid visible length 3.
selection-screen end of line.
selection-screen end of block b1.
initialization.
perform do_initialization.
at selection-screen output.
if i_layout[] is initial.
message i000(z01) with 'You have WON !!!'.
endif.
*** make the count field display only
loop at screen.
if screen-group1 = 'HID'.
screen-input = 0.
modify screen.
endif.
endloop.
at selection-screen.
*** make sure it is one of the buttons that is clicked and
*** not clicking the same button again
*** exception is if 2 are open and you want to keep the 2nd one open
*** you can do so....
check sscrfields-ucomm cs 'PB' and
( sscrfields-ucomm <> current_ucomm or
not flg_two is initial ).
current_ucomm = sscrfields-ucomm.
*** making sure again that a button is clicked and get the icon
*** hidden in the clicked button.
read table i_layout with key row = sscrfields-ucomm+2(1)
col = sscrfields-ucomm+3(1).
check sy-subrc = 0.
perform validate.
*&---------------------------------------------------------------------*
*& Form validate
*&---------------------------------------------------------------------*
* checking whether its the 1st or the 2nd button click, assign the ucomm
* to the field-symbol. The trick is the buttons have been named same as
* its ucomm, so assigning it gives the value of the button.
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form validate.
if not flg_two is initial. "控制点击第三下时,如前面两次点击的不一样,则前面俩个icon消失
assign (b_one) to <fs>.
<fs> = '@5F@'.
assign (b_two) to <fs>.
<fs> = '@5F@'.
clear : flg_one,flg_two,
icon_one,icon_two,
b_one,b_two.
endif.
if flg_one is initial or
flg_two is initial.
assign (sscrfields-ucomm) to <fs>.
if sy-subrc = 0.
<fs> = i_layout-id. "display icon
endif.
if flg_one is initial.
flg_one = 'X'.
icon_one = i_layout-id.
b_one = sscrfields-ucomm.
elseif flg_two is initial.
flg_two = 'X'.
icon_two = i_layout-id.
b_two = sscrfields-ucomm.
endif.
endif.
if icon_one = icon_two.
p_tries = p_tries + 1.
delete i_layout where id = icon_one.
clear : flg_one,flg_two,icon_one,icon_two.
endif.
if not flg_two is initial.
p_tries = p_tries + 1.
endif.
endform. " validate
*&---------------------------------------------------------------------*
*& Form do_initialization
*&---------------------------------------------------------------------*
* Make all the buttons show blank space. Also select, the list of
* all icons from the standard table and select 32 from it randomly. Once
* the 32 icons are selected, lay it out in pairs on the 8 X 8 board of
* buttons.
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
form do_initialization.
no_tries = 'No. of Tries'.
pb11 = pb12 = pb13 = pb14 = pb15 = pb16 = pb17 = pb18 = icon_space.
pb21 = pb22 = pb23 = pb24 = pb25 = pb26 = pb27 = pb28 = icon_space.
pb31 = pb32 = pb33 = pb34 = pb35 = pb36 = pb37 = pb38 = icon_space.
pb41 = pb42 = pb43 = pb44 = pb45 = pb46 = pb47 = pb48 = icon_space.
pb51 = pb52 = pb53 = pb54 = pb55 = pb56 = pb57 = pb58 = icon_space.
pb61 = pb62 = pb63 = pb64 = pb65 = pb66 = pb67 = pb68 = icon_space.
pb71 = pb72 = pb73 = pb74 = pb75 = pb76 = pb77 = pb78 = icon_space.
pb81 = pb82 = pb83 = pb84 = pb85 = pb86 = pb87 = pb88 = icon_space.
select id from icon into table i_icons
where not id in ('@5F@','@E5@','@00@','@E6@','@E7@',
'@EI@','@GE@','@GG@','@JX@','@JY@',
'@JZ@','@K0@').
describe table i_icons lines len.
clear : subrc.
while subrc < 32.
call function 'QF05_RANDOM_INTEGER'
exporting
ran_int_max = len
ran_int_min = 1
importing
ran_int = ran_no
exceptions
invalid_input = 1
others = 2.
read table i_icons index ran_no.
read table i_iconlist with key id = i_icons-id.
if sy-subrc <> 0.
i_iconlist-id = i_icons-id.
append i_iconlist.
endif.
describe table i_iconlist lines subrc.
endwhile.
refresh : i_icons.
clear : subrc.
while subrc < 64.
if subrc <> 0.
read table i_layout index subrc.
if i_layout-col = 8.
i_layout-col = 1.
i_layout-row = i_layout-row + 1.
else.
i_layout-col = i_layout-col + 1.
endif.
else.
i_layout-row = 1.
i_layout-col = 1.
endif.
clear : count,i_iconlist.
call function 'QF05_RANDOM_INTEGER'
exporting
ran_int_max = 32
ran_int_min = 1
importing
ran_int = ran_no
exceptions
invalid_input = 1
others = 2.
read table i_iconlist index ran_no.
loop at i_layout into w_layout where id = i_iconlist-id.
count = count + 1.
endloop.
if count < 2.
i_layout-id = i_iconlist-id.
append i_layout.
endif.
clear : i_layout.
describe table i_layout lines subrc.
endwhile.
clear : flg_one,flg_two,icon_one,icon_two, current_ucomm.
endform. " do_initialization