📄 cogame.m
字号:
% ATLAST65中向量合成竞赛的程序cogame
% 《工程线性代数(MATLAB版)》引用
% 陈怀琛,高淑萍,杨威合编,电子工业出版社,2007年6月
% COGAME is an M-file for playing the coordinate game.
% The command cogame will generate a graph and a menu
% of levels. The player can choose any one of four levels
% of play or choose the two person game. For the basic game
% two vectors u and v and a target point O (a small blue circle)
% are drawn in the plane. The player is prompted to input scalars
% a and b so that the vector au+bv has its tip in the interior of
% the O. The resulting vector is plotted each time the player
% inputs a and b. In the two person version, the first player
% inputs u, v, and O and the second player must find a and b.
% The two players then reverse roles and the game is scored based
% on the number of guesses. The player with the lower score wins.
%
% Clicking on the clear guesses button will clear all but the last
% arrow. Clicking the button a second time in the same game
% will clear all of the arrows.
%
% Original version written by Bruce Yoshiwara.
% Revised by Steve Leon and Alex Bondarenko.
% Modified by Emily Moore to accept all user interaction
% on the graphics screen.
%Clean up the space
clc;
clear;
%Set up the Figure Window with level buttons
%
global FigureH;
%Figure Window
FigureH = figure('MenuBar','none',...
'NumberTitle','off','Name','Coordinate Game',...
'Units','normalized',...
'Position', [0.3 0.3 0.6 0.6],...
'Color','cyan');
%
%Graphics axes
AxesH = axes('Box','on',...
'Color','white',...
'NextPlot','add',...
'Position', [0.35 0.1 0.6 0.8]);
axis([-2,2,-2,2]); axis equal; axis square;
editcolor = [.85 .85 .85];
labelcolor = [.75 .75 .75];
framecolor = [.5 .5 .5];
flft = .03; % frame for menus dimensions
fwd = .25;fbot = .5;fht = .49;inc = .015;
lft = flft + inc;
wd = fwd - 2*inc;
ht = .045;
bot = fbot + fht - inc - ht;
%
%Set up Levels Menu
%
%The Frame for the Menu
LevelsFrame = uicontrol(FigureH,'Style','frame',...
'Units','normalized','Position', [flft fbot fwd fht]);
%
%Title of the Menu
MenuTitle = uicontrol(FigureH,'Style','text',...
'Units','normalized','Position', [lft bot wd ht],...
'String','Game Choices');
%
%Level 1 button
Level1H = uicontrol(FigureH,'Style','push',...
'String','Level 1',...
'Units','normalized','Position', [lft bot-ht-inc wd ht],...
'CallBack','levels(1)');
%
%Level 2 button
Level2H = uicontrol(FigureH,'Style','push',...
'String','Level 2',...
'Units','normalized','Position', [lft bot-2*(ht+inc) wd ht],...
'CallBack','levels(2)');
%
%Level 3 button
Level3H = uicontrol(FigureH,'Style','push',...
'String','Level 3',...
'Units','normalized','Position', [lft bot-3*(ht+inc) wd ht],...
'CallBack','levels(3)');
%
%Level 4 button
Level4H = uicontrol(FigureH,'Style','push',...
'String','Level 4',...
'Units','normalized','Position', [lft bot-4*(ht+inc) wd ht],...
'CallBack','levels(4)');
%
%Level 5 button
Level5H = uicontrol(FigureH,'Style','push',...
'String','Two Person Game',...
'Units','normalized','Position', [lft bot-5*(ht+inc) wd ht],...
'CallBack','levels(5)');
uicontrol( gcf, ...
'Style', 'push', ...
'Units', 'normalized',...
'Position', [lft bot-6*(ht+inc) wd ht],...
'String', 'Clear guesses', ...
'Callback', 'clrarrow' )
QuitH = uicontrol(FigureH,'Style','push',...
'String','Quit',...
'Units','normalized','Position',[lft bot-7*(ht+inc) wd ht],...
'CallBack','close(gcf)');
fbot = .03;
fht = .45;
bot = fbot + fht - ht - inc;
uicontrol( gcf, ...
'Style', 'frame', ...
'Units', 'normalized',...
'Position', [flft, fbot, fwd, fht])
% Frame
uicontrol( gcf, ...
'Style', 'text', ...
'Units', 'normalized', ...
'Position', [lft, bot, wd, ht], ...
'String', 'enter components' ) % Label box
uicontrol( gcf, ...
'Style', 'edit', ...
'Units', 'normalized', ...
'Position', [lft, bot-ht-inc, wd, ht], ...
'String', '', ...
'BackgroundColor', editcolor, ...
'Tag', 'enterpair', ...
'Callback', 'coenter' ) % Entry box
uicontrol( gcf, ...
'Style', 'edit', ...
'Units', 'normalized', ...
'Position', [lft, fbot+inc, wd, fht - 2*ht - 4*inc], ...
'Max', 10, ...
'String', '', ...
'Tag', 'storepairs', ...
'BackgroundColor', editcolor ) % Store box
fwd = .35;
wd = fwd - 2*inc;
flft = .3;
fht = .34;
bot = fbot + fht - ht - inc;
lft = .3+inc;
wd1 = wd/3;
wd2 = 2*wd1;
uicontrol( gcf, ...
'Style', 'frame', ...
'Units', 'normalized', ...
'Position', [ flft, fbot, fwd, fht], ...
'Visible', 'off', ...
'Tag', 'twoperson' )
uicontrol( gcf, ...
'Style', 'text', ...
'Units', 'normalized', ...
'Position', [ lft, bot, wd, ht], ...
'String', 'Player 1: Enter your challenge.', ...
'Visible', 'off', ...
'Tag', 'twoperson' )
uicontrol( gcf, ...
'Style', 'text', ...
'Units', 'normalized', ...
'Position', [ lft, bot-ht-inc, wd1, ht], ...
'String', 'u', ...
'Visible', 'off', ...
'Tag', 'twoperson' )
uicontrol( gcf, ...
'Style', 'edit', ...
'Units', 'normalized', ...
'Position', [ lft+wd1, bot-ht-inc, wd2, ht], ...
'String', '', ...
'Visible', 'off', ...
'Background', editcolor, ...
'Tag', 'twoperson' )
uicontrol( gcf, ...
'Style', 'text', ...
'Units', 'normalized', ...
'Position', [ lft, bot-2*(ht+inc), wd1, ht], ...
'String', 'v', ...
'Visible', 'off', ...
'Tag', 'twoperson' )
uicontrol( gcf, ...
'Style', 'edit', ...
'Units', 'normalized', ...
'Position', [ lft+wd1, bot-2*(ht+inc), wd2, ht], ...
'String', '', ...
'Visible', 'off', ...
'Background', editcolor, ...
'Tag', 'twoperson' )
uicontrol( gcf, ...
'Style', 'text', ...
'Units', 'normalized', ...
'Position', [ lft, bot-3*(ht+inc), wd1, ht], ...
'String', 'target', ...
'Visible', 'off', ...
'Tag', 'twoperson' )
uicontrol( gcf, ...
'Style', 'edit', ...
'Units', 'normalized', ...
'Position', [ lft+wd1, bot-3*(ht+inc), wd2, ht], ...
'String', '', ...
'Visible', 'off', ...
'Background', editcolor, ...
'Tag', 'twoperson' )
uicontrol( gcf, ...
'Style', 'push', ...
'Units', 'normalized', ...
'Position', [ lft+wd1, bot-4*(ht+inc)-inc, wd1, ht], ...
'String', 'Draw', ...
'Visible', 'off', ...
'Tag', 'twoperson', ...
'Callback', 'levels(6)' )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -