Imports System
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Public Class frmMain
Dim P As Integer
Dim PN As Integer
Dim DN As Integer
Dim DorU As Integer
Dim WinNo As Integer
Dim NowPlaying As Boolean
Dim Player(4) As Graphics
Dim img(4) As Image
Dim bitmap(4) As Bitmap
Dim EmptyImg As Image
Dim EmptyBitmap(4) As Bitmap
Dim BoardImg As Image
Dim BoardBitmap As Bitmap
Dim DiceImg(6) As Image
Dim Winner(4) As System.Windows.Forms.Label
Private Sub picNewGame_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picNewGame.MouseDown
picNewGame.Image = My.Resources.NewGame2
End Sub
Private Sub picNewGame_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picNewGame.MouseUp
picNewGame.Image = My.Resources.NewGame1
DiceTimer.Enabled = False
If Choice2.Checked = True Then
PN = 2
ElseIf Choice3.Checked = True Then
PN = 3
Else
PN = 4
End If
For P = 0 To 3
bitmap(P).Tag = “1″
Player(P) = picBoard.CreateGraphics()
Player(P).Clear(BackColor)
Player(P).Dispose()
Next P
picBoard.Refresh()
For P = 0 To PN – 1
MovePlayer(True)
Next P
P = -1
IncP()
DN = 1
DorU = 0
Rubber.Visible = False
Winner(0).Visible = False
Winner(1).Visible = False
Winner(2).Visible = False
Winner(3).Visible = False
Turn.Visible = True
NowPlaying = True
End Sub
Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If NowPlaying Then
If MsgBox(“Are you sure you want to abort the game?”, MsgBoxStyle.YesNo) = MsgBoxResult.No Then
e.Cancel = True
End If
End If
End Sub
Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
NowPlaying = False
DiceImg(0) = My.Resources.Dice1
DiceImg(1) = My.Resources.Dice2
DiceImg(2) = My.Resources.Dice3
DiceImg(3) = My.Resources.Dice4
DiceImg(4) = My.Resources.Dice5
DiceImg(5) = My.Resources.Dice6
img(0) = My.Resources.RedPlayer
img(1) = My.Resources.YellowPlayer
img(2) = My.Resources.BluePlayer
img(3) = My.Resources.GreenPlayer
For P = 0 To 3
bitmap(P) = New Bitmap(img(P), img(P).Width, img(P).Height)
bitmap(P).MakeTransparent(System.Drawing.Color.White)
Next P
Dim i As Integer
Dim j As Integer
Dim k As Integer
EmptyImg = My.Resources.EmptyPlayer
For i = 0 To 3
EmptyBitmap(i) = New Bitmap(EmptyImg, EmptyImg.Width, EmptyImg.Height)
For j = 0 To EmptyBitmap(i).Width – 1
For k = 0 To EmptyBitmap(i).Height – 1
EmptyBitmap(i).SetPixel(j, k, Color.White)
Next k
Next j
Next i
BoardImg = My.Resources.Board
BoardBitmap = New Bitmap(BoardImg, BoardImg.Width, BoardImg.Height)
For i = 0 To 3
Winner(i) = New System.Windows.Forms.Label
Winner(i).Size() = New Size(52, 16)
Winner(i).Font() = New System.Drawing.Font(Turn.Font.Name, 10, Turn.Font.Style, Turn.Font.Unit)
Winner(i).AutoSize = True
Winner(i).BackColor = Color.White
Winner(i).ForeColor = Color.Black
Winner(i).Text() = “Winner”
Next i
Me.Controls.AddRange(Winner)
Winner(0).Location = New System.Drawing.Point(501, 308)
Winner(1).Location = New System.Drawing.Point(501, 334)
Winner(2).Location = New System.Drawing.Point(501, 359)
Winner(3).Location = New System.Drawing.Point(501, 384)
For i = 0 To 3
Winner(i).BringToFront()
Winner(i).Visible = True
Next i
End Sub
Public Sub MovePlayer(ByVal Draw As Boolean)
Dim L As Integer
Dim T As Integer
Dim BN As Integer
BN = CInt(bitmap(P).Tag) – 1
L = (BN Mod
* 50
T = Int(BN /
* 50
If Int(BN /
/ 2 <> Int(Int(BN /
/ 2) Then
L = picBoard.Width – L – 50
End If
T = picBoard.Height – T
If P = 0 Then
T = T – 20
ElseIf P = 1 Then
L = L + 30
T = T – 20
ElseIf P = 2 Then
L = L + 30
T = T – 50
ElseIf P = 3 Then
T = T – 50
End If
Dim i As Integer
Dim j As Integer
If Draw Then
For i = 0 To EmptyBitmap(P).Width – 1
For j = 0 To EmptyBitmap(P).Height – 1
EmptyBitmap(P).SetPixel(i, j, BoardBitmap.GetPixel(L + i, T + j))
Next j
Next
Player(P) = picBoard.CreateGraphics()
Player(P).DrawImage(bitmap(P), L, T, bitmap(P).Width, bitmap(P).Height)
Else
Player(P) = picBoard.CreateGraphics()
Player(P).DrawImage(EmptyBitmap(P), L, T, EmptyBitmap(P).Width, EmptyBitmap(P).Height)
End If
Player(P).Dispose()
End Sub
Public Sub IncP()
NextPlayer:
P = P + 1
If P > PN – 1 Then P = 0
If bitmap(P).Tag = “64″ Then GoTo NextPlayer
DiceTimer.Interval = 100 – Int((CInt(bitmap(P).Tag) – 1) /
* 10
If P = 0 Then
Turn.Text = “RED Turn”
Turn.ForeColor = Color.Red
ElseIf P = 1 Then
Turn.Text = “YELLOW Turn”
Turn.ForeColor = Color.Yellow
ElseIf P = 2 Then
Turn.Text = “BLUE Turn”
Turn.ForeColor = Color.Blue
Else
Turn.Text = “GREEN Turn”
Turn.ForeColor = Color.Green
End If
End Sub
Private Sub DiceTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DiceTimer.Tick
DN = DN + 1
If DN > 6 Then DN = 1
picDice.Image = DiceImg(DN – 1)
picDice.Tag = CStr(DN) ‘DicePic(DN – 1).Tag
End Sub
Private Sub picDice_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picDice.Click
If NowPlaying = False Then Exit Sub
Dim i As Integer
Dim G As Integer
Dim N As Integer
Dim D As Integer
If DorU = 0 Then
My.Computer.Audio.Play(My.Resources.Dice, AudioPlayMode.Background)
DorU = 1
DiceTimer.Enabled = True
Else
DorU = 0
DiceTimer.Enabled = False
G = CInt(bitmap(P).Tag)
N = CInt(picDice.Tag)
D = G + N
MovePlayer(False)
If D <= 64 Then
bitmap(P).Tag = CStr(D)
End If
MovePlayer(True)
If D = 4 Then
MovePlayer(False)
bitmap(P).Tag = “21″
My.Computer.Audio.Play(My.Resources.Ladder, AudioPlayMode.Background)
MovePlayer(True)
ElseIf D = 9 Then
MovePlayer(False)
bitmap(P).Tag = “27″
My.Computer.Audio.Play(My.Resources.Ladder, AudioPlayMode.Background)
MovePlayer(True)
ElseIf D = 16 Then
MovePlayer(False)
bitmap(P).Tag = “3″
My.Computer.Audio.Play(My.Resources.Snake, AudioPlayMode.Background)
MovePlayer(True)
ElseIf D = 18 Then
MovePlayer(False)
bitmap(P).Tag = “33″
My.Computer.Audio.Play(My.Resources.Ladder, AudioPlayMode.Background)
MovePlayer(True)
ElseIf D = 24 Then
MovePlayer(False)
bitmap(P).Tag = “6″
My.Computer.Audio.Play(My.Resources.Snake, AudioPlayMode.Background)
MovePlayer(True)
ElseIf D = 30 Then
MovePlayer(False)
bitmap(P).Tag = “51″
My.Computer.Audio.Play(My.Resources.Ladder, AudioPlayMode.Background)
MovePlayer(True)
ElseIf D = 32 Then
MovePlayer(False)
bitmap(P).Tag = “17″
My.Computer.Audio.Play(My.Resources.Snake, AudioPlayMode.Background)
MovePlayer(True)
ElseIf D = 36 Then
MovePlayer(False)
bitmap(P).Tag = “14″
My.Computer.Audio.Play(My.Resources.Snake, AudioPlayMode.Background)
MovePlayer(True)
ElseIf D = 40 Then
MovePlayer(False)
bitmap(P).Tag = “55″
My.Computer.Audio.Play(My.Resources.Ladder, AudioPlayMode.Background)
MovePlayer(True)
ElseIf D = 47 Then
MovePlayer(False)
bitmap(P).Tag = “19″
My.Computer.Audio.Play(My.Resources.Snake, AudioPlayMode.Background)
MovePlayer(True)
ElseIf D = 48 Then
MovePlayer(False)
bitmap(P).Tag = “63″
My.Computer.Audio.Play(My.Resources.Ladder, AudioPlayMode.Background)
MovePlayer(True)
ElseIf D = 53 Then
MovePlayer(False)
bitmap(P).Tag = “60″
My.Computer.Audio.Play(My.Resources.Ladder, AudioPlayMode.Background)
MovePlayer(True)
ElseIf D = 56 Then
MovePlayer(False)
bitmap(P).Tag = “26″
My.Computer.Audio.Play(My.Resources.Snake, AudioPlayMode.Background)
MovePlayer(True)
ElseIf D = 61 Then
MovePlayer(False)
bitmap(P).Tag = “38″
My.Computer.Audio.Play(My.Resources.Snake, AudioPlayMode.Background)
MovePlayer(True)
End If
If bitmap(P).Tag = “64″ Then
If P = 0 Then
Winner(WinNo).Text = “Red”
Winner(WinNo).ForeColor = Color.Red
ElseIf P = 1 Then
Winner(WinNo).Text = “Yellow”
Winner(WinNo).ForeColor = Color.Yellow
ElseIf P = 2 Then
Winner(WinNo).Text = “Blue”
Winner(WinNo).ForeColor = Color.Blue
Else
Winner(WinNo).Text = “Green”
Winner(WinNo).ForeColor = Color.Green
End If
Winner(WinNo).Visible = True
My.Computer.Audio.Play(My.Resources.Yahoo, AudioPlayMode.Background)
WinNo = WinNo + 1
End If
If WinNo = PN – 1 Then
For i = 0 To PN – 1
If bitmap(i).Tag <> “64″ Then
If i = 0 Then
Winner(WinNo).Text = “Red”
Winner(WinNo).ForeColor = Color.Red
ElseIf i = 1 Then
Winner(WinNo).Text = “Yellow”
Winner(WinNo).ForeColor = Color.Yellow
ElseIf i = 2 Then
Winner(WinNo).Text = “Blue”
Winner(WinNo).ForeColor = Color.Blue
Else
Winner(WinNo).Text = “Green”
Winner(WinNo).ForeColor = Color.Green
End If
Winner(WinNo).Visible = True
DiceTimer.Enabled = False
Turn.Visible = False
Rubber.Visible = True
NowPlaying = False
Exit Sub
End If
Next i
End If
IncP()
End If
End Sub
Private Sub picNewGame_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles picNewGame.Click
End Sub
End Class
–
Remoting:
Class library:
Public Interface IMessage
Function read() As String
Sub write(ByVal str As String)
End Interface
Server:
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Tcp
Imports ClassLibrary1
Module Module1
Sub Main()
Dim t As New TcpChannel(9999)
ChannelServices.RegisterChannel(t, False)
RemotingConfiguration.RegisterWellKnownServiceType(GetType(Message), “message.rem”, WellKnownObjectMode.Singleton)
Console.WriteLine(“Server is Ready…”)
Console.WriteLine(“Press enter to shut down..”)
Console.Read()
End Sub
Public Class Message
Inherits MarshalByRefObject
Implements IMessage
Private str1 As String
Public Sub New()
Console.WriteLine(“Object created”)
End Sub
Public Function read() As String Implements ClassLibrary1.IMessage.read
read = “Hello ” & str1
End Function
Public Sub write(ByVal str As String) Implements ClassLibrary1.IMessage.write
str1 = str
End Sub
End Class
End Module
