LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-03-2016, 08:00 PM   #1
Seattlesweet
LQ Newbie
 
Registered: May 2016
Posts: 5

Rep: Reputation: Disabled
Question Random Color Guessing Game


Thanks!

Last edited by Seattlesweet; 06-07-2016 at 10:24 PM.
 
Old 06-05-2016, 12:10 PM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,388

Rep: Reputation: 398Reputation: 398Reputation: 398Reputation: 398
You mean display colors in the terminal?
There are some escaped code sequences
http://wiki.bash-hackers.org/scripting/terminalcodes
Code:
space="    "
for i in 1 2 3 4 5; do
  echo -e "\033[4${i}m${space}\033[0m"
done
 
Old 06-05-2016, 12:32 PM   #3
dab1414
Member
 
Registered: May 2011
Location: OK, USA
Distribution: Slackware 14.1_64
Posts: 70

Rep: Reputation: 50
look at this

or even
Code:
shuf -n 1 filename
just have a seperate file with one color per line
 
Old 06-07-2016, 06:58 AM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,661

Rep: Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256
Check the tput (how to use info) and terminfo man pages (how to set colors, and the options for using colors).
 
Old 06-07-2016, 10:15 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,437

Rep: Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842
hmmm ... I see where everyone else is going, but my first thought was, pick a colour from a set like red, blue, green or yellow (ie. like the set of numbers in original problem).

So if above was what you were looking for I would place the colours in an array so you can use your number randomizer as the index and then have the user enter a colour.

Now the gotcha would be to remember that text matching is case sensitive, so blue and Blue are not the same, so it would be up to you on how you would either overcome this issue or just tell
the user he/she is wrong if not spelt the same
 
Old 06-07-2016, 10:29 AM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,661

Rep: Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256Reputation: 1256
Welll, the shell includes operations for converting to lowercase...
 
Old 06-07-2016, 12:13 PM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,437

Rep: Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842
Quote:
Originally Posted by jpollard View Post
Welll, the shell includes operations for converting to lowercase...
Yes ... I was kind of leaving that for the user to work out
 
Old 06-07-2016, 04:46 PM   #8
Seattlesweet
LQ Newbie
 
Registered: May 2016
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thumbs up Thank You

I have figured it out! Thanks for the input everyone
 
Old 06-07-2016, 05:38 PM   #9
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,437

Rep: Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842Reputation: 2842
Please remember to share your findings so someone else may learn from your new found knowledge.

Also, please remember to mark the question as SOLVED
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Strategy Game 'Unknown Horizons' Gets Random Maps and New Graphics in Latest Update LXer Syndicated Linux News 0 07-03-2011 03:10 AM
DISCUSSION: [Hari's Linux Corner] Random Linux Game: foobillard vharishankar LQ Articles Discussion 0 12-17-2006 09:36 PM
DISCUSSION: [Hari's Linux Corner] Random Linux Game: Wormux vharishankar LQ Articles Discussion 0 10-29-2006 06:44 AM
DISCUSSION: [Hari's Linux Corner] Random Linux game: KGoldRunner vharishankar LQ Articles Discussion 3 09-27-2006 10:54 AM
Random Number Game tearinox Programming 4 08-20-2004 10:12 PM


All times are GMT -5. The time now is 08:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration