Skip to content

Commit

Permalink
fix: fixes minesweeper, circular import (this better work)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlin7 committed Jul 26, 2023
1 parent b98cba7 commit 8a79bcc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
11 changes: 5 additions & 6 deletions biscuit/core/components/editors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import os
from tkinter.constants import *

from .editor import BaseEditor
from biscuit.core.components.games.whoops import Whoops
from biscuit.core.settings.editor import SettingsEditor

from ..utils import FileType, Frame
from .breadcrumbs import BreadCrumbs

from .diffeditor import DiffEditor
from .editor import BaseEditor
from .imageviewer import ImageViewer
from .texteditor import TextEditor
from .misc import Welcome

from biscuit.core.components.games import Whoops
from biscuit.core.settings.editor import SettingsEditor
from .texteditor import TextEditor

editors = {f"::{i.name}":i for i in (Welcome, SettingsEditor)}

Expand Down
2 changes: 1 addition & 1 deletion biscuit/core/components/games/StackEngineer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from collections import Counter, deque
from tkinter import messagebox, ttk

from biscuit.core.components.editors import TextEditor
from biscuit.core.components.editors.texteditor import TextEditor

from .game import BaseGame

Expand Down
3 changes: 2 additions & 1 deletion biscuit/core/components/games/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
from ..utils import Frame
from .game import BaseGame
from .gameoflife import GameOfLife
from .minesweeper import Minesweeper
from .pong import Pong
from .snake import Snake
from .stackengineer import StackEngineer
from .tetris import Tetris
from .ttt import TicTacToe
from .whoops import Whoops

games = {i.name:i for i in (Tetris, GameOfLife, Pong, TicTacToe, Snake, StackEngineer)}
games = {i.name:i for i in (Tetris, GameOfLife, Pong, TicTacToe, Snake, StackEngineer, Minesweeper)}


def get_games(base):
Expand Down
29 changes: 12 additions & 17 deletions biscuit/core/components/games/minesweeper.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import tkinter as tk
import random
import tkinter as tk
from tkinter import messagebox

from .game import BaseGame

# Game constants
BOARD_SIZE = 10
NUM_MINES = 10

class Minesweeper:
def __init__(self, root):
self.root = root
self.root.title("Minesweeper")


class Minesweeper(BaseGame):
name = "Minesweeper!"

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

self.board = [[0 for _ in range(BOARD_SIZE)] for _ in range(BOARD_SIZE)]
self.mine_positions = []
self.buttons = [[None for _ in range(BOARD_SIZE)] for _ in range(BOARD_SIZE)]
Expand All @@ -28,7 +33,7 @@ def generate_mines(self):
def create_buttons(self):
for row in range(BOARD_SIZE):
for col in range(BOARD_SIZE):
button = tk.Button(self.root, width=2, height=1)
button = tk.Button(self, width=2, height=1)
button.grid(row=row, column=col)
button.bind("<Button-1>", lambda e, r=row, c=col: self.button_click(e, r, c))
self.buttons[row][col] = button
Expand Down Expand Up @@ -71,13 +76,3 @@ def game_over(self):
self.buttons[row][col].unbind("<Button-1>")

messagebox.showinfo("Game Over", "You hit a mine!")
self.root.destroy()

# Create the main window
root = tk.Tk()

# Create the Minesweeper game
minesweeper = Minesweeper(root)

# Start the Tkinter event loop
root.mainloop()

0 comments on commit 8a79bcc

Please sign in to comment.