dimanche 28 décembre 2014

How to make a computer move in a single player tic tac toe game [VB]

I'm trying to make a single player tic tac toe game. I already have 2 player working using some codes I found online but I'm not having any luck inputting the codes for single player with what I have already. I have a start menu that asks if you want to play 1 or 2 players then it goes to the game form to start the game (where all the main code is) Also I am new to vb and don't know all the terminology yet so if you can help out please be detailed and leave comments in the code.


What I'd like to do is make the computer move on a random choice for the first move then based on what is already played it will make the choice off of that. I think I can get that part on my own I just need help figuring out how to incorporate the random number generator into the code I already have.


One last thing I would like to know, is this vb.net or vb6? I don't really know the difference since this is my first Visual Basic project.


This is where I assume the code would go but if I am wrong let me know and I can post the entire code:



Public Class Form1
Dim flag As Boolean = False
Private mute As Integer = 0

Private Sub Buttons(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click, Button6.Click, Button7.Click, Button8.Click, Button9.Click

If flag = False Then
' DirectCast(sender, Button).Image = (My.Resources.Mario)
DirectCast(sender, Button).Text = "X"
flag = True
My.Computer.Audio.Play(My.Resources.fireball, AudioPlayMode.Background)
playerTurn.Text = " Turn: Player O "
buttonDisable()
computerMove()
Else
' DirectCast(sender, Button).Image = (My.Resources.Luigi)
DirectCast(sender, Button).Text = "O"
flag = False
My.Computer.Audio.Play(My.Resources.marioJump, AudioPlayMode.Background)
playerTurn.Text = " Turn: Player X "
buttonDisable()
End If
If muteOff.Visible = True Then
My.Computer.Audio.Stop()
End If
win()
checkDraw()
End Sub


Thanks in advanced!





Aucun commentaire:

Enregistrer un commentaire