Answer to Question #233215 in MatLAB for Patel parth

Question #233215
A simple text-based version of a grid game such as battleship or mine-sweeper.

This is the criteria:
The code that you use to produce that application must use a combination of at least two of:

Loops
Vectors or Arrays
Conditional execution
Optionally, your code might embed:

Functions.
Visualisation of data
1
Expert's answer
2021-09-05T08:24:35-0400
clc
clear all
close all
x2=randi([0,10],1,1);
y2=randi([0,10],1,1);
fprintf("This game has a grid of 10x10 where x and y can vary between 0 and 10 in which you need to guess the exact location\n\n");
dp=20;
while(1)
x1=input("Enter guess of yours for x coordinate: ");
y1=input("Enter guess of yours for y coordinate: ");
d=sqrt((x2-x1)^2+(y2-y1)^2);
if(x2==x1&&y2==y1)
disp("Congratulations you cleared");
break;
end
if(dp>d)
disp("you;re getting closer");
else
disp("you;re getting further away");
end
dp=d;
end

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS