23 Replies - 2735 Views - Last Post: 18 March 2013 - 02:24 PM
#1
Tic tac toe old project
Posted 16 March 2013 - 01:42 PM
Is that possible?
I'm not sure how to do it without envolving other variables, can't be done this way?
Thanks for anyone who helps.
Replies To: Tic tac toe old project
#3
Re: Tic tac toe old project
Posted 16 March 2013 - 01:55 PM
Not sure how you wrote it but I would set a While Loop that monitors a GameOver boolean or something similar
Combine the handles of your buttons and use the Sender object to determine if available and mark the current player's symbol.
Check for win by comparing = symbols (you don't need to check for x and check for o just do it all at once by seeing if the text is =
if it's a win then set GameOver = true otherwise, check if any buttons are left if neither is true switch to the other player for their turn.
Outside the loop, Display the winner or tie game. Ask to play again.
#4
Re: Tic tac toe old project
Posted 16 March 2013 - 03:07 PM
It's like this:
If Button1.Text = "X" And Button2.Text = "X" And Button3.Text = "X" Then
MsgBox("O " + Form2.TextBox1.Text + " é o vencedor", MsgBoxStyle.Exclamation)
vit1 = vit1 + 1
Label1.Text = Form2.TextBox1.Text & " : " & vit1
Label7.Visible = True
Timer1.Stop()
conta = conta + 1
Button1.Enabled = False
Button2.Enabled = False
Button3.Enabled = False
Button4.Enabled = False
Button5.Enabled = False
Button6.Enabled = False
Button7.Enabled = False
Button8.Enabled = False
Button9.Enabled = False
End If
And i did it for all the possibilities C+P'ed for the other buttons... yeah, it's pretty "lame" but it was what i knew at the time..
the msgbox says who won and i got a button to play again in the form, and it's basically it.
Vit is the number os victories for each player (vit1/vit2) conta is the % of wins overall between the two players.
i have a timer wich checks for a "thing" that i've putted in every piece of code above and if it was false then it would retrieve an "draw" messagebox.
I was asking another way to do it without making that random checks in every button.
Appreciate it.
#5
Re: Tic tac toe old project
Posted 16 March 2013 - 03:45 PM
If you're bored, it would be a good exercise to try to reduce repetitive code and learn new ways to accomplish what you're doing.
#6
Re: Tic tac toe old project
Posted 16 March 2013 - 04:07 PM
But this moment i was in need of accomplish that problem i've asked for a friend of mine who ask me for help for school too, i don't wanna give him my "timer-crap-invented" that i come up with xD
But the best way of reducing it would be some kind of arrays? I've seen that somewhere, can't remember well..
#7
Re: Tic tac toe old project
Posted 16 March 2013 - 07:40 PM
#8
Re: Tic tac toe old project
Posted 17 March 2013 - 02:16 PM
#9
Re: Tic tac toe old project
Posted 17 March 2013 - 07:42 PM
Jondeate, on 17 March 2013 - 03:40 AM, said:
We know because some of us have done it. If you find you are writing similar looking sections of code, maybe it can be extracted out into it own method. Then call that.
If you don't know about basic collections, or about reference types then do same basic independent study or research. There are tutorials on Dream.In.Code that cover those topics.
Ignore the GUI aspect of the problem (trust me it helps.)
Begin by thinking about the design (or the flow of the game) of the program. Use pencil and paper.
For example
Blank board
Current Player = Player 1
While the game is not in a end state
Await Current Player Move
Update Board with Current Player's Move
Check State of Board
Has Current Player Won? -> End Game( Player (Current Player ) Wins)
Is the Game Drawn? -> End Game( Drawn Game )
Current Player = Which Player is Next? ( Current Player )
End While
Now I would go and design a class (or classes) that encapsulates the playing of a game of tic-tsc-toe. I just done this as an exercise and it's about 120 LoC (and it is GUI neutral, when compiled it 90 IL LoC) .
This post has been edited by AdamSpeight2008: 17 March 2013 - 08:42 PM
#10
Re: Tic tac toe old project
Posted 18 March 2013 - 12:13 PM
Like: If count = 9 then
...?
I can't put game drawn because the last move still can be someone's victory...
Should i use Exit sub in every possibilitie of Victory to stop from reaching my draw statement if true?
This post has been edited by AdamSpeight2008: 18 March 2013 - 12:42 PM
#11
Re: Tic tac toe old project
Posted 18 March 2013 - 12:47 PM
Write it out an English statement that describes a drawn game.
#12
Re: Tic tac toe old project
Posted 18 March 2013 - 01:06 PM
AdamSpeight2008, on 18 March 2013 - 12:47 PM, said:
Write it out an English statement that describes a drawn game.
That was primarly my question... i was looking of a simple way to do it as i used to do it with timers and ramdom changes to check...
If i don't find an answer (easy one) i will have to find "other" way checking "random" things like label.text changed or something.
#13
Re: Tic tac toe old project
Posted 18 March 2013 - 01:28 PM
In my written example (in a prior) do you see any actual code?
For example create and define the definition you are going to use, for different aspects of the game.
This post has been edited by AdamSpeight2008: 18 March 2013 - 01:32 PM
#14
Re: Tic tac toe old project
Posted 18 March 2013 - 01:30 PM
If Button1.Text = "X" And Button2.Text = "X" And Button3.Text = "X" Then
'If player wins it does this
ElseIf Count = 9 Then
'If Tie Game it does this
End If
This post has been edited by IronRazer: 18 March 2013 - 01:30 PM
#15
Re: Tic tac toe old project
Posted 18 March 2013 - 01:37 PM
Quote
A player places his marker into one of the empty squares
If is it a winning move then they have won the game
But if it's not determined that anyone has won, then
If all the board squares are occupied then the game is drawn
Otherwise it is the other player's turn.
So a player set's their square: Did a win happen? If Yes then show who won: Game Over. If No, then check to see if there are any squares left for the other player. If not, you're already determined there wasn't a win so it's a draw: Game Over
This post has been edited by CharlieMay: 18 March 2013 - 01:41 PM
|
|

New Topic/Question
Reply



MultiQuote






|