Welcome to the world of Mainframe. 欢迎来到大型机的中文世界!

一个简单的REXX小游戏(A Simple REXX Game)

最近发现了一个REXX写的简单猜数字游戏,其中有很多内容很适合初学者来掌握REXX,游戏的源代码如下:

/********************** REXX ****************************************/

/* The NUMBER GAME – User tries to guess a number between 1 and 10  */

/* Generate a random number between 1 and 10                        */

   the_number = random(1,10)                                          

   say “I’m thinking of number between 1 and 10. What is it?”         

   pull the_guess                                                     

   if the_number = the_guess then                                     

      say ‘You guessed it!’                                           

   else                                                               

      say ‘Sorry, my number was: ‘ the_number                         

   say ‘Bye!’                         

运行:

在ISPF的’6 COMMAND’下输入以下内容:

EXEC ‘MIB.REXX.EXEC(NUMGAME)’ 

解释:

1. REXX语言不区分大小写,所以在上述程序中出现了’say’关键字用来输出信息,功能同’SAY’

2. ‘random’是REXX中内置的函数,用于生成一个随机数。

3. 程序中通过一个if…else语句,来完成对随机生成数字和用户输入数字的判断。   

4. 变量’the_guess’和’the_number’无需提前定义类型,在第一次使用时,系统会自动创建,并且分配内存空间。

相关文章

  • Top Links

  • 功能

  • 文章归档