|
-
Aug 15th, 2013, 09:13 AM
#50881
Re: Post Race!
My 12 year old boys talk about it now - seems to have legs...
-
Aug 15th, 2013, 09:15 AM
#50882
Re: Post Race!
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.
-
Aug 15th, 2013, 09:29 AM
#50883
Re: Post Race!
Right now I've decided to work on the game "Checkers" and this is what I have so far:
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
I'm dreading trying to work on checking for double/triple jumps :/
-
Aug 15th, 2013, 09:29 AM
#50884
Re: Post Race!
Right now it's pretty cool though, I can load up the board and move all the pieces around.
-
Aug 15th, 2013, 09:30 AM
#50885
Re: Post Race!
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
-
Aug 15th, 2013, 09:31 AM
#50886
Re: Post Race!
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.
-
Aug 15th, 2013, 09:46 AM
#50887
Re: Post Race!
Whenever I run the program it sits steadily at about 6,444K
-
Aug 15th, 2013, 09:58 AM
#50888
Re: Post Race!
Chuck Norris doesn't play chess. He is already King.
Are we allowed to make these up ourselves?
-
Aug 15th, 2013, 10:00 AM
#50889
Re: Post Race!
Of course, that's the best part of the Chuck Norris facts.
-
Aug 15th, 2013, 10:04 AM
#50890
Re: Post Race!
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.
-
Aug 15th, 2013, 10:34 AM
#50891
Re: Post Race!
Well I finished the game of checkers I was working on.
-
Aug 15th, 2013, 10:35 AM
#50892
Re: Post Race!
Unfortunately I couldn't work up how to check for double and triples.
-
Aug 15th, 2013, 12:30 PM
#50893
Re: Post Race!
So....your checkers doesn't check the checkers for extra checkers?
My usual boring signature: Nothing
 
-
Aug 15th, 2013, 12:32 PM
#50894
Re: Post Race!
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.
My usual boring signature: Nothing
 
-
Aug 15th, 2013, 12:38 PM
#50895
Re: Post Race!
 Originally Posted by Shaggy Hiker
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.
-
Aug 15th, 2013, 01:26 PM
#50896
Re: Post Race!
 Originally Posted by Shaggy Hiker
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.
wow.
-
Aug 15th, 2013, 01:31 PM
#50897
Re: Post Race!
 Originally Posted by Niya
wow.
Buggy right?
-
Aug 15th, 2013, 01:55 PM
#50898
Re: Post Race!
The stream of my consciousness has many meanders.
My usual boring signature: Nothing
 
-
Aug 15th, 2013, 01:56 PM
#50899
Re: Post Race!
 Originally Posted by dday9
Buggy right?
Yea man, I'm totally bugging out and that bugs me.
-
Aug 15th, 2013, 01:56 PM
#50900
Re: Post Race!
 Originally Posted by Shaggy Hiker
The stream of my consciousness has many meanders.
Stream.Close() ?
-
Aug 15th, 2013, 02:16 PM
#50901
Re: Post Race!
I would prefer Stream.Copy(Me) so I can be smarter.
-
Aug 15th, 2013, 03:39 PM
#50902
Re: Post Race!
Baloney, you're doing fine.
My usual boring signature: Nothing
 
-
Aug 15th, 2013, 04:25 PM
#50903
Re: Post Race!
I don't want to be that guy, but if Oscar Mayer's taught me anything, it's Bologna.
-
Aug 15th, 2013, 06:06 PM
#50904
Re: Post Race!
 Originally Posted by dday9
I don't want to be that guy, but if Oscar Mayer's taught me anything, it's Bologna.
Ah yes, Bologna sausage as invented by Germans in Chicago! Good to see that good old American cultural imperialism is alive and well. I'd stick to baloney lest the Bolognese, swept along by a tide of regionality in Europe at the moment, decide to sue!
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Aug 15th, 2013, 07:10 PM
#50905
Re: Post Race!
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
My usual boring signature: Nothing
 
-
Aug 15th, 2013, 08:29 PM
#50906
Re: Post Race!
MOAR SITH!!!
-
Aug 15th, 2013, 08:30 PM
#50907
-
Aug 15th, 2013, 08:31 PM
#50908
-
Aug 15th, 2013, 08:31 PM
#50909
-
Aug 15th, 2013, 08:32 PM
#50910
-
Aug 15th, 2013, 08:33 PM
#50911
-
Aug 15th, 2013, 08:34 PM
#50912
-
Aug 15th, 2013, 08:35 PM
#50913
-
Aug 15th, 2013, 08:36 PM
#50914
-
Aug 15th, 2013, 08:36 PM
#50915
-
Aug 15th, 2013, 08:37 PM
#50916
-
Aug 15th, 2013, 08:38 PM
#50917
-
Aug 15th, 2013, 08:38 PM
#50918
-
Aug 15th, 2013, 08:39 PM
#50919
-
Aug 15th, 2013, 08:40 PM
#50920
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|