编程语言
首页 > 编程语言> > 魔塔之拯救白娘子~我的第一个VB6+DX8做的小游戏源码~20开始游戏-对话处理

魔塔之拯救白娘子~我的第一个VB6+DX8做的小游戏源码~20开始游戏-对话处理

作者:互联网

魔塔之拯救白娘子 完整工程下载地址:
《魔塔之拯救白娘子》流程分析6:对话处理
游戏的对话处理比较简单,仅仅是根据游戏流程提供简单的对话系统,没有涉及复杂的东西。下边是设计的窗体:
对话处理



Option Explicit
Dim 对话内容() As String
Dim 要显示的对话次数 As Integer
Dim 当前显示的对话编号 As Integer
Dim npctalk(20) As String

Sub 写对话内容()
On Error Resume Next
Dim sFile As String
MkDir App.Path & "\npctalk"
 sFile = App.Path & "\npctalk\Talk1.dat"
 
npctalk(0) = "勇士:……"
npctalk(1) = "小青:姐夫,你醒了!"
npctalk(2) = "勇士:。。。。。。你是谁?我在哪里?"
npctalk(3) = "小青:自从姐姐被法海老秃驴关在这雷峰塔,你这个家伙就整天借酒消愁!今天我们一定要把姐姐救出来!你清醒一点啊!"
npctalk(4) = "勇士:救姐姐?我。。。。。。我晕,不会吧?是我在做梦吗?我刚才和朋友在喝酒啊。。。"
npctalk(5) = "小青:快点起来啦!趁法海老秃驴不在,我们得快点行动!这里每层楼都有很多被镇压的妖魔鬼怪,你现在得帮助我打败他们。"
npctalk(6) = "勇士:打妖魔鬼怪?靠,我不会打架!再说打赢了坐牢,打输了得进医院!"
npctalk(7) = "小青:别在胡说八道了,你听好了,我们分头行动。"
npctalk(8) = "小青:记住:有一层楼里有一个十字架,,中间有一颗红色的宝石。"
npctalk(9) = "勇士:十字架?我不信神的。不过红宝石我倒是喜欢。。"
npctalk(10) = "小青: 只拿到那个才能打开20层的门?"
npctalk(11) = "勇士: 我有点糊涂???"
npctalk(12) = "小青:在三楼有一把增加攻击的剑,五楼有增加防御的盾,而那个红宝石十字架放在七楼。在塔里的其它楼层上,还有一些存放了好几百年的宝剑和宝物。。。"
npctalk(13) = "勇士:宝剑和宝物?那不就是古董吗?这次可要发财了,我去看看。。。"
npctalk(14) = "小青:等下,我这里有三把不同颜色的钥匙,你先拿去。每种颜色钥匙开相应颜色的门。"
npctalk(15) = "勇士:好的!这下要发财了!走喽。。。。"
npctalk(16) = "小青:哎,姐夫想念姐姐,疯言疯语,希望这次能顺利救出姐姐。"
写文本文件 sFile, 16

 sFile = App.Path & "\npctalk\Talk2.dat"
 
npctalk(0) = "勇士:你是谁?"
npctalk(1) = "小偷:得救了,得救了!我是Trmup,谢谢你的救命之恩。现在你帮我打开了门,我可以帮你一个忙。"
npctalk(2) = "勇士:是吗?你会什么?"
npctalk(3) = "小偷:打开各种各样的门是我的强项!"
npctalk(4) = "勇士:太好了,我刚才路过一个门,我手上的钥匙没法打开,你可以帮我吗?"
npctalk(5) = "小偷:哦,这个门很easy哦。 我会帮你打开的。 如果你要去塔顶,还需要找到一把嵌了红宝石的铁榔头打开一个特殊的门。"
npctalk(6) = "勇士:嵌了红宝石的铁榔头?好的,我会找到的。"
npctalk(7) = "小偷:你找到后直接来这边找我,我在这边等你。"
npctalk(8) = "勇士:OK"
写文本文件 sFile, 8

sFile = App.Path & "\npctalk\Talk3.dat"
 npctalk(0) = "勇士:小青妹子,我已经将你说的那个十字架找到了。  "
npctalk(1) = "小青:太好了!这个是提升我们力量的关键物品,这次我们一定有很大机会救出姐姐!不过你要记住:如果你没有足够的实力的话,不要去第二十一层!在那一层里,你所有宝物的法力都会失去作用!"
npctalk(2) = "勇士:是吗?你会什么?"
npctalk(3) = "勇士:知道了,我会小心的"
写文本文件 sFile, 4

sFile = App.Path & "\npctalk\Talk4.dat"
 npctalk(0) = "勇士:TRump,快看,我找到了什么!   "
npctalk(1) = "小偷:太好了,这个东西果然是在这里。好吧,我现在就去帮你修好第20层的路面。"

写文本文件 sFile, 1

sFile = App.Path & "\npctalk\Talk5.dat"
 
npctalk(0) = "勇士:老婆!我来救你了!"
npctalk(1) = "白娘子:相公,你终于来了!"
npctalk(2) = "勇士:是的,我对你朝思暮想,今天终于见到你了。我们快走吧。  "
npctalk(3) = "白娘子:不行,现在还不是时候。 "
npctalk(4) = "勇士:为什么?"
npctalk(5) = "白娘子:我被法海老和尚下了一个连体诅咒。也就是说,必须把法海和尚的替身杀才行。"
npctalk(6) = "勇士:法海和尚的替身?"
npctalk(7) = "白娘子:是的,那个替身在这座塔的最顶层,你去杀了他!"
npctalk(8) = "勇士:好,那你等着,等我杀了那个替身再来这里救你!"
npctalk(9) = "白娘子:嗯,小心那个替身会释放幻影诅咒,他的攻击力和防御力都会提升至少一半以上。"
npctalk(10) = "勇士:放心吧,我心里有素。你一定要等我回来啊。"
npctalk(11) = "白娘子:相公,我等你!"

写文本文件 sFile, 11


sFile = App.Path & "\npctalk\Talk6.dat"
 
npctalk(0) = "勇士:老爹,我来救你的!"
npctalk(1) = "神秘老人:天哪,终于有人来救我了!我真是太感谢你了!这个地方阴暗潮湿,真不想呆在这里。"
npctalk(2) = "勇士:那你快走吧,我还要救白娘子呢。 "
npctalk(3) = "神秘老人:多谢多谢。我把这个东西就送给你吧!这是我年青的时候用过的,希望能助你一臂之力。 "
npctalk(4) = "勇士:谢谢老爹,我走了,多保重。"
npctalk(5) = "神秘老人:我在这边休息休息再走。在我走之前,你可以来我这边,兑换你想要的东西。"
npctalk(6) = "勇士:好的,没问题。"

写文本文件 sFile, 6

sFile = App.Path & "\npctalk\Talk7.dat"

npctalk(0) = "勇士:老伯,你还好吗?"
npctalk(1) = "商人:我没事,谢谢你救我。其实我是个商人,不知道为什么就被抓到这里来了。"
npctalk(2) = "勇士: 那你快走吧"
npctalk(3) = "商人:这个东西送给你,作为对你的感谢。"
npctalk(4) = "勇士:正好需要呢,多谢老伯。"
npctalk(5) = "商人:我在这里睡一会,你需要什么可以来换,世上有买有卖,才有钱途。"
npctalk(6) = "勇士: 那倒是??? (希望不是奸商!)"

写文本文件 sFile, 6

sFile = App.Path & "\npctalk\Talk8.dat"

npctalk(0) = "勇士:你腿脚倒是挺快的,居然比我先到这里?!"
npctalk(1) = "神秘老人:O(∩_∩)O,降妖除魔,我也有两把刷子的。"
npctalk(2) = "勇士:佩服佩服!"
npctalk(3) = "神秘老人:你看我刚得到一个好剑,你有没有兴趣?。"
npctalk(4) = "勇士:要多少钱?"
npctalk(5) = "神秘老人:你救了我,我怎么会跟你收钱呢?我想看看你有没有努力打怪,所以呢,你需要拿500点经验值兑换120点攻击力,怎么样?"
npctalk(6) = "勇士:好吧,那就将那把剑给我吧!"
npctalk(7) = "神秘老人:这把剑就给你了!我在下边等你来换其他东西。"
写文本文件 sFile, 7

sFile = App.Path & "\npctalk\Talk9.dat"

npctalk(0) = "勇士:你腿脚倒是挺快的,居然比我先到这里?!"
npctalk(1) = "神秘老人:O(∩_∩)O,降妖除魔,我也有两把刷子的。"
npctalk(2) = "勇士:佩服佩服!"
npctalk(3) = "神秘老人:你看我刚得到一个好剑,你有没有兴趣?。"
npctalk(4) = "勇士:要多少钱?"
npctalk(5) = "神秘老人:你救了我,我怎么会跟你收钱呢?我想看看你有没有努力打怪,所以呢,你需要拿500点经验值兑换120点攻击力,怎么样?"
npctalk(6) = "勇士:好吧,那就将那把剑给我吧!"
npctalk(7) = "神秘老人:这把剑就给你了!我在下边等你来换其他东西。"
写文本文件 sFile, 7

sFile = App.Path & "\npctalk\Talk10.dat"

npctalk(0) = "勇士:你腿脚倒是挺快的,居然比我先到这里?!"
npctalk(1) = "神秘老人:O(∩_∩)O,降妖除魔,我也有两把刷子的。"
npctalk(2) = "勇士:佩服佩服!"
npctalk(3) = "神秘老人:你看我刚得到一个好剑,你有没有兴趣?。"
npctalk(4) = "勇士:要多少钱?"
npctalk(5) = "神秘老人:你救了我,我怎么会跟你收钱呢?我想看看你有没有努力打怪,所以呢,你需要拿500点经验值兑换120点攻击力,怎么样?"
npctalk(6) = "勇士:哎呀,我的经验值不够啊!"
npctalk(7) = "神秘老人:看来你没有努力打怪啊!等你经验值够了再来我这边!"
写文本文件 sFile, 7

sFile = App.Path & "\npctalk\Talk11.dat"

npctalk(0) = "勇士:你腿脚真快。。。"
npctalk(1) = "商人:O(∩_∩)O,行走江湖,没有两把刷子怎么混啊?!"
npctalk(2) = "勇士:佩服佩服!"
npctalk(3) = "商人:你看我刚得到一个好的盾牌,你有没有兴趣?"
npctalk(4) = "勇士:要多少钱?"
npctalk(5) = "商人:给你打个折吧,只要500个金币救可以兑换120点防御力,走过路过千万不要错过!怎么样?"
npctalk(6) = "勇士:没那么多钱,可以欠账吗?"
npctalk(7) = "神秘老人:年轻人要讲武德,怎么能欠账呢?万一你不还钱,那我不救亏大了!"
npctalk(8) = "勇士:好吧!"
npctalk(9) = "神秘老人:等你有钱了再来找我!"

写文本文件 sFile, 9

sFile = App.Path & "\npctalk\Talk12.dat"

npctalk(0) = "红衣魔王:停止吧!愚蠢的人类!赶紧回去吧,现在放手还不算太晚!"
npctalk(1) = "勇士:老妖怪,该停止的是你!快说,法海老秃驴的替身在哪里?"
npctalk(2) = "红衣魔王:等你打赢了我再说吧!"
npctalk(3) = "勇士:受死吧,老妖怪!"
写文本文件 sFile, 3

sFile = App.Path & "\npctalk\Talk13.dat"

npctalk(0) = "小偷:你找到锄头了吗? "
npctalk(1) = "勇士:还在找!"
npctalk(2) = "小偷:真能墨迹!快点去找!"
npctalk(3) = "是是是!"
写文本文件 sFile, 3

sFile = App.Path & "\npctalk\Talk14.dat"

npctalk(0) = "小青:找到红宝石十字架了? "
npctalk(1) = "勇士:还没有哦!"
npctalk(2) = "小青:那你还不赶快去找?等什么呢?等天黑吗?"

写文本文件 sFile, 2

sFile = App.Path & "\npctalk\Talk15.dat"

npctalk(0) = "白娘子:相公,我等你!快去吧! "


写文本文件 sFile, 0

sFile = App.Path & "\npctalk\Talk16.dat"

npctalk(0) = "勇士:红衣老妖!你的死期到了! "
npctalk(1) = "红衣大魔王:哈哈哈,就凭你?O(∩_∩)O,真是太好笑了!想打败我,你还嫩着点呢!  !"
npctalk(2) = "勇士:废话少说,看剑!!"
npctalk(3) = "红衣大魔王:现在的年轻人真是不讲武德!来,骗,来,偷袭,我六十多岁的老同志,这好吗?这不好。"
npctalk(4) = "勇士:。。。。。。"
npctalk(5) = "红衣大魔王:我劝,你这个年轻人好自为之,好好反思,以后不要再犯这样的错误,小聪明啊"
npctalk(6) = "去死吧!"
写文本文件 sFile, 6

sFile = App.Path & "\npctalk\Talk17.dat"

npctalk(0) = "小青:你怎么才来,速度真慢!   ! "
npctalk(1) = "勇士:我有点路痴。。。"
npctalk(2) = "小青:现在还需要3枚圣光徽,才能消除法海老秃驴咒术!"
npctalk(3) = "勇士:。。。。。。知道了!"
npctalk(4) = "小青:去吧、"

写文本文件 sFile, 4

sFile = App.Path & "\npctalk\Talk18.dat"

npctalk(0) = "冥灵魔王:停止吧!愚蠢的人类!赶紧回去吧,现在放手还不算太晚!   "
npctalk(1) = "勇士:老妖怪,该停止的是你!快说,法海老秃驴的替身在哪里?"
npctalk(2) = "冥灵魔王:你真是不见棺材不掉泪啊!天堂有路你不走,地狱无门你偏入!"
npctalk(3) = "勇士:受死吧,老妖怪!"
npctalk(4) = "冥灵魔王:哈哈哈哈,就凭你!看我的地狱神功!"

写文本文件 sFile, 4

sFile = App.Path & "\npctalk\Talk19.dat"

npctalk(0) = "血影:嗯~o(* ̄▽ ̄*)o?我看你是活的不耐烦了!赶紧滚!  "
npctalk(1) = "勇士:你就是法海老秃驴的替身?"
npctalk(2) = "血影:替身?(ノ⊙ω⊙)ノ嚯,告诉你吧,法海在我的肚子呢!"
npctalk(3) = "勇士:真的?太好了,那没事了,我走了!"
npctalk(4) = "血影:想走?哈哈,迟了!我正好肚子饿了,借你一用!"
npctalk(5) = "勇士:靠,看你皮痒,让你看看我的厉害!"
npctalk(6) = "血影:找死!"
写文本文件 sFile, 6

sFile = App.Path & "\npctalk\Talk20.dat"

npctalk(0) = "白娘子:相公,我们赢了! "
npctalk(1) = "勇士:是啊!"
npctalk(2) = "白娘子:我们自由了!"
npctalk(3) = "勇士:是啊!"
npctalk(4) = "白娘子:小青呢?"
npctalk(5) = "小青:我在这里,姐姐,想死你了!"
npctalk(6) = "白娘子:我也是啊"
npctalk(7) = "勇士:我们走吧。"
npctalk(8) = "小青:好。"
npctalk(9) = "白娘子:走吧。"
npctalk(10) = "勇士:魔塔仿制版是一款采用VB6+DX8编写的小游戏,@by 高保洪 QQ127644712 这是一个用来练手的作品,源码都是网上搜集,错误之处在所难免。"

写文本文件 sFile, 10

End Sub


'write file

 Sub 写文本文件(fName As String, 写入的数量 As Integer)
 On Error Resume Next

      Dim i As Integer
    Dim nHandle As Integer
    
    'fName = "d:\1.txt"
    nHandle = FreeFile
    Open fName For Output As #nHandle
    For i = 0 To 写入的数量
    Print #nHandle, npctalk(i)
'    Print #nHandle, "2"
    
    Next
    
    Close nHandle
  End Sub
'----------------------------------
'read file
Sub 读文本文件(fName As String)
On Error Resume Next

    Dim nHandle As Integer
    
    '按行读
    
Open fName For Input As #1
Do While Not EOF(1)

要显示的对话次数 = 要显示的对话次数 + 1
ReDim Preserve 对话内容(要显示的对话次数)
Line Input #1, 对话内容(要显示的对话次数)
Loop
Close #1
    
' Dim a() As Byte
'Dim al As Long
'Dim b As String
'   '2进制方式bai读取文本文件
'Open fName For Binary As #1
'     al = LOF(1)
'     ReDim a(al)
'     Get #1, , a
'    Close #1
'   ' Debug.Print a
'    '把bai2进制信息转换成字符串
'    Label_对话显示 = StrConv(a, vbUnicode)
    
 '全读
'    nHandle = FreeFile
'    Open fName For Input As #nHandle
'
'    Do Until EOF(nHandle)
'        Line Input #nHandle, 对话内容
'        Debug.Print 对话内容
'    Loop
'    Close nHandle


End Sub







Private Sub Form_KeyPress(KeyAscii As Integer)

  If KeyAscii = vbKeySpace Then
      显示对话内容
End If


End Sub

'Print
Private Sub Form_Load()
     

     '获得主窗口的坐标
     Me.Left = frmMain.Left + 1000
     Me.Top = frmMain.Top + 3000
    
    Dim rtn As Long
    rtn = GetWindowLong(hWnd, GWL_EXSTYLE)
    rtn = rtn Or WS_EX_LAYERED
    SetWindowLong hWnd, GWL_EXSTYLE, rtn
    SetLayeredWindowAttributes hWnd, 0, 150, LWA_ALPHA
   
'让窗口在顶层
rtn = SetWindowPos(Me.hWnd, -1, 0, 0, 0, 0, 3)
'取消窗口在顶层
'rtn = SetWindowPos(F_V.hwnd, -2, 0, 0, 0, 0, 3)
    当前显示的对话编号 = 0
    要显示的对话次数 = 0
    
    '读取对话子程序
    对话内容初始化
    显示对话内容
    
  
  '
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
'点击空格或者鼠标左键进行下一项对话处理

If Button = 1 Then

   显示对话内容



End If

End Sub



Private Sub Label_对话显示_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = 1 Then

   显示对话内容



End If
End Sub

Sub 显示对话内容()
  On Error Resume Next

    Dim m() As String
   
 If 要显示的对话次数 = 0 Then Exit Sub
 'if 当前显示的对话编号=0 then 当前显示的对话编号=1
 当前显示的对话编号 = 当前显示的对话编号 + 1
 If 当前显示的对话编号 > 要显示的对话次数 Then Unload Me: 对话窗口显示标志 = False: Exit Sub '对话标志 = 2:
 
 
m = Split(对话内容(当前显示的对话编号), ":")

 If m(0) = "小青" Then
    Image_显示NPC图标.Picture = LoadPicture(App.Path & "\ico\小青.bmp")
      
    End If
 
 If m(0) = "勇士" Then
    Image_显示NPC图标.Picture = LoadPicture(App.Path & "\ico\勇者.bmp")
      
    End If
 
 If m(0) = "小偷" Then
    Image_显示NPC图标.Picture = LoadPicture(App.Path & "\ico\小偷.bmp")
      
    End If
    
    If m(0) = "神秘老人" Then
    Image_显示NPC图标.Picture = LoadPicture(App.Path & "\ico\老人.bmp")
      
    End If
 
 If m(0) = "商人" Then
    Image_显示NPC图标.Picture = LoadPicture(App.Path & "\ico\商人.bmp")
      
    End If
    
 If m(0) = "红衣魔王" Then
    Image_显示NPC图标.Picture = LoadPicture(App.Path & "\ico\红衣魔王.bmp")
      
    End If
    
    If m(0) = "红衣大魔王" Then
    Image_显示NPC图标.Picture = LoadPicture(App.Path & "\ico\红衣大魔王.bmp")
      
    End If
    
    If m(0) = "白娘子" Then
    Image_显示NPC图标.Picture = LoadPicture(App.Path & "\ico\白娘子.bmp")
      
    End If
    
    If m(0) = "冥灵魔王" Then
    Image_显示NPC图标.Picture = LoadPicture(App.Path & "\ico\冥灵魔王.bmp")
      
    End If
    
    If m(0) = "血影" Then
    Image_显示NPC图标.Picture = LoadPicture(App.Path & "\ico\BOSS.bmp")
      
    End If
 
 
 Label_对话显示.Caption = 对话内容(当前显示的对话编号)

End Sub





Sub 对话内容初始化()
Dim sFile As String
 sFile = App.Path & "\npctalk\Talk" & 对话文件名编号 & ".dat"
        If CheckPathFile(sFile) = False Then
'            MsgBox "对话文件丢失,对游戏有一些影响,但还可以继续!" & vbCrLf & vbCrLf & sFile, vbCritical
            写对话内容
            
'            Exit Sub
       End If
读文本文件 (sFile)



End Sub

Private Sub Timer1_Timer()
'根据主窗口调整背身窗口
'如果主窗口变小就隐身
If frmMain.WindowState = 1 Then
Me.Hide
Else
Me.Show
End If
'如果主窗口移动就跟着移动
'     Me.Left = frmMain.Left + 1000
'     Me.Top = frmMain.Top + 3000
     If Me.Left - 1000 <> frmMain.Left Then Me.Left = frmMain.Left + 1000
     If Me.Top - 3000 <> frmMain.Top Then Me.Top = frmMain.Top + 3000

End Sub

标签:npctalk,20,DX8,App,sFile,源码,对话,Path,勇士
来源: https://blog.csdn.net/gosub60/article/details/112862813