function whack()

% here is the window for the game
f = figure('Visible', 'off', 'color', 'white', 'Position', [360, 500, 550, 600]);
set (f, 'Name', 'Whack-a-Mole');
movegui(f, 'center')
v = 1;

% these are coordinates for the 5 moles on the board
x = [75 150 225 300 375];

% each position on the board is a pushbutton
for ii = 1:5
   mole(ii) = uicontrol('style','pushbutton', 'position', [x(ii),100,50,50], ...
      'Callback', @ouch, 'Fontsize', 10, 'UserData', ii, 'string', 'hello');
end

% score box
score = uicontrol('style', 'text', 'Position', [100, 200, 300, 50], ...
    'String', 'Enjoy Whack-a-Mole', 'Fontsize', 20);

% reset button to start a new round 
hit = uicontrol('style', 'pushbutton', 'Position', [200, 300, 100, 50], ...
    'String', 'Start', 'Fontsize', 20, 'Callback', @hitme);

set(f, 'Visible', 'on')

% ================= CALL BACK FOR START ==================
function hitme(source, ~)
   set(score, 'string', 'hello')
   v = randi([1 5]);
   set(mole(v), 'string', 'hit me')
end

% ---------------- CALL BACK FOR MOLE -----------
function ouch(source, ~)
   if get(source, 'UserData') == v
      set(source, 'string', 'hello')
      set(score, 'string', 'You got me!')
   end
end
end

