My 12 year old boys talk about it now - seems to have legs...
Printable View
My 12 year old boys talk about it now - seems to have legs...
I first heard the Chuck Norris facts in Boy Scouts about 8 or 9 years ago. And every once in a while someone will come up with a new one.
Right now I've decided to work on the game "Checkers" and this is what I have so far:
I'm dreading trying to work on checking for double/triple jumps :/Code:Option Strict On
Option Explicit On
Public Class Form1
Private board(7, 7) As Panel
Private Sub Load_Board()
'Nested loop from 0 to 7 for both dimensions
For x As Integer = 0 To board.GetUpperBound(0)
For y As Integer = 0 To board.GetUpperBound(1)
'A panel will hold our checker
Dim pnl As New Panel
With pnl
'Make the checkered pattern by checking if we're on an odd or even x
'Then alternated based if y is odd or even
If CBool(x Mod 2) Then
If CBool(y Mod 2) Then
.BackColor = Color.SaddleBrown
Else
.BackColor = Color.Peru
End If
Else
If CBool(y Mod 2) Then
.BackColor = Color.Peru
Else
.BackColor = Color.SaddleBrown
End If
End If
.BorderStyle = BorderStyle.FixedSingle
.Location = New Point(x * 55, y * 55)
.Size = New Size(55, 55)
End With
'Add the panel to the board and to the form
board(x, y) = pnl
Me.Controls.Add(pnl)
'Add the click event handler
AddHandler pnl.Click, AddressOf pnl_click
Next
Next
End Sub
Private Sub Load_Checkers()
Dim x As Integer = 0
'loop from 0 to 2 or the top 3 rows of our board
For y As Integer = 0 To 2
'Set x based on which row we're on as we don't want
'Any checkers to be on the wrong colored panel
If y = 1 Then
x = 1
Else
x = 0
End If
'Loop from either 0 - 3 or 1 - 4
For i As Integer = x To x + 3
'Set up a new check and set the properties
Dim check As New Checker
With check
.BackColor = Color.Black
.IsKing = True
.IsSelected = False
.Location = New Point(2, 2)
.Player = 2
.Size = New Size(50, 50)
End With
'Add the checker to the panel
board(x, y).Controls.Add(check)
'Set up the event handler
AddHandler check.Click, AddressOf checker_click
'Increment x by two so the next checker doesn't sit on the wrong colored panel
x += 2
Next
Next
'Do the same thing as above, only for the last 3 rows of our board
x = 1
For y As Integer = 5 To 7
If y = 6 Then
x = 0
Else
x = 1
End If
For i As Integer = x To x + 3
Dim check As New Checker
With check
.BackColor = Color.White
.IsKing = True
.IsSelected = False
.Location = New Point(2, 2)
.Player = 1
.Size = New Size(50, 50)
End With
board(x, y).Controls.Add(check)
AddHandler check.Click, AddressOf checker_click
x += 2
Next
Next
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'Set up the board and checkers
Call Load_Board()
Call Load_Checkers()
'Get the title width and height to later set the form's size
Dim title_wid As Integer = CInt(Me.Width - Me.ClientSize.Width)
Dim title_hei As Integer = CInt(Me.Height - Me.ClientSize.Height)
'Set the form's properties
With Me
.Size = New Size(8 * 55 + title_wid, 8 * 55 + title_hei)
.StartPosition = FormStartPosition.CenterScreen
.Text = "Checkers"
End With
End Sub
Private selected_checker As Checker
Private Sub pnl_click(sender As Object, e As EventArgs)
'Get the panel that was just clicked
Dim pnl_clicked As Panel = DirectCast(sender, Panel)
If Not (IsNothing(selected_checker)) AndAlso CheckMove(selected_checker, pnl_clicked) Then
MoveChecker(selected_checker, pnl_clicked)
End If
End Sub
Private Sub checker_click(sender As Object, e As EventArgs)
Dim checker_clicked As Checker = DirectCast(sender, Checker)
If Not (IsNothing(selected_checker)) Then
If checker_clicked Is selected_checker Then
'Check to see if the selected checker is the one that was just clicked
'If it was, then just set selected checker to nothing
selected_checker.IsSelected = False
selected_checker = Nothing
Else
'If it wasn't the checker that was just clicked then select it
selected_checker = checker_clicked
checker_clicked.IsSelected = True
End If
Else
'If it wasn't the checker that was just clicked then select it
selected_checker = checker_clicked
checker_clicked.IsSelected = True
End If
End Sub
Private Function CheckMove(ByVal moving_checker As Checker, ByVal pnl_to_move_to As Panel) As Boolean
'If the panel that was clicked had a checker on it, then ignore the click
'Also check to make sure that the selected checker isn't nothing
If pnl_to_move_to.Controls.Count = 0 AndAlso Not (IsNothing(moving_checker)) Then
'Get the x and y number in the board for both panels declared above
Dim x_sel, y_sel, x_cur, y_cur As Integer
For col As Integer = 0 To board.GetUpperBound(0)
For row As Integer = 0 To board.GetUpperBound(1)
If board(col, row) Is pnl_to_move_to Then
x_sel = col
y_sel = row
End If
If board(col, row) Is DirectCast(moving_checker.Parent, Panel) Then
x_cur = col
y_cur = row
End If
Next
Next
'Now we check if the move was legal
If moving_checker.Player = 1 Then
If x_sel - x_cur = -1 AndAlso y_sel - y_cur = -1 Then
'First check if the move is one to the left and up
Return True
ElseIf x_sel - x_cur = -2 AndAlso y_sel - y_cur = -2 Then
Dim pnl As Panel = DirectCast(board(x_sel + 1, y_sel + 1), Panel)
If pnl.Controls.Count > -1 AndAlso DirectCast(pnl.Controls(0), Checker).Player = 2 Then
'Check if the move is two to the left and up and that the checker that's one left/one up is a player 2 checker
pnl.Controls.Clear()
Return True
Else
Return False
End If
ElseIf x_sel - x_cur = 1 AndAlso y_sel - y_cur = -1 Then
'Check if the move is one to the right and up
Return True
ElseIf x_sel - x_cur = 2 AndAlso y_sel - y_cur = -2 Then
'Check if the move is two to the right and up
Dim pnl As Panel = DirectCast(board(x_sel - 1, y_sel + 1), Panel)
If pnl.Controls.Count > -1 AndAlso DirectCast(pnl.Controls(0), Checker).Player = 2 Then
'Check if the move is two to the left and up and that the checker that's one left/one up is a player 2 checker
pnl.Controls.Clear()
Return True
Else
Return False
End If
'------------------------------------------------------------------------------------------
'-------------------------These next moves apply only to the king--------------------------
'------------------------------------------------------------------------------------------
ElseIf moving_checker.IsKing AndAlso x_sel - x_cur = -1 AndAlso y_sel - y_cur = 1 Then
'First check if the move is one to the left and down
Return True
ElseIf moving_checker.IsKing AndAlso x_sel - x_cur = -2 AndAlso y_sel - y_cur = 2 Then
Dim pnl As Panel = DirectCast(board(x_sel + 1, y_sel - 1), Panel)
If pnl.Controls.Count > -1 AndAlso DirectCast(pnl.Controls(0), Checker).Player = 2 Then
'Check if the move is two to the left and down and that the checker that's one left/one down is a player 2 checker
pnl.Controls.Clear()
Return True
Else
Return False
End If
ElseIf moving_checker.IsKing AndAlso x_sel - x_cur = 1 AndAlso y_sel - y_cur = 1 Then
'Check if the move is one to the right and down
Return True
ElseIf moving_checker.IsKing AndAlso x_sel - x_cur = 2 AndAlso y_sel - y_cur = 2 Then
'Check if the move is two to the right and down
Dim pnl As Panel = DirectCast(board(x_sel - 1, y_sel - 1), Panel)
If pnl.Controls.Count > -1 AndAlso DirectCast(pnl.Controls(0), Checker).Player = 2 Then
'Check if the move is two to the left and down and that the checker that's one left/one up is a player 2 checker
pnl.Controls.Clear()
Return True
Else
Return False
End If
Else
Return False
End If
Else
If x_sel - x_cur = -1 AndAlso y_sel - y_cur = 1 Then
'First check if the move is one to the left and up
Return True
ElseIf x_sel - x_cur = -2 AndAlso y_sel - y_cur = 2 Then
Dim pnl As Panel = DirectCast(board(x_sel + 1, y_sel - 1), Panel)
If pnl.Controls.Count > -1 AndAlso DirectCast(pnl.Controls(0), Checker).Player = 1 Then
'Check if the move is two to the left and up and that the checker that's one left/one up is a player 2 checker
pnl.Controls.Clear()
Return True
Else
Return False
End If
ElseIf x_sel - x_cur = 1 AndAlso y_sel - y_cur = 1 Then
'Check if the move is one to the right and down
Return True
ElseIf x_sel - x_cur = 2 AndAlso y_sel - y_cur = 2 Then
'Check if the move is two to the right and down
Dim pnl As Panel = DirectCast(board(x_sel - 1, y_sel - 1), Panel)
If pnl.Controls.Count > -1 AndAlso DirectCast(pnl.Controls(0), Checker).Player = 1 Then
'Check if the move is two to the left and up and that the checker that's one left/one up is a player 2 checker
pnl.Controls.Clear()
Return True
Else
Return False
End If
'------------------------------------------------------------------------------------------
'-------------------------These next moves apply only to the king--------------------------
'------------------------------------------------------------------------------------------
ElseIf moving_checker.IsKing AndAlso x_sel - x_cur = -1 AndAlso y_sel - y_cur = -1 Then
'First check if the move is one to the left and down
Return True
ElseIf moving_checker.IsKing AndAlso x_sel - x_cur = -2 AndAlso y_sel - y_cur = -2 Then
Dim pnl As Panel = DirectCast(board(x_sel + 1, y_sel + 1), Panel)
If pnl.Controls.Count > -1 AndAlso DirectCast(pnl.Controls(0), Checker).Player = 1 Then
'Check if the move is two to the left and up and that the checker that's one left/one down is a player 2 checker
pnl.Controls.Clear()
Return True
Else
Return False
End If
ElseIf moving_checker.IsKing AndAlso x_sel - x_cur = 1 AndAlso y_sel - y_cur = -1 Then
'Check if the move is one to the right and down
Return True
ElseIf moving_checker.IsKing AndAlso x_sel - x_cur = 2 AndAlso y_sel - y_cur = -2 Then
'Check if the move is two to the right and down
Dim pnl As Panel = DirectCast(board(x_sel - 1, y_sel + 1), Panel)
If pnl.Controls.Count > -1 AndAlso DirectCast(pnl.Controls(0), Checker).Player = 1 Then
'Check if the move is two to the left and down and that the checker that's one left/one up is a player 2 checker
pnl.Controls.Clear()
Return True
Else
Return False
End If
Else
Return False
End If
End If
Else
Return False
End If
End Function
Private Sub MoveChecker(ByVal moving_checker As Checker, ByVal pnl_to_move_to As Panel)
'Unselect the moving checker
moving_checker.IsSelected = False
'Clear the controls from the old panel
Dim moving_from_pnl As Panel = DirectCast(moving_checker.Parent, Panel)
moving_from_pnl.Controls.Clear()
'Add the checker to the new panel
pnl_to_move_to.Controls.Add(moving_checker)
'Set the selected_checker to nothing
selected_checker = Nothing
End Sub
End Class
Right now it's pretty cool though, I can load up the board and move all the pieces around.
Ahh, I forgot to upload the checker:
Code:Option Strict On
Option Explicit On
Public Class Checker
Inherits Control
Private king As Boolean
Public Property IsKing() As Boolean
Get
Return king
End Get
Set(ByVal value As Boolean)
king = value
End Set
End Property
Private selected As Boolean
Public Property IsSelected() As Boolean
Get
Return selected
End Get
Set(ByVal value As Boolean)
selected = value
End Set
End Property
Private _player As Integer
Public Property Player() As Integer
Get
Return _player
End Get
Set(ByVal value As Integer)
_player = value
End Set
End Property
Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
Dim path As New Drawing2D.GraphicsPath
Dim rect As Rectangle = Me.DisplayRectangle
'Deflate to draw the border
rect.Inflate(-1, -1)
'Draw the border
e.Graphics.DrawEllipse(New Pen(Brushes.Black, 3), rect)
'Deflate to fill in the checker
rect.Inflate(-1, -1)
'Fill in the circle
e.Graphics.FillEllipse(New SolidBrush(Me.BackColor), rect)
'Inflate back to the original size
rect.Inflate(2, 2)
'Add the ellipse to the graphics path
path.AddEllipse(rect)
'Set the region
Me.Region = New Region(path)
'If it's a king, then draw a 'k' on it
If king Then
e.Graphics.DrawString("K", Me.Font, Brushes.Black, New PointF(CSng(Me.Width / 2 - Me.FontHeight / 2), CSng(Me.Height / 2 - Me.FontHeight / 2)))
End If
If IsSelected Then
Dim pnl As Panel = DirectCast(Me.Parent, Panel)
pnl.BorderStyle = BorderStyle.Fixed3D
Else
Dim pnl As Panel = DirectCast(Me.Parent, Panel)
pnl.BorderStyle = BorderStyle.FixedSingle
End If
End Sub
End Class
The reason in Load_Checkers I have both player 1 and 2 pieces defaulted to IsKing is because I just got done testing if it's not king then it can only move one direction and if it's king then it can move in both directions.
Whenever I run the program it sits steadily at about 6,444K
Chuck Norris doesn't play chess. He is already King.
Are we allowed to make these up ourselves?
Of course, that's the best part of the Chuck Norris facts.
The two major types are:
Chuck Norris doesn't <verb>, he <verbs>
&
Chuck Norris doesn't <verb> <noun>, <noun> <verb>s Chuck Norris
Like:
Chuck Norris doesn't sleep, he waits
&
Chuck Norris doesn't swim in water, water moves around Chuck Norris.
Well I finished the game of checkers I was working on.
Unfortunately I couldn't work up how to check for double and triples.
So....your checkers doesn't check the checkers for extra checkers?
By the way, I thought your bug had bugged out, then I saw an icon that made me think that either your bug was bugged or my browser was bugged, which bugged me a bit. Now the bug is back, which suggests my browser bugged out for a bit, but presently I'll bug out for a bite then be by for a byte, which might result in a bug.
The stream of my consciousness has many meanders.
I would prefer Stream.Copy(Me) so I can be smarter.
Baloney, you're doing fine.
I don't want to be that guy, but if Oscar Mayer's taught me anything, it's Bologna.
It's an interesting point. I was sure I had seen both spellings in common use, and it turns out it is a real word:
http://www.merriam-webster.com/dictionary/baloney