There are four pictures in my project,
each of them has a question on it.
If i turn my phone the correct direction,
it will show a big BANG!, else, it will show a big 母牠喔.
clear all; %clear all things in work space
m = mobiledev;
swing=0;
score = 0; %set score to 0
pic=imread('start.jpg');
image(pic)
pause(3)
while swing==0 %while loop
disp('start'); %show start to make sure it start
direction=round(3*rand(1,1))+1; %generate one randon number between 1 to 4
if direction==1
pic=imread('RIGHT.jpg'); %load the question picture
elseif direction==2
pic=imread('DOWN.jpg'); %load the question picture
elseif direction==3
pic=imread('LEFT.jpg'); %load the question picture
elseif direction==4
pic=imread('UP.jpg'); %load the question picture
end
image(pic) %show the question
pause(2)
m.Logging = 1; %start getting signal from cellphone
pause(2);
m.Logging = 0; %stop getting signal from cellphone
[or, tor] = orientlog(m);
x = or(:,2);
c=x(end); %get the last signal
y = or(:,3);
d=y(end); %get the last signal
load_system('judge'); %load the simulink system
sim('judge'); %judge answer in simulink
b = dir(2,1);
if b==4
pic=imread('correct.jpg');
image(pic)
score = score + 1;
elseif b==1
pic=imread('correct.jpg');
image(pic)
score = score + 1;
elseif b==2
pic=imread('correct.jpg');
image(pic)
score = score + 1;
elseif b==3
pic=imread('correct.jpg');
image(pic)
score = score + 1;
elseif b==5
pic=imread('wrong.jpg');
swing=1; %break the while loop
image(pic)
pause(2)
pic=imread('gameover.jpg'); %load game over picture
image(pic) %show game over picture
disp('YOUR SCOER:') %display the score
disp(score)
pause(4)
end %end of while loop
pause(2);
end