0% found this document useful (0 votes)
6 views3 pages

Game Gui - Py

The document contains a Python script that implements a 2v2 battle game using the Tkinter library for the GUI. Players can input names and select character types (Warrior, Mage, Archer) for two characters, and the game simulates a battle between them, displaying the battle log and announcing the winner. The game utilizes classes for character types and includes methods for attacking and checking health status.

Uploaded by

nawalbaloch489
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Game Gui - Py

The document contains a Python script that implements a 2v2 battle game using the Tkinter library for the GUI. Players can input names and select character types (Warrior, Mage, Archer) for two characters, and the game simulates a battle between them, displaying the battle log and announcing the winner. The game utilizes classes for character types and includes methods for attacking and checking health status.

Uploaded by

nawalbaloch489
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import tkinter as tk

from tkinter import messagebox


from characters import Warrior, Mage, Archer
import random

class GameGUI:
def __init__(self, root):
[Link] = root
[Link]("2v2 Battle Game")

# Character 1 Input
[Link](root, text="Character 1 Name:").pack()
self.char1_name = [Link](root)
self.char1_name.pack()

[Link](root, text="Character 1 Type:").pack()


self.char1_type = [Link](value="Warrior")
[Link](root, self.char1_type, "Warrior", "Mage", "Archer").pack()

# Character 2 Input
[Link](root, text="Character 2 Name:").pack()
self.char2_name = [Link](root)
self.char2_name.pack()

[Link](root, text="Character 2 Type:").pack()


self.char2_type = [Link](value="Mage")
[Link](root, self.char2_type, "Warrior", "Mage", "Archer").pack()

# Battle Button
[Link](root, text="Start Battle", command=self.start_battle).pack(pady=10)

# Battle Log
[Link] = [Link](root, height=10, width=50)
[Link]()

def start_battle(self):
# Clear previous log
[Link](1.0, [Link])

# Create characters
char1 = self.create_character(
self.char1_name.get(),
self.char1_type.get()
)
char2 = self.create_character(
self.char2_name.get(),
self.char2_type.get()
)

# Simulate battle
[Link]([Link], "=== BATTLE BEGINS ===\n")
[Link]([Link], f"{[Link]} ({char1.__class__.__name__}) vs {[Link]}
({char2.__class__.__name__})\n\n")

while [Link]() and [Link]():


# Character 1 attacks
damage = [Link]()
[Link](damage)
[Link]([Link], f"{[Link]} attacks {[Link]} for {damage} damage!\n")

if not [Link]():
break

# Character 2 attacks
damage = [Link]()
[Link](damage)
[Link]([Link], f"{[Link]} attacks {[Link]} for {damage} damage!\n")

[Link]([Link], f"Status: {[Link]} ({[Link]} HP), {[Link]}


({[Link]} HP)\n\n")
[Link]() # Update GUI

# Show winner
winner = char1 if [Link]() else char2
[Link]("Battle Over", f"{[Link]} wins the battle!")

def create_character(self, name, char_type):


if not name:
name = "Unknown"

if char_type == "Warrior":
return Warrior(name, [Link](15, 25), [Link](80, 120))
elif char_type == "Mage":
return Mage(name, [Link](10, 20), [Link](60, 90))
else:
return Archer(name, [Link](12, 22), [Link](70, 100))

# Run the GUI


if __name__ == "__main__":
root = [Link]()
app = GameGUI(root)
[Link]()

You might also like