User:Pluke/maze
Jump to navigation
Jump to search
Public Class frmGame
Structure character
Dim x As Integer
Dim y As Integer
Dim name As String
End Structure
Dim player As character
Dim msize As Integer
Dim h = 10
Dim w = 10
Dim marray(,) As Integer
'reads the file
Private Sub frmGame_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ReDim marray(w + 1, h)
player.x = 3
player.y = 3
msize = 10
Dim reader As New System.IO.StreamReader("H:\file.txt")
For y = 0 To h
For x = 0 To w + 1
marray(x, y) = reader.Read()
'MessageBox.Show(m(x, y))
Next
Next
End Sub
'move the player around the screen?
Private Sub frmGame_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.Up Then
player.y = player.y - 1
End If
If e.KeyCode = Keys.Down Then
If marray(player.x, player.y + 1) = "49" Then
Beep()
Else
player.y = player.y + 1
End If
End If
Invalidate()
End Sub
'draw the screen
Private Sub frmGame_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim pallete As Drawing.Graphics = Me.CreateGraphics
Dim brush_black As New SolidBrush(Color.Black)
For y = 0 To h
For x = 0 To w
'MessageBox.Show(m(x, y))
If marray(x, y) = "49" Then
pallete.FillRectangle(Brushes.DarkGreen, x * msize, y * msize, msize, msize)
End If
If marray(x, y) = "48" Then
pallete.FillRectangle(Brushes.HotPink, x * msize, y * msize, msize, msize)
End If
Next
Next
pallete.FillRectangle(brush_black, New Rectangle(player.x * msize, player.y * msize, msize, msize))
End Sub
End Class
' 1. get the game working. Create a file.txt in the correct location made of 1s and 0s
' 2. what does marray(x, y) = "49" do?
' 3. stop the player walking through walls in all directions
' 4. resize the map to fill the whole screen
' 5. give players a score attribute that decreases on hitting a wall
' 6. add some gold coins to the map and increase the score on picking them up