Borrar filtros
Borrar filtros

Guess my favourite colour!

3 visualizaciones (últimos 30 días)
Sohail Nadeem
Sohail Nadeem el 27 de Feb. de 2019
Respondida: Stephen23 el 2 de Abr. de 2019
I want to make a game where the user has to guess my favourite colour
They will get 3 attempts and if they fail to guess the right colour the game will end.
So far i have the basics on how to make this for numbers. I know i can choose the answer as let say 4 and if the user says anything higher or lower theyre wrong. If they say 4 theyre correct and the game has ended. I dont know how to convert this to colours, could i assign each colour a number?
Could problems also arise if i code in the answer as 'black' and the user types 'Black', would matlab recognise these as different?

Respuestas (2)

Bob Thompson
Bob Thompson el 2 de Abr. de 2019
You are going to have several problems with doing any kind of comparison of the color answers to make them relate to numbers. This is simply because you have to find a relationship that already exists before you can do so. I recommend looking something up on google and declaring that that is what you are using in the rules of you game if you decide to go this way.
As for checking of something is correct or not in MATLAB, you can use strcmp, regexp, or just == to determine if an input text is equal to a predefined answer. I believe there are ways to check for upper and lower case conditions, but I haven't personally tried exploring them.
For a more detailed answer than that, feel free to post what you have so far for your code and we can work with it.
Also, I recommend looking over the File Exchange, as there is likely something similar to what you're trying to do available on there.
  1 comentario
Walter Roberson
Walter Roberson el 2 de Abr. de 2019
strcmpi(). Or strcmp() after using lower() or upper() on both parts.

Iniciar sesión para comentar.


Stephen23
Stephen23 el 2 de Abr. de 2019
You will need to:
  • Decide on a colorspace to measure the color differences in: https://en.wikipedia.org/wiki/Color_difference . For a simple project like this CIELAB is probably adequate.
  • Decide how to encode the three dimensions (which most common colorspaces have) into feedback for the users, e.g. "My color is more blue", "My color is lighter". Using CIELAB, CAM02, DIN 99, or any similar colorspace makes this quite easy (just compare and give feedback for each dimension independently).
If you want to display the colors as well then you will need to obtain a list of color RGB values and their names: one easy solution is to download my FEX submssion colornames, which converts from RGB to names and from names to RGB:
It already handles colornames ignoring the character case and even the space characters (in most cases). Otherwise you can simply use strcmpi to perform a case-insenstive match of character vectors / strings.

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by