home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR22 / JORF21_2.ZIP / ATTACK.J < prev    next >
Text File  |  1993-07-05  |  12KB  |  399 lines

  1. Class:Attack
  2.   StartSpeed
  3.   TypeWord
  4.   ThisWord
  5.   CurrSpeed
  6.   CurrLevel
  7.   CurrScore
  8.   CurrHits
  9.   Restart
  10.   Sound
  11.   WordList
  12.   InpRow
  13.   InpCol
  14.  
  15. Attack:Start
  16.   New (Attack:AtStru)
  17.  
  18.   AtStru->StartSpeed = 45
  19.   AtStru->CurrSpeed  = 45
  20.   AtStru->CurrLevel  = 20
  21.   AtStru->Sound      = "Y"
  22.   AtStru->Restart    = False
  23.   AtStru->WordList   = File:Load("Attack.Txt")
  24.  
  25.   Attack:OpenWindow(AtStru)
  26.   If (Kbd:Got!='Esc_Key')
  27.     Event:Add("Attack")
  28.     Attack:MainWindow(AtStru,Here)
  29.     Attack:DrawCastle()
  30.     Win:Msg("Press Escape to Exit, Press Enter to Pause")
  31.     While (Kbd:Got!="Esc_Key")
  32.       Attack:GetWord(AtStru)
  33.       Attack:Attack(AtStru)
  34.       Jorf:Flush(80)
  35.   Return (Ok)
  36.  
  37. Attack:About
  38.   Msg:Add
  39.     JORF Typewriter Attack
  40.  
  41.     A sample program for the
  42.     JORF Interpreter.
  43.  
  44.     November 23, 1992
  45.     By Wayland Bruns
  46.   Return (Ok)
  47.  
  48. Attack:Attack(AtStru)
  49.   New (Len,HalfLen,Spaces,Row,Col,Wait,WaitEnd)
  50.   Len = Str:Len(AtStru->ThisWord)
  51.   HalfLen = Len/2
  52.   Row = 1
  53.   Col = Num:Rand(1, 78-Len)
  54.   AtStru->InpRow = 22
  55.   AtStru->InpCol = 40 - Halflen
  56.   Wait   = ((55-AtStru->CurrSpeed)*2)
  57.  
  58.   Move:To (AtStru->InpRow,1)
  59.   Str:Put(Str:AtSet(Null,1,' ',78))
  60.  
  61.   Move:To (AtStru->InpRow-2,1)
  62.   Str:Put("Level "+Num:Str(AtStru->CurrLevel/20,"#.##")+"  ")
  63.   Str:Put("Speed "+AtStru->CurrSpeed+" Mph")
  64.  
  65.   Move:To (AtStru->InpRow-1,1)
  66.   Str:Put("Score "+Str:Aft(Num:Str(AtStru->CurrScore,"#,###,###,##0")," "))
  67.   Str:Put(" Points")
  68.  
  69.   Attack:DrawCastle()
  70.   AtStru->TypeWord = ""
  71.   Spaces = Str:AtSet(Null,1,' ',Len)
  72.   While (Row < 21)
  73.     Move:To(Row,Col)
  74.     Str:Put(AtStru->ThisWord)
  75.     WaitEnd = Time:Ticks()+Wait
  76.     While (Ok)
  77.       While (Kbd:Hit())
  78.         Kbd:Get()
  79.       If (AtStru->Restart Or Str:In(AtStru->TypeWord,AtStru->ThisWord))
  80.  
  81.         Move:To(Row,Col)
  82.         Str:Put(Str:AtSet(Null,1,"■",Len))
  83.         Kbd:Hit()
  84.     Attack:Sound(AtStru,440,4)
  85.  
  86.         Move:To(Row,Col)
  87.         Str:Put(Str:AtSet(Null,1,"░",Len))
  88.         Kbd:Hit()
  89.     Attack:Sound(AtStru,240,4)
  90.  
  91.         Move:To(Row,Col)
  92.         Str:Put(Str:AtSet(Null,1,"∙",Len))
  93.         Kbd:Hit()
  94.     Attack:Sound(AtStru,440,4)
  95.  
  96.         Move:To(Row,Col)
  97.         Str:Put(Str:AtSet(Null,1," ",Len))
  98.         Kbd:Hit()
  99.     Attack:Sound(AtStru,240,4)
  100.  
  101.         AtStru->CurrScore = AtStru->CurrScore + ((AtStru->CurrSpeed/20)*(AtStru->CurrLevel/20)) + 1
  102.         AtStru->CurrHits  = AtStru->CurrHits + Num:Max(1,Num:Int((14-Row)/2))
  103.         AtStru->CurrSpeed = Num:Btw(1,55,AtStru->CurrSpeed+Num:Int((10-Row)/4))
  104.         AtStru->Restart = False
  105.         Return (Ok)
  106.       If (Kbd:Got=="Esc_Key")
  107.         Return(Ok)
  108.       If (Time:Ticks > WaitEnd)
  109.         Break
  110.     Move:To(Row,Col)
  111.     Str:Put(Spaces)
  112.     ++Row
  113.     If (Col > (39-HalfLen))
  114.       Col = Col - ((Col-(39-HalfLen))/10)
  115.     Else
  116.       Col = Col + (((39-Halflen)-Col)/10)
  117.   Attack:Boom(AtStru)
  118.   AtStru->CurrSpeed = AtStru->CurrSpeed-5
  119.   AtStru->CurrHits  = 0
  120.   Return (Ok)
  121.  
  122. Attack:Backspace_Key
  123.   If (Str:Len(AtStru->TypeWord) > 0)
  124.     AtStru->TypeWord = Str:At(AtStru->TypeWord,1,-1)
  125.     Move:To (AtStru->InpRow,AtStru->InpCol)
  126.     Str:Put(AtStru->TypeWord)
  127.     Str:Put(" ")
  128.   Return ("Esc_Key")
  129.  
  130. Attack:Boom(AtStru)
  131.   Move:To(18,32)
  132.   Str:Put("       ╖  ")
  133.   Move:To(19,32)
  134.   Str:Put("          ")
  135.   Move:To(20,32)
  136.   Str:Put("    ▄■█▄█")
  137.   Move:To(21,32)
  138.   Str:Put("     ▄█■█ ")
  139.   Attack:Sound(AtStru,40,8)
  140.   Attack:Sound(AtStru,20,8)
  141.   Attack:Sound(AtStru,40,8)
  142.   Move:To(17,32)
  143.   Str:Put("            ")
  144.   Move:To(18,32)
  145.   Str:Put("   ■     ╛  ■")
  146.   Move:To(19,32)
  147.   Str:Put("           ")
  148.   Move:To(20,32)
  149.   Str:Put("   ■ ▄■ ▄ ")
  150.   Move:To(21,32)
  151.   Str:Put("     ■█■█ ")
  152.   Attack:Sound(AtStru,40,8)
  153.   Attack:Sound(AtStru,20,8)
  154.   Move:To(17,32)
  155.   Str:Put("                   ")
  156.   Move:To(18,32)
  157.   Str:Put("             ")
  158.   Move:To(19,32)
  159.   Str:Put("  ■      ╛    ■")
  160.   Move:To(20,32)
  161.   Str:Put("    .  ▄■..■.")
  162.   Move:To(21,32)
  163.   Str:Put("  ■▄  ■█■█ ■")
  164.   Attack:Sound(AtStru,40,8)
  165.   Attack:Sound(AtStru,20,8)
  166.   Move:To(18,32)
  167.   Str:Put("                   ")
  168.   Move:To(19,32)
  169.   Str:Put("      .   .    ")
  170.   Move:To(20,32)
  171.   Str:Put("        ▄  . . ")
  172.   Move:To(21,32)
  173.   Str:Put(" ■▄█▄▄■█■█ ■▄█")
  174.   Attack:Sound(AtStru,40,8)
  175.   Attack:Sound(AtStru,20,8)
  176.   Move:To(19,32)
  177.   Str:Put("                   ")
  178.   Move:To(20,32)
  179.   Str:Put("      .   .    ")
  180.   Move:To(21,32)
  181.   Str:Put(" ■▄█▄▄■█■█ ■▄█")
  182.   Attack:Sound(AtStru,40,8)
  183.   Attack:Sound(AtStru,20,8)
  184.   Move:To(20,32)
  185.   Str:Put("                   ")
  186.   Move:To(21,32)
  187.   Str:Put(" ■▄▄ ▄ ▄.▄▄..▄")
  188.   Attack:Sound(AtStru,40,8)
  189.   Attack:Sound(AtStru,20,8)
  190.   Attack:Correction(AtStru)
  191.   Move:To(21,32)
  192.   Str:Put("                   ")
  193.   Return (Ok)
  194.  
  195. Attack:Correction(AtStru)
  196.   New (NewWOrd)
  197.   Kbd:Bye()
  198.   Event:Add()
  199.   Event:Add("EditKey")
  200.   Switch
  201.     Case (Str:Len(AtStru->ThisWord) > 25)
  202.       Win:Add ("Typewriter Attack", 2, 10, 9, 78)
  203.         Idle:"Attack:Correctidle()"
  204.         Input:"What you typed was", Row:2 Col:2 Field:"AtStru->Typeword", Wid:55 Before:"Null"
  205.         Input:"The word was      ", Row:4 Col:2 Field:"AtStru->Thisword" Wid:55 Before:"Null"
  206.         Input:"Type the word now ", Row:6, Col:2, Field:"NewWord" Wid:55
  207.         Button:"&Ok" Action:"Null"  Row:8 Col:30 Wid:20
  208.     Case (Str:Len(AtStru->ThisWord) > 1)
  209.       Win:Add ("Typewriter Attack", 2, 10, 9, 50)
  210.         Idle:"Attack:Correctidle()"
  211.         Input:"What you typed was", Row:2 Col:5 Field:"AtStru->Typeword", Wid:25 Before:"Null"
  212.         Input:"The word was      ", Row:4 Col:5 Field:"AtStru->Thisword" Wid:25 Before:"Null"
  213.         Input:"Type the word now ", Row:6, Col:5, Field:"NewWord" Wid:25
  214.         Button:"&Ok" Action:"Null"  Row:8 Col:20 Wid:20
  215.     Else
  216.       Win:Add ("Typewriter Attack", 2, 10, 9, 40)
  217.         Idle:"Attack:Correctidle()"
  218.         Input:"What you typed was  ", Row:2 Col:5 Field:"AtStru->Typeword",Wid:4 Before:"Null"
  219.         Input:"The letter was      ", Row:4 Col:5 Field:"AtStru->Thisword" Wid:4 Before:"Null"
  220.         Input:"Type the letter now ", Row:6, Col:5, Field:"NewWord" Wid:4
  221.         Button:"&Ok" Action:"Null"    Row:8 Col:10 Wid:20
  222.   Return (Ok)
  223.  
  224. Attack:CorrectIdle
  225.   If (NewWord==AtStru->ThisWord)
  226.     Msg:Add
  227.       Very good!  Are you ready
  228.       to continue?
  229.     Kbd:Put("Enter_Key")
  230.     Return (Null)
  231.   Return (Ok)
  232.  
  233. Attack:DrawCastle
  234.   Move:To(19,36)
  235.   Str:Put("   ╒ ")
  236.   Move:To(20,36)
  237.   Str:Put("█▄█▄█▄█")
  238.   Move:To(21,36)
  239.   Str:Put(" █▄█▄█ ")
  240.   Return (Ok)
  241.  
  242. Attack:Else(Key)
  243.   If (Str:At(Key,2,4) = '_Key')
  244.     Move:To (AtStru->InpRow,AtStru->InpCol)
  245.     If (Str:Len(Atstru->TypeWord) < (78-AtStru->InpCol))
  246.       AtStru->TypeWord = AtStru->TypeWord + Str:At(Key,1,1)
  247.     Str:Put(AtStru->TypeWord)
  248.     Return ("Esc_key")
  249.   Return (Null)
  250.  
  251. Attack:Enter_Key()
  252.   Msg:Add("Game Paused")
  253.     Press the {Bold:"Lo"}Enter{Bold:"No"} key when you
  254.     are ready to continue.
  255.   AtStru->Restart = True
  256.   Return (Ok)
  257.  
  258. Attack:Esc_Key
  259.   Return ("Esc_Key")
  260.  
  261. Attack:Finish()
  262.   Msg:Add "End"
  263.     You have finished the highest level of this &
  264.     program with a score of &
  265.     {Str:Aft(Num:Str(CurrScore,"#,###,###,##0")," ")} Points.
  266.  
  267.     You are a typing Champion!
  268.  
  269.     Press Enter to keep playing on level 9.
  270.   Return (Ok)
  271.  
  272. Attack:GetWord(AtStru)
  273.   New (Row, Line,Word)
  274.   If (AtStru->CurrHits > 4)
  275.     ++AtStru->CurrLevel
  276.     If (AtStru->Currlevel % 20 == 19)
  277.       ++AtStru->CurrLevel
  278.       If (AtStru->CurrLevel >= 200)
  279.         Attack:Finish(AtStru)
  280.         AtStru->CurrLevel = 181
  281.       Else
  282.         Msg:Add
  283.           Get ready for level {AtStru->CurrLevel/20}!
  284.     AtStru->CurrHits = 0
  285.   Row = (Num:Int(AtStru->CurrLevel / 20)-1) * 20
  286.   Row = Row + (AtStru->CurrLevel%20) + 2
  287.   Line = Text:At(AtStru->WordList,Row)
  288.   While (Word:At(Line,1)==Null)
  289.     Line = Text:Prev(Line)
  290.   Word = Word:At(Line,Num:Rand(1,Word:Len(Line)))
  291.   AtStru->ThisWord = Word
  292.   Return (Ok)
  293.  
  294. Attack:MainWindow(AtStru,Level)
  295.   Win:Add("Typewriter Attack!", 0, 0, 22, 78, Level)
  296.     Menu:"&File"
  297.       Menu:"&Pause"  Action:"Attack:Enter_Key" Hotkey:"Alt_P_Key"
  298.       Menu:"E&xit"   Action:"Return Null"
  299.     Menu:"&Levels"
  300.       Menu:"Level &1 - Single Letters",
  301.         Action:"Attack:SetLevel(AtStru,20)"
  302.         HotKey:"Alt_1_Key"
  303.       Menu:"Level &2 - Home row words",
  304.         Action:"Attack:SetLevel(AtStru,40)"
  305.         HotKey:"Alt_2_Key"
  306.       Menu:"Level &3 - Simple words",
  307.         Action:"Attack:SetLevel(AtStru,60)"
  308.         HotKey:"Alt_3_Key"
  309.       Menu:"Level &4 - Longer Words",
  310.         Action:"Attack:SetLevel(AtStru,80)"
  311.         HotKey:"Alt_4_Key"
  312.       Menu:"Level &5 - Names and Titles",
  313.         Action:"Attack:SetLevel(AtStru,100)"
  314.         HotKey:"Alt_5_Key"
  315.       Menu:"Level &6 - Punctuation Characters",
  316.         Action:"Attack:SetLevel(AtStru,120)"
  317.         HotKey:"Alt_6_Key"
  318.       Menu:"Level &7 - Short Sentences",
  319.         Action:"Attack:SetLevel(AtStru,140)"
  320.         HotKey:"Alt_7_Key"
  321.       Menu:"Level &8 - Grab Bag",
  322.         Action:"Attack:SetLevel(AtStru,160)"
  323.         HotKey:"Alt_8_Key"
  324.       Menu:"Level &9 - Expert Typist",
  325.         Action:"Attack:SetLevel(AtStru,180)"
  326.         HotKey:"Alt_9_Key"
  327.     Menu:"&Speed"
  328.       Menu:"Starter      -  5 Mph",
  329.         Action:"Attack:SetSpeed(AtStru,5)"
  330.       Menu:"Novice       - 15 Mph",
  331.         Action:"Attack:SetSpeed(AtStru,15)"
  332.       Menu:"Intermediate - 25 Mph"
  333.         Action:"Attack:SetSpeed(AtStru,25)"
  334.       Menu:"Expert       - 35 Mph"
  335.         Action:"Attack:SetSpeed(AtStru,35)"
  336.       Menu:"Pro          - 45 Mph"
  337.         Action:"Attack:SetSpeed(AtStru,45)"
  338.       Menu:"Full Speed   - 55 Mph"
  339.         Action:"Attack:SetSpeed(AtStru,55)"
  340.     Menu:"S&ound"
  341.       Menu:"Use Sound" Action:"Attack:SetSound(AtStru,'Y')"
  342.       Menu:"No Sound " Action:"Attack:SetSound(AtStru,'N')"
  343.     Menu:"&About" Action:"Attack:About"
  344.  
  345. Attack:OpenWindow(AtStru)
  346.   New (StartLevel)
  347.   StartLevel = Num:Int(AtStru->CurrLevel/20)
  348.   Win:Add("Welcome to Typewriter Attack!", 4, 4, 20, 64)
  349.     String:'The object of this game is to "Shoot" the falling letters by'
  350.     String:"typing them on the keyboard.  The sooner you shoot, the faster"
  351.     String:"the game will go.
  352.     String:""
  353.     String:"There are nine levels, each with about 100 words.  If you can"
  354.     String:"complete to level 9, you will become an expert typist."
  355.     String:""
  356.     String:"This program is a sample of what you can write using the"
  357.     String:"JORF Interpreter.  The source code for this program is in the"
  358.     String:"Attack.J source file."
  359.     String:""
  360.     String:"Please set these starting parameters:"
  361.     String:""
  362.     Input:"Starting Level (1-9)", Row:14  Col:15 Field:"StartLevel", Wid:4
  363.     Input:"Starting Speed (Mph)", Row:15, Col:15 Field:"AtStru->StartSpeed", Wid:4
  364.     Input:"Use Sound      (Y/N)", Row:16, Col:15 Field:"AtStru->Sound", Wid:4
  365.  
  366.     Button:"&Ok",   Row:18, Col:5 Wid:20 Action:"Null"
  367.     Button:"E&xit", Row:18, Col:40 Wid:20 Action:"Kbd:Put('Esc_Key')"
  368.   AtStru->CurrLevel = Num:Btw(StartLevel * 20,20,180)
  369.   Return (Ok)
  370.  
  371. Attack:SetLevel(AtStru,Level)
  372.   AtStru->CurrLevel = Level
  373.   AtStru->CurrSpeed = AtStru->StartSpeed
  374.   AtStru->Restart = True
  375.   Return (Null)
  376.  
  377. Attack:SetSound(AtStru,NewSound)
  378.   AtStru->Sound = NewSound
  379.   AtStru->Restart = True
  380.   Return (Ok)
  381.  
  382. Attack:SetSpeed(AtStru,Speed)
  383.   AtStru->StartSpeed = Speed
  384.   AtStru->CurrSpeed  = Speed
  385.   AtStru->Restart    = True
  386.   Return (Ok)
  387.  
  388. Attack:Sound(AtStru,Tone,Dur)
  389.   If (AtStru->Sound=="Y")
  390.     Jorf:Sound(Tone,Dur)
  391.   Else
  392.     Win:Pause(Dur)
  393.   Return (Ok)
  394.  
  395. Attack:Space_Bar()
  396.   AtStru->TypeWord = AtStru->TypeWord + " "
  397.   Return ("Esc_Key")
  398.  
  399.