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

Add the Alarm_Clock APP #370

Merged
merged 7 commits into from Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,8 @@ cython_debug/
.idea

# macOS files
.DS_Store
.DS_Store!/PYTHON APPS/Alarm_Clock/media/image/main.png

!/PYTHON APPS/Alarm_Clock/media/image/chose_timer.png

!/PYTHON APPS/Alarm_Clock/media/image/start_alarm.png
2 changes: 1 addition & 1 deletion GAMES/TIC_TAC_TOE/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ In this way is very easy to change the color, the font and kind of everthing you

## Visual

<img alt="empty" height="200" src="/home/mary/Documents/Marinel_Projects/Apps_GUI/TIC_TAC_TOE/Tic_Tac_Toe.png" width="200"/>
![Tic_Tac_Toe.png](media%2FTic_Tac_Toe.png)

## Contributing

Expand Down
Binary file removed GAMES/TIC_TAC_TOE/Tic_Tac_Toe.png
Binary file not shown.
Binary file added GAMES/TIC_TAC_TOE/media/Tic_Tac_Toe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 27 additions & 22 deletions GAMES/tic_tac_toe/README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
# Tic Tac Toe
# Tic Tac Toe with ttkbootstrap and pygame

Tic Tac Toe is a popular game for two players, X and O, who take turns marking the spaces in a 3×3 grid.
The player who succeeds in placing three of their marks in a diagonal, horizontal,
or vertical row is the winner.
Simple and good looking tic tac toe game including sound. The game is only for 2 player, sadly I am not ready
enough to add the AI boot (I don't want to add the random boot :) )

For more information about the the game, check [here](https://en.wikipedia.org/wiki/Tic-tac-toe).
## Description

The game was implemented in Python, using **Numpy** library.
The game is made only in ttkboostrap and some little pygame for the sound. You can customize this game as you
want. The main thing you can do is to change the color and many things. To see them check the OPTION part.

## How to launch
first you need to install *numpy*:\
`pip install -r requirements.txt`\
then you can directly launch the main script:\
`python main.py`
## Installation

good luck :)
Use the package manager [pip](https://pip.pypa.io/en/stable/) to
install [ttkboostrap](https://ttkbootstrap.readthedocs.io/en/latest/) and the [pygame ](https://www.pygame.org/news)

```bash
pip install ttkboostrap
```

#### Game Sample
each play, in turn, will choose one of the available positions by
entering the corresponding number. Numbers are 0-8 from going from top-left
to bottom-right corner.
```bash
pip install pygame
```

*start*
## Option

![Start](media/start.JPG)
The configuration.py file is made in that the information is stored in dictionary/hash-map or like json file.
In this way is very easy to change the color, the font and kind of everthing you want :/ (so be carefull)

*first move*
## Visual

![first-move](media/first-move.JPG)
![Tic_Tac_Toe.png](media%2FTic_Tac_Toe.png)

*winner*
## Contributing

![winner](media/winner.JPG)
Pull request are wellcome, if you have any advice I am open. If you know to add the AI boot, I will very happy
to add to my code

## License

[GNU GPLv3](https://choosealicense.com/licenses/gpl-3.0/)
266 changes: 206 additions & 60 deletions GAMES/tic_tac_toe/main.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,206 @@
import numpy as np


grid = np.full((3,3), '-')
cells = {'0': (0,0), '1': (0,1), '2': (0,2),
'3': (1,0), '4': (1,1), '5': (1,2),
'6': (2,0), '7': (2,1), '8': (2,2)}

diagonal_1 = [0,1,2], [0,1,2] # main diagonal
diagonal_2 = [0,1,2], [2,1,0] # reverse diagonal
ver_hor_lines = {'v1': grid[:,0], 'v2': grid[:,1], 'v3': grid[:,2], # verticals
'h1': grid[0,:], 'h2': grid[1,:], 'h3': grid[2,:]} # horizontals

player = ''
turn = 1
free_spots = ['0', '1', '2', '3', '4', '5', '6', '7', '8']
spot = ''

while True:
# printing the grid
for el in grid:
print(' '.join(el.astype(str)))

# check if player won
if np.all(grid[diagonal_1] == player) or np.all(grid[diagonal_2] == player):
print(f"player {player.upper()}, you won !")
quit()
for line in ver_hor_lines:
if np.all(ver_hor_lines[line] == player):
print(f"player {player.upper()}, you won !")
quit()
print('available positions: {}'.format(' '.join(free_spots)))

# check if game ended as a tie
if not free_spots:
print('END GAME: TIE')
break

# update the player
if turn % 2 == 0:
player = 'o'
else:
player = 'x'

# ask the input
spot = input('player {}, enter a position: '.format(player.upper()))
# entering 'out' will end the game at anytime
if spot == 'out':
quit()
# check if input is valid
if spot in free_spots:
# update the grid
position = cells[spot]
grid[position] = player
free_spots.remove(spot)
turn += 1
else:
print('not valid. Enter again.')

print()
import os
import sys
import ttkbootstrap as ttk

from tkinter import IntVar
from widgets import BoardGame, BoardScore
from configuration import (
# layout
MAIN_SIZE, BOARD_GAME, BOARD_SCORE, RESET_BUTTON,
# style
FRAME_STYLE_SCORE, FRAME_STYLE_GAME, BUTTON_BOARD_STYLE, BUTTON_RESET_STYLE, LABEL_SCORE_STYLE,
)

# import the modules for windows (it works only on windows)

try:
from ctypes import windll, byref, sizeof, c_int
except Exception:
pass


def path_resource(relative_path: str) -> str:
"""
it take the relative path and return the absolute path of the file from your system, is used for making the
app into a exe file for window

"""
try:
base_path: str = sys._MEIPASS
except Exception:
base_path = os.path.abspath('.')
return os.path.join(base_path, relative_path)


class TicTacToe(ttk.Window):

player_1: IntVar
player_2: IntVar
tie_score: IntVar

def __init__(self):
super().__init__()

self.bind('<Alt-s>', lambda event: self.destroy())
self.title('')
self.set_emtpy_icon()
self.set_title_bar_color()
self.set_window_size(width = MAIN_SIZE[0], height = MAIN_SIZE[1])

# set up the style
self.Style = ttk.Style(theme = 'darkly')

# style for the score/ board_score
self.Style.configure(

background = BOARD_SCORE['BACKGROUND'],
style = FRAME_STYLE_SCORE,

)

self.Style.configure(

background = BOARD_GAME['BACKGROUND_FRAME'],
style = FRAME_STYLE_GAME,

)

self.Style.configure(

background = BOARD_GAME['BACKGROUND'],
bordercolor = BOARD_GAME['BORDER_COLOR'],
borderthickness = BOARD_GAME['BORDER_THICKNESS'],
borderwidth = BOARD_GAME['BORDER_WIDTH'],
font = (BOARD_GAME['FONT'], BOARD_GAME['FONT_SIZE']),
justify = BOARD_GAME['JUSTIFY'],
relief = BOARD_GAME['RELIEF'],
style = BUTTON_BOARD_STYLE,

)

self.Style.map(

style = BUTTON_BOARD_STYLE,
foreground = [
('active', BOARD_GAME['TEXT_COLOR_ACTIVE']),
('disabled', BOARD_GAME['TEXT_COLOR_DISABLED'])
],
background = [
('active', BOARD_GAME['HOVER_COLOR_ACTIVE']),
('disabled', BOARD_GAME['HOVER_COLOR_DISABLED'])
]
)

self.Style.configure(

background = RESET_BUTTON['BACKGROUND'],
bordercolor = RESET_BUTTON['BORDER_COLOR'],
borderthickness = RESET_BUTTON['BORDER_THICKNESS'],
borderwidth = RESET_BUTTON['BORDER_WIDTH'],
font = (RESET_BUTTON['FONT'], RESET_BUTTON['SIZE']),
justify = RESET_BUTTON['JUSTIFY'],
relief = RESET_BUTTON['RELIEF'],
style = BUTTON_RESET_STYLE,

)
self.Style.map(

style = BUTTON_RESET_STYLE,
foreground = [
('active', RESET_BUTTON['TEXT_COLOR_ACTIVE']),
('disabled', RESET_BUTTON['TEXT_COLOR_DISABLED'])
],
background = [
('active', RESET_BUTTON['HOVER_COLOR_ACTIVE']),
('disabled', RESET_BUTTON['HOVER_COLOR_DISABLED'])]

)

self.Style.configure(

background = BOARD_SCORE['BACKGROUND'],
font = (BOARD_SCORE['FONT'], BOARD_SCORE['FONT_SIZE']),
foreground = BOARD_SCORE['TEXT_COLOR'],
style = LABEL_SCORE_STYLE,

)

# set player data
self.player_1 = ttk.IntVar(value = 0)
self.player_2 = ttk.IntVar(value = 0)
self.tie_score = ttk.IntVar(value = 0)

# set widgets
self.board_game = BoardGame(

parent = self,
style_cells = BUTTON_BOARD_STYLE,
style_frame = FRAME_STYLE_GAME,
player_1 = self.player_1,
tie = self.tie_score,
player_2 = self.player_2,

)

self.board_score = BoardScore(

parent = self,
style_labels = LABEL_SCORE_STYLE,
style_frame = FRAME_STYLE_SCORE,
style_button = BUTTON_RESET_STYLE,
player_1 = self.player_1,
tie = self.tie_score,
player_2 = self.player_2,
function = self.clean_board

)

# run
self.mainloop()

def clean_board(self):
"""
It clean the board and reset the score
"""
self.board_game.clean_board()
self.player_1.set(0)
self.player_2.set(0)
self.tie_score.set(0)

def set_emtpy_icon(self) -> None:
"""
It sets the icon to one empty from the title bar

"""
try:
path_image: str = path_resource('media/empty.ico')
self.iconbitmap(path_image)
except Exception:
pass

def set_window_size(self, width: int, height: int) -> None:
"""
It adjust the window size to be in the center of the screen

"""
left = int(self.winfo_screenwidth() / 2 - width / 2)
top = int(self.winfo_screenheight() / 2 - height / 2)
self.geometry(f'{width}x{height}+{left}+{top}')

def set_title_bar_color(self) -> None:
"""
It works only on Windows, not on GNU/Linux and macOS.
"""
try:
HWND = windll.user32.GetParent(self.winfo_id())
DWMWA_ATTRIBUTE: int = 35 # target the title bar
color_tile: int = 0x00030303
windll.dwmapi.DwmSetWindowAttribute(HWND, DWMWA_ATTRIBUTE, byref(c_int(color_tile)), sizeof(c_int))
except Exception:
pass


if __name__ == '__main__':

# starts the game
TicTacToe()
40 changes: 40 additions & 0 deletions PYTHON APPS/Alarm_Clock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Alarm clock with ttkbootstrap and pygame

Simple, good (quite good :) )looking alarm and simple to use

## Description

The app is made in ttkboostrap and some little pygame for the sound.

## Installation

Use the package manager [pip](https://pip.pypa.io/en/stable/) to
install [ttkboostrap](https://ttkbootstrap.readthedocs.io/en/latest/) and the [pygame ](https://www.pygame.org/news)

```bash
pip install ttkboostrap
```

```bash
pip install pygame
```

## How to use:

1. Press on the bottom button to add a new alarm.
2. Next choose your time and press ok or press cancel to quit
3. To start or to stop the alarm press the button near the delete button
4. To delete the alarm press the 'Delete' button

![main.png](media%2Fimage%2Fmain.png)
![chose_timer.png](media%2Fimage%2Fchose_timer.png)
![start_alarm.png](media%2Fimage%2Fstart_alarm.png)

## Contribution:

Pull request are wellcome, if you have any advice I am open. If you are a UI guy and want to make it more beautiful
you are wellcome to do it. (I am pretty bad at the GUI)

## License

[GNU GPLv3](https://choosealicense.com/licenses/gpl-3.0/)
Loading
Loading