Inform - Resources - Examples

Back to List

Inventory
Complete

Backward
Forward

Plain
Coloured
Gaudy

This code
in plain text

Browsing Balances.inf

13. A Bazaar Lottery (lines 1286-1530)

1286  Global last_called = 1;
1287  Global explicit_flag = 0;
1288  Global tickets_taken = 0;
1289   
1290  Class Ticket(6)
1291    with number -1, name "ticket",
1292         description
1293         [;  if (self.number==2306) "It is labelled ~First Prize~!";
1294             if (self.number==5802) "It is labelled ~Nineteenth Prize~.";
1295             "~You lose,~ says the ticket, with a smily face.  ~Try again!~";
1296         ],
1297         short_name
1298         [;  if (self.number==-1) rfalse;
1299             print "lottery ticket ", self.number; rtrue;
1300         ],
1301         parse_name
1302         [ i j w;
1303             i=0;
1304             if (NextWord()=='lottery') i++; else wn--;
1305             if (NextWord()=='tickets')
1306             {   parser_action=##PluralFound; return i+1; } else wn--;
1307             if (NextWord()~='ticket') return 0;
1308             i++;
1309             w=TryNumber(wn);
1310             if (w==-1000) { explicit_flag = false; return i; }
1311             if (w==0) return 0;
1312             if (self.number==-1)
1313             {   objectloop(j ofclass Ticket)
1314                     if (w == j.number) return 0;
1315             }
1316             else
1317             {   if (self.number~=w) return 0;
1318             }
1319             i++; last_called = w; explicit_flag = true; return i;
1320         ],
1321         before
1322         [;  Examine:
1323                 if (self in board)
1324                    "It would be cheating to see what's written on the curled up
1325                     tickets still in the board.";
1326             Cast: "~Get outta here, bub!~, the barker says, disgusted.";
1327         ];
1328   
1329  Place Bazaar "Crowded Bazaar"
1330    with description
1331             "This is a crowded, noisy bazaar.  Directly in front of you is
1332              a lottery!  But the contemptuous-looking barker is doing a
1333              very poor trade: hardly anyone wants his first prize, the
1334              big cuddly toy elephant, or even his nineteenth prize, a
1335              featureless white cube.",
1336         each_turn
1337         [;   switch(random(4))
1338              {   1: "^~Roll up!  Roll up!  One silver piece for three goes!~";
1339                  2: "^~Come on, then!  Just a silver coin gets you three!~";
1340                  3: "^~Think what you could win, all for one silver coin!~";
1341                  4: "^~This could be your lucky day!~";
1342              }
1343         ],
1344         before
1345         [;   Learn:
1346                  "~None of that!~ snaps the barker angrily, putting you off
1347                   your study habits.  He mutters about ~Enchanter cheats~,
1348                   but under the circumstances you decide to let the insult
1349                   pass.";
1350         ],
1351         cant_go "Everywhere, the crowds of jabbering natives block your way
1352             to all the good stalls.  In fact, the only one you can get at is
1353             this dismal lottery.";
1354   
1355  Object -> board "lottery board"
1356    with credit 0,
1357         name "board" "lottery" "holes",
1358         description
1359             "There are a hundred holes each way, making, um, let's see, yes,
1360              ten thousand tickets in all. Still, there are nineteen prizes,
1361              so your odds must be, oh, well, not too awful anyway.",
1362         before
1363         [ i; LetGo:
1364                  if (self.credit == 0)
1365                     "The barker stabs you in the chest with
1366                      his finger.  ~That's a silver coin to you, bub!~";
1367   
1368                  if (explicit_flag)
1369                  {   objectloop (i ofclass Ticket)
1370                          if (last_called == i.number)
1371                              "That ticket's already taken.";
1372                  }
1373                  else
1374                  {   .RandomChoice;
1375                      last_called = random(10000);
1376                      objectloop (i ofclass Ticket)
1377                          if (last_called == i.number)
1378                              jump RandomChoice;
1379                  }
1380   
1381                  tickets_taken++;
1382                  self.credit--;
1383   
1384                  i = Ticket.create();
1385                  if (i == 0)
1386                     "The barker looks metaphysically embarrassed. ~Um,
1387                      Inform's object creation system seems not to have worked.~";
1388   
1389                  i.number = last_called; itobj = i;
1390   
1391                  move i to player; give i moved proper;
1392                  if (explicit_flag==0)
1393                      print "Randomly picking from the ", 10001-tickets_taken,
1394                            " numbered holes with tickets in, you ";
1395                      else print "You ";
1396                  print_ret "take ", (the) i, " out of the board.";
1397   
1398              Examine: ;
1399              Receive:
1400                  if (noun ofclass Ticket)
1401                     "~No changes of mind, that's your ticket now!  Give it to
1402                       me if you want to play it.~";
1403                  <<Push self>>;
1404              default:
1405                  "The barker is burly, and won't let you
1406                   tamper with the board.";
1407         ],
1408         initial
1409             "Behind the barker is a huge drilled board, and inside each little
1410              numbered hole is a rolled-up lottery ticket."
1411    has  static container open;
1412   
1413  Ticket -> -> ticket_in_board "rolled-up ticket from the board"
1414    with article "a";
1415   
1416  Object -> barker "barker"
1417    with name "barker" "burly" "man",
1418         number 0,
1419         description
1420             "A boxer gone to seed who failed as a magician all down the
1421              coast, that'd be your guess.",
1422         life
1423         [;  Attack, Kiss: "No way.  He must weigh twice what you do.";
1424             Ask:  switch(noun)
1425                   {   'prize', 'prizes':
1426                           "~Just one silver coin and a prize could be yours!~";
1427                       'white', 'featureless', 'cube':
1428                           "He blows the dust off it.  ~Genuine antique, that.~";
1429                       'elephant', 'toy', 'cuddly':
1430                           "~Good quality merchandise,~ he says, in a way that
1431                            suggests he can only spell one of those three words.";
1432                       'ticket', 'tickets', 'lottery':
1433                           "~Three tickets for one silver coin!~";
1434                       default: "~Just play the game, bub.~";
1435                   }
1436             Order, Answer: "The barker glowers at you.";
1437             Give: if (noun ofclass Ticket)
1438                   {   remove noun;
1439                       if (noun.number==2306)
1440                       {   move elephant to player; give elephant moved;
1441                           remove pelephant;
1442                           Bazaar.description =
1443             "This is a crowded, noisy bazaar.  Directly in front of you is
1444              the lottery!";
1445                           "With very bad grace, the barker shoves the
1446                            cuddly toy elephant into your arms.";
1447                       }
1448                       if (noun.number==5802)
1449                       {   move barker_cube to player; give barker_cube moved;
1450                           remove pcube;
1451                           Bazaar.description =
1452             "This is a crowded, noisy bazaar.  Directly in front of you is
1453              the lottery!";
1454                           score=score+5;
1455                           "With concealed relief, the barker shoves the
1456                            featureless white cube into your hands.";
1457                       }
1458                       "~Bad luck!  You lose!~";
1459                   }
1460                   if (self.number==2) "~You've had enough goes already!~ he
1461                       growls.  No wonder trade is bad.";
1462                   if (~~(noun ofclass Coin))
1463                       "~What do you call that? One silver coin to play!~";
1464                   if ((noun.&name)-->0 == 'bronze')
1465                       "~Bronze!  Not a chance, sunshine.~";
1466                   remove noun;
1467                   board.credit = board.credit + 3;
1468                   self.number++;
1469                   if ((noun.&name)-->0 == 'gold')
1470                       "Gleefully the barker snatches the gold coin. ~Sorry
1471                        bub, no change. Business is slack today!~";
1472                   "Grudgingly the barker takes the silver coin and stands
1473                    back to let you at the board, arms folded.";
1474         ],
1475         before
1476         [;  Cast: switch(the_spell_was)
1477                   {   bozbar_spell:
1478                          "He's not that much of an animal.";
1479                       lobal_spell:
1480                          "His problem is listening, not hearing.";
1481                       caskly_spell:
1482                          "For a moment his hair seems to comb itself. 
1483                           Irritated, he ruffles it again, and the spell dies
1484                           an ignominious death.";
1485                       yomin_spell:
1486                           if (elephant has moved || barker_cube has moved)
1487                           "The barker's mind is a heap of grumbles about lost
1488                            prizes and scrawny Enchanters.";
1489                           if (self hasnt general)
1490                           {   give self general;
1491                              "~Hope that scrawny Enchanter doesn't pick 2306!~
1492                               thinks the barker (slowly).";
1493                           }
1494                           "~If that mark does win, hope it's only worthless
1495                            old 5802,~ ponders the barker.";
1496                   }
1497         ],
1498    has  animate scenery;
1499   
1500  Object -> prizes "prizes"
1501    with name "prize" "prizes",
1502         before [; "~Hands off those prizes!~"; ],
1503    has  scenery;
1504   
1505  Object -> pelephant "prize elephant"
1506    with name "prize" "elephant" "cuddly" "toy",
1507         description "Pink, cuddly, toy, elephant.  Says it all, really.",
1508         before [; Examine: ; default: "~Hands off those prizes!~"; ],
1509    has  scenery;
1510         
1511  Object -> pcube "prize cube"
1512    with name "prize" "featureless" "white" "cube",
1513         description "Wouldn't you like to win it?",
1514         before [; Examine: ; default: "~Hands off those prizes!~"; ],
1515    has  scenery;
1516   
1517  Object elephant "cuddly toy elephant"
1518    with name "cuddly" "toy" "elephant",
1519         description "Pink, cuddly, toy, elephant.  Says it all, really.",
1520         before
1521         [;  Cast: if (the_spell_was == bozbar_spell)
1522                       "Let me get this straight.  You, the enchanter who
1523                        defeated Krill, the head of the Borphee Guild
1524                        himself...  are attempting to grow wings on a pink
1525                        cuddly elephant?";
1526                   if (the_spell_was == yomin_spell) "Woolly.";
1527         ];
1528   
1529  FeaturelessCube barker_cube "cube";
1530   


Last updated 23 June 2004. This site is no longer supported; information may be out of date.
Maintained as a historical archive by the Interactive Fiction Technology Foundation. Copyright 1993-2018 IFTF, CC-BY-SA unless otherwise noted.
This page was originally managed by Graham Nelson (graham@gnelson.demon.co.uk) assisted by C Knight.