From 7133a728596918544601a18e3090281eaff34ad1 Mon Sep 17 00:00:00 2001 From: melody! Date: Wed, 7 Aug 2024 21:23:52 -0400 Subject: did stuff --- TODO.md | 14 ++++++++++++++ app/Main.hs | 36 +++++++++++++++++++++++++++++++++--- app/Screen.hs | 7 +++++++ beekeep.cabal | 17 ++++++++++------- src/Bee.hs | 9 +++++++++ src/Beekeep.hs | 41 +++++++++++++++++++++++++++++++++++++++++ src/MyLib.hs | 4 ---- src/Plant.hs | 27 +++++++++++++++++++++++++++ 8 files changed, 141 insertions(+), 14 deletions(-) create mode 100644 TODO.md create mode 100644 app/Screen.hs create mode 100644 src/Bee.hs create mode 100644 src/Beekeep.hs delete mode 100644 src/MyLib.hs create mode 100644 src/Plant.hs diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..ff4d802 --- /dev/null +++ b/TODO.md @@ -0,0 +1,14 @@ +# beekeeping +## game goals +- game played over time +- casual, low risk, comfy +- no punishment for not playing in a while +- multiplayer + +## game loop +- start with small nucleus of bees and a few flowers +- goal is to produce as much aggricultural product as possible +- you can trade fruits/honey/honeycomb/flowers with other users +- you can also send your bees to other peoples crops +- random chance of getting new seeds from bees dropping them off + diff --git a/app/Main.hs b/app/Main.hs index 60d904e..f8e8c5f 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,8 +1,38 @@ module Main where +import Screen -import qualified MyLib (someFunc) +import Beekeep + ( Garden + , newGarden + , gardenWidth + -- , gardenHeight + , gardenGet ) + +printGarden' :: [(Int, Int)] -> Garden -> IO () +printGarden' [] _ = return () +printGarden' ((x,y):xs) g = + do + _ <- gardenGet g (x, y) + putChar 'x' + if x == viewportWidth then + putStrLn "" + else return () + printGarden' xs g + +viewportWidth :: Int +viewportWidth = 32 + +viewportHeight :: Int +viewportHeight = 16 + +printGarden :: Garden -> IO () +printGarden = printGarden' [(x, y) | + y <- [1..viewportHeight], + x <- [1..viewportWidth]] main :: IO () main = do - putStrLn "Hello, Haskell!" - MyLib.someFunc + clear + g <- newGarden + printGarden g + diff --git a/app/Screen.hs b/app/Screen.hs new file mode 100644 index 0000000..9962cde --- /dev/null +++ b/app/Screen.hs @@ -0,0 +1,7 @@ +module Screen + ( clear + ) where + +clear :: IO () +clear = putStr "\ESC[H\ESC[2J" + diff --git a/beekeep.cabal b/beekeep.cabal index cd3cb10..455d902 100644 --- a/beekeep.cabal +++ b/beekeep.cabal @@ -46,6 +46,7 @@ build-type: Simple -- Extra doc files to be distributed with the package, such as a CHANGELOG or a README. extra-doc-files: CHANGELOG.md + , README.md -- Extra source files to be distributed with the package, such as examples, or a tutorial module. -- extra-source-files: @@ -58,16 +59,18 @@ library import: warnings -- Modules exported by the library. - exposed-modules: MyLib + exposed-modules: Beekeep -- Modules included in this library but not exported. - -- other-modules: + other-modules: Plant + , Bee -- LANGUAGE extensions used by modules in this package. -- other-extensions: -- Other library packages from which modules are imported. - build-depends: base ^>=4.17.2.1 + build-depends: base ^>=4.13.0.0 + , array ^>= 0.5.4.0 -- Directories containing source files. hs-source-dirs: src @@ -83,15 +86,15 @@ executable beekeep main-is: Main.hs -- Modules included in this executable, other than Main. - -- other-modules: + other-modules: Screen -- LANGUAGE extensions used by modules in this package. -- other-extensions: -- Other library packages from which modules are imported. build-depends: - base ^>=4.17.2.1, - beekeep + base ^>=4.13.0.0 + , beekeep -- Directories containing source files. hs-source-dirs: app @@ -123,5 +126,5 @@ test-suite beekeep-test -- Test dependencies. build-depends: - base ^>=4.17.2.1, + base ^>=4.13.0.0, beekeep diff --git a/src/Bee.hs b/src/Bee.hs new file mode 100644 index 0000000..b83e67e --- /dev/null +++ b/src/Bee.hs @@ -0,0 +1,9 @@ +module Bee + ( Beehive (..) + ) where + +data Beehive = Beehive + { hiveWorkers :: Int + , hiveOwner :: String + } + diff --git a/src/Beekeep.hs b/src/Beekeep.hs new file mode 100644 index 0000000..9fb874a --- /dev/null +++ b/src/Beekeep.hs @@ -0,0 +1,41 @@ +module Beekeep + ( Garden + , Block (..) + , gardenWidth + , gardenHeight + , newGarden + , gardenSet + , gardenGet + ) where +import Bee +import Plant +import Data.Array.IO + +someFunc :: IO () +someFunc = putStrLn "someFunc" + +data Block = + BEmpty + | BPlant Plant + | BHive Beehive + +type Garden = IOArray Int Block + +gardenWidth :: Int +gardenWidth = 128 + +gardenHeight :: Int +gardenHeight = 128 + +newGarden :: IO Garden +newGarden = newArray (1, gardenWidth * gardenHeight) BEmpty + +calcGardenIndex :: (Int, Int) -> Int +calcGardenIndex (x, y) = x + y * gardenHeight + +gardenGet :: Garden -> (Int, Int) -> IO Block +gardenGet g coords = readArray g (calcGardenIndex coords) + +gardenSet :: Garden -> (Int, Int) -> Block -> IO () +gardenSet g coords b = writeArray g (calcGardenIndex coords) b + diff --git a/src/MyLib.hs b/src/MyLib.hs deleted file mode 100644 index e657c44..0000000 --- a/src/MyLib.hs +++ /dev/null @@ -1,4 +0,0 @@ -module MyLib (someFunc) where - -someFunc :: IO () -someFunc = putStrLn "someFunc" diff --git a/src/Plant.hs b/src/Plant.hs new file mode 100644 index 0000000..04e35e7 --- /dev/null +++ b/src/Plant.hs @@ -0,0 +1,27 @@ +module Plant + ( GrowthStage (..) + , PlantType (..) + , Plant (..) + , Seed (..) + ) where + +data GrowthStage = + SSeed + | SSapling + | SGrown + +data PlantType = + TFlower + | TCrop + | TTree + +data Plant = Plant + { plantName :: String + , plantType :: PlantType + , plantStage :: GrowthStage + } + +data Seed = Seed + { seedName :: String + , seedType :: PlantType } + -- cgit 1.4.1-2-gfad0