Having learned some basic MATLAB coding and GUI design this semester, I decided to challenge myself by making a classic game like Snake or Tetris. Well, turns out they both are still a bit too challenging, so I made the classic card-matching memory game; and with the help of mobile sensors, a player can match pairs remotely with a phone. Try it!!
Mobile Acceleration Sensor Test:
(When the phone is horizontal to the ground and the screen facing...)
(When the phone is vertical to the ground and the screen facing yourself... )
-There are more but these five are which I used.
Simulink & Stateflow:
My Code:
m.Logging = 1; %start getting data from mobile sensor pause(2);m.Logging = 0; %stop getting data from mobile sensor [A, T] = accellog(m); %save data into array AxAcc = A(:,1); x=xAcc(end); %fetch only the last data from the array yAcc = A(:,2); y=yAcc(end);zAcc = A(:,3); z=zAcc(end);load_system('untitled'); %load Simulink file sim('untitled'); if direction == 1 disp('UP'); pause(3);elseif direction == 2 disp('DOWN'); pause(3);elseif direction == 3 disp('LEFT'); pause(3);elseif direction == 4 disp('RIGHT'); pause(3);elseif direction == 5 disp('GUESS'); pause(3); end switch number case 1 set(handles.pushbutton9,'ForegroundColor','blue'); set(handles.pushbutton46,'ForegroundColor','black'); set(handles.pushbutton43,'ForegroundColor','black'); set(handles.pushbutton49,'ForegroundColor','black'); set(handles.pushbutton41,'ForegroundColor','black'); set(handles.pushbutton47,'ForegroundColor','black'); set(handles.pushbutton44,'ForegroundColor','black'); set(handles.pushbutton50,'ForegroundColor','black'); set(handles.pushbutton42,'ForegroundColor','black'); set(handles.pushbutton48,'ForegroundColor','black'); set(handles.pushbutton45,'ForegroundColor','black'); set(handles.pushbutton51,'ForegroundColor','black'); case 2......endswitch number case 1 pushbutton9_Callback(hObject, eventdata, handles); case 2 pushbutton46_Callback(hObject, eventdata, handles); case 3 pushbutton43_Callback(hObject, eventdata, handles);......endfunction pushbutton9_Callback(hObject, eventdata, handles)global count color1 color2 green yellow cyan red blue black count = count + 1;if count == 1 set(handles.pushbutton9,'BackgroundColor','green'); color1 = 1;else set(handles.pushbutton9,'BackgroundColor','green'); color2 = 1; if color1 == color2 count = 0; green = 1; else count = 0; end pause(1); if green == 0 set(handles.pushbutton9,'BackgroundColor','white'); set(handles.pushbutton44,'BackgroundColor','white'); end if cyan == 0 set(handles.pushbutton46,'BackgroundColor','white'); set(handles.pushbutton51,'BackgroundColor','white'); end if yellow == 0 set(handles.pushbutton42,'BackgroundColor','white'); set(handles.pushbutton50,'BackgroundColor','white'); end if red == 0 set(handles.pushbutton48,'BackgroundColor','white'); set(handles.pushbutton47,'BackgroundColor','white'); end if blue == 0 set(handles.pushbutton49,'BackgroundColor','white'); set(handles.pushbutton41,'BackgroundColor','white'); end if black == 0 set(handles.pushbutton43,'BackgroundColor','white'); set(handles.pushbutton45,'BackgroundColor','white'); end endShow the number of guesses.
if green == 1 && cyan == 1 && blue == 1 && yellow == 1 red == 1 && black == 1 count2 = count2 / 2; S = 1; %exit loop fprintf('You tried %.0f times.\n', count2); %print out the number of guessesend