Skip to content

Commit f266d47

Browse files
skeptomaiclaude
andcommitted
feat: Add specialized polymorphic handling for egg object
Add humorous specialized handle_take(egg) and handle_drop(egg) functions with ticking egg messages and special behavior for the jewel-encrusted egg. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 48cd8a7 commit f266d47

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

examples/mini_zork.grue

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,35 @@ fn handle_take(obj) {
369369
fn handle_take(leaflet){
370370
clear_quit_state();
371371
player.score = player.score + 2;
372+
if leaflet.location == player {
373+
println("You already have that.");
374+
return;
375+
}
372376

377+
if !player_can_see(leaflet) {
378+
println("You can't see any such thing.");
379+
return;
380+
}
373381
move(leaflet, player);
374382
println("Took leaflet.");
375383
}
376384

385+
fn handle_take(egg){
386+
clear_quit_state();
387+
if egg.location == player {
388+
println("You already have that.");
389+
return;
390+
}
391+
392+
if !player_can_see(egg) {
393+
println("You can't see any such thing.");
394+
return;
395+
}
396+
397+
move(egg, player);
398+
println("You are the proud owner of a very special egg.. Is it ticking?");
399+
}
400+
377401
fn handle_drop(obj) {
378402
if obj.location != player {
379403
println("You don't have that.");
@@ -384,6 +408,16 @@ fn handle_drop(obj) {
384408
println("Dropped.");
385409
}
386410

411+
fn handle_drop(egg) {
412+
if egg.location != player {
413+
println("You don't have that.");
414+
return;
415+
}
416+
417+
move(egg, player.location);
418+
println("Ok, now I really think it's ticking. Perhaps you should walk away... quickly");
419+
}
420+
387421
fn show_inventory() {
388422
let items = player.contents();
389423
if items.empty() {

tests/mini_zork_test.z3

380 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)