For diagonal, only the center could match 5, but again, just going to 1-1 and 5-1 and moving along can check for that. If at any time I don't have a match or I have an empty space, that line isn't a win. If it matches my player, then go to 2-3, and continue to 5-3. So if I mark position 2-3, then I simply start at 1-3 and see if it matches x or o. If you need to get a complete line of 5, then you simply need to use the start or the row or column to determine if it's correct. When a player marks a spot (x or o), we should know what options are available. Note this is just a quick thought and might require tweaking.įirst I'd set up a grid so each spot knows what row and column it's on. Just a quick thought of how I'd probably set it up. You would end up with a grid that looks something like this. Then after something has been placed you check the row and column in which you have placed something for if there are is a series of three 1's or 2's. I was thinking of having 5 int arrays for each row and column and then whenever you place something the int in the array corresponding to the row or column you placed something on will be set to 1 if you are team 1 and 2 if you are team 2. I had decided that I would only check for vertical and horizontal but that still would have been a lot of if statements and unreadable code. Then check if you are one cell from the edge, in that case, only check one cell on that side and two on the other side.Īnd if you are in the middle, check two cells to the left and two cells to the right. I have a sort of solution but it involves tons and tons of if statements.įirst check if the cell you are standing on is on the edge, in that case, only check on the other side. On a normal 3x3 board this is really easy, but when you expand the board it becomes much more difficult. But I am really struggling to check when a player has won. Hey, I am making a sort of tic-tac-toe game, with a board of 5x5 and added features.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |