Skip to content

Commit

Permalink
Version 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
NevoKaplan committed Jan 29, 2022
0 parents commit 5297987
Show file tree
Hide file tree
Showing 972 changed files with 283,756 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

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

10 changes: 10 additions & 0 deletions .idea/Connect_Four.iml

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.

4 changes: 4 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.

Binary file added Assets/Board_First.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Board_First_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Board_Last.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Board_Last_smaller.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Connect-Four-Pause.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Fix_box.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Glow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Good_Red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Good_Red_Inv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Good_Yellow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Good_Yellow_Inv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Menu Click.wav
Binary file not shown.
Binary file added Assets/MenuMouse.wav
Binary file not shown.
Binary file added Assets/Open.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Open_Pressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Winning_Sound.wav
Binary file not shown.
Binary file added Assets/Winning_sound_end.wav
Binary file not shown.
Binary file added Assets/Zelda & Chill.mp3
Binary file not shown.
Binary file added Assets/exitdoor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/falling sound finish - Old.wav
Binary file not shown.
Binary file added Assets/falling sound finish.wav
Binary file not shown.
Binary file added Assets/falling sound finish2.wav
Binary file not shown.
Binary file added Assets/falling sound.wav
Binary file not shown.
Binary file added Assets/fishining screens.pdn
Binary file not shown.
Binary file added Assets/hamar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/lessGlow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/red finish.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/tie finish.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/tie_sound.wav
Binary file not shown.
Binary file added Assets/yellow finish.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions asimon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import constants


class Place:
# one square
def __init__(self, row, col):
# each square has a row/col position.
self.row = row
self.col = col
self.left, self.top = self.left_top_coordinates_of_box()
self.image = ''
self.image_pre = ''
self.color = ''

def left_top_coordinates_of_box(self):
# Convert board coordinates to pixel coordinates
left = self.col * (constants.BOX_SIZE_X + constants.GAP_SIZE_X) + constants.X_MARGIN + 32
top = self.row * (constants.BOX_SIZE_Y + constants.GAP_SIZE_Y) + constants.Y_MARGIN + 93
return left, top
123 changes: 123 additions & 0 deletions board.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import constants
import asimon
import pygame


class Board:
def __init__(self):
self.board = []
for row in range(constants.BOARD_ROWS):
self.board.append([])
lst = self.board[-1]
for col in range(constants.BOARD_COLS):
lst.append(asimon.Place(row, col))

def all_chips(self):
chips = []
for row in range(constants.BOARD_ROWS):
for col in range(constants.BOARD_COLS):
chips.append(self.board[row][col])
return chips

def draw_board(self, screen, has_won, fine):
# draws all of the boxes in their covered or revealed stage
for chip in self.all_chips():
if not chip.image == '':
if has_won and fine:
screen.blit(chip.image_pre, (chip.left, chip.top))
for i in range(len(fine)):
screen.blit(fine[i].image, (fine[i].left, fine[i].top))
else:
screen.blit(chip.image, (chip.left, chip.top))

@staticmethod
def create_call():
rect_list = []
rect = pygame.Rect(397, 52, 165, 990)
rect_list.append(rect)
n = 0
for i in range(1, constants.BOARD_COLS):
n += 1
rect = pygame.Rect(rect.right, rect.top, 165, 990)
rect_list.append(rect)
return rect_list

@staticmethod
def find_place_col(x, y, rect_list):
col = -1
for rect in rect_list:
col += 1
if rect.collidepoint(x, y):
return col, rect
return -1, None

# checks if the col is full
def legal_col(self, col):
if self.board[0][col].image == '':
return True
return False

def find_place_row(self, col):
row = -1
for chip in range(constants.BOARD_ROWS):
if self.board[chip][col].image == '':
row = chip
else:
return row
if chip == constants.BOARD_ROWS - 1:
return constants.BOARD_ROWS - 1

def place_asimon(self, asimon, asimon_pre, color, col, screen, FPS_CLOCK, direction_list):
row = self.find_place_row(col)
fall = 0
has_won = False
fine = []
asimon_r = asimon.get_rect()
asimon_r.move_ip(self.board[row][col].left, constants.distance)
constants.falling_sound.play()
while self.board[row][col].top >= asimon_r.top:
pygame.display.flip()
screen.blit(constants.Board_first_small, (377, 0))
asimon_r.move_ip(0, fall)
fall += 0.08
screen.blit(asimon, asimon_r)
self.draw_board(screen, has_won, fine)
screen.blit(constants.Board_last, (341, 157))
constants.screen.blit(constants.Fix_Box, (340, 515))
FPS_CLOCK.tick(240)
constants.falling_sound.stop()
if row == constants.BOARD_ROWS - 1:
constants.falling_sound_finish.play()
else:
constants.falling_sound_finish2.play()
self.board[row][col].image = asimon
self.board[row][col].image_pre = asimon_pre
self.board[row][col].color = color
has_won, fine_list = self.check_win(col, row, color, direction_list)
return has_won, fine_list

def check_win(self, col, row, color, direction_list):
fine2 = []
for i in range(4):
(x1, x2, x3, x4) = direction_list[i]
count1, list1 = self.check_line(col, row, color, x1, x2, True)
count2, list2 = self.check_line(col, row, color, x3, x4, False)
if count1 + count2 >= 4:
fine2 += list1 + list2

if fine2:
return True, fine2
return False, []

def check_line(self, col, row, color, dr, dc, first):
count = 0
winning_asimon = []
if first:
count = 1
winning_asimon = [self.board[row][col]]
while 0 <= col + dc < constants.BOARD_COLS and 0 <= row + dr < constants.BOARD_ROWS and self.board[row + dr][col + dc].color == color:
row += dr
col += dc
winning_asimon.append(self.board[row][col])
count += 1
return count, winning_asimon
83 changes: 83 additions & 0 deletions constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import pygame
pygame.init()
pygame.mixer.init()


def getImage(file, alpha):
if alpha:
return pygame.image.load(file).convert_alpha()
else:
return pygame.image.load(file).convert()


def getSound(file):
return pygame.mixer.Sound(file)


# set mouse cursor
pygame.mouse.set_cursor(*pygame.cursors.tri_left)

FPS = 100 # frames per second, the general speed of the program
WINDOW_WIDTH = 1920 # size of window's width in pixels
WINDOW_HEIGHT = 1080 # size of windows' height in pixels
BOX_SIZE_X = 124 # size of box width in pixels
BOX_SIZE_Y = 124 # size of box height in pixels
GAP_SIZE_X = 41 # size of gap between boxes in pixels
GAP_SIZE_Y = 14
BOARD_COLS = 7 # number of columns of icons // 7
BOARD_ROWS = 6 # number of rows of icons // 6
X_MARGIN = (WINDOW_WIDTH - (BOARD_COLS * (BOX_SIZE_X + GAP_SIZE_X))) // 2
Y_MARGIN = (WINDOW_HEIGHT - (BOARD_ROWS * (BOX_SIZE_Y + GAP_SIZE_Y))) // 2
distance = 50
screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))


# R G B
GRAY = (100, 100, 100)
NAVYBLUE = (60, 60, 100)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
YELLOW = (255, 255, 0)
ORANGE = (255, 128, 0)
PURPLE = (255, 0, 255)
CYAN = (0, 255, 255)
BLACK = (0, 0, 0)

# images
Board_first = getImage('Assets/Board_First.png', False)
Board_first_small = getImage('Assets/Board_First_small.png', False) # better sometimes
Board_last = getImage('Assets/Board_Last_smaller.png', True)
Asimon_Red = getImage('Assets/Good_Red.png', True)
Asimon_Yel = getImage('Assets/Good_Yellow.png', True)
Inv_Red = getImage('Assets/Good_Red_Inv.png', True)
Inv_Yel = getImage('Assets/Good_Yellow_Inv.png', True)
Open_Pressed = getImage('Assets/Open.png', False)
Open = getImage('Assets/Open_Pressed.png', False)
EasterEgg = getImage('Assets/hamar.png', False)
Pause_image = getImage('Assets/Connect-Four-Pause.png', False)
Fix_Box = getImage('Assets/Fix_box.png', False)
Glow_Strong = getImage('Assets/Glow.png', True)
Glow_weak = getImage('Assets/lessGlow.png', True)
win_yel = getImage('Assets/yellow finish.png', True)
win_red = getImage('Assets/red finish.png', True)
tie_finish = getImage('Assets/tie finish.png', True)
exit_door = getImage('Assets/exitdoor.png', True)
Asimon_Red = pygame.transform.scale(Asimon_Red, (140, 140))
Asimon_Yel = pygame.transform.scale(Asimon_Yel, (140, 140))
Inv_Red = pygame.transform.scale(Inv_Red, (140, 140))
Inv_Yel = pygame.transform.scale(Inv_Yel, (140, 140))
Glow_Strong = pygame.transform.scale(Glow_Strong, (140, 135))
Glow_weak = pygame.transform.scale(Glow_weak, (140, 135))
exit_door = pygame.transform.scale(exit_door, (140, 140))

# sounds
Mouse_Hover = getSound('Assets/MenuMouse.wav')
falling_sound = getSound('Assets/falling sound.wav')
falling_sound_finish = getSound('Assets/falling sound finish2.wav')
Click_sound = getSound('Assets/Menu Click.wav')
win_sound = getSound('Assets/Winning_Sound.wav')
win_sound_end = getSound('Assets/Winning_sound_end.wav')
falling_sound_finish2 = getSound('Assets/falling sound finish.wav')
tie_sound = getSound('Assets/tie_sound.wav')
Loading

0 comments on commit 5297987

Please sign in to comment.