Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Module Module1
- Dim box(26) As String
- Dim win As Integer
- Sub Main()
- start:
- startgame()
- Do While 1 = 1
- player1()
- If won() <> 0 Then GoTo result
- player2()
- If won() <> 0 Then GoTo result
- Loop
- result:
- bord()
- If won() = 1 Then
- Console.WriteLine("Player 1 has won!")
- ElseIf won() = 2 Then
- Console.WriteLine("Player 2 has won!")
- ElseIf won() = 3 Then
- Console.WriteLine("Player ... oh it's a draw!")
- End If
- Console.WriteLine("Would you like to play again? (y/n)")
- If Console.ReadLine() = "y" Then
- GoTo start
- End If
- End Sub
- Public Sub player1()
- start:
- Dim place As Integer
- bord()
- Console.WriteLine("Player 1 's go please choose a number that is not already taken.")
- numberedbord()
- place = Console.ReadLine()
- If box(place) = "-" Then
- box(place) = "X"
- Else
- Console.WriteLine("That place is taken.")
- GoTo start
- End If
- End Sub
- Public Sub player2()
- start2:
- Dim place As Integer
- bord()
- Console.WriteLine("Player 2 's go please choose a number that is not already taken.")
- numberedbord()
- place = Console.ReadLine()
- If box(place) = "-" Then
- box(place) = "O"
- Else
- Console.WriteLine("That place is taken.")
- GoTo start2
- End If
- End Sub
- Public Sub bord()
- Console.WriteLine(box(0) & "|" & box(1) & "|" & box(2) & " " & box(9) & "|" & box(10) & "|" & box(11) & " " & box(18) & "|" & box(19) & "|" & box(20) & " ")
- Console.WriteLine(box(3) & "|" & box(4) & "|" & box(5) & " " & box(12) & "|" & box(13) & "|" & box(14) & " " & box(21) & "|" & box(22) & "|" & box(23) & " ")
- Console.WriteLine(box(6) & "|" & box(7) & "|" & box(8) & " " & box(15) & "|" & box(16) & "|" & box(17) & " " & box(24) & "|" & box(25) & "|" & box(26) & " ")
- End Sub
- Public Sub numberedbord()
- Console.WriteLine("0|1|2 9 |10|11 18|19|20")
- Console.WriteLine("3|4|5 12|13|14 21|22|23")
- Console.WriteLine("6|7|8 15|16|17 24|25|26")
- End Sub
- Public Sub startgame()
- Dim i As Integer
- Console.Clear()
- For i = 0 To 26
- box(i) = "-"
- Next
- Console.WriteLine("Instructions: ")
- Console.WriteLine("The bord: ")
- numberedbord()
- Console.WriteLine("To play each player pickes it in turn chosing where to go. To make it easyer you pick a number of the bord above.")
- Console.WriteLine("The bord is in 3D so you have to imagen that box number 9 is behind box number 0")
- Console.WriteLine("This means that there are more ways to win for example:")
- box(0) = "X"
- box(13) = "X"
- box(26) = "X"
- bord()
- Console.WriteLine()
- For i = 0 To 26
- box(i) = "-"
- Next
- End Sub
- Public Function won()
- Dim winner As String
- Dim i As Integer
- winner = ""
- 'across
- For i = 0 To 26 Step 3
- If box(i) = box(i + 1) And box(i + 1) = box(i + 2) Then
- If box(i) <> "-" Then
- winner = box(i)
- End If
- End If
- Next
- 'down
- For i = 0 To 2
- If box(i) = box(i + 3) And box(i + 3) = box(i + 6) Then
- If box(i) <> "-" Then
- winner = box(i)
- End If
- End If
- Next
- For i = 9 To 11
- If box(i) = box(i + 3) And box(i + 3) = box(i + 6) Then
- If box(i) <> "-" Then
- winner = box(i)
- End If
- End If
- Next
- For i = 18 To 20
- If box(i) = box(i + 3) And box(i + 3) = box(i + 6) Then
- If box(i) <> "-" Then
- winner = box(i)
- End If
- End If
- Next
- 'back
- For i = 0 To 8
- If box(i) = box(i + 9) And box(i + 9) = box(i + 18) Then
- If box(i) <> "-" Then
- winner = box(i)
- End If
- End If
- Next
- '2d diagonal vertical (2DDV)
- For i = 0 To 18 Step 9
- If box(i) = box(i + 4) And box(i + 4) = box(i + 8) Then
- If box(i) <> "-" Then
- winner = box(i)
- End If
- ElseIf box(i + 2) = box(i + 4) And box(i + 4) = box(i + 6) Then
- If box(i + 2) <> "-" Then
- winner = box(i + 2)
- End If
- End If
- Next
- '2DDH horizontal
- If box(0) = box(10) And box(10) = box(20) Then
- If box(0) <> "-" Then
- winner = box(0)
- End If
- ElseIf box(3) = box(13) And box(13) = box(23) Then
- If box(3) <> "-" Then
- winner = box(0)
- End If
- ElseIf box(6) = box(16) And box(16) = box(26) Then
- If box(6) <> "-" Then
- winner = box(0)
- End If
- End If
- '3DD
- If box(0) = box(13) And box(13) = box(26) Then
- If box(0) <> "-" Then
- winner = box(0)
- End If
- ElseIf box(2) = box(13) And box(13) = box(24) Then
- If box(2) <> "-" Then
- winner = box(2)
- End If
- ElseIf box(6) = box(13) And box(13) = box(20) Then
- If box(13) <> "-" Then
- winner = box(13)
- End If
- ElseIf box(8) = box(13) And box(13) = box(18) Then
- If box(13) <> "-" Then
- winner = box(13)
- End If
- End If
- If box(0) <> "-" And box(1) <> "-" And box(2) <> "-" And box(3) <> "-" And box(4) <> "-" And box(5) <> "-" And box(6) <> "-" And box(7) <> "-" And box(8) <> "-" Then
- winner = "D"
- End If
- Console.WriteLine(winner)
- If winner = "X" Then
- won = "1"
- ElseIf winner = "O" Then
- won = "2"
- ElseIf winner = "D" Then
- won = "3"
- Else
- won = "0"
- End If
- End Function
- End Module
Advertisement
Add Comment
Please, Sign In to add comment