final project

code

number = 3;

imshow('main.jpg');

while number>0

way = unidrnd(2);

clear m;

m = mobiledev;

switch way

case 1

imshow('leftready.PNG');

[Fx,Fs] = audioread('ready.mp3');

sound(Fx,Fs);

pause(5);

case 2

imshow('rightready.PNG');

[Fx,Fs] = audioread('ready.mp3');

sound(Fx,Fs);

pause(5);

end

m.Logging = 1;

pause(2);

m.Logging = 0;

test=m.Orientation(3);

assignin('base','t',max(test));

load_system('tennisway');

sim('tennisway');

result=max(simout);

if(result==1)

switch way

case 1

imshow('shake.PNG');

pause(0.5);

m.Logging = 1;

pause(1);

m.Logging = 0;

az=m.Acceleration(3);

assignin('base','pz',max(az));

load_system('tennisshake');

sim('tennisshake');

zresult=max(zsimout);

[Fx,Fs] = audioread('hit.mp3');

sound(Fx,Fs);

imshow('leftready.PNG');

pause(0.5);

imshow('lefthit.PNG');

pause(1.5);

if(zresult==2)

number=number-1;

end

if(zresult==1)

[Fx,Fs] = audioread('lose.mp3');

sound(Fx,Fs);

imshow('lose.PNG');

pause(2);

break;

end

case 2

[Fx,Fs] = audioread('lose.mp3');

sound(Fx,Fs);

imshow('lose.PNG');

pause(2);

break;

end

elseif(result==2)

switch way

case 1

[Fx,Fs] = audioread('lose.mp3');

sound(Fx,Fs);

imshow('lose.PNG');

pause(2);

break;

case 2

imshow('shake.PNG');

pause(0.5);

m.Logging = 1;

pause(1);

m.Logging = 0;

az=m.Acceleration(3);

assignin('base','pz',max(az));

load_system('tennisshake');

sim('tennisshake');

zresult=max(zsimout);

[Fx,Fs] = audioread('hit.mp3');

sound(Fx,Fs);

imshow('rightready.PNG');

pause(0.5);

imshow('righthit.PNG');

pause(1.5);

if(zresult==2)

number=number-1;

end

if (zresult==1)

[Fx,Fs] = audioread('lose.mp3');

sound(Fx,Fs);

imshow('lose.PNG');

pause(2);

break;

end

end

elseif(result==3)

[Fx,Fs]=audioread('lose.mp3');

sound(Fx,Fs);

imshow('lose.PNG');

pause(2);

break;

end

end

if(number==0)

imshow('win.PNG');

[Fx,Fs] = audioread('win.mp3');

sound(Fx,Fs);

pause(5);

end