-2
Filename = ".\characters.txt"
LoadCharacters()

While MenuOption <> "x"
  TextWindow.Write("Menu : (a) adjust characters, (v) view 

characters, (x) exit, (c) Create Character : ")
  MenuOption = TextWindow.Read()
  MenuOption = Text.ConvertToLowerCase(MenuOption)
  If MenuOption = "a" Then
    TextWindow.WriteLine("Adjusting Characters")
    AdjustCharacters()
  EndIf  

  If MenuOption = "v" Then
    TextWindow.WriteLine("Viewing Characters")
    ViewCharacters()
  EndIf

  If MenuOption = "x" Then
    TextWindow.WriteLine("Exiting program")
    Program.Delay(500)
    Program.End()
  EndIf

  If MenuOption = "c" Then
    TextWindow.WriteLine("Creating Characters")
    Createcharacter()
  EndIf
EndWhile

'================================================
'c:

sub Createcharacter
  TextWindow.WriteLine("Please enter the number of 

characters you want")
  Characternum = TextWindow.ReadNumber()
    For x = 1 To Characternum
    TextWindow.WriteLine("Please enter the name of the 

character" + x)
    Character[x] = TextWindow.Read()
    Strength[x] = 10
    Skill[x] = 10
  EndFor
  AdjustCharacters()
EndSub 

'================================================
'a:

Sub AdjustCharacters
  For X = 1 To Characternum
    Strength[x] = Strength[x] + Math.Floor

(Math.GetRandomNumber(12)/Math.GetRandomNumber(4))
    Skill[x] = Skill[x] + Math.Floor(Math.GetRandomNumber

(12)/Math.GetRandomNumber(4))
  EndFor
  SaveCharacters()
EndSub

'================================================
'v:

Sub ViewCharacters
  For X = 1 To Characternum
    TextWindow.WriteLine("Character " + x + " - " + 

Character[x] + ", stength = " + Strength[x] + ", skill = " 

+ Skill[x])
  EndFor
EndSub

'================================================

Sub LoadCharacters
  ' Requires Filename to be set
  Characternum = File.ReadLine(Filename,1)
  TextWindow.WriteLine("Number of characters = " + 

Characternum)
  For x = 1 To Characternum
    Character[x] = File.ReadLine(Filename,x * 3 - 1) ' Get 

name
    Strength[x] = File.ReadLine(Filename,x * 3) ' Get 

strength
    Skill[x] = File.ReadLine(Filename,x * 3 + 1) ' Get 

skill
  EndFor
EndSub

'================================================

Sub SaveCharacters
  ' Requires Filename and TotalCharacters to be set
  File.WriteLine(Filename,1,Characternum)
  For x = 1 To Characternum
    File.WriteLine(Filename,x * 3 - 1,Character[x]) ' Set 

name
    File.WriteLine(Filename,x * 3, Strength[x]) ' Set 

strength
    File.WriteLine(Filename,x * 3 + 1, Skill[x]) ' Set 

skill
  EndFor
    EndSub  

真的坚持下去,需要让我的头绕过它。它在 Small basic 中,我必须教孩子们如何用伪代码编写它。如果有人能解释这段代码可以用来做什么,将不胜感激。

干杯

4

1 回答 1

1

它是游戏的一部分,玩家可以看到一个菜单来创建、调整和查看游戏角色。Createcharacter 询问玩家角色的名字,adjust characters 给角色随机的力量和技能点,save characters 将角色写入文件,Load 从文件中加载并放入内存,查看角色打印角色名称和屏幕上的统计数据。

于 2013-10-07T10:22:03.573 回答