1 /* robotfindskitten for maemo
2 * original by Leonard Richardson, 1997
3 * ported to maemo by Thomas Thurman, 2009
6 * gcc -Wall -g rfk.c -o rfk `pkg-config --cflags --libs gtk+-2.0 hildon-1`
12 #include <hildon/hildon.h>
14 #define ARENA_WIDTH 25
15 #define ARENA_HEIGHT 12
17 const int amount_of_random_stuff = 15;
19 const char *explanation =
20 "In this game, you are robot (#). "
21 "Your job is to find kitten. This task is complicated "
22 "by the existence of various things which are not kitten. "
23 "Robot must touch items to determine if they are kitten or "
24 "not. The game ends when robotfindskitten. You may move "
25 "robot about by tapping on any side of robot, or with the "
28 static char* messages[] =
30 "\"I pity the fool who mistakes me for kitten!\", sez Mr. T.",
31 "That's just an old tin can.",
32 "It's an altar to the horse god.",
33 "A box of dancing mechanical pencils. They dance! They sing!",
34 "It's an old Duke Ellington record.",
35 "A box of fumigation pellets.",
36 "A digital clock. It's stuck at 2:17 PM.",
37 "That's just a charred human corpse.",
38 "I don't know what that is, but it's not kitten.",
39 "An empty shopping bag. Paper or plastic?",
40 "Could it be... a big ugly bowling trophy?",
41 "A coat hanger hovers in thin air. Odd.",
42 "Not kitten, just a packet of Kool-Aid(tm).",
43 "A freshly-baked pumpkin pie.",
44 "A lone, forgotten comma, sits here, sobbing.",
45 "ONE HUNDRED THOUSAND CARPET FIBERS!!!!!",
46 "It's Richard Nixon's nose!",
47 "It's Lucy Ricardo. \"Aaaah, Ricky!\", she says.",
48 "You stumble upon Bill Gates' stand-up act.",
49 "Just an autographed copy of the Kama Sutra.",
50 "It's the Will Rogers Highway. Who was Will Rogers, anyway?",
51 "It's another robot, more advanced in design than you but strangely immobile.",
52 "Leonard Richardson is here, asking people to lick him.",
53 "It's a stupid mask, fashioned after a beagle.",
54 "Your State Farm Insurance(tm) representative!",
55 "It's the local draft board.",
56 "Seven 1/4\" screws and a piece of plastic.",
58 "One of those stupid \"Homes of the Stars\" maps.",
59 "A signpost saying \"TO KITTEN\". It points in no particular direction.",
60 "A hammock stretched between a tree and a volleyball pole.",
61 "A Texas Instruments of Destruction calculator.",
62 "It's a dark, amphorous blob of matter.",
64 "It's a mighty zombie talking about some love and prosperity.",
65 "\"Dear robot, you may have already won our 10 MILLION DOLLAR prize...\"",
66 "It's just an object.",
67 "A mere collection of pixels.",
68 "A badly dented high-hat cymbal lies on its side here.",
69 "A marijuana brownie.",
71 "Daily hunger conditioner from Australasia",
73 "Why are you touching this when you should be finding kitten?",
74 "A glorious fan of peacock feathers.",
75 "It's some compromising photos of Babar the Elephant.",
76 "A copy of the Weekly World News. Watch out for the chambered nautilus!",
77 "It's the proverbial wet blanket.",
78 "A \"Get Out of Jail Free\" card.",
79 "An incredibly expensive \"Mad About You\" collector plate.",
80 "Paul Moyer's necktie.",
81 "A haircut and a real job. Now you know where to get one!",
82 "An automated robot-hater. It frowns disapprovingly at you.",
83 "An automated robot-liker. It smiles at you.",
84 "It's a black hole. Don't fall in!",
85 "Just a big brick wall.",
86 "You found kitten! No, just kidding.",
87 "Heart of Darkness brand pistachio nuts.",
88 "A smoking branding iron shaped like a 24-pin connector.",
89 "It's a Java applet.",
90 "An abandoned used-car lot.",
91 "A shameless plug for Maemo.",
92 "A shameless plug for the UCLA Linux Users Group: http://linux.ucla.edu/",
93 "A can of Spam Lite.",
94 "This is another fine mess you've gotten us into, Stanley.",
95 "It's scenery for \"Waiting for Godot\".",
96 "This grain elevator towers high above you.",
98 "It's the constellation Pisces.",
99 "It's a fly on the wall. Hi, fly!",
100 "This kind of looks like kitten, but it's not.",
101 "It's a banana! Oh, joy!",
102 "A helicopter has crashed here.",
103 "Carlos Tarango stands here, doing his best impression of Pat Smear.",
104 "A patch of mushrooms grows here.",
105 "A patch of grape jelly grows here.",
106 "A spindle, and a grindle, and a bucka-wacka-woom!",
107 "A geyser sprays water high into the air.",
108 "A toenail? What good is a toenail?",
109 "You've found the fish! Not that it does you much good in this game.",
110 "A Buttertonsils bar.",
111 "One of the few remaining discoes.",
112 "Ah, the uniform of a Revolutionary-era minuteman.",
113 "A punch bowl, filled with punch and lemon slices.",
114 "It's nothing but a G-thang, baby.",
115 "IT'S ALIVE! AH HA HA HA HA!",
116 "This was no boating accident!",
117 "Wait! This isn't the poker chip! You've been tricked! DAMN YOU, MENDEZ!",
118 "A livery stable! Get your livery!",
119 "It's a perpetual immobility machine.",
120 "\"On this spot in 1962, Henry Winkler was sick.\"",
121 "There's nothing here; it's just an optical illusion.",
122 "The World's Biggest Motzah Ball!",
123 "A tribe of cannibals lives here. They eat Malt-O-Meal for breakfast, you know.",
124 "This appears to be a rather large stack of trashy romance novels.",
125 "Look out! Exclamation points!",
126 "A herd of wild coffee mugs slumbers here.",
127 "It's a limbo bar! How low can you go?",
128 "It's the horizon. Now THAT'S weird.",
129 "A vase full of artificial flowers is stuck to the floor here.",
130 "A large snake bars your way.",
131 "A pair of saloon-style doors swing slowly back and forth here.",
132 "It's an ordinary bust of Beethoven... but why is it painted green?",
133 "It's TV's lovable wisecracking Crow! \"Bite me!\", he says.",
134 "Hey, look, it's war. What is it good for? Absolutely nothing. Say it again.",
135 "It's the amazing self-referential thing that's not kitten.",
136 "A flamboyant feather boa. Now you can dress up like Carol Channing!",
137 "\"Sure hope we get some rain soon,\" says Farmer Joe.",
138 "\"How in heck can I wash my neck if it ain't gonna rain no more?\" asks Farmer Al.",
139 "\"Topsoil's all gone, ma,\" weeps Lil' Greg.",
140 "This is a large brown bear. Oddly enough, it's currently peeing in the woods.",
141 "A team of arctic explorers is camped here.",
142 "This object here appears to be Louis Farrakhan's bow tie.",
143 "This is the world-famous Chain of Jockstraps.",
144 "A trash compactor, compacting away.",
145 "This toaster strudel is riddled with bullet holes!",
146 "It's a hologram of a crashed helicopter.",
147 "This is a television. On screen you see a robot strangely similar to yourself.",
148 "This balogna has a first name, it's R-A-N-C-I-D.",
149 "A salmon hatchery? Look again. It's merely a single salmon.",
150 "It's a rim shot. Ba-da-boom!",
151 "It's creepy and it's kooky, mysterious and spooky. It's also somewhat ooky.",
152 "This is an anagram.",
153 "This object is like an analogy.",
154 "It's a symbol. You see in it a model for all symbols everywhere.",
155 "The object pushes back at you.",
156 "A traffic signal. It appears to have been recently vandalized.",
157 "\"There is no kitten!\" cackles the old crone. You are shocked by her blasphemy.",
158 "This is a Lagrange point. Don't come too close now.",
159 "The dirty old tramp bemoans the loss of his harmonica.",
160 "Look, it's Fanny the Irishman!",
161 "What in blazes is this?",
162 "It's the instruction manual for a previous version of this game.",
163 "A brain cell. Oddly enough, it seems to be functioning.",
164 "Tea and/or crumpets.",
165 "This jukebox has nothing but Cliff Richards albums in it.",
166 "It's a Quaker Oatmeal tube, converted into a drum.",
167 "This is a remote control. Being a robot, you keep a wide berth.",
168 "It's a roll of industrial-strength copper wire.",
169 "Oh boy! Grub! Er, grubs.",
170 "A puddle of mud, where the mudskippers play.",
171 "Plenty of nothing.",
172 "Look at that, it's the Crudmobile.",
173 "Just Walter Mattheau and Jack Lemmon.",
174 "Two crepes, two crepes in a box.",
175 "An autographed copy of \"Primary Colors\", by Anonymous.",
176 "Another rabbit? That's three today!",
177 "It's a segmentation fault. Core dumped, by the way.",
178 "A historical marker showing the actual location of /dev/null.",
179 "Thar's Mobius Dick, the convoluted whale. Arrr!",
180 "It's a charcoal briquette, smoking away.",
181 "A pizza, melting in the sun.",
182 "It's a \"HOME ALONE 2: Lost in New York\" novelty cup.",
183 "A stack of 7 inch floppies wobbles precariously.",
184 "It's nothing but a corrupted floppy. Coaster anyone?",
185 "A section of glowing phosphor cells sings a song of radiation to you.",
186 "This TRS-80 III is eerily silent.",
187 "A toilet bowl occupies this space.",
188 "This peg-leg is stuck in a knothole!",
189 "It's a solitary vaccuum tube.",
190 "This corroded robot is clutching a mitten.",
191 "\"Hi, I'm Anson Williams, TV's 'Potsy'.\"",
192 "This subwoofer was blown out in 1974.",
193 "Three half-pennies and a wooden nickel.",
194 "It's the missing chapter to \"A Clockwork Orange\".",
195 "It's a burrito stand flyer. \"Taqueria El Ranchito\".",
196 "This smiling family is happy because they eat LARD.",
197 "Roger Avery, persona un famoso de los Estados Unidos.",
198 "Ne'er but a potted plant.",
199 "A parrot, kipping on its back.",
200 "A forgotten telephone switchboard.",
201 "A forgotten telephone switchboard operator.",
202 "It's an automated robot-disdainer. It pretends you're not there.",
203 "It's a portable hole. A sign reads: \"Closed for the winter\".",
204 "Just a moldy loaf of bread.",
205 "A little glass tub of Carmex. ($.89) Too bad you have no lips.",
206 "A Swiss-Army knife. All of its appendages are out. (toothpick lost)",
207 "It's a zen simulation, trapped within an ASCII character.",
208 "It's a copy of \"The Rubaiyat of Spike Schudy\".",
209 "It's \"War and Peace\" (unabridged, very small print).",
210 "A willing, ripe tomato bemoans your inability to digest fruit.",
211 "A robot comedian. You feel amused.",
212 "It's KITT, the talking car.",
213 "Here's Pete Peterson. His batteries seem to have long gone dead.",
214 "\"Blup, blup, blup\", says the mud pot.",
215 "More grist for the mill.",
216 "Grind 'em up, spit 'em out, they're twigs.",
217 "The boom box cranks out an old Ethel Merman tune.",
218 "It's \"Finding kitten\", published by O'Reilly and Associates.",
219 "Pumpkin pie spice.",
220 "It's the Bass-Matic '76! Mmm, that's good bass!",
221 "\"Lend us a fiver 'til Thursday\", pleas Andy Capp.",
222 "It's a tape of '70s rock. All original hits! All original artists!",
223 "You've found the fabled America Online disk graveyard!",
224 "Empty jewelboxes litter the landscape.",
225 "It's the astounding meta-object.",
226 "Ed McMahon stands here, lost in thought. Seeing you, he bellows, \"YES SIR!\"",
228 "It's 1000 secrets the government doesn't want you to know!",
229 "The letters O and R.",
230 "A magical... magic thing.",
231 "It's a moment of silence.",
232 "It's Sirhan-Sirhan, looking guilty.",
233 "It's \"Chicken Soup for the Kitten-seeking Soulless Robot.\"",
234 "It is a set of wind-up chatter teeth.",
235 "It is a cloud shaped like an ox.",
236 "You see a snowflake here, melting slowly.",
237 "It's a big block of ice. Something seems to be frozen inside it.",
238 "Vladimir Lenin's casket rests here.",
239 "It's a copy of \"Zen and The Art of Robot Maintenance\".",
240 "This invisible box contains a pantomime horse.",
241 "A mason jar lies here open. It's label reads: \"do not open!\".",
242 "A train of thought chugs through here.",
243 "This jar of pickles expired in 1957.",
244 "Someone's identity disk lies here.",
245 "\"Yes!\" says the bit.",
246 "\"No!\" says the bit.",
247 "A dodecahedron bars your way.",
248 "Mr. Hooper is here, surfing.",
249 "It's a big smoking fish.",
250 "You have new mail in /var/spool/robot",
251 "Just a monitor with the blue element burnt out.",
252 "A pile of coaxial plumbing lies here.",
253 "It's a rotten old shoe.",
254 "It's a hundred-dollar bill.",
255 "It's a Dvorak keyboard.",
256 "It's a cardboard box full of 8-tracks.",
257 "Just a broken hard drive containg the archives of Nerth Pork.",
258 "A broken metronome sits here, it's needle off to one side.",
259 "A sign reads: \"Go home!\"",
260 "A sign reads: \"No robots allowed!\"",
261 "It's the handheld robotfindskitten game, by Tiger.",
262 "This particular monstrosity appears to be ENIAC.",
263 "This is a tasty-looking banana creme pie.",
264 "A wireframe model of a hot dog rotates in space here.",
265 "Just the empty husk of a locust.",
266 "You disturb a murder of crows.",
267 "It's a copy of the robotfindskitten EULA.",
269 "It's an autographed copy of \"Secondary Colors,\" by Bob Ross.",
270 "It is a marzipan dreadnought that appears to have melted and stuck.",
271 "It's a DVD of \"Crouching Monkey, Hidden Kitten\", region encoded for the moon.",
272 "It's Kieran Hervold. Damn dyslexia!"
273 "A non-descript box of crackers.",
274 "Carbonated Water, High Fructose Corn Syrup, Color, Phosphoric Acid, Flavors, Caffeine.",
275 "\"Move along! Nothing to see here!\"",
276 "It's the embalmed corpse of Vladimir Lenin.",
277 "A coupon for one free steak-fish at your local family diner.",
278 "A set of keys to a 2001 Rolls Royce. Worthless."
281 GtkWidget *arena[ARENA_WIDTH][ARENA_HEIGHT];
282 GtkWidget *table, *window, *robot, *kitten;
283 int robot_x, robot_y;
284 gboolean used[G_N_ELEMENTS (messages)] = { 0, };
286 GdkPixbuf *robot_pic, *love_pic, *kitten_pic;
287 GtkWidget *animation_area;
289 const GdkColor black = { 0, };
291 /****************************************************************/
292 /* Random object descriptions. */
293 /****************************************************************/
302 r = random() % G_N_ELEMENTS (messages);
311 /****************************************************************/
312 /* Placing objects. */
313 /****************************************************************/
316 place_in_arena_at_xy (GtkWidget *item, int x, int y)
320 gtk_table_attach_defaults (GTK_TABLE (table),
333 place_in_arena_randomly (GtkWidget *item)
339 x = random() % ARENA_WIDTH;
340 y = random() % ARENA_HEIGHT;
344 place_in_arena_at_xy (item, x, y);
347 /****************************************************************/
348 /* Labels representing things the robot might find. */
349 /****************************************************************/
352 random_character (gchar *description)
354 gchar character[2] = { random() % ('~'-'!') + '!', 0 };
355 gchar *escaped_character = g_markup_escape_text (character, -1);
356 gchar *markup = g_strdup_printf ("<span color=\"#%02x%02x%02x\">%s</span>",
357 (int) (random() % 0x7F)+0x80,
358 (int) (random() % 0x7F)+0x80,
359 (int) (random() % 0x7F)+0x80,
361 GtkWidget *result = gtk_label_new (NULL);
362 gtk_label_set_markup (GTK_LABEL (result), markup);
364 g_free (escaped_character);
366 g_object_set_data (G_OBJECT (result), "examine", description);
371 /****************************************************************/
372 /* Talking back to the user. */
373 /****************************************************************/
376 show_message (const char *message)
378 HildonNote* note = HILDON_NOTE
379 (hildon_note_new_information (GTK_WINDOW (window),
381 gtk_dialog_run (GTK_DIALOG (note));
382 gtk_widget_destroy (GTK_WIDGET (note));
385 /****************************************************************/
386 /* The ending animation. */
387 /****************************************************************/
390 ending_animation_quit (gpointer data)
397 ending_animation_draw (GtkWidget *widget, GdkEventExpose *event, gpointer data)
399 /* We only run through once, so just make it static. */
400 static int cycle_count = 0;
402 static int robot_x = 0;
403 static int robot_stop = 0;
404 static int kitten_x = 0;
405 static int all_y = 0;
407 const int stepsize = 3;
411 all_y = (event->area.height - gdk_pixbuf_get_height (love_pic)) / 2;
413 robot_stop = gdk_pixbuf_get_width (robot_pic) + gdk_pixbuf_get_width (love_pic);
414 kitten_x = event->area.width - (cycle_count*stepsize + gdk_pixbuf_get_width (kitten_pic));
417 gdk_gc_set_foreground (widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
420 gdk_draw_rectangle (GDK_DRAWABLE(widget->window),
421 widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
423 0, 0, event->area.width, event->area.height);
425 gdk_draw_pixbuf (GDK_DRAWABLE(widget->window),
426 widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
430 GDK_RGB_DITHER_NONE, 0, 0);
432 gdk_draw_pixbuf (GDK_DRAWABLE(widget->window),
433 widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
437 GDK_RGB_DITHER_NONE, 0, 0);
441 kitten_x -= stepsize;
443 if (robot_x+robot_stop >= kitten_x)
445 gdk_draw_pixbuf (GDK_DRAWABLE(widget->window),
446 widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
448 robot_x + gdk_pixbuf_get_width (robot_pic), all_y,
450 GDK_RGB_DITHER_NONE, 0, 0);
452 g_object_unref (love_pic);
455 g_timeout_add (2000, ending_animation_quit, NULL);
462 ending_animation_step (gpointer data)
466 gdk_window_invalidate_rect (animation_area->window,
478 robot_pic = gdk_pixbuf_new_from_file ("/usr/share/pixmaps/rfk-robot.png", NULL);
479 love_pic = gdk_pixbuf_new_from_file ("/usr/share/pixmaps/rfk-love.png", NULL);
480 kitten_pic = gdk_pixbuf_new_from_file ("/usr/share/pixmaps/rfk-kitten.png", NULL);
481 animation_area = gtk_drawing_area_new ();
483 gtk_container_remove (GTK_CONTAINER (window), GTK_WIDGET (table));
484 gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (animation_area));
485 gtk_widget_show_all (window);
487 g_signal_connect (G_OBJECT (animation_area),
488 "expose_event", G_CALLBACK (ending_animation_draw), NULL);
489 g_timeout_add (10, ending_animation_step, NULL);
492 /****************************************************************/
493 /* Moving the robot. Way to go, robot! */
494 /****************************************************************/
497 move_robot (int dx, int dy)
499 GtkWidget *new_space;
504 robot_x+dx>=ARENA_WIDTH ||
505 robot_y+dy>=ARENA_HEIGHT)
508 new_space = arena[robot_x+dx][robot_y+dy];
509 found = g_object_get_data (G_OBJECT (new_space), "examine");
513 show_message (found);
515 if (new_space == kitten)
522 g_object_ref (new_space);
524 gtk_container_remove (GTK_CONTAINER (table), robot);
525 gtk_container_remove (GTK_CONTAINER (table), new_space);
527 place_in_arena_at_xy (new_space, robot_x, robot_y);
528 place_in_arena_at_xy (robot, robot_x+dx, robot_y+dy);
530 g_object_unref (new_space);
534 /****************************************************************/
535 /* Event handlers. */
536 /****************************************************************/
539 on_window_clicked (GtkWidget *widget,
540 GdkEventButton *event,
546 rx = (robot->allocation.x+robot->allocation.width/2);
547 ry = (robot->allocation.y+robot->allocation.height/2);
549 w1 = (event->x - rx) > (event->y - ry);
550 w2 = (rx - event->x) > (event->y - ry);
571 on_key_pressed (GtkWidget *widget,
576 switch (event->keyval) {
578 case GDK_Up: case 'k': move_robot ( 0, -1); break;
579 case GDK_Down: case 'j': move_robot ( 0, 1); break;
580 case GDK_Left: case 'h': move_robot (-1, 0); break;
581 case GDK_Right: case 'l': move_robot ( 1, 0); break;
588 /****************************************************************/
589 /* Let's kick the whole thing off... */
590 /****************************************************************/
598 gtk_init (&argc, &argv);
601 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
602 gtk_window_set_title (GTK_WINDOW (window), "robot finds kitten");
603 gtk_widget_modify_bg (window, GTK_STATE_NORMAL, &black);
604 g_signal_connect (G_OBJECT (window), "button-press-event", G_CALLBACK (on_window_clicked), NULL);
605 g_signal_connect (G_OBJECT (window), "key-press-event", G_CALLBACK (on_key_pressed), NULL);
606 g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
608 table = gtk_table_new (ARENA_HEIGHT, ARENA_WIDTH, TRUE);
609 gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (table));
611 robot = gtk_label_new ("#");
612 g_object_ref (robot);
613 kitten = random_character ("You found kitten! Way to go, robot!");
615 place_in_arena_randomly (robot);
616 place_in_arena_randomly (kitten);
618 for (x=0; x < amount_of_random_stuff; x++)
619 place_in_arena_randomly (random_character (description ()));
621 for (x=0; x < ARENA_WIDTH; x++)
622 for (y=0; y < ARENA_HEIGHT; y++)
624 place_in_arena_at_xy (gtk_label_new (NULL), x, y);
626 gtk_widget_show_all (window);
628 gdk_window_set_events (GTK_WIDGET (window)->window,
629 gdk_window_get_events(GTK_WIDGET (window)->window) | GDK_BUTTON_PRESS_MASK);
632 show_message (explanation);