Current location - Education and Training Encyclopedia - Graduation thesis - Matlab game code
Matlab game code
Give you a simulation shooting program of teacher Zhou Qunyi from the Institute of Bioelectricity of Hunan University for your reference!

% target making and shooting score

Clear% clears the variable.

n = 10; % number of rings

th =(0:360)* pi/ 180; ? % angle vector

Figure? % Create a graphic window

Axis? Equality? % equalizes the coordinate intervals.

Keep? On the% hold image

cc = ' gcmyrbgcmy? % color character (1)

For what? I= 1:n% period times the number of rings (2)

x =(n+ 1-I)* cos(th); ? % abscissa

y =(n+ 1-I)* sin(th); ? % ordinate

Fill(x, y, cc(i))% color fill (3)

End% ends the loop.

s = 0; ? Percentage of total scores cleared

ht 1=text(-n,n- 1,'',' FontSize ', 16); ? % Get Text Handle (4)

ht2=text(-n,-n+ 1,'',' FontSize ', 16); % Get Text Handle (4)

For what? I= 1:n% number of cycles.

[x,y]= ginput( 1); ? % get coordinates (5)

plot(x,y,' k . ',' MarkerSize ',20)? % Draw a dot

Set(ht 1,' String', [' times:', num2str(i)])% Number of times to set the string (6)

r=sqrt(x^2+y^2); ? % find the bull's-eye distance of the shooting point

M = n- floor (r); Percentage of scores (7)

What if? m & gt0? % If the score is greater than zero (8)

Text (x, y, num2str (m),' fontsize', 16)% displays the score (9).

s = s+m; ? Cumulative score percentage

Set(ht2,' String', [' total score:', num 2 str(s)]% sets the total score string (10).

End% end condition

End% ends the loop.