Microsoft Small Basic

Program Listing: VMH230
'V0.02 2014/12/14 メッセージ・戦闘追加。メッセージはみ出し対策も完了。
'V0.01 2014/12/13 平原のみ。移動は完成。(視界外を隠すシステムも追加)
'初期設定(自身のステータスや敵・魔法などを定義)
Status[1]="Lv"
Status[2]="HP"
Status[3]="MP"
Status[4]="AT"
Status[5]="XP"
AddPoint["Lv"]=0
AddPoint["HP"]=3
AddPoint["MP"]=1
AddPoint["AT"]=2
AddPoint["XP"]=0
NXP=10
NSP=2
SkillPoint=2
Gold=0
Mystatus["Lv"]=1
Mystatus["HP"]=30
Mystatus["MP"]=3
Mystatus["AT"]=8
Mystatus["XP"]=0
HP=Mystatus["HP"]
Enemystatus["スライム"]["Lv"]=1
Enemystatus["スライム"]["HP"]=10
Enemystatus["スライム"]["MP"]=0
Enemystatus["スライム"]["AT"]=3
Enemystatus["スライム"]["XP"]=2
Enemystatus["青スライム"]["Lv"]=1
Enemystatus["青スライム"]["HP"]=20
Enemystatus["青スライム"]["MP"]=0
Enemystatus["青スライム"]["AT"]=5
Enemystatus["青スライム"]["XP"]=5
Enemystatus["赤スライム"]["Lv"]=2
Enemystatus["赤スライム"]["HP"]=30
Enemystatus["赤スライム"]["MP"]=3
Enemystatus["赤スライム"]["AT"]=5
EnemyMagic["赤スライム"][1]=1'魔法リスト参照
Enemystatus["赤スライム"]["XP"]=10
Enemystatus["軽ゴブリン"]["Lv"]=2
Enemystatus["軽ゴブリン"]["HP"]=30
Enemystatus["軽ゴブリン"]["MP"]=0
Enemystatus["軽ゴブリン"]["AT"]=10
Enemystatus["軽ゴブリン"]["XP"]=15
'魔法リスト
Magic[1]="グレートアタック"
UseMP[1]=2
MinPT[1]=5
Magic[2]="ミラクルアタック"
UseMP[2]=5
MinPT[2]=35
Magic[3]="ガード"
UseMP[3]=3
MinPT[3]=10
Magic[4]="バーン"
UseMP[4]=5
MinPT[4]=25
Magic[5]="フリーズ"
UseMP[5]=5
MinPT[5]=30
Magic[6]="ヒール"
UseMP[6]=10
MinPT[6]=20
Magic[7]="ビッグヒール"
UseMP[7]=30
MinPT[7]=40
'----
'マップ設定
Background="Green"
Outside="blue"
Mapname="平原エリア"
Looktype=0'0は長方形タイプ、1は斜め正方形タイプ。
lookX=2'斜め正方形タイプの場合は設定するのはlookXのみでOK
lookY=2
UserX=1
UserY=3
mapbuild[1][1]=" "'Xは壁、Eは敵、Uはアイテム。画面端は壁になり、通過できない。
mapbuild[1][2]=" "
mapbuild[1][3]=" E "
mapbuild[1][4]=" E"
mapbuild[1][5]=" "
Spawnenemy[1][1]="スライム"
enemyProb[1][1]=75
Spawnenemy[1][2]="青スライム"
enemyProb[1][2]=25
mesLength=6
message[1]="WASDで移動です。Xは壁、Eは敵、oがプレイヤー、Iがアイテム、"
message[2]="wは武器です。敵に当たると戦闘開始です。"
message[3]="敵を倒すとゴールドを落とします。時々アイテムも落とします。"
message[4]="アイテムの使い方はiキーを押して、上下キーで選択します。"
message[5]="zキーで使用アイテム決定です。武器も同じです。"
message[6]="※プレイ画面が下なのはこのメッセージを表示するためです。"
If Text.GetSubText(mapbuild[1][UserY],UserX,1)<>" " Then
TextWindow.WriteLine("マップの読み込みに失敗しました")
TextWindow.PauseWithoutMessage()
Program.End()
EndIf
MakeMap()
While "True"
While PushKey <> "w" And PushKey <> "s" And PushKey <> "a" And PushKey <> "d" And PushKey <> "i"
PushKey = TextWindow.ReadKey()
PushKey = Text.ConvertToLowerCase(PushKey)
EndWhile
BeforeX=UserX
BeforeY=UserY
If PushKey = "w" Then
UserY = UserY-1
ElseIf PushKey = "s" Then
UserY = UserY+1
ElseIf PushKey = "a" Then
UserX = UserX-1
ElseIf PushKey = "d" Then
UserX = UserX+1
Else

EndIf
If Text.GetSubText(mapbuild[1][UserY],UserX,1) = "X" Or UserX>Text.GetLength(mapbuild[1][UserY]) Or UserX<1 Or UserY>Array.GetItemCount(mapbuild[1]) Or UserY<1 Then
UserX=BeforeX
UserY=BeforeY
ElseIf Text.GetSubText(mapbuild[1][UserY],UserX,1) = "E" Then
WarLv=1
Battle()
EndIf
MakeMap()
PushKey=0
EndWhile

Sub MakeMap
amountEnemy=0
TextWindow.BackgroundColor=Outside
TextWindow.ForegroundColor=Background
TextWindow.Clear()
TextWindow.WriteLine(" "+Mapname)
If mesLength>8 Then
For iE=1 To mesLength
message[iE-1]=message[iE]
EndFor
mesLength=8
EndIf
For iE=1 To mesLength
TextWindow.WriteLine(" "+message[iE])
EndFor
For i_F=1 To 8-mesLength
TextWindow.WriteLine("")
EndFor
For iA=1 To Array.GetItemCount(mapbuild[1])
TextWindow.BackgroundColor=Outside
TextWindow.Write(" ")
For iB=1 To Text.GetLength(mapbuild[1][iA])
GetText=Text.GetSubText(mapbuild[1][iA],iB,1)
If GetText="X" Then
If Background="White" Then
TextWindow.BackgroundColor="Gray"
Else
TextWindow.BackgroundColor="White"
EndIf
TextWindow.ForegroundColor="Black"
ElseIf GetText=" " Then
TextWindow.BackgroundColor=Background
If iB = UserX And iA = UserY Then
GetText = "o"
If Background="Green" Then
TextWindow.ForegroundColor="DarkYellow"
Else
TextWindow.ForegroundColor="Green"
EndIf
EndIf
ElseIf GetText="E" Then
TextWindow.BackgroundColor=Background
TextWindow.ForegroundColor="Red"
amountEnemy=amountEnemy+1
EndIf
If Looktype=0 Then
If Math.Abs(iB-UserX)<=lookX And Math.Abs(iA-UserY)<=lookY Then
TextWindow.Write(GetText)
Else
TextWindow.BackgroundColor="Gray"
TextWindow.ForegroundColor="White"
TextWindow.Write("?")
EndIf
Else
If Math.Abs(iB-UserX)+Math.Abs(iA-UserY)<=lookX Then
TextWindow.Write(GetText)
Else
TextWindow.BackgroundColor="Black"
TextWindow.Write(" ")
EndIf
EndIf
EndFor
TextWindow.WriteLine("")
EndFor
If amountEnemy=0 And Array.ContainsValue(message,"クリア!")<>"True" Then
mesLength=mesLength+1
message[mesLength]="クリア!"
EndIf
TextWindow.BackgroundColor=Outside
TextWindow.ForegroundColor=Background
TextWindow.WriteLine("")
EndSub

Sub Battle
SetedTrue=0
iC=0
Probality = Math.GetRandomNumber(100)
While SetedTrue=0 And iC iC=iC+1
If Probality>enemyProb[WarLv][iC] And SetedTrue=0 Then
Probality=Probality-enemyProb[WarLv][iC]
Else
SetedTrue=1
EndIf
EndWhile
If SetedTrue=1 Then
VSenemy=Spawnenemy[WarLv][iC]
TextWindow.BackgroundColor=Outside
TextWindow.Clear()
EnemyHP=Enemystatus[VSenemy]["HP"]
TextWindow.ForegroundColor="Red"
TextWindow.WriteLine("レベル"+Enemystatus[VSenemy]["Lv"]+"の"+VSenemy+"が現れた!")
Program.Delay(500)
First = 1
Hint[0]=""
Hint[1]="、Zで攻撃"
If Enemystatus[VSenemy]["Lv"]>Mystatus["Lv"] Then
Turn = 1
Else
Turn = 0
EndIf
While EnemyHP>0
If Turn = 1 Then
TextWindow.ForegroundColor="Red"
TextWindow.WriteLine("相手の攻撃!")
TextWindow.WriteLine(Enemystatus[VSenemy]["AT"]+"のダメージを喰らった!")
HP=HP-Enemystatus[VSenemy]["AT"]
If HP<=0 Then
Program.Delay(1000)
TextWindow.WriteLine("あなたはやられた・・・")
TextWindow.Pause()
Program.End()
EndIf
Else
TextWindow.ForegroundColor=Background
TextWindow.WriteLine("あなたの番"+Hint[First]+"だ!")
PushKey=0
While PushKey <> "z"
PushKey = TextWindow.ReadKey()
EndWhile
TextWindow.WriteLine("あなたの攻撃!")
TextWindow.WriteLine("相手に"+Mystatus["AT"]+"のダメージを与えたようだ!")
EnemyHP=EnemyHP-Mystatus["AT"]
First = 0
EndIf
Turn = Math.Remainder(Turn+1,2)
Program.Delay(500)
EndWhile
Program.Delay(500)
DeleteEnemy()
mesLength=mesLength+1
message[mesLength]=VSenemy+"を倒した!"
TextWindow.PauseWithoutMessage()
Else
mesLength=mesLength+1
message[mesLength]="戦いから避けられた!"
EndIf
EndSub

Sub DeleteEnemy
aftermap=""
For iD=1 To Text.GetLength(mapbuild[WarLv][UserY])
If iD=UserX Then
aftermap=aftermap+" "
Else
aftermap=aftermap+Text.GetSubText(mapbuild[WarLv][UserY],iD,1)
EndIf
EndFor
mapbuild[WarLv][UserY] = aftermap
EndSub

Sub ItemSelect
EndSub