Nettrix.vb
上传用户:c_chunwei
上传日期:2022-05-07
资源大小:80k
文件大小:11k
源码类别:

其他智力游戏

开发平台:

Visual Basic

  1. Imports System
  2. Imports System.Drawing
  3. Imports System.Collections
  4. Imports System.ComponentModel
  5. Imports System.Windows.Forms
  6. Namespace Nettrix
  7.     _
  8.     '/ <Summary>
  9.     '/ Summary Description For .
  10.     '/ </Summary>
  11.     Public Class NetTrix
  12.         Inherits System.Windows.Forms.Form
  13.         Friend PicBackground As System.Windows.Forms.PictureBox
  14.         Friend LblScore As System.Windows.Forms.Label
  15.         Friend WithEvents CmdStart As System.Windows.Forms.Button
  16.         Friend PicNextBlock As System.Windows.Forms.PictureBox
  17.         Friend LblNextBlock As System.Windows.Forms.Label
  18.         Friend LblScoreValue As System.Windows.Forms.Label
  19.         Friend WithEvents TmrGameClock As System.Windows.Forms.Timer
  20.         Private components As System.ComponentModel.IContainer
  21.         Private StillProcessing As Boolean = False
  22.         Private Score As Integer = 0
  23.         Private CurrentBlock As Block
  24.         Private NextBlock As Block
  25.         Public Sub New()
  26.             '
  27.             ' Required For Windows Form Designer Support
  28.             '
  29.             InitializeComponent()
  30.         End Sub 'New
  31.         '/ <Summary>
  32.         '/ Clean Up Any Resources Being Used.
  33.         '/ </Summary>
  34.         Protected Overloads Sub Dispose(ByVal Disposing As Boolean)
  35.             If Disposing Then
  36.                 If Not (Components Is Nothing) Then
  37.                     Components.Dispose()
  38.                 End If
  39.             End If
  40.             MyBase.Dispose(Disposing)
  41.         End Sub 'Dispose
  42.         '/ Required Method For Designer Support - Do Not Modify
  43.         '/ The Contents Of This Method With The Code Editor.
  44.         '/ </Summary>
  45.         Private Sub InitializeComponent()
  46.             Me.components = New System.ComponentModel.Container
  47.             Me.PicBackground = New System.Windows.Forms.PictureBox
  48.             Me.LblScore = New System.Windows.Forms.Label
  49.             Me.CmdStart = New System.Windows.Forms.Button
  50.             Me.PicNextBlock = New System.Windows.Forms.PictureBox
  51.             Me.LblNextBlock = New System.Windows.Forms.Label
  52.             Me.LblScoreValue = New System.Windows.Forms.Label
  53.             Me.TmrGameClock = New System.Windows.Forms.Timer(Me.components)
  54.             CType(Me.PicBackground, System.ComponentModel.ISupportInitialize).BeginInit()
  55.             CType(Me.PicNextBlock, System.ComponentModel.ISupportInitialize).BeginInit()
  56.             Me.SuspendLayout()
  57.             '
  58.             'PicBackground
  59.             '
  60.             Me.PicBackground.BackColor = System.Drawing.SystemColors.ControlDark
  61.             Me.PicBackground.Location = New System.Drawing.Point(0, 0)
  62.             Me.PicBackground.Name = "PicBackground"
  63.             Me.PicBackground.Size = New System.Drawing.Size(179, 346)
  64.             Me.PicBackground.TabIndex = 0
  65.             Me.PicBackground.TabStop = False
  66.             '
  67.             'LblScore
  68.             '
  69.             Me.LblScore.Location = New System.Drawing.Point(193, 5)
  70.             Me.LblScore.Name = "LblScore"
  71.             Me.LblScore.Size = New System.Drawing.Size(91, 20)
  72.             Me.LblScore.TabIndex = 3
  73.             Me.LblScore.Text = "Score:"
  74.             '
  75.             'CmdStart
  76.             '
  77.             Me.CmdStart.Location = New System.Drawing.Point(192, 155)
  78.             Me.CmdStart.Name = "CmdStart"
  79.             Me.CmdStart.Size = New System.Drawing.Size(82, 27)
  80.             Me.CmdStart.TabIndex = 9
  81.             Me.CmdStart.Text = "Start!"
  82.             '
  83.             'PicNextBlock
  84.             '
  85.             Me.PicNextBlock.BackColor = System.Drawing.Color.DarkGray
  86.             Me.PicNextBlock.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
  87.             Me.PicNextBlock.Location = New System.Drawing.Point(192, 78)
  88.             Me.PicNextBlock.Name = "PicNextBlock"
  89.             Me.PicNextBlock.Size = New System.Drawing.Size(90, 68)
  90.             Me.PicNextBlock.TabIndex = 6
  91.             Me.PicNextBlock.TabStop = False
  92.             '
  93.             'LblNextBlock
  94.             '
  95.             Me.LblNextBlock.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  96.             Me.LblNextBlock.Location = New System.Drawing.Point(192, 52)
  97.             Me.LblNextBlock.Name = "LblNextBlock"
  98.             Me.LblNextBlock.Size = New System.Drawing.Size(91, 17)
  99.             Me.LblNextBlock.TabIndex = 7
  100.             Me.LblNextBlock.Text = "Next Block:"
  101.             '
  102.             'LblScoreValue
  103.             '
  104.             Me.LblScoreValue.Location = New System.Drawing.Point(192, 33)
  105.             Me.LblScoreValue.Name = "LblScoreValue"
  106.             Me.LblScoreValue.Size = New System.Drawing.Size(91, 20)
  107.             Me.LblScoreValue.TabIndex = 8
  108.             Me.LblScoreValue.Text = "0"
  109.             Me.LblScoreValue.TextAlign = System.Drawing.ContentAlignment.TopCenter
  110.             '
  111.             'TmrGameClock
  112.             '
  113.             Me.TmrGameClock.Interval = 330
  114.             '
  115.             'NetTrix
  116.             '
  117.             Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
  118.             Me.ClientSize = New System.Drawing.Size(312, 318)
  119.             Me.Controls.Add(Me.CmdStart)
  120.             Me.Controls.Add(Me.PicNextBlock)
  121.             Me.Controls.Add(Me.LblNextBlock)
  122.             Me.Controls.Add(Me.LblScoreValue)
  123.             Me.Controls.Add(Me.LblScore)
  124.             Me.Controls.Add(Me.PicBackground)
  125.             Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
  126.             Me.Name = "NetTrix"
  127.             Me.Text = ".NETTrix"
  128.             CType(Me.PicBackground, System.ComponentModel.ISupportInitialize).EndInit()
  129.             CType(Me.PicNextBlock, System.ComponentModel.ISupportInitialize).EndInit()
  130.             Me.ResumeLayout(False)
  131.         End Sub 'InitializeComponent
  132.         '/ <Summary>
  133.         '/ The Main Entry Point For The Application.
  134.         '/ </Summary>
  135.         <STAThread()> Shared _
  136.         Sub Main()
  137.             Application.Run(New Nettrix)
  138.         End Sub 'Main
  139.         Private Sub TmrGameClock_Tick(ByVal Sender As System.Object, ByVal E As System.EventArgs) Handles TmrGameClock.Tick
  140.             Dim ErasedLines As Integer
  141.             If StillProcessing Then
  142.                 Return
  143.             End If
  144.             StillProcessing = True
  145.             'Manage The Falling Block
  146.             If Not CurrentBlock.Down() Then
  147.                 If CurrentBlock.Top() = 0 Then
  148.                     TmrGameClock.Enabled = False
  149.                     CmdStart.Enabled = True
  150.                     MessageBox.Show("GAME OVER", ".NETTrix", MessageBoxButtons.OK, MessageBoxIcon.Stop)
  151.                     StillProcessing = False
  152.                     Return
  153.                 End If
  154.                 'Increase Score Based On # Of Deleted Lines
  155.                 ErasedLines = GameField.CheckLines()
  156.                 If ErasedLines > 0 Then
  157.                     Score += 100 * ErasedLines
  158.                     LblScoreValue.Text = Score.ToString()
  159.                     'Clear The Game Field And Force The Window To Re-Paint
  160.                     PicBackground.Invalidate()
  161.                     Application.DoEvents()
  162.                     GameField.Redraw()
  163.                 End If
  164.                 'Replace The Current Block...
  165.                 CurrentBlock = New Block(New Point(GameField.SquareSize * 6, 0), NextBlock.BlockType)
  166.                 CurrentBlock.Show(PicBackground.Handle)
  167.                 'Create The Next Block
  168.                 NextBlock.Hide(PicNextBlock.Handle)
  169.                 NextBlock = New Block(New Point(20, 10), Block.BlockTypes.Undefined)
  170.                 NextBlock.Show(PicNextBlock.Handle)
  171.             End If
  172.             StillProcessing = False
  173.         End Sub 'TmrGameClock_Tick
  174.         Private Sub CmdStart_Click(ByVal Sender As Object, ByVal E As System.EventArgs) Handles CmdStart.Click
  175.             TmrGameClock.Enabled = True
  176.             CmdStart.Enabled = False
  177.             LblScoreValue.Text = "0"
  178.             ' Clean The Game Field
  179.             PicBackground.Invalidate()
  180.             Application.DoEvents()
  181.             GameField.Reset()
  182.             GameField.Redraw()
  183.             ' Create And Show The Current And Next Blocks
  184.             CurrentBlock = New Block(New Point(GameField.SquareSize * 6, 50), Block.BlockTypes.Undefined)
  185.             CurrentBlock.Show(PicBackground.Handle)
  186.             NextBlock = New Block(New Point(20, 10), Block.BlockTypes.Undefined)
  187.             NextBlock.Show(PicNextBlock.Handle)
  188.         End Sub 'CmdStart_Click
  189.         Private Sub NetTrix_KeyDown(ByVal Sender As Object, ByVal E As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
  190.             Select Case E.KeyCode
  191.                 Case Keys.Right
  192.                     CurrentBlock.Right()
  193.                 Case Keys.Left
  194.                     CurrentBlock.Left()
  195.                 Case Keys.Up
  196.                     CurrentBlock.Rotate()
  197.                 Case Keys.Down
  198.                     CurrentBlock.Down()
  199.                 Case Keys.Escape
  200.                     TmrGameClock.Enabled = Not TmrGameClock.Enabled
  201.                     If TmrGameClock.Enabled Then
  202.                         Me.Text = ".NETTrix"
  203.                     Else
  204.                         Me.Text = ".NETTrix -- Press 'Esc' To Continue"
  205.                     End If
  206.                 Case Else
  207.             End Select
  208.             Invalidate()
  209.         End Sub 'NetTrix_KeyDown
  210.         Private Sub NetTrix_Load(ByVal Sender As Object, ByVal E As System.EventArgs) Handles MyBase.Load
  211.             GameField.BackColor = PicBackground.BackColor
  212.             GameField.WinHandle = PicBackground.Handle
  213.             'Adjusts The Size Of The Form And Position Of Controls Based On The Class Constants
  214.             'On The Window Height, Sums The Size Of The Window Title Bar
  215.             Height = GameField.Height * GameField.SquareSize + (Height - ClientSize.Height) + 3 '3=Border Width
  216.             Width = GameField.Width * GameField.SquareSize + 120
  217.             PicBackground.Height = GameField.Height * GameField.SquareSize + 4
  218.             PicBackground.Width = GameField.Width * GameField.SquareSize + 4
  219.             PicNextBlock.Left = GameField.Width * GameField.SquareSize + 12
  220.             LblNextBlock.Left = GameField.Width * GameField.SquareSize + 12
  221.             LblScore.Left = GameField.Width * GameField.SquareSize + 12
  222.             LblScoreValue.Left = GameField.Width * GameField.SquareSize + 12
  223.             CmdStart.Left = GameField.Width * GameField.SquareSize + 12
  224.             '
  225.             'Block - Creates The First Block And The First NEXT Block
  226.             '
  227.             GameField.WinHandle = PicBackground.Handle
  228.             GameField.BackColor = PicBackground.BackColor
  229.         End Sub 'NetTrix_Load
  230.         Private Sub NetTrix_Activated(ByVal Sender As Object, ByVal E As System.EventArgs) Handles MyBase.Activated
  231.             '        This Event Occurs When The Window Receives Back The Focus After Losing It To Another Window
  232.             '        So, We Redraw The Whole Game Field
  233.             '        Clear The Game Field
  234.             PicBackground.Invalidate()
  235.             Application.DoEvents()
  236.             GameField.Redraw()
  237.             If Not (NextBlock Is Nothing) Then
  238.                 NextBlock.Show(PicNextBlock.Handle)
  239.             End If
  240.         End Sub 'NetTrix_Activated
  241.     End Class 'NetTrix
  242. End Namespace 'Nettrix