Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use matlab to solve This task is based on your completed work in Credit Task 1 (

ID: 3890089 • Letter: U

Question

Use matlab to solve

This task is based on your completed work in Credit Task 1 (question 2) and Distinction Task 1. You will design a game interface in a MATLAB program named HDTask1.m. In this game, an animation should be created to display the flying trajectories of the ball shot from a fixed initial height and fixed initial velocity at release. The game player will attempt to adjust the release angle (shooting angle) of the ball to hit a board placed at the ground. Once the ball hits the board, the player will score one point. Then, the board will be randomly re-located to another position for the player to attempt another round. The specific design requirements are given below: • Initial height of ball at release is fixed at 1.5 m. • Initial velocity of ball at release is fixed at 4 m/s. • Board length is of 0.5 m and located at height 0 horizontally. • Diameter of ball is approximately one-third of the board length. • The ball should be at rest on the board for at least 0.5 second once hit. • The should be randomly a range by ball for board re-located within reachable the each new round. • Scores should be displayed. • The player could adjust the shooting angle in command window and command the action of shooting. • The program should have a command for player to exit the program. • The program should handle exceptions such as when player enters an invalid shooting angle, etc. • The program should not crash MATLAB during running line, good reliability). • You may add additional functions to your program to make it funny.

Explanation / Answer

% Game Description:
% There are n bags, each can contain any number of balls. Two players take
% turns. Each player chooses a bag, and takes out any number of balls from
% the bag. The one who takes the last ball wins.

function Ballgame()
clear;clc;
first=input('First Player Name: ','s');
second=input(' Second Player Name: ','s');
fprintf(' ---Input number of bags, and balls containing in those bags: --- ')
bags=input('Enter no. of bags: ');
for i=1:bags
fprintf(' Enter no. of balls in bag %d: ',i);
balls(i)=input('');
end
fprintf(' Game Starts! ')
ma=0;mb=0;
while(sum(balls)~=0)
fprintf(' %s! pick a bag: ',first);
a=input('');
while((a>bags) || ( a<=0) || (balls(a)==0))
fprintf('There is no bag or balls in it! pick again: ');
a=input('');
end
fprintf('Pick number of balls from bag %d: ',a);
a1=input('');
while(balls(a)-a1<0)
fprintf('No enough balls! pick again from bag %d: ',a);
a1=input('');
end
balls(a)=balls(a)-a1;
balls(balls<0)=0;
k=sum(balls);
ma=ma+1;
if(k==0)
message = sprintf('%s Won the Game! in %d moves',first,ma);
uiwait(msgbox(message));
return;
end
display(balls);
if(k~=0)
fprintf(' %s! pick a bag: ',second);
b=input('');
while((b>bags) || (b<=0) || (balls(b)==0))
fprintf('There is no bag or balls in it! pick other bag: ');
b=input('');
end
fprintf('Pick number of balls from bag %d: ',b);
b1=input('');
while(balls(b)-b1<0)
fprintf('No enough balls! pick again from bag %d: ',b);
b1=input('');
end
balls(b)=balls(b)-b1;
balls(balls<0)=0;
k=sum(balls);
mb=mb+1;
if(k==0)
message = sprintf('%s Won the Game! in %d moves',second,mb);
uiwait(msgbox(message));
return;
end;
display(balls);
end
end