I've been making a game of tic tac tow where you can click to enter your "x" or "o" but am having trouble centering each of them and making the "x" or " o" bigger. This is what I have currently.
TTCboard = zeros(3,3);
% for creating the standard tic-tac-toe board in green
figure
plot([.5 3.5],[-1.5 -1.5], 'g','linewidth',1);% creates top horizontal line in board
hold on
plot([2.5 2.5],[-.5 -3.5], 'g','linewidth',1)% creates right-most vertical line
plot([.5 3.5],[-2.5 -2.5], 'g','linewidth',1)% creates bottom horizontal line
plot([1.5 1.5],[-.5 -3.5], 'g','linewidth',1)% creates left-most vertical line
axis off % keeps the X & y-axis off, creating a better looking natural board
hold off% ensures later commands are added to existing board
xticks([0 1 2 3]); yticks([0 1 2 3]);
xticklabels([]); yticklabels([]);
player = 'X'
while true
fprintf('%s click to place a piece\n', player);
[x, y] = ginput(1);
x = floor(x) + 1/2;
y = floor(y) + 1/2;
text(x, y, player);
break;
end
Any tips on how to center the x's/o's and make them bigger?

 채택된 답변

Bob Thompson
Bob Thompson 2021년 3월 15일
편집: Bob Thompson 2021년 3월 15일

0 개 추천

Hmm, maybe I spoke too soon on the centering.
Size can be set by adding a 'name,value' pair to the text command.
text(x,y,player,'Fontsize',24);

댓글 수: 4

Nathan Ross
Nathan Ross 2021년 3월 15일
edit: I was able to figure out the centering issue and move on, thank you very much for your help.
I fixed the centering by adjusting the location of your lines. The issue was that the different boxes ranged from x.5 -> (x+1).5. This meant that 'flooring' the selected range ended up putting you somewhere other than the box you selected, usually.
TTCboard = zeros(3,3);
% for creating the standard tic-tac-toe board in green
figure
plot([0 3],[-1 -1], 'g','linewidth',1);% creates top horizontal line in board
hold on
plot([2 2],[0 -3], 'g','linewidth',1)% creates right-most vertical line
plot([0 3],[-2 -2], 'g','linewidth',1)% creates bottom horizontal line
plot([1 1],[0 -3], 'g','linewidth',1)% creates left-most vertical line
axis off % keeps the X & y-axis off, creating a better looking natural board
hold off% ensures later commands are added to existing board
xticks([0 1 2 3]); yticks([0 1 2 3]);
xticklabels([]); yticklabels([]);
player = 'X'
while true
fprintf('%s click to place a piece\n', player);
[x, y] = ginput(1);
x = floor(x)+0.43;
y = floor(y)+0.5;
text(x, y, player, 'Fontsize', 24);
break;
end
I also made an adjustment to the +0.5 that followed the floor, to better center the X based on font size, but your 'horizontalalignment' name value option is a much better choice.
Nathan Ross
Nathan Ross 2021년 3월 15일
mind if I ask one more question?
Bob Thompson
Bob Thompson 2021년 3월 15일
You're welcome to ask, I will do my best to answer.
I will ask, as politely as I can, that if it's technically a new question it should be posted as a new query, per forum roles. I'm not going to be a stickler, but I believe the intention is to make sure answers that might help other people don't get buried in threads.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Nathan Ross
Nathan Ross 2021년 3월 15일

0 개 추천

Ill post a new thread

카테고리

도움말 센터File Exchange에서 Strategy & Logic에 대해 자세히 알아보기

태그

질문:

2021년 3월 15일

답변:

2021년 3월 15일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by