Final Project

Fishing game

Turn left or right to throw the rod.

If the fish snap the bait, turn the phone back to pull the rod back.

If the phone aren't pull back in time, the fish will swim away.

Demo

Code

clear all

global go;


ready=0;

m = mobiledev;

pic=imread('start.jpg');

image(pic);

while ready==0

pause(1);


m.Logging = 1;

pause(2);

m.Logging = 0;

[or,tor] = orientlog(m);

y = or(:,3);

d = y(end);

if d>=-25&&d<=25

pic=imread('fish.jpg');

image(pic);

ready=0;

elseif d>25

pic=imread('right.jpg');

image(pic);

ready=1;

go=0;

elseif d<-25

pic=imread('left.jpg');

image(pic);

ready=1;

go=0;

end


while go==0

pause(2)

m.Logging = 1;

pause(2);

m.Logging = 0;

[or,tor] = orientlog(m);

x = or(:,3);

e = x(end);

sim(sec');

w = simout;

if w==1

pic=imread('fail.jpg');

image(pic);

ready=0;

go=1;

elseif w==0

pic=imread('catch.jpg');

image(pic);

ready=0;

go=1;

end

pause(2);

end

end

Simulink

Stateflow