跳转到内容

LOLGraphics 3.4 编程/制作简单的 LOLGraphics 游戏

100% developed
来自维基教科书,开放世界开放书籍

在本教程中,我们将制作一个简单的 WASD 控制游戏,你将控制一个方块。如果你掉进熔岩池,你就会输,如果你到达紫色地毯,你将会被问到一个多项选择题(美国第一任总统是谁)。如果你答对了,你就赢了。如果你答错了,你就输了。足够简单吧。

由于代码将分段编写,本章将遵循以下约定:新行(在先前版本中不存在的)将以绿色突出显示,应删除的行将以红色突出显示,应保留的行将以蓝色突出显示。

绘制场地

[编辑 | 编辑源代码]

你将从一个空程序开始。让我们开始绘制场地。背景将像草地一样是绿色的,将有一个红色方块代表熔岩池,还有一个洋红色方块。


HAI 3.4 0 1
IM IN UR CODE EXECUTIN UR KOMANDZ

PLZ RUN SUBPROGRAM DRAW_FIELD

IM OUTTA UR CODE

IM IN UR SUBPROGRAM DAT IZ KALLED DRAW_FIELD
PLZ CHANGE PAINT BRUSH 0 154 23
PLZ FILL RECT 0 0 630 430
PLZ CHANGE PAINT BRUSH RED
PLZ FILL RECT 100 100 50 50
PLZ CHANGE PAINT BRUSH MAGENTA
PLZ FILL RECT 300 200 50 50
IM OUTTA UR SUBPROGRAM

请注意,延迟被设置为 1。这是可能的最低值,出于使游戏尽可能流畅运行的目的,我们特意这样设置。

绘制玩家

[编辑 | 编辑源代码]

玩家将是一个可以在屏幕上移动的橙色方块。


HAI 3.4 0 1
IM IN UR CODE EXECUTIN UR KOMANDZ

PLZ RUN SUBPROGRAM DRAW_FIELD
PLZ RUN SUBPROGRAM DEFALT_VARIABLES

IM OUTTA UR CODE

 IM IN UR SUBPROGRAM DAT IZ KALLED DEFALT_VARIABLES
I HAS A TWO BYTE DAT IZ CALLED X
I HAS A TWO BYTE DAT IZ CALLED Y
PLZ SET TWO BYTE X 200
PLZ SET TWO BYTE Y 150
PLZ CHANGE PAINT BRUSH ORANGE
PLZ FILL RECT X Y 25 25
IM OUTTA UR SUBPROGRAM

 IM IN UR SUBPROGRAM DAT IZ KALLED DRAW_FIELD
PLZ CHANGE PAINT BRUSH 0 154 23
PLZ FILL RECT 0 0 630 430
PLZ CHANGE PAINT BRUSH RED
PLZ FILL RECT 100 100 50 50
PLZ CHANGE PAINT BRUSH MAGENTA
PLZ FILL RECT 300 200 50 50
IM OUTTA UR SUBPROGRAM

请注意,绘制操作是在设置默认变量的相同子程序中完成的。这将改变。

玩家移动

[编辑 | 编辑源代码]

就目前而言,我们还没有太多游戏。让我们实现玩家移动。


HAI 3.4 0 1
IM IN UR CODE EXECUTIN UR KOMANDZ

PLZ RUN SUBPROGRAM DEFALT_VARIABLES
PLZ RUN SUBPROGRAM DRAW_FIELD
PLZ RUN SUBPROGRAM DEFALT_VARIABLES
FOREVER RUN MOVE

IM OUTTA UR CODE

IM IN UR SUBPROGRAM DAT IZ KALLED DEFALT_VARIABLES
I HAS A TWO BYTE DAT IZ CALLED X
I HAS A TWO BYTE DAT IZ CALLED Y
I HAS A TWO BYTE DAT IZ CALLED BUTTON
PLZ SET TWO BYTE X 200
PLZ SET TWO BYTE Y 150
PLZ SET TWO BYTE BUTTON -1
PLZ CHANGE PAINT BRUSH ORANGE
PLZ FILL RECT X Y 25 25
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED DRAW_FIELD
PLZ CHANGE PAINT BRUSH 0 154 23
PLZ FILL RECT 0 0 630 430
PLZ CHANGE PAINT BRUSH RED
PLZ FILL RECT 100 100 50 50
PLZ CHANGE PAINT BRUSH MAGENTA
PLZ FILL RECT 300 200 50 50
PLZ CHANGE PAINT BRUSH ORANGE
PLZ FILL RECT X Y 25 25
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED MOVE
PLZ READ CHAR BUTTON
SWITCH [[BUTTON]]
CASE 56,87,119 UP
CASE 52,65,97 LEFT
CASE 50,83,115 DOWN
CASE 54,68,100 RIGHT
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED UP
PLZ SET TWO BYTE BUTTON -1
PLZ SET TWO BYTE Y Y-10
PLZ RUN SUBPROGRAM DRAW_FIELD
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED DOWN
PLZ SET TWO BYTE BUTTON -1
PLZ SET TWO BYTE Y Y+10
PLZ RUN SUBPROGRAM DRAW_FIELD
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED LEFT
PLZ SET TWO BYTE BUTTON -1
PLZ SET TWO BYTE X X-10
PLZ RUN SUBPROGRAM DRAW_FIELD
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED RIGHT
PLZ SET TWO BYTE BUTTON -1
PLZ SET TWO BYTE X X+10
PLZ RUN SUBPROGRAM DRAW_FIELD
IM OUTTA UR SUBPROGRAM

请注意,玩家绘制例程已移至场地,并且程序现在在开始绘制之前设置默认值。此外,在 switch/case 语句中,它将变量与 WASD 和 8462 键的 ASCII 值进行比较。

检测熔岩

[编辑 | 编辑源代码]

现在我们已经完成了移动,但你可以随意走动,包括在熔岩之上。让我们来解决这个问题。让我们添加检测你是否掉入熔岩并结束游戏的代码。


HAI 3.4 0 1
IM IN UR CODE EXECUTIN UR KOMANDZ

PLZ RUN SUBPROGRAM DEFALT_VARIABLES
PLZ RUN SUBPROGRAM DRAW_FIELD
FOREVER RUN MOVE

IM OUTTA UR CODE

IM IN UR SUBPROGRAM DAT IZ KALLED DEFALT_VARIABLES
I HAS A TWO BYTE DAT IZ CALLED X
I HAS A TWO BYTE DAT IZ CALLED Y
I HAS A TWO BYTE DAT IZ CALLED BUTTON
PLZ SET TWO BYTE X 200
PLZ SET TWO BYTE Y 150
PLZ SET TWO BYTE BUTTON -1
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED DRAW_FIELD
PLZ CHANGE PAINT BRUSH 0 154 23
PLZ FILL RECT 0 0 630 430
PLZ CHANGE PAINT BRUSH RED
PLZ FILL RECT 100 100 50 50
PLZ CHANGE PAINT BRUSH MAGENTA
PLZ FILL RECT 300 200 50 50
PLZ CHANGE PAINT BRUSH ORANGE
PLZ FILL RECT X Y 25 25
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED MOVE
PLZ READ CHAR BUTTON
SWITCH [[BUTTON]]
CASE 56,87,119 UP
CASE 52,65,97 LEFT
CASE 50,83,115 DOWN
CASE 54,68,100 RIGHT
PLZ RUN SUBPROGRAM CKECK_LAVA_X
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED UP
PLZ SET TWO BYTE BUTTON -1
PLZ SET TWO BYTE Y Y-10
PLZ RUN SUBPROGRAM DRAW_FIELD
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED DOWN
PLZ SET TWO BYTE BUTTON -1
PLZ SET TWO BYTE Y Y+10
PLZ RUN SUBPROGRAM DRAW_FIELD
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED LEFT
PLZ SET TWO BYTE BUTTON -1
PLZ SET TWO BYTE X X-10
PLZ RUN SUBPROGRAM DRAW_FIELD
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED RIGHT
PLZ SET TWO BYTE BUTTON -1
PLZ SET TWO BYTE X X+10
PLZ RUN SUBPROGRAM DRAW_FIELD
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED FELL_IN_LAVA
PLZ PRINT TEXT YOU FELL IN LAVA
IM OUTTA UR CODE
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED CKECK_LAVA_X
SWITCH [[X]]
CASE 80,90,100,110,120,130,140 CKECK_LAVA_Y
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED CKECK_LAVA_Y
SWITCH [[Y]]
CASE 80,90,100,110,120,130,140 FELL_IN_LAVA
IM OUTTA UR SUBPROGRAM

现在,如果你掉进熔岩,你会收到一条信息,告知你这一点,并且游戏结束。请注意,由于玩家从坐标 (200,150) 开始,并以 10 像素/迭代的速度移动,因此 x 和 y 值将始终是可以被 10 整除的数字。

检测地毯

[编辑 | 编辑源代码]

现在我们可以检测玩家是否进入熔岩,让我们也检测玩家是否踏在地毯上。


HAI 3.4 0 1
IM IN UR CODE EXECUTIN UR KOMANDZ

PLZ RUN SUBPROGRAM DEFALT_VARIABLES
PLZ RUN SUBPROGRAM DRAW_FIELD
FOREVER RUN MOVE

IM OUTTA UR CODE

IM IN UR SUBPROGRAM DAT IZ KALLED DEFALT_VARIABLES
I HAS A TWO BYTE DAT IZ CALLED X
I HAS A TWO BYTE DAT IZ CALLED Y
I HAS A TWO BYTE DAT IZ CALLED BUTTON
PLZ SET TWO BYTE X 200
PLZ SET TWO BYTE Y 150
PLZ SET TWO BYTE BUTTON -1
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED DRAW_FIELD
PLZ CHANGE PAINT BRUSH 0 154 23
PLZ FILL RECT 0 0 630 430
PLZ CHANGE PAINT BRUSH RED
PLZ FILL RECT 100 100 50 50
PLZ CHANGE PAINT BRUSH MAGENTA
PLZ FILL RECT 300 200 50 50
PLZ CHANGE PAINT BRUSH ORANGE
PLZ FILL RECT X Y 25 25
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED MOVE
PLZ READ CHAR BUTTON
SWITCH [[BUTTON]]
CASE 56,87,119 UP
CASE 52,65,97 LEFT
CASE 50,83,115 DOWN
CASE 54,68,100 RIGHT
PLZ RUN SUBPROGRAM CKECK_LAVA_X
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED UP
PLZ SET TWO BYTE BUTTON -1
PLZ SET TWO BYTE Y Y-10
PLZ RUN SUBPROGRAM DRAW_FIELD
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED DOWN
PLZ SET TWO BYTE BUTTON -1
PLZ SET TWO BYTE Y Y+10
PLZ RUN SUBPROGRAM DRAW_FIELD
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED LEFT
PLZ SET TWO BYTE BUTTON -1
PLZ SET TWO BYTE X X-10
PLZ RUN SUBPROGRAM DRAW_FIELD
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED RIGHT
PLZ SET TWO BYTE BUTTON -1
PLZ SET TWO BYTE X X+10
PLZ RUN SUBPROGRAM DRAW_FIELD
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED FELL_IN_LAVA
PLZ PRINT TEXT YOU FELL IN LAVA
IM OUTTA UR CODE
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED CKECK_LAVA_X
SWITCH [[X]]
CASE 80,90,100,110,120,130,140 CKECK_LAVA_Y
PLZ RUN SUBPROGRAM CKECK_CARPET_X
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED CKECK_LAVA_Y
SWITCH [[Y]]
CASE 80,90,100,110,120,130,140 FELL_IN_LAVA
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED ON_CARPET
PLZ PRINT TEXT YOU WIN
IM OUTTA UR CODE
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED CKECK_CARPET_X
SWITCH [[X]]
CASE 280,290,300,310,320,330,340 CKECK_CARPET_Y
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED CKECK_CARPET_Y
SWITCH [[Y]]
CASE 180,190,200,210,220,230,240 ON_CARPET
IM OUTTA UR SUBPROGRAM

琐事问题

[编辑 | 编辑源代码]

现在,当你踏上地毯时,你就会立即获胜。让我们把它改成你需要回答一个琐事问题,只有答对了才能获胜。


HAI 3.4 0 1
IM IN UR CODE EXECUTIN UR KOMANDZ

PLZ RUN SUBPROGRAM DEFALT_VARIABLES
PLZ RUN SUBPROGRAM DRAW_FIELD
FOREVER RUN MOVE

IM OUTTA UR CODE

IM IN UR SUBPROGRAM DAT IZ KALLED DEFALT_VARIABLES
I HAS A TWO BYTE DAT IZ CALLED X
I HAS A TWO BYTE DAT IZ CALLED Y
I HAS A TWO BYTE DAT IZ CALLED BUTTON
PLZ SET TWO BYTE X 200
PLZ SET TWO BYTE Y 150
PLZ SET TWO BYTE BUTTON -1
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED DRAW_FIELD
PLZ CHANGE PAINT BRUSH 0 154 23
PLZ FILL RECT 0 0 630 430
PLZ CHANGE PAINT BRUSH RED
PLZ FILL RECT 100 100 50 50
PLZ CHANGE PAINT BRUSH MAGENTA
PLZ FILL RECT 300 200 50 50
PLZ CHANGE PAINT BRUSH ORANGE
PLZ FILL RECT X Y 25 25
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED MOVE
PLZ READ CHAR BUTTON
SWITCH [[BUTTON]]
CASE 56,87,119 UP
CASE 52,65,97 LEFT
CASE 50,83,115 DOWN
CASE 54,68,100 RIGHT
PLZ RUN SUBPROGRAM CKECK_LAVA_X
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED UP
PLZ SET TWO BYTE BUTTON -1
PLZ SET TWO BYTE Y Y-10
PLZ RUN SUBPROGRAM DRAW_FIELD
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED DOWN
PLZ SET TWO BYTE BUTTON -1
PLZ SET TWO BYTE Y Y+10
PLZ RUN SUBPROGRAM DRAW_FIELD
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED LEFT
PLZ SET TWO BYTE BUTTON -1
PLZ SET TWO BYTE X X-10
PLZ RUN SUBPROGRAM DRAW_FIELD
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED RIGHT
PLZ SET TWO BYTE BUTTON -1
PLZ SET TWO BYTE X X+10
PLZ RUN SUBPROGRAM DRAW_FIELD
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED FELL_IN_LAVA
PLZ PRINT TEXT YOU FELL IN LAVA
PLZ PRINT TEXT
PLZ PRINT TEXT YOU LOSE
IM OUTTA UR CODE
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED CKECK_LAVA_X
SWITCH [[X]]
CASE 80,90,100,110,120,130,140 CKECK_LAVA_Y
PLZ RUN SUBPROGRAM CKECK_CARPET_X
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED CKECK_LAVA_Y
SWITCH [[Y]]
CASE 80,90,100,110,120,130,140 FELL_IN_LAVA
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED ON_CARPET
PLZ PRINT TEXT WHO WAS THE FIRST 
PLZ PRINT TEXT WHO PRESIDENT OF THE 
PLZ PRINT TEXT UNITED STATES?
PLZ PRINT TEXT
PLZ PRINT TEXT 1) RICHARD NIXON
PLZ PRINT TEXT 2) GEORGE WASHINGTON
PLZ PRINT TEXT 3) DONALD TRUMP
PLZ PRINT TEXT 4) JOHN ADAMS

I HAS A ONE BYTE DAT IZ CALLED ANSWER
PLZ ASK TEH USR 2 GIMME A ONE BYTE ANSWER
PLZ CLEAR TEH CONSOLE
SWITCH [ANSWER]
LABELCASE 2 WIN
PLZ PRINT TEXT YOU LOSE!
PLZ GOTO LABEL END
DIS IZ MY LABEL! IT IZ KALLED WIN
PLZ PRINT TEXT YOU WIN!
DIS IZ MY LABEL! IT IZ KALLED END
IM OUTTA UR CODE
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED CKECK_CARPET_X
SWITCH [[X]]
CASE 280,290,300,310,320,330,340 CKECK_CARPET_Y
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED CKECK_CARPET_Y
SWITCH [[Y]]
CASE 180,190,200,210,220,230,240 ON_CARPET
IM OUTTA UR SUBPROGRAM

现在,当你踏上地毯时,你会被问到美国第一任总统是谁。此外,当你掉进熔岩时,除了 “你掉进熔岩” 之外,还会显示 “你输了” 的文本。这个 “游戏” 可以被认为是完成了,但是我们还要添加一件事情。

略微改进

[编辑 | 编辑源代码]

你会期望玩家掉进熔岩后,他不会被绘制在屏幕上。然而,这并非目前游戏中发生的事情。让我们来解决这个问题。有多种方法可以做到这一点。

  1. 一种方法是将玩家的 x 和 y 值设置为越界值,然后重新绘制屏幕。这会导致玩家被 “绘制”,但由于它将位于屏幕外,所以你不会看到他。你可以随意使用这种方法,但这并不是我们将在本书中使用的。
  2. 第二种方法是创建一个名为 IN_LAVA 的单字节变量,将其设置为 0,当玩家掉进熔岩时,将其设置为 1。绘制例程将检查该变量的值,如果等于 1,则不会绘制玩家。你可以在代码中随意使用它,但这也不是我们将在本书中做的。
  3. 第三种方法是将 x 或 y 的值设置为一个数字,例如 -1,然后在绘制例程中检查 x 是否等于 -1,如果是,则不会绘制玩家。你可以使用任何不能被 10 整除的数字,它不会影响代码的运行方式,因为玩家以 10 像素/迭代的速度移动,并且以 x、y 坐标开始,这些坐标可以被 10 整除。这就是我们将要做的。

所以,以下是改进后的代码。


HAI 3.4 0 1
IM IN UR CODE EXECUTIN UR KOMANDZ

PLZ RUN SUBPROGRAM DEFALT_VARIABLES
PLZ RUN SUBPROGRAM DRAW_FIELD
FOREVER RUN MOVE

IM OUTTA UR CODE

IM IN UR SUBPROGRAM DAT IZ KALLED DEFALT_VARIABLES
I HAS A TWO BYTE DAT IZ CALLED X
I HAS A TWO BYTE DAT IZ CALLED Y
I HAS A TWO BYTE DAT IZ CALLED BUTTON
PLZ SET TWO BYTE X 200
PLZ SET TWO BYTE Y 150
PLZ SET TWO BYTE BUTTON -1
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED DRAW_FIELD
PLZ CHANGE PAINT BRUSH 0 154 23
PLZ FILL RECT 0 0 630 430
PLZ CHANGE PAINT BRUSH RED
PLZ FILL RECT 100 100 50 50
PLZ CHANGE PAINT BRUSH MAGENTA
PLZ FILL RECT 300 200 50 50

SWITCH [[X]]
LABELCASE -1 END

PLZ CHANGE PAINT BRUSH ORANGE
PLZ FILL RECT X Y 25 25
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED MOVE
PLZ READ CHAR BUTTON
SWITCH [[BUTTON]]
CASE 56,87,119 UP
CASE 52,65,97 LEFT
CASE 50,83,115 DOWN
CASE 54,68,100 RIGHT
PLZ RUN SUBPROGRAM CKECK_LAVA_X
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED UP
PLZ SET TWO BYTE BUTTON -1
PLZ SET TWO BYTE Y Y-10
PLZ RUN SUBPROGRAM DRAW_FIELD
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED DOWN
PLZ SET TWO BYTE BUTTON -1
PLZ SET TWO BYTE Y Y+10
PLZ RUN SUBPROGRAM DRAW_FIELD
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED LEFT
PLZ SET TWO BYTE BUTTON -1
PLZ SET TWO BYTE X X-10
PLZ RUN SUBPROGRAM DRAW_FIELD
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED RIGHT
PLZ SET TWO BYTE BUTTON -1
PLZ SET TWO BYTE X X+10
PLZ RUN SUBPROGRAM DRAW_FIELD
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED FELL_IN_LAVA
PLZ PRINT TEXT YOU FELL IN LAVA
PLZ PRINT TEXT
PLZ PRINT TEXT YOU LOSE
PLZ SET TWO BYTE X -1
PLZ RUN SUBPROGRAM DRAW_FIELD
IM OUTTA UR CODE

IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED CKECK_LAVA_X
SWITCH [[X]]
CASE 80,90,100,110,120,130,140 CKECK_LAVA_Y
PLZ RUN SUBPROGRAM CKECK_CARPET_X
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED CKECK_LAVA_Y
SWITCH [[Y]]
CASE 80,90,100,110,120,130,140 FELL_IN_LAVA
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED ON_CARPET
PLZ PRINT TEXT WHO WAS THE FIRST 
PLZ PRINT TEXT WHO PRESIDENT OF THE 
PLZ PRINT TEXT UNITED STATES?
PLZ PRINT TEXT
PLZ PRINT TEXT 1) RICHARD NIXON
PLZ PRINT TEXT 2) GEORGE WASHINGTON
PLZ PRINT TEXT 3) DONALD TRUMP
PLZ PRINT TEXT 4) JOHN ADAMS

I HAS A ONE BYTE DAT IZ CALLED ANSWER
PLZ ASK TEH USR 2 GIMME A ONE BYTE ANSWER
PLZ CLEAR TEH CONSOLE
SWITCH [ANSWER]
LABELCASE 2 WIN
PLZ PRINT TEXT YOU LOSE!
PLZ GOTO LABEL END
DIS IZ MY LABEL! IT IZ KALLED WIN
PLZ PRINT TEXT YOU WIN!
DIS IZ MY LABEL! IT IZ KALLED END
IM OUTTA UR CODE

IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED CKECK_CARPET_X
SWITCH [[X]]
CASE 280,290,300,310,320,330,340 CKECK_CARPET_Y
IM OUTTA UR SUBPROGRAM

IM IN UR SUBPROGRAM DAT IZ KALLED CKECK_CARPET_Y
SWITCH [[Y]]
CASE 180,190,200,210,220,230,240 ON_CARPET
IM OUTTA UR SUBPROGRAM

请注意,标签 “END” 与地毯子程序中的标签相同。这无关紧要,因为在它之后是 IM OUTTA UR CODE,它会结束程序。

华夏公益教科书