2013-10-07 113 views
-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 

真的停留在它上面,需要讓我的頭繞它。它的基礎小,我必須教孩子們如何寫在僞代碼。如果有人可以解釋這個代碼可以用於它會非常感激。這段代碼是什麼意思?

歡呼

+3

你不明白哪一點?你從哪裏得到代碼?當你運行它會發生什麼? – doctorlove

+2

如果您不完全理解此代碼的作用,您打算如何編寫僞代碼?更重要的是:你打算如何教別人去做你自己做不到的事情? – varocarbas

+0

我得到了我正在工作的一所學校的代碼,但從未教過VB課程,因此學習了它。 - 這就是我計劃教授它的方式。 –

回答

1

這是一場遊戲,在這裏玩家呈現一個菜單來創建,調整和查看遊戲人物的一部分。 Createcharacter向玩家詢問角色的名字,調整角色給出角色的隨機強度和技能點,保存角色將角色寫入文件,Load從文件中加載它們並將它們放入內存中,查看角色輸出角色名稱和統計在屏幕上。

+0

謝謝。這真的很有幫助。它爲我提供了一些工作依據。在我教授它之前,我將會學習這一點。 –