⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 show.m

📁 国际象棋程序,解压到当前目录,在matlab窗口输入chess即可应用
💻 M
字号:
function handle = show(fig_name,pos,color)
% show  displays a chess figure.
% A chess figure is displayed at a certain position.
% 
% Note: There are currently two sets of chess figures available.
%
% Inputs:
% * fig_name ... name of the chess figure
% * pos ... the position of the chess figure
% * color ... color of the chess figure (black or white)
% * global board ... structure of the chess board and related information
% * global layer ... display layer of graphic objects (z-coordinate)
%
% Outputs:
% * handle ... handle to chess figure
%
% Example
% Assume there is a global board and global layer variable defined.
% To display a white Knight at c3 [3 6] you would type
% |show('N',[3 6],1)|.
%
% See also: setFiguresPosition, Knight, Chess
%
%% Signature
% Author: W.Garn
% E-Mail: wgarn@yahoo.com
% Date: 2006/03/23 12:00:00 
% 
% Copyright 2006 W.Garn
%
global board;
global layer;

handle=[];
switch board.which_set
    case 1 % just letters
        switch fig_name
            case 'Pawn'
                fig = 'p';
            case 'Knight'
                fig = 'n';
            case 'Bishop'
                fig = 'b';
            case 'Rook'
                fig = 'r';
            case 'Queen'
                fig = 'q';
            case 'King'
                fig = 'k';
            otherwise
                fig = 'x';
        end
        if color %white
            fig = upper(fig);
        else
            fig = lower(fig);
        end

        handle = text(pos(2)-.5,9-pos(1)-.5,layer.figures,fig ,'FontName','Comic Sans MS','FontSize',25,'Color','k','HorizontalAlignment','center');
        
    case 2 % Basic set
       switch fig_name
            case 'Pawn'
                fig = 'p';
            case 'Knight'
                fig = 'n';
            case 'Bishop'
                fig = 'b';
            case 'Rook'
                fig = 'r';
            case 'Queen'
                fig = 'q';
            case 'King'
                fig = 'k';
            otherwise
                fig = 'x';
       end
        
        if fig ~='x'
            directory = 'images\basic\';
            name = '120px-Chess_tile_';
            ext = '.png';
            if color %white (attention - transparency issues)
                color_letter='l';
            else
                color_letter='d';
            end
            file_name = [directory name lower(fig) color_letter ext];
            [X, map, alpha]  = imread(file_name);
            %handle = image(pos(2)-1+[0 1],8-pos(1)+[0 1],mirrorImage(X),'AlphaData',mirrorImage(alpha));
            handle = image(pos(2)-1+[.1 .9],8-pos(1)+[.1 .9],mirrorImage(X),'AlphaData',mirrorImage(alpha));
            
            % There are some major transparency issues!!!
            set(handle,'AlphaDataMapping','direct');

        end
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -