# How to Use the Game Classes

## The Simplest Game

Here is the absolute minimum to invoke the pygsear game framework:

from pygsear.Game import Game
g = Game()
g.mainloop()

Not very exciting. You can press escape to bring up the configuration screen, change the size of the window, and save your configuration. That's about it. You will of course want to add some code to customize your game.

## Initialization

As one of the final steps in the creation of the `Game` object, the `initialize` method will be called.

The `initialize` method is where you should place your code to customize the set up of the game. Like this:

from pygsear.Game import Game
from pygsear.locals import GREEN
class MyFirstGame(Game):
def initialize(self):
self.set_background(color=GREEN)
mfg = MyFirstGame()
mfg.mainloop()

## The main loop

In most games (and in most programs with a graphical interface) there is one central piece of code which is repeated very quickly while waiting for the player (the user) to tell it what to do.

This central piece of code is often called the event loop since it watches for external events like pressing keys on the keyboard, moving the mouse or clicking the mouse buttons, the passage of time, etc.

In the pygsear `Game` classes, the main event loop is a method called `mainloop`.

Once everything for the game is set up (initialized) you should call the `mainloop`, and that loop will run until the game is over or the player has chosen to quit.