forked from Dr-Nekoma/h-vita
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac5b37f
commit 12a919b
Showing
9 changed files
with
102 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# EditorConfig is awesome: https://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = false | ||
insert_final_newline = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,27 @@ | ||
# h-vita | ||
|
||
This is the [game of life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) implemented in Haskell. | ||
|
||
## External Dependencies | ||
|
||
- [Data.Matrix](https://hackage.haskell.org/package/matrix-0.3.6.1/docs/Data-Matrix.html) | ||
- [Graphics.Gloss](https://hackage.haskell.org/package/gloss) | ||
|
||
## How to use run the Game | ||
|
||
To execute the game you do: | ||
|
||
`stack run` | ||
|
||
If you want to see a different game (not the glider one), open the REPL and use: | ||
|
||
`playGame OTHER_GAME` | ||
|
||
## Developers | ||
|
||
- EduardoLR10 | ||
- ribeirotomas1904 | ||
|
||
## Dr.Nekoma | ||
|
||
Builded live on [twitch](https://www.twitch.tv/drnekoma) and archived on [youtube](https://www.youtube.com/channel/UCMyzdYsPiBU3xoqaOeahr6Q) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ import Display | |
import Types | ||
|
||
main :: IO () | ||
main = print "Hello World!" | ||
main = playGame gliderGrid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,32 @@ | ||
module Display where | ||
module Display where | ||
|
||
import Data.Matrix | ||
import Graphics.Gloss | ||
import Graphics.Gloss.Interface.Pure.Simulate | ||
import GameOfLife | ||
import Games | ||
import Types | ||
|
||
render :: DisplayCellSize -> Grid -> Picture | ||
render (width, height) grid = Pictures $ toList $ mapPos f grid | ||
where | ||
xAxis column width = (fromIntegral column) * width + borderSize * (fromIntegral column) | ||
yAxis row height = (* (-1)) $ (fromIntegral row) * height + borderSize * (fromIntegral row) | ||
borderSize = 2 | ||
f (row, column) cell | ||
| cell == dead = Blank | ||
| otherwise = Translate (xAxis column width) (yAxis row height) | ||
$ rectangleSolid width height | ||
|
||
advanceGame :: ViewPort -> Float -> Grid -> Grid | ||
advanceGame _ _ = advanceGridGeneration | ||
|
||
playGame :: Grid -> IO () | ||
playGame game | ||
= simulate | ||
(InWindow "h-vita" (800, 600) (10, 10)) -- Setting up window for the game | ||
white -- Background color of the board | ||
2 -- Number of steps per second | ||
game -- Initial state of the game | ||
(render (10.0, 10.0)) -- Function to convert grid to a Picture | ||
advanceGame -- Function to advance generation of the grid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
module Types where | ||
import Data.Matrix | ||
|
||
type Location = (Int, Int) -- Cell's position on the Grid | ||
type NumberOfNeighbours = Int -- The size of the Grid | ||
type Cell = Bool -- Cell | ||
alive = True | ||
dead = False | ||
type Neighbours = [Cell] -- Cell | ||
type Grid = Matrix Cell -- The board | ||
type Location = (Int, Int) -- Cell's position on the Grid | ||
type NumberOfNeighbours = Int -- The number of neighbours for a given cell | ||
type Cell = Bool -- Cell | ||
alive = True -- State for alive cell | ||
dead = False -- State for dead Cell | ||
type Neighbours = [Cell] -- Alias for cell neighbours | ||
type Grid = Matrix Cell -- The game board | ||
type DisplayCellSize = (Float, Float) -- Size of cell for display |