Othello Board

arish

New member
Joined
Dec 12, 2004
Messages
1
Programming Experience
3-5
I need to build an othello program and i d like some ideas around the designing of the board... I already have a class square for each square of the board but i m having troubles with the graphics. Please Help!
THANX
 
That a pretty wide open request.

What problems are you having?

I would suggest having the square class be a userControl that paints either a black circle, a white circle, or nothing (you could also paint an opaque circle on mouseOvers to give a hint if a piece can be played in that square). The class would be something like this:

VB.NET:
Imports System.Drawing
Imports System.Drawing.Drawing2D

Public Class Square
    Inherits System.Windows.Forms.UserControl

#Region " Windows Form Designer generated code "

    Private rec As Rectangle
    Private gp As GraphicsPath

    Public Enum PieceType
        Empty
        Black
        BlackPotential
        White
        WhitePotential
    End Enum

    'most new squares will empty, so set it to empty 
    Private _piece As Square.PieceType = PieceType.Empty
    Public Property Piece() As PieceType
        Get
            Return _piece
        End Get
        Set(ByVal Value As PieceType)
            _piece = Value
            Refresh()
        End Set
    End Property

    Private Sub Square_Paint(ByVal sender As Object, _
      ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
        e.Graphics.Clear(Me.BackColor)
        'Draw a border
        e.Graphics.DrawRectangle(Pens.Black, Me.ClientRectangle)
        Dim brGrad As PathGradientBrush
        brGrad = New Drawing2D.PathGradientBrush(gp)
        'to give 3D effect, move the centerpoint
        brGrad.CenterPoint = New PointF(CSng(rec.Right - 2), CSng(rec.Top - 2))
        Select Case _piece
            Case Is = PieceType.Empty
                Exit Sub
            Case Is = PieceType.Black
                brGrad.CenterColor = Color.Gray
                brGrad.SurroundColors = New Color() {Color.DarkGray, Color.Black}
            Case Is = PieceType.BlackPotential
                brGrad.CenterColor = Color.FromArgb(80, Color.Black)
                brGrad.SurroundColors = New Color() {Color.FromArgb(80, Color.Black)}
            Case Is = PieceType.White
                brGrad.CenterColor = Color.LightSteelBlue
                brGrad.SurroundColors = New Color() {Color.LightGray, Color.White}
            Case Is = PieceType.WhitePotential
                brGrad.CenterColor = Color.FromArgb(120, Color.White)
                brGrad.SurroundColors = New Color() {Color.FromArgb(120, Color.White)}
        End Select
        e.Graphics.FillEllipse(brGrad, rec) 'Me.ClientRectangle)
        brGrad.Dispose()
    End Sub

    Private Sub Square_Resize(ByVal sender As Object, _
      ByVal e As System.EventArgs) Handles MyBase.Resize
        SetGraphicsObjects()
        Refresh()
    End Sub

    Private Sub SetGraphicsObjects()
        'make the circular piece a little smaller than the square
        rec = New Rectangle(2, 2, Width - 4, Height - 4)
        'set the graphics path for the PathGradientBrush
        gp = New GraphicsPath()
        gp.AddEllipse(Me.ClientRectangle)
    End Sub
End Class

I went a bit overBoard, but I was trying to figure out how to use the PathGradientBrush myself and I created this code so I didn't want it to go to waste.
 
Back
Top