Рефераты. Greating game on visual basic with multiplayer system

multiplayermode = True

End Sub

Private Sub Layer_A_Click (Index As Integer)

playerdisplaylabel. Caption = ""

'Used For single player board selection or multiplayer your turn selection

Debug. Print "Layer A Click Turn Status " & MyTurn

Debug. Print "Layer A Multiplayer Mode Status " & multiplayermode

If multiplayermode = True And MyTurn = False Then 'Easy way to exit if not your turn

Exit Sub

End If

If Sq_Left Mod 2 = 1 Then 'check remainder of squares left divided by 2

If sw = True Then ' sets who goes first X or O

Layer_A (Index). Caption = "X"

Else

Layer_A (Index). Caption = "O"

End If

Layer_A (Index). Enabled = False 'Sets selected square to not available

Player_A (Index) = 1

Computer_A (Index) = - Token

LoadPlayer

If multiplayermode = True And MyTurn = True Then 'checks for multiplayer and turn status

'This routine below packs message to send

'to other player to select the square chosen.

Dim dpmsg As DirectPlayMessage 'alot direct playmessage

Set dpmsg = dxplay. CreateMessage 'set and create the message

Call dpmsg. WriteLong (MSG_MOVE) 'pack message structure and identify type

Call dpmsg. WriteByte (Index) 'Packs case selection number to msgtype.

'This sends the pack message structure

Call dxplay. Send (MyPlayer, DPID_ALLPLAYERS, DPSEND_GUARANTEED, dpmsg)

End If

If multiplayermode = True Then 'Sets routines to not your turn on multiplayer

Dim Y As Integer

Y = 0

For Y = 0 To 8

Layer_A (Y). MouseIcon = LoadResPicture ("nyt", vbResIcon)

Next Y

'Update Status displays

StatusBar1. SimpleText = "Game count is " & score & " " & opponentsname & ": " & opponentsscore & " | " & profilename & ": " & profilenamescore & " " & opponentsname & "'s Turn"

Out_Box. Caption = opponentsname & "'s Turn."

End If

'Everything below until mod else statement is single player

If multiplayermode = False Then 'Sets X or O turn status on single player

If sw = True Then

StatusBar1. SimpleText = "New Game Initialized O's Turn"

Else

StatusBar1. SimpleText = "New Game Initialized X's Turn"

End If

If sw = True Then

Y = 0

For Y = 0 To 8

Layer_A (Y). MouseIcon = LoadResPicture ("o", vbResIcon)

Next Y

Else

Y = 0

For Y = 0 To 8

Layer_A (Y). MouseIcon = LoadResPicture ("x", vbResIcon)

Next Y

End If

If sw = True Then

Out_Box. Caption = "O's Turn"

Else

Out_Box. Caption = "X's Turn"

End If

End If

Else

'Mod else*********************************

If sw = True Then

Layer_A (Index). Caption = "O"

Else

Layer_A (Index). Caption = "X"

End If

Layer_A (Index). Enabled = False

Player_A (Index) = - Token

Computer_A (Index) = 1

If multiplayermode = True Then

StatusBar1. SimpleText = "Game count is " & score & " " & opponentsname & ": " & opponentsscore & " | " & profilename & ": " & profilenamescore & " " & opponentsname & "'s Turn"

For Y = 0 To 8

Layer_A (Y). MouseIcon = LoadResPicture ("nyt", vbResIcon)

Next Y

Out_Box. Caption = opponentsname & "'s Turn."

End If

If multiplayermode = False Then

If sw = True Then

StatusBar1. SimpleText = "New Game Initialized X's Turn"

Else

StatusBar1. SimpleText = "New Game Initialized O's Turn"

End If

If sw = True Then

Y = 0

For Y = 0 To 8

Layer_A (Y). MouseIcon = LoadResPicture ("x", vbResIcon)

Next Y

Out_Box. Caption = "X's Turn"

Else

Y = 0

For Y = 0 To 8

Layer_A (Y). MouseIcon = LoadResPicture ("o", vbResIcon)

Next Y

Out_Box. Caption = "O's Turn"

End If

End If

LoadComputer

If multiplayermode = True And MyTurn = True Then

'Same as above packs message and sends move to other player

Dim dpmsg2 As DirectPlayMessage

Set dpmsg2 = dxplay. CreateMessage

Call dpmsg2. WriteLong (MSG_MOVE)

Call dpmsg2. WriteByte (Index)

Call dxplay. Send (MyPlayer, DPID_ALLPLAYERS, DPSEND_GUARANTEED, dpmsg2)

End If

End If

Sq_Left = Sq_Left - 1

EvalNextMove

MyTurn = False

End Sub

Public Function layer_A_online (Index As Integer)

playerdisplaylabel. Caption = ""

'This routine is called to mark sqares when remote computer

'sends a move made command.

'Same as above with some redundant routines removed

If Sq_Left Mod 2 = 1 Then

If sw = True Then

Layer_A (Index). Caption = "X"

Else

Layer_A (Index). Caption = "O"

End If

Layer_A (Index). Enabled = False

Player_A (Index) = 1

Computer_A (Index) = - Token

If multiplayermode = True Then

If sw = True Then

StatusBar1. SimpleText = "Game count is " & score & " " & opponentsname & ": " & opponentsscore & " | " & profilename & ": " & profilenamescore & " " & profilename & "'s Turn"

Out_Box. Caption = profilename & "'s Turn."

Dim Y As Integer

For Y = 0 To 8

Layer_A (Y). MouseIcon = LoadResPicture ("o", vbResIcon)

Next Y

Else

StatusBar1. SimpleText = "Game count is " & score & " " & opponentsname & ": " & opponentsscore & " | " & profilename & ": " & profilenamescore & " " & profilename & "'s Turn"

Out_Box. Caption = profilename & "'s Turn."

Y = 0

For Y = 0 To 8

Layer_A (Y). MouseIcon = LoadResPicture ("x", vbResIcon)

Next Y

End If

End If

If multiplayermode = False Then

If sw = True Then

Y = 0

For Y = 0 To 8

Layer_A (Y). MouseIcon = LoadResPicture ("o", vbResIcon)

Out_Box. Caption = "O's Turn"

Next Y

Else

Y = 0

For Y = 0 To 8

Layer_A (Y). MouseIcon = LoadResPicture ("x", vbResIcon)

Out_Box. Caption = "X's Turn"

Next Y

End If

End If

LoadPlayer

Else

If sw = True Then

Layer_A (Index). Caption = "O"

Else

Layer_A (Index). Caption = "X"

End If

Layer_A (Index). Enabled = False

Player_A (Index) = - Token

Computer_A (Index) = 1

If multiplayermode = True Then

If sw = True Then

StatusBar1. SimpleText = "Game count is " & score & " " & opponentsname & ": " & opponentsscore & " | " & profilename & ": " & profilenamescore & " " & profilename & "'s Turn"

Out_Box. Caption = profilename & "'s Turn."

Y = 0

For Y = 0 To 8

Layer_A (Y). MouseIcon = LoadResPicture ("x", vbResIcon)

Next Y

Else

StatusBar1. SimpleText = "Game count is " & score & " " & opponentsname & ": " & opponentsscore & " | " & profilename & ": " & profilenamescore & " " & profilename & "'s Turn"

Out_Box. Caption = profilename & "'s Turn."

Y = 0

For Y = 0 To 8

Layer_A (Y). MouseIcon = LoadResPicture ("o", vbResIcon)

Next Y

End If

End If

If multiplayermode = False Then

If sw = True Then

StatusBar1. SimpleText = "New Game Initialized X's Turn"

Else

StatusBar1. SimpleText = "New Game Initialized O's Turn"

End If

If sw = True Then

Y = 0

For Y = 0 To 8

Layer_A (Y). MouseIcon = LoadResPicture ("x", vbResIcon)

Next Y

Out_Box. Caption = "X's Turn"

Else

Y = 0

For Y = 0 To 8

Layer_A (Y). MouseIcon = LoadResPicture ("o", vbResIcon)

Next Y

Out_Box. Caption = "O's Turn"

End If

End If

LoadComputer

End If

Sq_Left = Sq_Left - 1

Страницы: 1, 2, 3, 4, 5



2012 © Все права защищены
При использовании материалов активная ссылка на источник обязательна.