Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pull request #25

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1edd624
sudoku class update
sickunicorn24 Nov 21, 2024
f6e7ac1
def is_valid
sickunicorn24 Nov 21, 2024
26d3694
added a constants file
DerekCamilo Nov 25, 2024
1bc28bf
Created a baseline for the title page, tweaked constants values
DerekCamilo Nov 25, 2024
b43859a
def is_valid
sickunicorn24 Nov 26, 2024
f8859ce
def is_valid
sickunicorn24 Nov 26, 2024
ffb6fa1
Merge pull request #1 from DerekCamilo/main
sickunicorn24 Nov 28, 2024
a5136ca
Add files via upload
guhansattanathan Nov 28, 2024
7b2bcef
fill functions and remove function
sickunicorn24 Dec 1, 2024
3386993
fill functions and remove function
sickunicorn24 Dec 1, 2024
08762b3
changed the buttons because they were wrong
DerekCamilo Dec 2, 2024
27e5dcc
filled out the during game screen function
DerekCamilo Dec 2, 2024
0eb4038
def win_screen function
DerekCamilo Dec 2, 2024
c0309a5
figured out outlines
DerekCamilo Dec 2, 2024
8a9ea48
finished
sickunicorn24 Dec 2, 2024
98bbf47
Merge remote-tracking branch 'origin/main'
sickunicorn24 Dec 2, 2024
9fdbb65
Merge pull request #2 from DerekCamilo/main
sickunicorn24 Dec 2, 2024
42973f6
fill box and removed functions changed
sickunicorn24 Dec 2, 2024
cd52b76
Merge remote-tracking branch 'origin/main'
sickunicorn24 Dec 2, 2024
c99233d
Added cell and board
BTYWAR Dec 2, 2024
da48ba2
Updated Board
BTYWAR Dec 2, 2024
e4b69e7
changed constant variables to reflect colors to avoid confusion, chan…
DerekCamilo Dec 2, 2024
f57b520
Revert Board
BTYWAR Dec 3, 2024
ea3bd33
Attempted to get the board to appear.
BTYWAR Dec 3, 2024
a3b40fd
Merge remote-tracking branch 'origin/guhansattanathan-board.py'
sickunicorn24 Dec 3, 2024
d030a5f
Merge remote-tracking branch 'origin/main'
sickunicorn24 Dec 3, 2024
394f5a3
updated
sickunicorn24 Dec 3, 2024
c6044ca
Got the board to appear
BTYWAR Dec 3, 2024
38cd4e8
Added user inputs, fixed highlights and buttons
BTYWAR Dec 4, 2024
cca3fc5
Cleanup + Add checker and win and lose screen
BTYWAR Dec 5, 2024
c7d3310
Finished up the final touches on the UI and other game based visual i…
DerekCamilo Dec 6, 2024
4a348cc
Finished all UI and visuals.
DerekCamilo Dec 6, 2024
121bd7f
Merge branch 'main' into main
BTYWAR Dec 7, 2024
4cda2b2
Merge pull request #4 from DerekCamilo/main
BTYWAR Dec 7, 2024
ba10574
Revert "Merge pull request #4 from DerekCamilo/main"
BTYWAR Dec 7, 2024
eff859f
test
BTYWAR Dec 7, 2024
67a6a54
Correct version
BTYWAR Dec 7, 2024
777cee3
Scale down
BTYWAR Dec 7, 2024
ea12739
Cleanup
BTYWAR Dec 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/Sudoku-Project.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

98 changes: 98 additions & 0 deletions board.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import pygame
from pygame.examples.moveit import WIDTH
from constants import *

from cell import Cell

class Board:
def __init__(self, width, height, screen, difficulty):
self.width = width
self.height = height
self.screen = screen
self.difficulty = difficulty
self.cells = [[Cell(0, i, j, screen) for j in range(9)] for i in range(9)]
self.current = None
self.original_values = [[cell.value for cell in row] for row in self.cells]

def draw(self):
for row in range(10):
thickness = 3 if row % 3 == 0 else 1
pygame.draw.line(self.screen, (0, 0, 0), (0, row * cell_size), (WIDTH, row * cell_size), thickness)
pygame.draw.line(self.screen, (0, 0, 0), (row * cell_size, 0), (row * cell_size, WIDTH), thickness)
for row in self.cells:
for cell in row:
cell.draw()

def select(self, row, col):
if self.current:
self.current.selected = False

if self.cells[row][col].editable:
self.cells[row][col].selected = True
self.current = self.cells[row][col]
else:
self.current = None

def click(self, x, y):
if x < self.width and y < self.height:
row = y // cell_size
col = x // cell_size
self.select(row, col)
return row, col
return None

def clear(self):
if self.current and self.current.value == 0:
self.current.set_sketched_value(0)

def sketch(self, value):
if self.current and self.current.value == 0:
self.current.set_sketched_value(value)

def place_number(self, value):
if self.current and self.current.value == 0:
self.current.set_cell_value(value)
self.current.set_sketched_value(0)

def reset_to_original(self):
for i in range(9):
for j in range(9):
if self.cells[i][j].editable:
self.cells[i][j].set_cell_value(self.original_values[i][j])
self.cells[i][j].set_sketched_value(0)

def is_full(self):
for row in self.cells:
for cell in row:
if cell.value == 0:
return False
return True

def update_board(self):
board = [[cell.value for cell in row] for row in self.cells]
return board

def find_empty(self):
for row in range(9):
for col in range(9):
if self.cells[row][col].value == 0:
return row, col
return None

def check_board(self):
for row in self.cells:
if not self._is_valid_group([cell.value for cell in row]):
return False
for col in range(9):
if not self._is_valid_group([self.cells[row][col].value for row in range(9)]):
return False
for i in range(0, 9, 3):
for j in range(0, 9, 3):
subgrid = [self.cells[x][y].value for x in range(i, i + 3) for y in range(j, j + 3)]
if not self._is_valid_group(subgrid):
return False
return True

def _is_valid_group(self, values):
nums = [v for v in values if v != 0]
return len(nums) == len(set(nums))
35 changes: 35 additions & 0 deletions cell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import pygame
from constants import *

class Cell:
def __init__(self, value, row, col, screen):
self.value = value
self.row = row
self.col = col
self.screen = screen
self.selected = False
self.sketched_val = None
self.editable = True

def set_cell_value(self, value):
self.value = value

def set_sketched_value(self, value):
self.sketched_value = value

def draw(self):
cell_size = 70
font_num = pygame.font.Font(None, 56)
if self.value != 0:
num_surface = font_num.render(str(self.value), True, BLACK)
num_rectangle = num_surface.get_rect(center=(self.col * cell_size + cell_size // 2, self.row * cell_size + cell_size // 2))
self.screen.blit(num_surface, num_rectangle)
if self.selected:
red_square = pygame.Rect(self.col * cell_size, self.row * cell_size, cell_size, cell_size)
pygame.draw.rect(self.screen, (255, 0, 0), red_square, 3) # Red outline with 3 px thickness
if self.sketched_val is not None:
font_sketch = pygame.font.Font(None, 28)
sketch_surface = font_sketch.render(str(self.sketched_val), True, BLACK)
sketch_rectangle = sketch_surface.get_rect(
center=(100 * self.col + 50, 100 * self.row + 50))
self.screen.blit(sketch_surface, sketch_rectangle)
15 changes: 15 additions & 0 deletions constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#All of these values are subject to change

WIDTH = 630
HEIGHT = 750
LIGHT_BLUE = (0, 47, 255) #Light Blue
PURPLE = (200, 0, 255) #Purple
GREEN = (125, 255, 125) # Green
RED = (250, 52, 52) # Red
BLACK = (0, 0, 0) #Black
PINK = (255, 10, 200) #Pink
WHITE = (255, 255, 255)
EASY = 30
MEDIUM = 40
HARD = 50
cell_size = 70
Loading