![]() ![]() For example, you could write a verb in the square and the students need to say what the verb is in the past. You can use it as is or you can modified by writing on the squares to make the game meet your learning objectives. Use the tic-tac-toe board game above as the basis for your game. To play this game in class you need to divide your class into two groups (X and O). Students all over the world are familiar with how to play it and even if they don’t it is such a simple game to learn it is always a go to game in the classroom. Return board.Any(state => state = BoardState.Tic Tac Toe is a versatile game that can be used in any classroom with any subject. Return GameState.ComputerWon(winningLine) If (line.All(state => state = BoardState.Computer)) If (line.All(state => state = BoardState.Human)) Together, it might look like this: public static GameState GetGameState(Board board)įoreach (var winningLine in WinningLines) ![]() Return an object representing the game state, instead of modifying private fields. ![]() Pass the board to the function, or make this a method of your Board class, instead of referring to GameBoard.Content. It will also allow you to guard against errors such as overwriting a non-empty board square. One benefit is that a bad index will throw an IndexOutOfRangeException, while a dictionary will not complain.īoard logic should be encapsulated in a class, so that you can make changes to your implementation (like switching from a dictionary to an array) without the rest of your code having to change. This will protect you against mistakes like board = "x".Ī dictionary is overkill for a 3x3 board, you can just use an array. Use enums instead of strings for board squares. Var xResult = board.Where(containsX).ToDictionary() ![]() Var oResult = board.Where(containsO).ToDictionary() Var board = GameBoard.Content //stores data as dictionaryįor (int i = 0 i, bool> containsO = input => (input.Key = a || input.Key = b || input.Key = c) & input.Value = "O" įunc, bool> containsX = input => (input.Key = a || input.Key = b || input.Key = c) & input.Value = "X" I'm wondering if this is a good approach, and if there is a better way of doing this (maybe by monitoring the state of the board). I have the below code to check for a winner in a Tic Tac Toe game. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |