-
Notifications
You must be signed in to change notification settings - Fork 839
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4759 from priyashuu/main
New Game:-Dice_Rolling_simulator
- Loading branch information
Showing
10 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
### Description | ||
The dice rolling simulator is a simple application built using Python and the Tkinter library for the graphical user interface (GUI). The simulator mimics the action of rolling a dice, providing a random outcome between 1 and 6 each time the user interacts with the interface. This application is useful for games, educational purposes, or simply for fun. | ||
|
||
### Game_Logic | ||
|
||
- Initialization: When the program starts, it initializes the main window using Tkinter. | ||
- Dice Roll: A function generates a random number between 1 and 6 using Python's random module. | ||
- Display: The result of the dice roll is displayed on the GUI, typically as a number or a graphical representation of a dice face. | ||
- Interaction: The user can roll the dice by clicking a button on the GUI, which triggers the dice roll function. | ||
|
||
### FEATURES | ||
Random Dice Roll: Uses the random.randint(1, 6) function to generate a number between 1 and 6. | ||
Graphical Interface: A user-friendly interface built with Tkinter, making it easy to interact with the simulator. | ||
Roll Button: A button that the user clicks to roll the dice. | ||
Display Area: Shows the result of the dice roll, either as a numeric value or a visual representation. | ||
|
||
### Screenshot![Dice_Rolling_simulator_Game](https://github.com/priyashuu/GameZone/assets/150767072/46569298-3844-4240-a3c3-544fc47c524e) | ||
### Video | ||
|
||
https://github.com/priyashuu/GameZone/assets/150767072/0d88b796-9125-4bf4-bb58-7178a456ecc8 | ||
|
||
|
||
|
||
|
||
### Tech Stack Overview | ||
|
||
The dice rolling simulator utilizes a combination of technologies and libraries to create a functional and interactive application. Below is a breakdown of the tech stack used: | ||
|
||
#### **Programming Language:** | ||
- **Python** | ||
|
||
#### **Graphical User Interface (GUI):** | ||
- **Tkinter** | ||
|
||
#### **Libraries and Modules:** | ||
- **Random** | ||
|
||
#### **Development Environment:** | ||
- **IDLE** | ||
- **VS Code** | ||
#### **Version Control:** | ||
- **Git** | ||
- **GitHub** | ||
### Example of Tech Stack in Action | ||
1. **Python**: The logic of the dice roll is implemented in Python using simple functions and conditional statements. | ||
2. **Tkinter**: Used to create the main window, buttons, and labels that make up the user interface. | ||
3. **Random Module**: Utilized within the dice roll function to generate a random number between 1 and 6 each time the user clicks the roll button. | ||
4. **Git and GitHub**: The code is version-controlled using Git and hosted on GitHub, making it easy to share and collaborate with others. | ||
|
||
### Installation Instructions | ||
1. **Install Python**: Download and install Python from [python.org](https://www.python.org/). | ||
2. **Install Tkinter**: Tkinter is included with Python, so no additional installation is required. | ||
3. **Clone the Repository**: If the project is hosted on GitHub, clone the repository using Git. | ||
```bash | ||
git clone https://github.com/username/repository-name.git | ||
``` | ||
4. **Run the Application**: Navigate to the project directory and run the Python script. | ||
```bash | ||
cd repository-name | ||
python dice_simulator.py | ||
``` | ||
<<<<<<< HEAD | ||
|
||
======= | ||
>>>>>>> priyashuu-patch-1 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import tkinter as tk | ||
from PIL import Image, ImageTk | ||
import random | ||
import time | ||
import os | ||
|
||
# Initialize the Tkinter window | ||
window = tk.Tk() | ||
window.geometry("500x360") | ||
window.title("Dice Roll") | ||
window.configure(bg='black') | ||
|
||
# Define a list of dice images | ||
dice = ["dice_1.png", "dice_2.png", "dice_3.png", "dice_4.png", "dice_5.png", "dice_6.png"] | ||
|
||
# Verify that all dice images exist | ||
for dice_image in dice: | ||
if not os.path.exists(dice_image): | ||
print(f"Error: {dice_image} not found.") | ||
exit() | ||
|
||
# Define a list of colors for the animation | ||
colors = ['red', 'orange', 'yellow', 'green', 'blue', 'purple', 'pink'] | ||
|
||
# Choose a random image for each dice and display them initially on the window | ||
image1 = ImageTk.PhotoImage(Image.open(random.choice(dice))) | ||
image2 = ImageTk.PhotoImage(Image.open(random.choice(dice))) | ||
label1 = tk.Label(window, image=image1, bg='black') | ||
label2 = tk.Label(window, image=image2, bg='black') | ||
label1.image = image1 | ||
label2.image = image2 | ||
label1.place(x=40, y=100) | ||
label2.place(x=900, y=100) | ||
|
||
# Define a function named "dice_roll" with animation | ||
def dice_roll(): | ||
for _ in range(10): # Number of frames in the animation | ||
color = random.choice(colors) # Choose a random color for the background | ||
image1 = ImageTk.PhotoImage(Image.open(random.choice(dice))) | ||
label1.configure(image=image1, bg=color) | ||
label1.image = image1 | ||
image2 = ImageTk.PhotoImage(Image.open(random.choice(dice))) | ||
label2.configure(image=image2, bg=color) | ||
label2.image = image2 | ||
window.update() # Update the window to show changes | ||
time.sleep(0.1) # Pause to create animation effect | ||
# Set the final images and background to black after animation | ||
image1 = ImageTk.PhotoImage(Image.open(random.choice(dice))) | ||
label1.configure(image=image1, bg='black') | ||
label1.image = image1 | ||
image2 = ImageTk.PhotoImage(Image.open(random.choice(dice))) | ||
label2.configure(image=image2, bg='black') | ||
label2.image = image2 | ||
|
||
# Define a button widget labeled "ROLL" with green background and white text, positioned at the top of the window | ||
button = tk.Button(window, text="ROLL", bg="green", fg="white", font="Times 20 bold", command=dice_roll) | ||
button.place(x=660, y=10) | ||
|
||
# Display the Tkinter window and wait for user interaction | ||
window.mainloop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.