Quantcast
Viewing all articles
Browse latest Browse all 16

[VB.Net] I think I may be looping to much.

I'm using visual studios 2010 and I'm working on a Sudoku project. First let me show y'all my code:

Code:

Option Strict On
Option Explicit On
Public Class Sudoku
    Private intBoard(8, 8) As Integer
    Private rectBoard(8, 8) As Rectangle

    Private Sub Panel1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
        Call drawBoard(e.Graphics)
    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Call addColumns()
    End Sub

    Private Sub addColumns()
        '81 cells for a 9x9 board
        Dim higt As Integer = CInt(Panel1.Size.Height / 9)
        Dim wid As Integer = CInt(Panel1.Size.Width / 9)
        Dim cellSize As New Size(wid, higt)

        'Column 1
        For i As Integer = 0 To 8 Step 1
            rectBoard(0, i) = New Rectangle(New Point(wid - wid, i * higt), cellSize)
        Next
        'Column 2
        For i As Integer = 0 To 8 Step 1
            rectBoard(1, i) = New Rectangle(New Point(wid * 2 - wid, i * higt), cellSize)
        Next
        'Column 3
        For i As Integer = 0 To 8 Step 1
            rectBoard(2, i) = New Rectangle(New Point(wid * 3 - wid, i * higt), cellSize)
        Next
        'Column 4
        For i As Integer = 0 To 8 Step 1
            rectBoard(3, i) = New Rectangle(New Point(wid * 4 - wid, i * higt), cellSize)
        Next
        'Column 5
        For i As Integer = 0 To 8 Step 1
            rectBoard(4, i) = New Rectangle(New Point(wid * 5 - wid, i * higt), cellSize)
        Next
        'Column 6
        For i As Integer = 0 To 8 Step 1
            rectBoard(5, i) = New Rectangle(New Point(wid * 6 - wid, i * higt), cellSize)
        Next
        'Column 7
        For i As Integer = 0 To 8 Step 1
            rectBoard(6, i) = New Rectangle(New Point(wid * 7 - wid, i * higt), cellSize)
        Next
        'Column 8
        For i As Integer = 0 To 8 Step 1
            rectBoard(7, i) = New Rectangle(New Point(wid * 8 - wid, i * higt), cellSize)
        Next
        'Column 9
        For i As Integer = 0 To 8 Step 1
            rectBoard(8, i) = New Rectangle(New Point(wid * 9 - wid, i * higt), cellSize)
        Next
    End Sub

    Private Sub drawBoard(g As Graphics)
        Dim bigPen As New Pen(Brushes.Black, 4)

        'Column 1
        For i As Integer = 0 To 8 Step 1
            g.DrawRectangle(Pens.Black, rectBoard(0, i))
        Next

        'Column 2
        For i As Integer = 0 To 8 Step 1
            g.DrawRectangle(Pens.Black, rectBoard(1, i))
        Next

        'Column 3
        For i As Integer = 0 To 8 Step 1
            g.DrawRectangle(Pens.Black, rectBoard(2, i))
        Next

        'Column 4
        For i As Integer = 0 To 8 Step 1
            g.DrawRectangle(Pens.Black, rectBoard(3, i))
        Next

        'Column 5
        For i As Integer = 0 To 8 Step 1
            g.DrawRectangle(Pens.Black, rectBoard(4, i))
        Next

        'Column 6
        For i As Integer = 0 To 8 Step 1
            g.DrawRectangle(Pens.Black, rectBoard(5, i))
        Next

        'Column 7
        For i As Integer = 0 To 8 Step 1
            g.DrawRectangle(Pens.Black, rectBoard(6, i))
        Next

        'Column 8
        For i As Integer = 0 To 8 Step 1
            g.DrawRectangle(Pens.Black, rectBoard(7, i))
        Next

        'Column 9
        For i As Integer = 0 To 8 Step 1
            g.DrawRectangle(Pens.Black, rectBoard(8, i))
        Next

        'Draws the bolded lines to make a 3X3 board outta the 9X9 board
        g.DrawLine(bigPen, rectBoard(3, 0).Location, New Point(rectBoard(3, 8).X, rectBoard(3, 8).Y + rectBoard(3, 8).Height))
        g.DrawLine(bigPen, rectBoard(6, 0).Location, New Point(rectBoard(6, 8).X, rectBoard(6, 8).Y + rectBoard(6, 8).Height))
        g.DrawLine(bigPen, rectBoard(0, 3).Location, New Point(rectBoard(8, 3).X + rectBoard(8, 3).Width, rectBoard(8, 3).Y))
        g.DrawLine(bigPen, rectBoard(0, 6).Location, New Point(rectBoard(8, 6).X + rectBoard(8, 6).Width, rectBoard(8, 6).Y))
    End Sub

End Class

As you can tell, I haven't done much yet. I just made the board and drew it. I think that I'm looping way to much. My concern is that, if somebody wants to play this on their computer, I think that it would slow down tremendously. Do y'all have any suggestions?

Viewing all articles
Browse latest Browse all 16

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>