clear;
clc;
disp(' -------------------------------------------------------------------------------- ')
disp(' | |')
disp(' | The Product Game v.2 |')
disp(' | ===================== |')
disp(' | |')
disp(' | To win this game you have to collect at least 420 points |')
disp(' | |')
disp(' | __** Good Luck **__ |')
disp(' | |')
disp(' | Difficulty Levels : |')
disp(' | easy |')
disp(' | medium |')
disp(' | hard |')
disp(' | |')
disp(' | Description : |')
disp(' | (easy) level contains tables from (1) to (10) |')
disp(' | (medium) level contains tables from (1) to (13) generated by random |')
disp(' | (hard) level contains tables (1) to (15) random and limited time |')
disp(' | |')
disp(' | |')
disp(' | ! ENJOY ! |')
disp(' | |')
disp(' | |')
disp(' | Coded by MOHAMED OSAMA |')
disp(' | Copyright CSE Dept. Minia Universty 2007 Inc. ,All Rights Reserved |')
disp(' -------------------------------------------------------------------------------- ')
disp(' ') %leave a line
disp(' ') %leave a line
easy=0; medium=1; hard=3; quit=-1; off=-2; start=-3;
s=0; h=200; s1=0; h1=100; s2=0; h2=180;
disp(' 1) Easy Level')
disp(' ') %leave a line
disp(' This level start in table 1 ,then 2 and so on.')
disp(' You will take 2 points ( Score ) in each problem')
disp(' If you missed any problem you have 2 tries but you will take nothing in your score')
disp(' For testing the game : ')
disp(' - Enter " off " to skip the current table and move to next table ')
disp(' - Press "Enter" button to skip current level and move to next level')
disp(' ') %leave a line
disp(' Enter "start" to start level Enter "quit" to end game')
disp(' ')%leave a line
q=input(' ');
disp(' ')%leave a line
if q==start
for t=[1 2 3 4 5 6 7 8 9 10]
for a=1:10
fprintf(' %d * %d = %d\n',t,a),p=input(''); % Print the product form
r1=t*a; % r1 ===> MATLAB Answer
% The Comparison System
if p==off ; break;
elseif p==quit;return;
end
% Condition1:When you enter a correct answer
if p==r1
disp(' Excellent')
s=s+2;
fprintf(' Your Score : %d / %d\n', s,h) % Print the score
% Condition2:When you enter a wrong answer
elseif p~=r1 % wrong input
disp(' False , You have 2 tries'),disp(' ')% leave a line
p=input(' 1-Try entering correct answer: '); % First try
if p==r1 ; 1;%To avoid displaying two (Exellent)
elseif p~=r1
disp(' False , You have 1 try'),disp(' ')% leave a line
p=input(' 2-Try entering correct answer: '); % Second try
end
if p==r1
disp(' Excellent')
elseif p~=r1
disp(' '),disp(' ')% leave a line
disp(' Game Over ')
disp(' '),disp(' ')% leave a line
return; % End the game
end
%--------------------------------------------------------------
else % No input , the Comparison System will repeat
disp(' Error!!! ,Expected an input'),disp(' ')
p=input(' Enter a valid input : ');
if p==off ; break;
elseif p==quit;return;
end
if p==r1
disp(' Excellent')
s=s+2;
fprintf(' Your Score : %d / %d\n', s,h)
elseif p~=r1
disp(' False , You have 2 tries')
disp(' ')
p=input(' 1-Try entering correct answer: ');
if p==r1 ; 1;
elseif p~=r1
disp(' False , You have 1 try')
disp(' ')
p=input(' 2-Try entering correct answer: ');
end
if p==r1
disp(' Excellent')
elseif p~=r1
disp(' '),disp(' ')% leave a line
disp(' Game Over ')
disp(' '),disp(' ')% leave a line
return; % End the game
end
end
end % End of Comparison System
end
end
elseif q==quit;return;
end
%........................................medium level
disp(' ')%leave a line
disp(' 2) Medium Level')
disp(' ')%leave a line
disp(' The product numbers in this level will be random')
disp(' You will take 4 points ( Score ) in each problem')
disp(' If you missed any problem you have 2 tries but you will take nothing in your score')
disp(' ')%leave a line
disp(' Enter "start" to start level Enter "quit" to end game')
disp(' ')%leave a line
q1=input(' ');
disp(' ')%leave a line
if q1==start
for b=1:25
x=ceil(rand*12); % This is a technique generates numbers 1:12
y=ceil(rand*13); % This is a technique generates numbers 1:13
fprintf(' %d) %d * %d = %d\n',b,x,y),z=input('');
r2=x*y; % r2 ===> MATLAB Answer
% The Comparison System
if z==quit;return;end
if z==r2 ;disp(' Excellent')
s1=s1+4;
fprintf(' Your Score : %d / %d\n', s1,h1)
elseif z~=r2
disp(' False , You have 2 tries'),disp(' ') % leave a line
z=input(' 1-Try entering correct answer: ');
if z==r2 ; 1;
elseif z~=r2
disp(' False , You have 1 try'),disp(' ') % leave a line
z=input(' 2-Try entering correct answer: ');
end
if z==r2 ;disp(' Excellent')
elseif z~=r2
disp(' '),disp(' ') % leave 2 lines
disp(' Game Over ')
disp(' '),disp(' ') % leave 2 lines
return;
end
%---------------------------------------------------------------
else % No input , the Comparison System will repeat
disp(' Error!!! ,Expected an input'),disp(' ') % leave a line
z=input(' Enter a valid input : ');
if z==quit;return;end
if z==r2 ;disp(' Excellent')
s1=s1+1;
fprintf(' Your Score : %d / %d\n', s1,h1)
elseif z~=r2
disp(' False , You have 2 tries'),disp(' ') % leave a line
z=input(' 1-Try entering correct answer: ');
if z==r2 ; 1;
elseif z~=r2
disp(' False , You have 1 try'),disp(' ') % leave a line
z=input(' 2-Try entering correct answer: ');
end
if z==r2 ;disp(' Excellent')
elseif z~=r2
disp(' '),disp(' ') % leave 2 lines
disp(' Game Over ')
disp(' '),disp(' ') % leave 2 lines
return;
end
end
end % End of Comparison System
end
elseif q1==quit;return;
end
% ................................................hard level
disp(' ')%leave a line
disp(' 3) Hard Level')
disp(' ')%leave a line
disp(' The product numbers in this level will be random and in limited time')
disp(' You will take 6 points ( Score ) in each problem')
disp(' If you missed any problem you have 2 tries but you will take nothing in your score')
disp(' You have only 12 sec. to answer each problem and 10 sec. in your tries')
disp(' ')%leave a line
disp(' Enter "start" to start level Enter "quit" to end level')
disp(' ')%leave a line
q2=input(' ');
disp(' ')%leave a line
if q2 == start
for c = 1:30
x1=ceil(rand*14);y1=ceil(rand*15);
tic % This expression start a stopwatch
fprintf(' %d) %d * %d = %d\n',c,x1,y1),z1=input('');
toc % This expression computes the elapsed time
r=x1*y1; % r ===> MATLAB Answer
% The Comparison System
if z1 == quit ; break; end
% If the first answer takes less than 12 sec.
if toc <= 12
if z1 == r ;disp(' Excellent')
s2=s2+6;
fprintf(' Your Score : %d / %d\n', s2,h2)
% If your answer is wrong
% the game will give you 10 sec. in first try
% and 5 sec. in second try
elseif z1 ~= r
disp(' False , You have 2 tries'),disp(' ') % leave a line
tic
z1=input(' 1-Try entering correct answer(you have 10 second): ');% First try
toc
% "10 second" Logic
if toc <= 10
if z1 == r ;disp(' Excellent')
elseif z1 ~= r
disp(' False , You have 1 try'),disp(' ') % leave a line
tic
z1=input(' 2-Try entering correct answer(you have 5 second): ');% Second try
toc
% "5 second" Logic
if toc <= 5
if z1 == r ; disp(' Excellent')
elseif z1 ~= r
disp(' '),disp(' ') % leave 2 lines
disp(' Game Over ')
disp(' '),disp(' ') % leave 2 lines
return;
end
elseif toc > 5
disp(' '),disp(' ') % leave 2 lines
disp(' Game Over ')
disp(' '),disp(' ') % leave 2 lines
return;
end % End of "5 second" Logic
end
elseif toc > 10
disp(' '),disp(' ') % leave 2 lines
disp(' Game Over ')
disp(' '),disp(' ') % leave 2 lines
return; % End the game
end % End of "10 second" Logic
%-------------------------------------------------------------------
else % No input,the comparison system will repeat
disp(' Error!!! ,Expected an input'),disp(' ')
tic
z1=input(' Enter a valid input : ');
toc
if toc <= 12
if z1 == r ;disp(' Excellent')
s2=s2+6;
fprintf(' Your Score : %d / %d\n', s2,h2)
elseif z1 ~= r
disp(' False , You have 2 tries'),disp(' ')
tic
z1=input(' 1-Try entering correct answer(you have 10 second): ');
toc
if toc <= 10
if z1 == r ; disp(' Excellent')
elseif z1 ~= r
disp(' False , You have 1 try'),disp(' ')
tic
z1=input(' 2-Try entering correct answer(you have 5 second): ');
toc
if toc <= 5
if z1 == r;disp(' Excellent')
elseif z1 ~= r
disp(' '),disp(' ')
disp(' Game Over ')
disp(' '),disp(' ')
end
elseif toc > 5
disp(' '),disp(' ')
disp(' Game Over ')
disp(' '),disp(' ')
end
end
elseif toc > 10
disp(' '),disp(' ')
disp(' Game Over ')
disp(' '),disp(' ')
return;
end
end
elseif toc > 12
disp(' Time is out, You have 1 try'),disp(' ')
tic
z1=input(' 3-Try entering an answer(you have 10 second): ');
toc
if toc <= 10
if z1 == r;disp(' Excellent')
elseif z1 ~= r
disp(' '),disp(' ')
disp(' Game Over ')
disp(' '),disp(' ')
return; % End the game
end
elseif toc > 10
disp(' '),disp(' ')
disp(' Game Over ')
disp(' '),disp(' ')
return; % End the game
end
end % End of " No input " logic
end
% If the first answer takes more than 12 sec.
elseif toc > 12
disp(' Time is out, You have 1 try'),disp(' ') % leave a line
tic
z1=input(' 3-Try entering an answer(you have 10 second): ');
toc
if toc <= 10
if z1 == r;disp(' Excellent')
elseif z1 ~= r
disp(' '),disp(' ')
disp(' Game Over ')
disp(' '),disp(' ')
return; % End the game
end
elseif toc > 10
disp(' '),disp(' ')
disp(' Game Over ')
disp(' '),disp(' ')
return; % End the game
end
end % End of Comparison System
end
elseif q2==quit;return;
end
% max(s) ===> score that the player collected in easy level
% max(s1) ===> ===> score that the player collected in medium level
% max(s2) ===> ===> score that the player collected in hard level
% tot ===> the summation of total score
tot=sum(max(s)+max(s1)+max(s2));
disp(' ') % leave a lines
fprintf(' Your Total Score is : %d Points\n',tot)
disp(' '),disp(' ') % leave 2 lines
% 420 ===> score the player have to collect
% If the player collected 420 points or above
if tot == 420 || tot > 420
disp(' ! Congratulations !')
disp(' ') % leave a line
disp(' *** You Won *** ')
% If the player collected less than 420 points
elseif tot < 420
disp(' Sorry , You lost , Try again next time')
end
% -------------------------------------- End of Program ---------------------------------------