The task is to produce a matrix of 20 hexagon shaped widgets in a honeycomb arrangement. The matrix should be arranged in such a manner that there are five
columns of four hexagons. The hexagons in columns one, three and five are aligned horizontally, whereas the hexagons in columns two and four occupy a lower position within the arrangement. Each hexagon should be the same colour, and should
display a unique randomly selected single capital letter on the front. The application should now wait for the user to select a hexagon, either by using a pointing device, or by pressing a key that carries a corresponding letter on a hexagon. For platforms that support pointing devices and keyboards, the application should support both methods of selection. A record of the chosen letters should be maintained and the code should be suitably commented, at the point where the the selected letter has been determined. The selected hexagon should now change colour on the display. The cycle repeats until the user has chosen all of the letters. Note that each letter can only be selected once and previously selected hexagons retain their colour after selection. The program terminates when all letters have been chosen.

Optionally: output the list of selected letters and show the last selected letter, cater for a different number of columns or a different number of hexagons in each column, cater for two players, (turns alternate and the hexagons change a different colour depending on whether they were selected by player one or player two and records of both players selections are maintained.)



require'ide/qt/gl2'
coinsert'jgl2'
 
NB. corners of a unit hexagon
ucorn=: +.^j.2p1*(%~i.)6
 
NB. center to center offset for columns and rows
uof=: %:2.3 3
 
shape=: 4 5
scale=: 50
scorn=: scale*ucorn
centers=: scale*(((%:0 0.75)*/~2|{:"1)+uof*"1 1:+|."1)shape#:i.shape
 
honeycomb=: {{)n
  pc honeycomb nosize closeok;
  minwh 460 460;
  cc hex isidraw flush;
  pshow;
}}{{
  sel=: 0"0 grid=: shape$u:65+(*/shape)?26
  txt=:''
  wd m
  draw y
}}
 
draw=: {{
  glfill 0 0 0 255
  hex"0 i.$grid
  gltextcolor glrgb 0 0 255
  glfont 'courier 24'
  gltextxy 60 10
  glpaint gltext txt
}}
 
hex=: {{
  coord=. <shape#:y
  center=. coord{centers
  glbrush glrgb (-coord{sel)|.255 255 0
  glrgb 255 255 255
  glpen 3,PS_SOLID
  glpolygon,<.center+"1 scorn
  gltextcolor glrgb 255 0 0
  glfont 'courier 24 bold'
  gltextxy <.center-10
  gltext coord{grid
}}
 
select_character=: {{
  if. -. y{,sel do. NB. the selected character has been determined
    txt=:txt, y{,grid
  end.
  draw sel=: 1 (y"_)} sel
}}
 
honeycomb_hex_char=: {{
  ch=. toupper {.sysdata
  if. ch e. ,grid do. select_character (,grid)i.ch end.
}}
 
honeycomb_hex_mbldown=:{{
  xy=. 2{.".sysdata
  k=. (i.<./)dist=.,+/&.:*:"1 centers-"1 xy
  if. scale > k{dist do.select_character k end.
}}
 
honeycomb''