【发布时间】:2018-04-17 19:22:16
【问题描述】:
我目前正致力于在 MATLAB 中创建基于 GUI 的 BlackJack 游戏。我为庄家手和闲家手设置了两个轴,如下所示:
self.window = figure('Name', 'Blackjack',...
'Units', 'normalized',...
'Position', [.02, .05, .95, .85]);
self.dealerHand = axes('Parent', self.window,...
'XLimMode', 'manual',...
'XLim', [0, 10],...
'YLimMode', 'manual',...
'YLim', [0, 1],...
'Title', 'Dealer',...
'Units', 'normalized',...
'Position', [.05, .70, .90, .25]);
self.playerHand = axes('Parent', self.window,...
'XLimMode', 'manual',...
'XLim', [0, 10],...
'YLimMode', 'manual',...
'YLim', [0, 1],...
'Title', 'Player',...
'Units', 'normalized',...
'Position', [.05, .20, .90, .25]);
如您所见,我已将“手”XLim 和 YLim 模式都设置为手动模式。但是,当我运行此脚本时:
bjWindow = BlackJackWindow;
deck = DeckOfCards;
deck.shuffle
playerHand{1} = deck.cards{1};
dealerHand{1} = deck.cards{2};
playerHand{2} = deck.cards{3};
dealerHand{2} = deck.cards{4};
hold on
image(bjWindow.dealerHand, [0, 1], [0, 1], dealerHand{1}.img)
image(bjWindow.dealerHand, [1, 2], [0, 1], dealerHand{2}.img)
hold off
hold on
image(bjWindow.playerHand, [0, 1], [1, 0], playerHand{1}.img)
image(bjWindow.playerHand, [1, 2], [1, 0], playerHand{2}.img)
hold off
庄家“手”自动调整大小并拉伸第二张牌,如下所示:
如果我在第一个代码块中颠倒手牌的顺序,则错误发生在玩家“手牌”中。换句话说,在初始化窗口时首先创建的任何轴都会出现此错误。另一个不那么重要的问题,因为我找到了解决方法,为什么玩家“手”翻转轴,这样我必须将 y 位置设置为 [1, 0] 而不是 [0, 1]?
【问题讨论】:
标签: image matlab matlab-figure