Public feed #526965

David Richardson

public text v1 · immutable
Raw Edit
·published 2007-06-01 02:22 UTC
rendered paste body
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms


Namespace Queens
End Namespace 'Queens
 _
Class Queens
   Inherits Form '
   'ToDo: Error processing original source shown below
   '
   '
   '------------^--- 'class', 'struct', 'interface' or 'delegate' expected
   '
   'ToDo: Error processing original source shown below
   '
   '
   '--------------------^--- Syntax error: ';' expected
   Public buttons(8, 8) As Button 'this is the multidimensional
   'array of buttons that the user can click on (either white/black)
   Public lastMove As Point 'this is the location of the last move the user makes.
   Public queenCount As Integer = 0
   Public openSquares As Integer = 64
   '//End Globals////
   'The two Bitmap variables below are the images of the knights. Knight.png is
'
         * the image that appears in a regular white button thats clicked. Knightblack
'
         * is the image that appears in a black square. This was necessery because 
'
         * I had problems getting the software to accept the transparent backround. 
   
   Private queenWhite As New Bitmap(GetType(Queens), "QueenWhite.png")
   Private queenBlack As New Bitmap(GetType(Queens), "QueenBlack.png")
   Private dotWhite As New Bitmap(GetType(Queens), "DotWhite.png")
   Private dotBlack As New Bitmap(GetType(Queens), "DotBlack.png")
   Private firstMove As Boolean = True 'this bool value stays true until the user clicks button
   Private counter As Double = 0.0
    'value that stores the percentage the user has completed
   Public Sub New()
      InitializeComponent() 'loads the form
      Dim i As Integer
      For i = 0 To 7
         'This for loop creates each of the buttons in the grid and then fills
'
                 * in their properties. Including name, width, height, location and
'
                 * their backround colour 
         Dim j As Integer
         For j = 0 To 7
            ' create each of the buttons
            buttons(i, j) = New Button()
            ' initialize each button here
            buttons(i, j).Name = "b" +(i * 100 + j).ToString() 'button name
            buttons(i, j).Width = 50 'sets button width
            buttons(i, j).Height = 50 'sets button height
            buttons(i, j).Location = New Point(i * 50, j * 50) 'sets location
            ' adds the click event handler
            AddHandler buttons(i, j).Click, AddressOf ButtonClick 'if button is
            'clicked then go to the function ButtonClick().
            'the if/else statement below creates a chessboard pattern by
            'painting alternate squares white and black.
            If(i + j) Mod 2 = 0 Then 'if i + j equals an even number
               buttons(i, j).BackColor = Color.Black 'sets backround colour
            'if i + j equals an odd number
            Else
               buttons(i, j).BackColor = Color.White 'sets backround colour
            End If ' add the button controls to the form
            Me.Controls.Add(buttons(i, j)) 'adds the button to the form
         Next j
      Next i
      Invalidate()
   End Sub 'New
   
   
   Private Sub ButtonClick(sender As Object, e As EventArgs)
      Dim b As Button = CType(sender, Button) 'determines which button was clicked 
      Dim x As Integer = Convert.ToInt32(b.Name.TrimStart("b"c)) / 100 'gets the position (horizontal)
      Dim y As Integer = Convert.ToInt32(b.Name.TrimStart("b"c)) Mod 100 ' gets the position (verticle)
      If Not (buttons(x, y).Image Is Nothing) Then
         MessageBox.Show("This Spot Is Already Taken...", "Error:")
         Return
      End If
      Dim i As Integer
      For i = 0 To 7
         '////PRINTS//VERTICAL//LINES//////
         If(x + i) Mod 2 = 0 Then
            buttons(x, i).Image = dotBlack
         Else
            buttons(x, i).Image = dotWhite
         End If '////PRINTS//HORIZONTAL//LINES/////
         If(i + y) Mod 2 = 0 Then
            buttons(i, y).Image = dotBlack
         Else
            buttons(i, y).Image = dotWhite
         End If '////PRINTS//DIAGONAL//LINES//////
         'The following if statements basically just draw all your 
'
                 * diagonal lines. The reason I used several if statements is 
'
                 * because the diagonal line has to be drawn in 4 different 
'
                 * directions. 
         If x + i < 8 And y + i < 8 Then
            'this if statement draws diagonal lines up and to the right
            If buttons(x + i, y + i).BackColor = Color.Black Then
               buttons(x + i, y + i).Image = dotBlack
            Else
               buttons(x + i, y + i).Image = dotWhite
            End If
         End If
         If x - i >= 0 And y - i >= 0 Then
            'this if statement draws diagonal lines down and left
            If buttons(x - i, y - i).BackColor = Color.Black Then
               buttons(x - i, y - i).Image = dotBlack
            Else
               buttons(x - i, y - i).Image = dotWhite
            End If
         End If
         If x + i >= 0 And y - i >= 0 And x + i < 8 And y - i < 8 Then
            'this one draws them up and to the left.
            If buttons(x + i, y - i).BackColor = Color.Black Then
               buttons(x + i, y - i).Image = dotBlack
            Else
               buttons(x + i, y - i).Image = dotWhite
            End If
         End If 
         If x - i >= 0 And y + i >= 0 And x - i < 8 And y + i < 8 Then
            'this one draws them down and to the right
            If buttons(x - i, y + i).BackColor = Color.Black Then
               buttons(x - i, y + i).Image = dotBlack
            Else
               buttons(x - i, y + i).Image = dotWhite
            End If
         End If
      Next i '///////SETS QUEEN IMAGE//////////
      If(x + y) Mod 2 = 0 Then 'if x + y equals an even number
         b.Image = queenBlack 'black image of queen is used (blacksquare)
      'if x + y equals an odd number
      Else
         b.Image = queenWhite 'white image of queen is used (whitesquare)
      End If
      queenCount += 1 'increases number of queens that have been played
      openSquares = 0 'resets the number of open squares to 0.
      Dim h As Integer
      For h = 0 To 7
         'this simple for loop counts up how many availible squares the
         'usr has. If there are no images it counts it as an open square
         'and then increments the interger value.
         Dim j As Integer
         For j = 0 To 7
            If buttons(h, j).Image Is Nothing Then 'if no image
               openSquares += 1 'increments count
            End If 'end for
         Next j
         labelCount.Text = "Queens: " + queenCount + " || Open Squares: " + openSquares 'updates display
         Invalidate() 'updates form
      Next h 'end for
      If openSquares = 0 Then
         'if there are no free squares then display a message telling user
         'they won.
         MessageBox.Show("Good Job You Completed The Game Using Only: " + queenCount.ToString() + " Queens!", "Game Over...")
         NewGame() 'send to form => newgame
      End If 'end if
   End Sub 'ButtonClick
    'end buttonClick()
   Private Sub exitToolStripMenuItem_Click(sender As Object, e As EventArgs)
      'When user wants to click File>Exit 
      Me.Dispose() 'shuts down form and ends all processes
   End Sub 'exitToolStripMenuItem_Click
    'end exitToolStrip
   Private Sub aboutToolStripMenuItem_Click(sender As Object, e As EventArgs)
      'displays a form telling the user about the program
      Dim about As New aboutForm() 'aboutForm is aboutForm.cs
      about.ShowDialog() 'displays the form
   End Sub 'aboutToolStripMenuItem_Click
    'end
   Private Sub instructionsToolStripMenuItem_Click(sender As Object, e As EventArgs)
      'displays a form telling the user how to use the program
      Dim instructions As New instructForm() 'instructForm.cs
      instructions.ShowDialog() 'displays instructions
   End Sub 'instructionsToolStripMenuItem_Click
    'end
   Private Sub newGameToolStripMenuItem_Click(sender As Object, e As EventArgs)
      NewGame() 'calls newGame function
      MessageBox.Show("New Game Started", "Notice...") 'notifies usr :(
   End Sub 'newGameToolStripMenuItem_Click
    'end newGameToolStrip()
   Private Sub NewGame()
      'this function resets the form to it's original state.
      Dim form As New Form() 'creates a new form
      Me.Hide() 'hides the current form
      form = New Queens() 'sets new form equal to current
      form.Show() 'shows the new form
   End Sub 'NewGame 'end NewGame()
End Class 'Queens 'end public Queens
'
'ToDo: Error processing original source shown below
'
'
'-^--- expression expected
'end namespace