Lab Exercise 6 (Game of Life: Pyxel View)
Context
See Lab Exercise 3 for the background information for Game of Life, as well as the interfaces for Grids and Rulesets.
Overview
You will be structuring your code using the Model-View-Controller design pattern, and applying some Object-Oriented Programming principles you learned so far.
The Model and the Controller, as well as a terminal View will be provided in the Git repo; your job is to create a Pyxel-based View, as well as extend the Model for some bonus tasks.
Summary of Task
Your task is to implement a GameOfLifePyxelView for the Game of Life simulator and variants. The implementation will exhibit separation of concerns using the MVC pattern, as well as the Observer pattern. You may add custom methods to the Grid and Ruleset classes on top of the required interface.
The files for the implementation should all be in the lab06/pyxel_version directory.
You may adopt and modify the existing sample code in the lab06/sample directory, or use your own implementation from Lab 03.
Your program should be runnable using the command python3 -m lab06.game_of_life from the base directory, after importing the correct files.
The Grids and Rulesets should still work for both the terminal GameOfLifeView from the sample code and your new Pyxel GameOfLifePyxelView implementation.
Main task: View
Your task is to write a GameOfLifePyxelView class using Pyxel. By default, set the Pyxel FPS (frames-per-second) to \(30\).
-
The View should show the playing grid should be centered vertically and horizontally on the screen. One cell of the grid should be at least \(3 \times 3\) pixels in size.
-
The grid is initially all empty, but you may load an initial state using the
init_gridmethod of theGridtypes. -
The current turn count should be displayed on the upper left corner of the UI. This count is initially \(0\).
-
There should be two buttons below the playing grid:
- A "button" to toggle pausing/resuming the simulation. The game shold be paused at the start.
- A "button" to reset the grid back to its initial state. The turn count should also be reset to \(0\).
-
Make sure the mouse cursor is visible by calling
pyxel.mouse(True)in your initialization code.
Game Of Life Ruleset
At any time, a mouse left clicks on a grid cell should toggle the cell state, i.e. Alive to Empty or Empty to Alive.
P2Life Ruleset
At any time, a mouse left click or mouse right click on an occupied grid cell should set that cell to Empty.
A mouse LEFT click on an empty grid cell should set that cell to a White token.
A mouse RIGHT click on an empty grid cell should set that cell to a Black token.
The View class should have the following methods:
-
def __init__(self, width, height)- Takes two arguments for the width and height of the Pyxel screen.
-
def start_game(self, update_handler: UpdateHandler, draw_handler: DrawHandler) -> None- Entry point for the Pyxel runtime; this method will call at least
pyxel.init(...)andpyxel.run(...)
- Entry point for the Pyxel runtime; this method will call at least
-
def get_clicked_cell(self) -> Coords | None- Checks to see if any of the cells have been clicked, and returns the corresponding
Coordsfor the cell. If no cell was clicked, returnsNone.
- Checks to see if any of the cells have been clicked, and returns the corresponding
-
def draw_grid(self, grid: Grid) -> None:- Draws the grid on the Pyxel screen
-
def draw_turn_count(self, grid: Grid) -> None:- Draws the current turn count on the Pyxel screen
-
def reset_screen(self) -> None:- Resets the screen to one color
The UpdateHandler Protocol supports the following methods:
def update(self)- A method/function accepting no parameters, used for the Pyxel runtime
The DrawHandler Protocol supports the following methods:
def draw(self)- A method/function accepting no parameters, used for the Pyxel runtime
Scoring
This lab exercise will be scored in phases. You can get \(0/20/50/80/100 \%\) of the points in a phase depending on how far/close you are from meeting the phase's requirements. You must get \(\ge 80 \%\) of the points in each of the previous phases to get nonzero points for a certain phase.
This lab will be scored over \(100\) 🔴.
Note
For all phases, your program should be runnable using the command python3 -m lab06.game_of_life.
Indicate the farthest phase you (think you) got in a README.md file.
Phase 1 (\(60\) 🔴)
For this phase, you will implement the base functionalities for the Pyxel view, supporting the base Game of Life ruleset.
In terms of graphics, we expect you to implement simple shapes only (built-in shapes in Pyxel).
Phase 2 (\(40\) 🔴)
For Phase 2, you should also support custom View functionality for the P2Life ruleset, with Phase 1 features still working.
Phase 3 (\(20\) 🔴)
For Phase 3, you should also support custom View functionality for your custom ruleset from Lab 03. This phase is only applicable if you submitted a custom ruleset in your Lab 03 submission.
Sprites bonus (\(20\) ❤️)
For the Sprites bonus, you can create your own sprites for the buttons or additional UI elements. See https://kitao.github.io/pyxel/web/editor-manual/ for more details, and feel free to consult other resources.
Sound effects bonus (\(20\) ❤️)
For the Sound effects bonus, you can create your own sound effects or game music to play for the game. Add at least two sound effects, (1) for when you click a grid cell, and (2) for when you click the "Reset" button. See https://kitao.github.io/pyxel/web/editor-manual/ for more details, and feel free to consult other resources.
Submission
Via DCS Yagit (https://yagit.upd-dcs.work/). Submit by pair.
Deadline: October 16, 2026 (Th) 11:12 pm
Checkpoint
Toggling grid (20 ❤️)
Before the lab session ends, you should be able to implement a 6 x 7 playing grid, implemented with Pyxel.
Initially, the grid of cells all have Pyxel color 7, denoting an empty cell.
- Doing a left click on an empty cell turns it to Pyxel color 10, making the cell "occupied".
- Doing a right click on an empty cell turns it to Pyxel color 8, making the cell "occupied".
- Doing a left or right click on an "occupied" cell turns it back to Pyxel color 7.
- Make sure the mouse cursor is visible by calling
pyxel.mouse(True)in your initialization code.
Your implementation does NOT have to follow MVC.
Call the attention of your lab instructor once you are done with the checkpoint task. Once your toggling board has been verified to work, you will gain 20 ❤️ points, and your attendance will be recorded (and you may leave early).
If you are not able to finish the checkpoint task within the lab time, your attendance will be recorded at the very end of the lab session.