Displaying multi line functions next to eachother
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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
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?
Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!