Displaying multi line functions next to eachother

1 Ansicht (letzte 30 Tage)
Daniel Volan
Daniel Volan am 28 Okt. 2020
Kommentiert: Jan am 28 Okt. 2020
I am creating Blackjack and I made a function that creates the card using multiple lines of fprintf and and i statement displaying the correct card name and color in the middle. I want to be able to display these cards next to eachother with ease in the command window like a playing board. This is what I have written as the function:
function[cardName] = cardTemplate(cardName,pickCard)
fprintf('\t _______________\n');
fprintf('\t| |\n');
fprintf('\t| |\n');
fprintf('\t| |\n');
fprintf('\t| |\n');
if pickCard<27 %red card
fprintf('\t| ');
if pickCard==10||pickCard==23
fprintf(2,'%s ',cardName);
else
fprintf(2,'%s ',cardName);
end
fprintf(' |\n');
else %black card
if pickCard==10||pickCard==23
fprintf('\t| %s |\n',cardName);
else
fprintf('\t| %s |\n',cardName);
end
end
fprintf('\t| |\n');
fprintf('\t| |\n');
fprintf('\t| |\n');
fprintf('\t| |\n');
fprintf('\t|_______________|\n\n');
end
Since 10's are one character longer in the string I need to remove a space for those and also have the red text for the red cards. pickCard is a number 1-52 that is assigned a certain card and defined in a separate function.
If there is some easy way I could do this please let me know!
  1 Kommentar
Jan
Jan am 28 Okt. 2020
It is a bad idea to use the command window for such output. Do you really have a good reason to avoid a GUI?

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Card games finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by