16,549
社区成员
发帖
与我相关
我的任务
分享
Public Const danWei As Integer = 25 '地图单位大小
Public DiTu(33, 33) As Integer '地图数组,地图长宽850*850像素
Public Class TanKe
Public ShengMing As Integer '生命
Public WeiZhiX As Integer '位置X方向
Public WeiZhiY As Integer '位置Y方向
Public SuDu As Integer '速度
Public FangXiang As Integer '方向
Public HuoLi As Integer '火力
Public WaiXing As Integer '外型
End Class
Public Class frmDituBianji
Private DT(33, 33) As Integer
Private Const dtDANWEI As Integer = 20 '地图单位大小
Private DTyuanshu As Integer = 0
Private dtx As Integer
Private dty As Integer
Private p0 As Point, p1 As Point
Private mouseleftDown As Boolean
Private Sub dituchushihua()
For i0 As Integer = 0 To 33
DT(0, i0) = 222
DT(33, i0) = 222
DT(i0, 0) = 222
DT(i0, 33) = 222
Next
piliangSheZhiDiTu(16, 1, 31, 1, 99) : piliangSheZhiDiTu(15, 0, 30, 2, 66) : piliangSheZhiDiTu(18, 0, 30, 2, 66) : piliangSheZhiDiTu(16, 1, 30, 0, 66)
End Sub
Private Sub piliangSheZhiDiTu(ByVal ksX As Integer, ByVal slX As Integer, ByVal ksY As Integer, ByVal slY As Integer, ByVal Zhi As Integer) '对地图批量赋值
For i As Integer = ksX To ksX + slX
For j As Integer = ksY To ksY + slY
If i < 0 Or i > DT.GetUpperBound(0) Or j < 0 Or j > DT.GetUpperBound(1) Then
Else
DT(i, j) = Zhi
End If
Next
Next
End Sub
Public Function HuiTu() As Bitmap '绘地图
Dim map As Bitmap = New Bitmap(dtDANWEI * 34, dtDANWEI * 34)
Dim ea As Drawing.Graphics = Graphics.FromImage(map)
ea.Clear(Color.Transparent)
For i As Integer = 0 To 33
For j As Integer = 0 To 33
If DT(i, j) <> 0 Then
Select Case DT(i, j)
Case 55 '水
ea.DrawImage(My.Resources.S, i * dtDANWEI, j * dtDANWEI, dtDANWEI, dtDANWEI)
Case 66 '砖墙
ea.DrawImage(My.Resources.q, i * dtDANWEI, j * dtDANWEI, dtDANWEI, dtDANWEI)
Case 77 '草丛
ea.DrawImage(My.Resources.C, i * dtDANWEI, j * dtDANWEI, dtDANWEI, dtDANWEI)
Case 88 '石头
ea.DrawImage(My.Resources.q2, i * dtDANWEI, j * dtDANWEI, dtDANWEI, dtDANWEI)
Case 222 '边界
ea.DrawImage(My.Resources.q3, i * dtDANWEI, j * dtDANWEI, dtDANWEI, dtDANWEI)
End Select
End If
Next
Next
ea.DrawImage(My.Resources.Y, 16 * dtDANWEI, 31 * dtDANWEI, 2 * dtDANWEI, 2 * dtDANWEI)
Return map
ea.Dispose()
map.Dispose()
End Function
Private Sub frmDituBianji_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
frmMain.Show()
End Sub
Private Sub frmDituBianji_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
dituchushihua()
DTyuanshu = 0
picDT.Image = HuiTu()
End Sub
Private Sub picDT_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picDT.MouseDown
p0 = New Point(e.X \ dtDANWEI, e.Y \ dtDANWEI)
mouseleftDown = False
End Sub
Private Sub picDT_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picDT.MouseMove
dtx = e.X \ dtDANWEI
dty = e.Y \ dtDANWEI
If e.Button = Windows.Forms.MouseButtons.Left Then mouseleftDown = True
Label1.Text = "坐标:" + " x= " + dtx.ToString + " y= " + dty.ToString
End Sub
Private Sub picDT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picDT.Click
DT(dtx, dty) = DTyuanshu
dituchushihua()
picDT.Image = HuiTu()
End Sub
Private Sub picC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picC.Click, picS.Click, picQ2.Click, picQ1.Click, picD.Click
picC.BorderStyle = BorderStyle.None
picS.BorderStyle = BorderStyle.None
picQ1.BorderStyle = BorderStyle.None
picQ2.BorderStyle = BorderStyle.None
picD.BorderStyle = BorderStyle.None
sender.BorderStyle = BorderStyle.FixedSingle
DTyuanshu = sender.tag
Select Case DTyuanshu
Case 55
Label2.Text = "选择了河水"
Case 66
Label2.Text = "选择了砖墙"
Case 77
Label2.Text = "选择了草丛"
Case 88
Label2.Text = "选择了石头"
Case 0
Label2.Text = "选择了空地"
End Select
End Sub
Private Sub picDT_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picDT.MouseUp
If mouseleftDown Then
p1 = New Point(e.X \ dtDANWEI, e.Y \ dtDANWEI)
If p1.X >= p0.X And p1.Y >= p0.Y Then
piliangSheZhiDiTu(p0.X, p1.X - p0.X, p0.Y, p1.Y - p0.Y, DTyuanshu)
ElseIf p1.X >= p0.X And p1.Y < p0.Y Then
piliangSheZhiDiTu(p0.X, p1.X - p0.X, p1.Y, p0.Y - p1.Y, DTyuanshu)
ElseIf p1.X < p0.X And p1.Y < p0.Y Then
piliangSheZhiDiTu(p1.X, p0.X - p1.X, p1.Y, p0.Y - p1.Y, DTyuanshu)
ElseIf p1.X < p0.X And p1.Y >= p0.Y Then
piliangSheZhiDiTu(p1.X, p0.X - p1.X, p0.Y, p1.Y - p0.Y, DTyuanshu)
End If
dituchushihua()
picDT.Image = HuiTu()
mouseleftDown = False
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
dituchushihua()
myBaoCunDiTu(DT)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
myDuQuDiTu(DT)
picDT.Image = HuiTu()
End Sub
End Class
Public Sub myBaoCunDiTu(ByVal myDiTu(,) As Integer) '保存地图
Dim Savedlg As New SaveFileDialog
Savedlg.Filter = "地图|*.gk"
Savedlg.InitialDirectory = My.Application.Info.DirectoryPath
Savedlg.ShowDialog()
If Windows.Forms.DialogResult.OK Then
'创建(写入)一个文本文件
Dim Myfilename As String = Savedlg.FileName
Dim a As Integer = Myfilename.LastIndexOf(".")
If a = -1 Then
Myfilename += ".gk"
Else
Dim a34 As String = Myfilename.Substring(0, a)
Myfilename = a34 + ".gk"
End If
'以上对文件名进行判断,若扩展名不是“.gk”则自动增加
Dim MyStream As New System.IO.FileStream(Myfilename, System.IO.FileMode.Create)
Dim MyWriter As New System.IO.BinaryWriter(MyStream, System.Text.Encoding.Unicode)
Dim i As Integer
For i = 0 To myDiTu.GetUpperBound(0)
For j As Integer = 0 To myDiTu.GetUpperBound(1)
MyWriter.Write(CByte(myDiTu(i, j)))
Next
Next
MyWriter.Close()
MyStream.Close()
End If
End Sub
Public Sub myDuQuDiTu(ByRef myDiTu(,) As Integer) '读取地图到数组
Dim Opendlg As New OpenFileDialog
Opendlg.Filter = "地图|*.gk"
Opendlg.InitialDirectory = My.Application.Info.DirectoryPath
Opendlg.ShowDialog()
If Windows.Forms.DialogResult.OK Then
Try
If (System.IO.File.Exists(Opendlg.FileName)) Then '判断文件是否存在?
Dim FS As New System.IO.FileStream(Opendlg.FileName, IO.FileMode.Open)
Dim MyReader As New System.IO.BinaryReader(FS, System.Text.Encoding.Unicode)
For i As Integer = 0 To myDiTu.GetUpperBound(0)
For j As Integer = 0 To myDiTu.GetUpperBound(1)
myDiTu(i, j) = int(MyReader.ReadByte())
Next
Next
MyReader.Close()
FS.Close()
End If
Catch ex As Exception
MsgBox(ex.Data.ToString)
End Try
End If
End Sub
Public Class PaoDan
Public pdWeiZhiX As Integer
Public pdWeiZhiY As Integer
Public pdHuoLi As Integer
Public pdFanXiang As Integer
End Class
Public Class BaoWu
Public bwWeiZhiX As Integer
Public bwWeiZhiY As Integer
Public bwBianHao As Integer '11--定时器(限制移动);12--炸毁对方所有目标;13--增加(减少)基地生命值;14--加强火力;
End Class
Private Sub AxWindowsMediaPlayer1_PlayStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles AxWindowsMediaPlayer1.PlayStateChange
If AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsPaused Or AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsReady Then
Else
AxWindowsMediaPlayer1.Ctlcontrols.play()
End If
End Sub
Private Sub Label21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label21.DoubleClick
OpenFileDialog1.Filter = "*.wav;*.mp3|*.wav;*.mp3"
OpenFileDialog1.InitialDirectory = My.Application.Info.DirectoryPath
OpenFileDialog1.FileName = ""
If OpenFileDialog1.ShowDialog = DialogResult.OK Then
beiJingYinyue = OpenFileDialog1.FileName
AxWindowsMediaPlayer1.URL = beiJingYinyue
AxWindowsMediaPlayer1.Ctlcontrols.play()
End If
End Sub
Private Sub Label21_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label21.MouseEnter
Label21.ForeColor = Color.Red
End Sub
Private Sub Label21_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label21.MouseLeave
Label21.ForeColor = Color.Black
End Sub
以上代码实现播放、暂停及指定播放文件