Course:CPSC312-2018-UI-Explorer

From UBC Wiki

UI Explorer

Authors:

Jennifer Ahn, Curtis Fox

What is the problem?

We will investigate whether functional programming is suitable for building a game with a visual UI. To do this, we will create a game where the player must collect as many food pieces as possible for points (with a time limit), where the monster will also try to collect the food pieces as well. In addition, the monster will also chase after the player, and if the player is caught, the game ends.

What is the something extra?

We will create a game with a visible GUI, in addition to implementing a smart monster that will chase both the food pieces in the game as well as the player.

What did we learn from doing this?

One main thing in Haskell that we learned was how to apply data definitions and type definitions to a larger program. In addition, we learned how to work with a main function in Haskell. One other thing we learned was the importance of where blocks and helper functions in Haskell, especially as the program became larger. Using where blocks and helpers allowed us to repeat less code and more easily make changes to our code as we implemented more features.

In terms of limitations, one key limitation was the fact that Haskell is strongly typed, which made certain tasks difficult, such as working with random numbers. Random numbers must be generated as IO types, and the program we wrote required non-IO types, or at least would have been easier to write, if we were able to easily convert these IO types to non-IO types. Another limitation was the need to use a BMP (bitmap) file to import an image into our GUI. This is because the functions that Gloss provides for reading in images require a bitmap representation. Even after changing the file type of an image to a BMP file, it wasn't at all obvious how to read in the actual image using the provided functions in Gloss.

However, Haskell performed very well for setting up the actual GUI itself. By using the Gloss package, we were very easily able to render the actual GUI, and see any changes over time. This is done with the play function (as given in the Gloss documentation), which only requires passing some very simple parameters (such as the colour of the GUI) and rather basic function parameters (such as a render function and a handle keys function).

Links to code etc

https://github.com/curtis77/CPSC312-Project1