Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Scenario: while programming you have a sudden nostalgic urge for the '80s and cheesy games.

Requirements: Make a GUI program (text probably won't work) for Simon, the game. Input can be clicking, or pressing a key. You should divide the screen into 4 regions: yellow, blue, red, green. When the game starts, a random color lights up and you activate it. Then, two lights come on, one after the other, and you need to activate those in order, etc. The game ends when you press the wrong color.

Bonuses:

-100 if you include sound (a different note played when pressing each region and when the game shows you the colors)

-25 if you include a score counter.

share|improve this question
9  
GUI and code-golf don't generally work together. –  user80551 Mar 29 at 6:40
2  
This should be doable in Minecraft. Wouldn't surprise me if someone already has. Don't know how one'd submit that here though... –  Kninnug Mar 29 at 10:58
    
@Kninnug the amount of blocks * bytes per block;) –  Outlaw Lemur Mar 29 at 18:08

5 Answers 5

up vote 8 down vote accepted

Bash 318 297 281 273 268 244 240-125=115

This is primarily a response to "Text probably won't work"; the following text-based bash script runs fine in Konsole, gnome-terminal etc. on my Ubuntu 14.04 machine. To create the regions of colour it sets the text background color. In fact, adding text makes the game more accessible to color-blind players. To make the game yet more accessible it reads the characters that the player needs to press (it assumes that espeak is installed). It also assumes that the only file matching /d*/ur*/ is /dev/urandom. For the regions of color to be of non-trivial size you probably want to set the text size to be quite large. Also if you want the regions of color to be quadrants, you have to run it in a terminal that is two characters wide.

To play press y, r, g or b as appropriate.

cat <<"EOF"|sed s/E/`echo -e '\E'`/>simon_golf.sh;bash simon_golf.sh;wc simon_golf.sh
d(){ echo 'Ecx1r09mRx2g10mG
x3y11mYx4b14mBx0m'$s|sed s/.$1"//
s/[rgyb]..//g
s/x/E[48;5;/g";};x(){ d $c;espeak $c;d j;};l(){
for c in $o;{ eval $1;x;};};f(){ o=$o\ `tr -dc yrgb</dev/urandom|head -c1`
l;l 'read -n1 i;[ $c = $i ]||exit;let s++';sleep 1;f;};f
EOF

This solution contains two non-printable ESC characters. For your convenience, the script above contains only printable characters, generates the golfed version and calls it.

See also the original ungolfed version, and the slightly more playable 256 byte version.

The screenshots below are when the yellow light is on and the player's score is 7. The screenshot on the right has been desaturated to simulate colour-blindness.

screenshotBlackandWhite

share|improve this answer
    
Way too big for a code golf... –  Jan Dvorak Mar 29 at 7:02
1  
True. I am here more for the "Programming Puzzles" more than the "Code Golf". –  gmatht Mar 29 at 7:06
    
I have slightly golfed it now. –  gmatht Mar 29 at 11:25

Scratch, 150 – 125 = 25

I'm here for the fun, not the golf.

Edit: The scoring is based on this proposal at the moment. If another scoring system is generally adopted here, feel free to notify me or to edit this answer! For a break-down of this count, please see the comments.

Main program:

main

Individual sprites:

sprite

This is the sprite with number 0. The other sprites have the same script, except the number.

Play with it online.

Screenshot:

screenshot

Note: Please do not press two buttons within 0.3 seconds.

share|improve this answer
    
Ha, that's cool. A pause after a correct answer would be good, though, or some congratulatory sound. It sounds like my last move is part of the pattern. Also, I would play the sounds more slowly than the input cap, since rhythm and tone matching is how people (myself, at least) play... still, I like it. +1 –  krs013 Mar 29 at 8:56
    
Scratch? Srs? Also, the byte count imo should be the total size of the SB2. –  cjfaure Mar 29 at 11:06
    
@Trimsty Then it would be 126833 bytes (including the wav sound files etc), which is why I said "I'm here for the fun, not the golf." –  ace Mar 29 at 11:11
    
According to the scoring I suggested here, the score is 60 (27 blocks, 20 chars/digits in constants, 8 operators, 5 variable uses). With bonuses, you get -65. –  ugoren Mar 30 at 6:34
    
@ugoren This is actually only a partial answer. There are 4 sprites, and only the script for one is shown, since the other sprites have almost identical scripts except the number. I will update the answer based on your scoring. Thanks. –  ace Mar 30 at 15:53

Mathematica, 409 - 125 = 284

k = 2;
p = Tuples[{0, 1}, 2];
f[c_, p_] := 
 EventHandler[{c, Rectangle[p]}, 
  "MouseClicked" :> (AppendTo[x, p]; Beep[]; g)]
h[R_] := (i = 1; 
  RunScheduledTask[
   H = If[OddQ@i, 
     Beep[]; {EdgeForm[{Thickness[0.02], Black}], FaceForm[], 
      Rectangle@R[[Ceiling[i/2]]]}, {}]; i++, {.3, 2 Length@R}])
s := (m = 0; x = {}; h[R = RandomChoice[p, k]];)
g := (m++; If[Take[R, m] != x, k = 2; s, If[m == k, k++; s]])
Dynamic@Graphics[{MapThread[f, {{Yellow, Red, Blue, Green}, p}], H}, 
  PlotLabel -> k]
s

enter image description here

share|improve this answer

Windows PowerShell (CLI), 272 - 100 - 25 = 147

$d={param($c)cls;sleep -m 99;'R','Y','Blu','Gre'|
%{Write-Host '#' -N -F "$(if($i%4-ne $c){'Dark'})$_";
$i++}};$b={param($c)&$d $c;[console]::Beep(($c+1)*99,700);&$d};
$m=@();$s=0;for(){$m+=0..3|Get-Random;$m|%{&$b $_};$m|%{
if((read-host)-ne $_){$s;exit}&$b $_};$s++;sleep 1}

I've added newlines here to avoid side-scrolling, but it works as one line so the character count is without newlines.

Screenshot: Screenshot of game playing

To play:

  • Open PowerShell ISE (v3), paste script into text editor, press F5 to run.
  • Game will light up a color, play a sound, then wait for input
  • Press a number (0=red, 1=yellow, 2=blue, 3=green) then Enter.
  • If you are wrong it prints the score and quits. (NB. it might exit your console).
  • If you are right it goes for two notes.
  • You have to press Enter between each note when playing the sequence back.

Comments:

  • "divide the screen into 4 regions" - you didn't say they had to be quarters, so they aren't.
  • It's hard to see blue light up on the blue background, but it does.
  • Please run in PowerShell ISE - in the normal prompt "DarkYellow" shows as white.
  • You could arguably golf another 28 characters off by removing some of the timing (still making the game playable), and by interpreting the rule "sound (a note played when pressing and when the game shows you the colors)" to mean "they can all be the same sound - default error DING", but I think that's too far against the spirit of it.
share|improve this answer

ZXBasic: 422 - 100 - 25 = 297

This definitely counts as a nostalgic urge for the '80s...

ZXBasic uses a combination of FreeBASIC type commands and ZX Spectrum BASIC to allow loops and repeats which then turn into TZX format to load into a Spectrum emulator.

This version changes the border (although a legend on screen says which key to press). It plays the same notes as original Simon game (http://en.wikipedia.org/wiki/Simon_%28game%29).

d=0.5:s=0:l=1:t=1:n$="4261":dim m(4)=>{-8,9,1,4}
border 7
while l>0
 cls:a$="":print at 1,1;"Level: ";t;at 2,1;"Score:";s::for i=1 to 4:print at 0,i;paper val(n$(i));ink 0;i:next
 for i=1 to t
  c=1+int(rnd*4)
  border val(n$(c)):beep d,m(c):border 7
  a$=a$+str(c)
 next
 print at 10,1;"your turn"
 p$="":i=1
 do
  pause 100:k$=inkey:print at 6,i;k$
  if k$=a$(i) then s=s+1:print at 2,7;s:beep d,m(val(k$)):i=i+1
  else l=l-1:i=t+1:print "bad luck!"
  end if
 loop until i>t 
 t=t+1:pause 25
end while

Best score In play

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.