2
好吧,現在我正嘗試通過Matlab編碼創建連接四個遊戲;現在遊戲仍然是嬰兒,但我的問題是我無法在每個網格廣場上繪製圖形,或者我無法獲得「圓形」圖形進行繪製。請以任何可能的方式提供幫助。如果有人知道任何連接四個matlab教程,它將不勝感激。連接四個matlab
function [] = Kinect4(nrRows, nrCols)
board = zeros(nrRows, nrCols);
nrMoves = 0;
set(gca, 'xlim', [0 nrCols]);
set(gca, 'ylim', [0 nrRows]);
for r = 1 : 1 : nrRows - 1
line([0, nrCols], [r, r], ...
'LineWidth', 4, 'Color', [0 0 1]);
end
for c = 1 : 1 : nrCols - 1
line([c, c], [0, nrRows], ...
'LineWidth', 4, 'Color', [0 0 1]);
end
DrawBoard(nrRows, nrCols)
hold on;
while nrMoves < nrRows * nrCols %Computes ability to move polygon
[x, y] = ginput(1);
r = ceil(y); % convert to row index
c = ceil(x); % convert to column index
angles = 0 : 1 : 360;
x = cx + r .* cosd(angles);
y = cy + r .* sind(angles);
plot(x, y, 'Color', [1 1 1], 'LineWidth', 3);
axis square;
end
end
非常感謝你的幫助。我的下一個問題是,你將如何實現引力並檢查單元格是否已經被填充?我不需要確切的編碼,但如何去做的方向將非常感激。 – FunnyBro777
@ FunnyBro777有很多方法可以做到這一點。一種可視化的方式是使用「board」martix來跟蹤已填充的單元格。所以如果一個單元被佔用,相應的元素將不爲零。當玩家進入下一步棋子時,'ginput'只關心列('x')的位置,並替換該棋盤矩陣列中最後一個零元素。您可以將其翻轉爲1或2以跟蹤哪個球員已經進行了移動。 – mythealias
另一種選擇是使用一個行向量,並且每次玩家移動時只增加一個相應的列。您不需要立即吸引玩家的動作,因爲無法跟蹤所做的動作。 – mythealias