62 lines
1.6 KiB
Python
62 lines
1.6 KiB
Python
|
|
from typing import final
|
||
|
|
|
||
|
|
from PySide6.QtWidgets import QWidget
|
||
|
|
from Movie import Movie
|
||
|
|
from enum import Enum
|
||
|
|
|
||
|
|
class ShopItemType(Enum):
|
||
|
|
"""
|
||
|
|
Enum dictating types of items that can be bought from the cinema.
|
||
|
|
"""
|
||
|
|
Movie = 0
|
||
|
|
Popcorn = 1
|
||
|
|
Frozen_Coke = 2
|
||
|
|
|
||
|
|
@final
|
||
|
|
class ShopItem:
|
||
|
|
"""
|
||
|
|
Represents an item that can be bought from the cinema.
|
||
|
|
"""
|
||
|
|
def __init__(self, type: ShopItemType, quantity: int, movie: Movie | None = None):
|
||
|
|
"""
|
||
|
|
Creates a new ShopItem.
|
||
|
|
Throws:
|
||
|
|
ValueError - type is ShopItemType.Movie, but movie is not provided as a paramater
|
||
|
|
Example (creates a ShopItem with type popcorn and quantity 3):
|
||
|
|
ShopItem(ShopItemType.Popcorn, 3)
|
||
|
|
"""
|
||
|
|
self.type = type
|
||
|
|
self.movie = movie
|
||
|
|
self.quantity = quantity
|
||
|
|
self.cost: float
|
||
|
|
match type:
|
||
|
|
case ShopItemType.Movie:
|
||
|
|
if movie != None:
|
||
|
|
self.cost = movie.price
|
||
|
|
else:
|
||
|
|
raise ValueError("ShopItem with type ShopItemType.Movie must provide a movie as an argument")
|
||
|
|
case ShopItemType.Popcorn:
|
||
|
|
self.cost = 9.95
|
||
|
|
pass
|
||
|
|
case ShopItemType.Frozen_Coke:
|
||
|
|
self.cost = 4.95
|
||
|
|
|
||
|
|
@final
|
||
|
|
class Cart:
|
||
|
|
def __init__(self):
|
||
|
|
self.contents: list[ShopItem] = []
|
||
|
|
|
||
|
|
def addItem(self, item: ShopItem):
|
||
|
|
self.contents.append(item)
|
||
|
|
pass
|
||
|
|
|
||
|
|
cart = Cart()
|
||
|
|
|
||
|
|
|
||
|
|
class CartView(QWidget):
|
||
|
|
def __init__(self):
|
||
|
|
super().__init__()
|
||
|
|
global cart
|
||
|
|
self.setWindowTitle("Work in progress!")
|
||
|
|
|