Advertisement

TicTacToe in VB

Started by May 27, 2002 12:29 PM
1 comment, last by Avengelique 22 years, 5 months ago
okay I''m learning VB and my first assignment is to create a tic tac toe game. I"ve got most everything figured out except how to get the program to recognize 3 in a row. (and at that point I would create an msg box saying playerx is the winner). I had thought that perhaps I should assign each box with a numeric value. the first row of boxes would be 1,2, and 3. the second would be 10,20,30. the third would be 100,200,300. so that the possible combinations of 3 in a row would add up to 111,222,333,321,123,5,50, and 500. But the only problem with that is that it''s unlikely that someone''s just going to create a tictactoe in 3 moves. there are usually going to be other selections chosen that would mess up the math. so my question is: how do I get the program to recognize 3 in a row? yes I''m sure I could find a complete tic tac toe source online but that''s not going to teach me the logic of VB or programming. I understand the commands I just need to understand the login behind implimenting commands to create a certain effect. (plus I"m at work on a holiday and had a compulsion to post)
{holds up cardboard sign}"Will Code for Food"
Every round, go through your board array (it is in an array, right?). Step through the columns and check to see if there''s a line, then step through the rows and check for a line, then check the two diagonals for a line. To do these checks for a line: for each position in potential line, check which player owns the position; if the three positions are not owned by the same player, or are not owned by either, stop; else you have 3 in a row.
Advertisement
Ahhhhh...I had forgotton you can create arrays in multiple dimensions like that. muchos gracias.
{holds up cardboard sign}"Will Code for Food"

This topic is closed to new replies.

Advertisement