SHARE
TWEET

Untitled

a guest Jun 18th, 2019 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# LANGUAGE TypeFamilies, MultiParamTypeClasses, FlexibleContexts, FlexibleInstances #-}
  2.  
  3. class (Show pokemon, Show (Move pokemon)) => Pokemon pokemon where
  4.  data Move pokemon :: *
  5.  pickMove :: pokemon -> Move pokemon
  6.  
  7. --Существующие покемоны стихии огня
  8. data Fire = Charmander | Charmeleon | Charizard deriving Show
  9. instance Pokemon Fire where
  10. --Существующие атаки покемонов
  11.  data Move Fire = Ember | FlameThrower | FireBlast deriving Show
  12.  pickMove Charmander = Ember
  13.  pickMove Charmeleon = FlameThrower
  14.  pickMove Charizard = FireBlast
  15.  
  16. --Существующие покемоны стихии воды
  17. data Water = Squirtle | Wartortle | Blastoise deriving Show
  18. instance Pokemon Water where
  19. --Существующие атаки покемонов
  20.  data Move Water = Bubble | WaterGun deriving Show
  21.  pickMove Squirtle = Bubble
  22.  pickMove _ = WaterGun
  23.  
  24. --Существующие атаки покемонов земли
  25. data Grass = Bulbasaur | Ivysaur | Venusaur deriving Show
  26. instance Pokemon Grass where
  27. --Существующие атаки покемонов
  28.  data Move Grass = VineWhip deriving Show
  29.  pickMove _ = VineWhip
  30.  
  31. --Пикачу - имба, - “Пика-пи” :3
  32. data Imba = Pikachu deriving Show
  33. instance Pokemon Imba where
  34.  data Move Imba = PikaPi deriving Show
  35.  pickMove _ = PikaPi
  36.  
  37. printBattle :: String -> String -> String -> String -> String -> IO ()
  38. printBattle pokemonOne moveOne pokemonTwo moveTwo winner = do
  39.  putStrLn $ pokemonOne ++ " used " ++ moveOne
  40.  putStrLn $ pokemonTwo ++ " used " ++ moveTwo
  41.  putStrLn $ "Winner is: " ++ winner ++ "\n"
  42.  
  43. class (Show (Winner pokemon foe), Pokemon pokemon, Pokemon foe) => Battle pokemon foe where
  44.   type Winner pokemon foe :: *
  45.   type Winner pokemon foe = pokemon
  46.  
  47.   battle :: pokemon -> foe -> IO ()
  48.   battle pokemon foe = do
  49.     printBattle (show pokemon) (show move) (show foe) (show foeMove) (show winner)
  50.    where
  51.     foeMove = pickMove foe
  52.     move = pickMove pokemon
  53.     winner = pickWinner pokemon foe
  54.  
  55.   pickWinner :: pokemon -> foe -> (Winner pokemon foe)
  56.  
  57. instance Battle Water Fire where
  58.  pickWinner pokemon foe = pokemon
  59.  
  60. instance Battle Fire Water where
  61.  type Winner Fire Water = Water
  62.  pickWinner = flip pickWinner
  63.  
  64. instance Battle Grass Water where
  65.  pickWinner pokemon foe = pokemon
  66.  
  67. instance Battle Water Grass where
  68.  type Winner Water Grass = Grass
  69.  pickWinner = flip pickWinner
  70.  
  71. instance Battle Fire Grass where
  72.  pickWinner pokemon foe = pokemon
  73.  
  74. instance Battle Grass Fire where
  75.  type Winner Grass Fire = Fire
  76.  pickWinner = flip pickWinner
  77.  
  78. instance Pokemon a => Battle a Imba where
  79.  type Winner a Imba = Imba
  80.  pickWinner _ _ = Pikachu
  81.  
  82. instance Pokemon a => Battle Imba a where
  83.  type Winner Imba a = Imba
  84.  pickWinner _ _ = Pikachu
  85.    
  86. main :: IO ()
  87. main = do
  88.  battle Squirtle Charmander
  89.  putStrLn " "
  90.  battle Charmander Squirtle
  91.  putStrLn " "
  92.  battle Pikachu Charizard
  93.  putStrLn " "
  94.  battle Pikachu Squirtle
  95.  putStrLn " "
  96.  battle Squirtle Pikachu
  97.  putStrLn " "
  98.  battle Charmeleon Wartortle
  99.  putStrLn " "
  100.  battle Bulbasaur Blastoise
  101.  putStrLn " "
  102.  battle Wartortle Ivysaur
  103.  putStrLn " "
  104.  battle Charmeleon Ivysaur
  105.  putStrLn " "
  106.  battle Venusaur Charizard
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top