Skip to main content

Match Color

Basic Color matching game, press spacebar to create the tiles and target tile. The giant box at the bottom center is the tile to match.


Justin Ramos
(jramos)
Program to test a users color aptitude.

Links

Home Page
http://www.box.net/shared/v1gra8tyo3kmom8nvkbt

Releases

Match Color 1 — 19 Jul, 2011

Pygame.org account Comments

  • josmiley 2011-07-20 21:45:41

    a little shorter ...

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    from pygame import *
    from random import randint,choice

    scr = display.set_mode((480,485))
    tiles = [scr.fill(randint(0,0xffffff),(x,y,20,20)) for x in range(5,480,25) for y in range(5,255,25)]
    target = scr.fill(scr.get_at(choice(tiles).center),(205,300,75,75))
    display.flip()
    while len(tiles) > 1:
        ev = event.wait()
        if ev.type == MOUSEBUTTONDOWN:
            index = Rect(ev.pos,(0,0)).collidelist(tiles)
            if index > -1 and tiles[index] == target:
                display.update(scr.fill(0,tiles.pop(index)))
                target = display.update(scr.fill(scr.get_at(choice(tiles).center),(205,300,75,75)))
        elif ev.type == KEYDOWN and ev.key == K_SPACE:
            target = display.update(scr.fill(scr.get_at(choice(tiles).center),(205,300,75,75)))
        elif ev.type == QUIT: break

    josmiley 2011-07-20 21:53:47

    oops ....

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    from pygame import *
    from random import randint,choice

    scr = display.set_mode((480,485))
    tiles = [scr.fill(randint(0,0xffffff),(x,y,20,20)) for x in range(5,480,25) for y in range(5,255,25)]
    target = choice(tiles)
    scr.fill(scr.get_at(choice(tiles).center),(205,300,75,75))
    display.flip()
    while len(tiles) > 1:
        ev = event.wait()
        if ev.type == MOUSEBUTTONDOWN:
            index = Rect(ev.pos,(0,0)).collidelist(tiles)
            if index > -1 and tiles[index] == target:
                display.update(scr.fill(0,tiles.pop(index)))
                target = choice(tiles)
                display.update(scr.fill(scr.get_at(target.center),(205,300,75,75)))
        elif ev.type == KEYDOWN and ev.key == K_SPACE:
            target = choice(tiles)
            display.update(scr.fill(scr.get_at(target.center),(205,300,75,75)))
        elif ev.type == QUIT: break

    Ramosj85 2011-07-22 01:27:47

    The code is helpful.  A little tough to read, but it is interesting to me.