Tutorial : Tic-Tac-Toe

In this tutorial, we'll create a simple Tic Tac Toe game using the Aurora programming language. Tic Tac Toe is a classic two-player game where players take turns marking spaces in a 3x3 grid, aiming t

Step 1: Setting Up the Game Board

First, let's create the game board component. The game board will consist of a 3x3 grid where players can place their symbols (X or O).

pythonCopy codecomponent GameBoard:
    def __init__(self):
        self.board = [[' ']*3 for _ in range(3)]  # Initialize an empty 3x3 grid
    
    def render(self):
        board_html = ""
        for row in self.board:
            row_html = ""
            for cell in row:
                row_html += f"<div class='cell'>{cell}</div>"
            board_html += f"<div class='row'>{row_html}</div>"
        return f"<div class='board'>{board_html}</div>"

Step 2: Displaying the Game Board

Now, let's create the main component to display the game board and handle player interactions.

pythonCopy codecomponent TicTacToe:
    def __init__(self):
        self.board = GameBoard()
        self.current_player = 'X'
    
    def handle_click(self, row, col):
        if self.board[row][col] == ' ':
            self.board[row][col] = self.current_player
            self.current_player = 'O' if self.current_player == 'X' else 'X'
    
    def render(self):
        return f"""
            <div>
                <h1>Tic Tac Toe</h1>
                {self.board.render()}
            </div>
        """

Step 3: Adding CSS Styling

Let's add some basic CSS styling to make the game board visually appealing.

Step 4: Testing the Game

Now, let's create an instance of the TicTacToe component and render it.

Conclusion

Congratulations! You've created a simple Tic Tac Toe game using the Aurora programming language. Feel free to enhance the game by adding features like win detection, reset functionality, or a more visually appealing UI. Happy coding! 🎮🚀

Last updated