This is our final project for UCSD FA23 CSE230
Name | PID | Github account |
---|---|---|
Nai-En Kuo | A59025053 | imgradually |
Mingxuan Li | A69027684 | HunterLep |
Brian Chen | A59016113 | zychen5186 |
Jensen Chang | A59024883 | ycchang99 |
- ghc
- brick
- To clone and build locally:
$ git clone https://github.com/jtdaugherty/brick.git $ cd brick $ cabal new-build
- To clone and build locally:
To run the executable enter the project’s directory and run it, by inputting the following commands:
cd Haskell-Snake-Game
cabal run Haskell-Snake-Game
In this project, We decided to reproduce the classic snake game, with the primary aim to create a two-player gaming experience within the confines of the command line interface. These are the game functionality we will include in our project
- Starting Point: The game starts with a snake for each player with a score of 0 and a piece of food on a grid.
- Movement: The player can control the direction of the snake using arrow keys for P1 and WASD for P2. The snake moves continuously in the specified direction.
- Objective: The main goal is to guide the snake to eat the food, which causes the snake to grow longer and earns point with each consumed piece.
- Grid Boundaries: The snake moves within the boundaries of a defined grid. If it hits the edge of the grid, it dies.
- Eating and Growing: When the snake eats a piece of food, its length and speed increases. The goal is to eat as much food as possible without colliding.
- Game Over: The player must avoid having the collision with itself, the components body, or the boundaries, if any of the above happens, it dies. When both players' snake dies, the game ends.
- Scorekeeping: Points are awarded for each piece of food eaten. The Player with the higher score at the end of the game wins.
- Game State: The
Game
type represents the state of the Snake game, including the snake's position, direction, score, etc. - Rendering: The
drawUI
function combines widgets to create the user interface, including the score display, game over message, and the grid with the snake and food. - Input Handling: The
handleEvent
function responds to various events, such as ticks (for game progression), arrow key presses (for snake movement), and other key presses (e.g., 'r' for restarting and 'q' for quitting). - Initialization: The
initGame
function initializes the game state, and themain
function sets up the Brick application, event channel, and starts the main loop. - Game Logic: The game logic is encapsulated in the
step
andturn
functions, which handle the progression of the game state based on ticks and user input. - Brick App Definition: The
app
definition configures the Brick application, specifying the drawing, event handling, cursor behavior, and attribute mapping. - Attributes and Styles: The
theMap
defines attribute mappings for different elements, such as the snake, food, and game over message. These attributes are used in rendering to style the elements.
- Yes
https://github.com/samtay/snake.git
- Brick version compatibility :
next
andcontinue
are not supported in current version of brick library. Many other features need to be fixed as well, such as handling the collision to the border and the pause (restart) function whenp
(r
) is pressed. - Second player (snake) : Extend the game from a single-player game to a double-player game. This involves creating a second snake and defining a new conditions for game-over in this multiplayer setting.
- Start page : Insert a new brick App at the beginning of
main
to ask users to choose whether they are going to play in a single-player or double-player format. - Freezer : Create a new food-like object such that one can freeze its opponent for a while. Appears only in double-player mode. The snake that is freezed cannot die.
- Reverse : Allow user to press
g
or.
to switch its head and tail. - Changes in the decision of winning party : For double player mode, the system is designed to judge which player has won by the scores they get. We also introduced the draw result in case the scores are the same. And the Gameover box would show the result.
- Changes in game playing : For double player mode, because the results are decided by the scores, the game would still conitnue if one party dies until both parties are dead to accomodate the changes. We also noticed that because there are two snakes, there would be collision to each other, so when any snake crashes into another's body part, it would die. When these two snakes collides head to head, there would be a draw if the score is the same and whoever has the higher score secures the game.
- UI changes : Show help window and tip window aside when playing. These two windows are customized for different play modes. Change the snakes' heads attribute to different patterns so that the movements can be more easily recognized.