Advertisement
konalisp

DM.fs

Oct 26th, 2015
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 17.26 KB | None | 0 0
  1. namespace DM //Digital Manbaby
  2.  
  3. open System
  4.  
  5. [<CLIMutable>]
  6. type GlobalState = {
  7.     manbabyName : string;
  8.     happiness : int;
  9.     mentalHealth : int;
  10.     physicalHealth : int;
  11.     statusList : string array;
  12.     GBP : int;
  13.     playerName : string;
  14.     inventory : string array;
  15.     isDead : bool;
  16. }
  17.  
  18. module FileIO =
  19.    
  20.     open System.Xml.Serialization
  21.     open System.IO
  22.    
  23.     let filename = "save.dm"
  24.    
  25.     let chkfile () =
  26.         if not (File.Exists(filename)) then
  27.             use file = File.Create(filename)
  28.             file.Close()
  29.             true
  30.         else false
  31.    
  32.     type Write = GlobalState -> unit
  33.     let write : Write = fun gs ->
  34.         use file = new FileStream(filename, FileMode.Create, FileAccess.Write)
  35.         let ser = new XmlSerializer(typeof<GlobalState>)
  36.         ser.Serialize(file, gs)
  37.         file.Close()
  38.    
  39.     type Read = unit -> GlobalState
  40.     let read : Read = fun () ->
  41.         use file = new FileStream(filename, FileMode.Open, FileAccess.Read)
  42.         let ser = new XmlSerializer(typeof<GlobalState>)
  43.         let result = ser.Deserialize(file) :?> GlobalState
  44.         file.Close()
  45.         result
  46.  
  47. module Logic =
  48.    
  49.     let uppercase (n : string) =
  50.         match n with
  51.         | n when n.Length > 0 ->
  52.             string(n.[0]).ToUpper() + n.Substring(1)
  53.         | _ -> n
  54.    
  55.     let chkItem gs item =
  56.         let result = Array.tryFind (fun n -> n = item) gs.inventory
  57.         match result with
  58.         | Some x -> true
  59.         | None   -> false
  60.    
  61.     let remItem gs item =
  62.         let result =
  63.             match Array.tryFindIndex ((=) item) gs.inventory with
  64.             | Some 0 -> gs.inventory.[1..]
  65.             | Some i -> Array.append gs.inventory.[..i-1] gs.inventory.[i+1..]
  66.             | None   -> gs.inventory
  67.         { gs with inventory = result }
  68.    
  69.     let remStat gs stat =
  70.         let result =
  71.             match Array.tryFindIndex ((=) stat) gs.statusList with
  72.             | Some 0 -> gs.statusList.[1..]
  73.             | Some i -> Array.append gs.statusList.[..i-1] gs.statusList.[i+1..]
  74.             | None   -> gs.statusList
  75.         { gs with statusList = result }
  76.        
  77.     let hasStat gs st =
  78.         let m x = if x = st then true else false
  79.         let c = Array.tryFind m gs.statusList
  80.         match c with
  81.         | Some x -> true
  82.         | None   -> false
  83.    
  84.     let getInv gs =
  85.         let result = Array.rev (Array.sort gs.inventory)
  86.         let l = result.Length - 1
  87.         printfn "%s" "Inventory:"
  88.         if l < 0 then printfn "You have no items!"
  89.         for i in 0 .. l do
  90.             printfn " %i: %s" (i + 1) (uppercase result.[i])
  91.    
  92.  
  93. module Stats =
  94.    
  95.     let SeederState : GlobalState = {
  96.             manbabyName = "DM";
  97.             happiness = 100;
  98.             mentalHealth = 100;
  99.             physicalHealth = 100;
  100.             statusList = [|  |];
  101.             GBP = 50;
  102.             playerName = "Player";
  103.             inventory = [|  |];
  104.             isDead = false;
  105.     }
  106.    
  107.     let happiness gs n =
  108.         let t = gs.happiness + n
  109.         match t with
  110.         | t when t > 100 -> { gs with happiness = 100 }
  111.         | t when t < 0   -> { gs with happiness = 0   }
  112.         | _              -> { gs with happiness = t   }
  113.    
  114.     let mentalHealth gs n =
  115.         let t = gs.mentalHealth + n
  116.         match t with
  117.         | t when t > 100 -> { gs with mentalHealth = 100 }
  118.         | t when t < 0   -> { gs with mentalHealth = 0   }
  119.         | _              -> { gs with mentalHealth = t   }
  120.    
  121.     let physicalHealth gs n =
  122.         let t = gs.physicalHealth + n
  123.         match t with
  124.         | t when t > 100 -> { gs with physicalHealth = 100 }
  125.         | t when t < 0   -> { gs with physicalHealth = 0   }
  126.         | _              -> { gs with physicalHealth = t   }
  127.    
  128.     let private statuses = [
  129.         "Hungry";
  130.         "Sick";
  131.         "Brain Damaged";
  132.         "Angry";
  133.     ]
  134.    
  135.     let randomStatus gs =
  136.         let randNum = new Random()
  137.         randNum.Next() |> ignore
  138.         let seed = 2000
  139.         let r = randNum.Next(seed)
  140.         if r > seed/3 then
  141.             let b = List.nth statuses (randNum.Next(List.length statuses))
  142.             let d = Logic.hasStat gs b
  143.             if d then gs else
  144.                 let t = Array.append gs.statusList [| b |]
  145.                 { gs with statusList = t }
  146.         else gs
  147.    
  148.     let private updateOneStat gs num =
  149.         if gs.statusList.Length = 0 then
  150.             gs
  151.         else
  152.             match gs.statusList.[num] with
  153.             | "Hungry" | "Sick" ->
  154.                 let gsb = physicalHealth gs -5
  155.                 if gsb.physicalHealth = 0 then
  156.                     printfn "%s is dead. You won! You are finally free." gsb.manbabyName
  157.                     { gsb with isDead = true }
  158.                 else
  159.                     printfn "%s isn't feeling well!" gsb.manbabyName
  160.                     gsb
  161.             | "Brain Damaged" ->
  162.                 let gsb = mentalHealth gs -5
  163.                 if gsb.mentalHealth = 0 then
  164.                     printfn "%s is braindead. You are now stuck with a vegitable." gsb.manbabyName
  165.                     { gsb with isDead = true }
  166.                 else
  167.                     printfn "%s's brain is manfunctioning!" gsb.manbabyName
  168.                     gsb
  169.             | "Angry" ->
  170.                 printfn "%s is angry. This doesn't really matter." gs.manbabyName
  171.                 gs
  172.             | _ -> gs
  173.    
  174.     let rec private updateStatsHelper gs num =
  175.         if num >= gs.statusList.Length then
  176.             gs
  177.         else
  178.             let ggs = updateOneStat gs num
  179.             updateStatsHelper ggs (num + 1)
  180.    
  181.     let updateStats gs =
  182.         let ggs = randomStatus gs
  183.         updateStatsHelper ggs 0
  184.  
  185. module Manbabies =
  186.    
  187.     let private quotes = [
  188.         "MUMMY I WANT BOOBIES";
  189.         "BABOOO";
  190.         "FLUTTERSHY IS BEST PONY";
  191.         "SO EPIC!!!! UPBOAT!!!";
  192.         "DON'T MAKE ME GET MY KATANA";
  193.         "* (screams incoherently)";
  194.         "I HAVE TO TELL PEOPLE ON THE INERNET THEY'RE WRONG";
  195.         "I'M GETTING TRIGGERED";
  196.         "I do not talk to any MEN other than my father and Santa.";
  197.         "CWC gives us REAL autistics like me a BAD NAME"; //10
  198.         "MOMMY VOTE FOR RON PAUL";
  199.         "* (drools and shits himself)";
  200.         "99999999- *INTERNAL ERROR; REBOOTING*";
  201.         "OMG TWAINS! MUMMY I WANT A CHOO-CHOO TWAIN";
  202.         "MUMMY IT'S ALMOST MY 30TH BIRTHDAY!";
  203.         "*sigh* so lonesome";
  204.         "All I want for Christmas is a pretty girlfriend.";
  205.         "MUMMY I NEED $100 TO JOIN THIS MINECRAFT SERVER";
  206.         "MOM I NEED CREDIT CARD NOOOOOW";
  207.         "TENDIES!?!?!?!?"; //20
  208.     ]
  209.    
  210.     let play gs =
  211.         if gs.happiness = 0 then
  212.             printfn "%s isn't happy enough to play!" gs.manbabyName
  213.             gs
  214.         else
  215.             let randNum = new Random()
  216.             randNum.Next() |> ignore
  217.             let r = randNum.Next(20)
  218.             printfn "You jangled some keys in front of %s" gs.manbabyName
  219.             printfn "He was amused by this! You got %i GBP!" r
  220.             { gs with GBP = gs.GBP + r }
  221.    
  222.     let printManbaby mb st =
  223.         if st = "" then
  224.             let randNum = new Random()
  225.             randNum.Next() |> ignore
  226.             printfn "\n   %s" (List.nth quotes (randNum.Next(List.length quotes)))
  227.         else printfn "\n   %s" st
  228.         for i in mb do
  229.             printfn "%s" i
  230.    
  231.     let okaySmallArt = [|
  232.         "                                     ";
  233.         "                                     ";
  234.         "                __^                  ";
  235.         "               /, ,\\;                ";
  236.         "              /   . \\                ";
  237.         "              \\_____/                ";
  238.         "                                     ";
  239.     |]
  240.    
  241.     let okaySmall st =
  242.         printManbaby okaySmallArt st
  243.    
  244.     let deadSmallArt = [|
  245.         "                                     ";
  246.         "              . *                    ";
  247.         "                __^   .              ";
  248.         "            .  /x x\\;                ";
  249.         "              /   _ \\ *              ";
  250.         "              \\_____/                ";
  251.         "                                     ";
  252.     |]
  253.    
  254.     let deadSmall st =
  255.         printManbaby deadSmallArt st
  256.  
  257. module Items =
  258.    
  259.     let tendies gs =
  260.         let name = "tendies"
  261.         if (Logic.chkItem gs name) then
  262.             printfn "%s enjoyed the %s" gs.manbabyName (Logic.uppercase name)
  263.             let result = Stats.happiness gs 20
  264.             let bgs = Logic.remItem result name
  265.             Logic.remStat bgs "Hungry"
  266.         else gs
  267.    
  268.     let fedora gs =
  269.         let name = "fedora"
  270.         if (Logic.chkItem gs name) then
  271.             printfn "%s loves his %s!" gs.manbabyName (Logic.uppercase name)
  272.             let ggs = Stats.happiness gs 5
  273.             Logic.remStat ggs "Angry"
  274.         else gs
  275.    
  276.     let girlfriend gs =
  277.         let name = "girlfriend"
  278.         if (Logic.chkItem gs name) then
  279.             printfn "Congratulations! %s finally has a %s" gs.manbabyName (Logic.uppercase name)
  280.             printfn "But she murdered him and took all his GBP."
  281.             { gs with isDead = true; GBP = 0; }
  282.         else gs
  283.    
  284.     let medicine gs =
  285.         let name = "medicine"
  286.         if (Logic.chkItem gs name) then
  287.             printfn "%s hates %s, but it's for the best." gs.manbabyName (Logic.uppercase name)
  288.             let bgs = Stats.physicalHealth gs 10
  289.             let ags = Logic.remStat bgs "Sick"
  290.             let ggs = Logic.remStat ags "Brain Damaged"
  291.             if Logic.hasStat ggs "Angry" then ggs else
  292.             { ggs with statusList = Array.append ggs.statusList [| "Angry" |] }
  293.         else gs
  294.  
  295. module Store =
  296.    
  297.     let prices = [
  298.         ("tendies"   , 5 );
  299.         ("medicine"  , 0 );
  300.         ("fedora"    , 20);
  301.         ("girlfriend", 999999999);
  302.     ]
  303.    
  304.     let private ifItemExists item =
  305.         let m x = if (fst x) = item then true else false
  306.         match List.tryFindIndex m prices with
  307.         | Some d -> (true , d)
  308.         | None   -> (false, 0)
  309.    
  310.     let giveItem gs item =
  311.         let t, i = ifItemExists item
  312.         if t then
  313.             let r = gs.GBP - (snd prices.[i])
  314.             if r < 0 then
  315.                 printfn "You don't have enough GBP for that."
  316.                 gs
  317.             else
  318.                 { gs with
  319.                     inventory = ( Array.append gs.inventory [| (fst prices.[i]) |] )
  320.                     GBP = r
  321.                 }
  322.         else
  323.             printfn "Item \"%s\" not found in Store." (fst prices.[i])
  324.             gs
  325.    
  326.     let private slogans = [
  327.         "The only store where the diapers come pre-defecated.";
  328.         "Buy two Officer Nasty dolls, get the third half-price!";
  329.         "You stick your dick in it, you buy it.";
  330.         "Please be quiet, autistic manchildren scare easily.";
  331.         "* The faint smell of fecal matter fills the air.";
  332.         "You see a couple, and can't tell which is the motherly\nold hag and which is the cross-dressing manchild.";
  333.         "Don't ask where the bathrooms are. You don't want to use them.";
  334.         "Just because we sell a brand you don't like doesn't mean\nwe're going to burn every item we have in stock.";
  335.         "Psst. Don't get them a real laptop, just get a Spiderman\nLearning Laptop and they'll never tell the difference.";
  336.         "Our security officers have to dress like clowns\nor the customers get triggered.";
  337.         "No, we don't sell Team Fortress 2 furry mods.";
  338.         ]
  339.    
  340.     let shop gs =
  341.         for i in prices do
  342.             if (fst i).Length > 7 then
  343.                 printfn "%s\t%i" (Logic.uppercase (fst i)) (snd i)
  344.             else
  345.                 printfn "%s\t\t%i" (Logic.uppercase (fst i)) (snd i)
  346.        
  347.         printf "\n>"
  348.         let input = Console.ReadLine().ToLower()
  349.         if input = "leave" || input = "l" then
  350.             gs
  351.         elif input = "inventory" || input = "i" then
  352.             Logic.getInv gs
  353.             gs
  354.         else
  355.             let result, _ = ifItemExists input
  356.             if result then
  357.                 giveItem gs input
  358.             else gs
  359.    
  360.     let rec keepShopping gs =
  361.         printfn "Continue shopping? (Y/N):"
  362.         printf  ">"
  363.         let input = Console.ReadLine().ToLower()
  364.         if input = "y" then
  365.             let ggs = shop gs
  366.             keepShopping ggs
  367.         elif input = "n" then
  368.             printfn "Have an ABSOLUTELY beautiful day.\n\n"
  369.             gs
  370.         else
  371.             printfn "I didn't quite get that."
  372.             keepShopping gs
  373.    
  374.     let storeInterface gs =
  375.         let randNum = new Random()
  376.         printfn "\nWelcome to We Luv Manchildren!"
  377.         printfn "%s\n" (List.nth slogans (randNum.Next(List.length slogans)))
  378.         printfn "What would you like to buy today?"
  379.         printfn "(Type '[L]eave' to exit the store.)"
  380.         printfn "(Or '[I]nventory' to see what you have.)\n"
  381.        
  382.         let ggs = shop gs
  383.         keepShopping ggs
  384.  
  385. module Input =
  386.    
  387.     let useItemPrompt gs =
  388.         printfn "\nUse what item?"
  389.         printf  ">"
  390.         let input = Console.ReadLine().ToLower()
  391.         if (Logic.chkItem gs input) || input = "rich" then
  392.             printfn "Used the %s!" (input |> Logic.uppercase)
  393.             match input with
  394.             | "tendies"    -> Items.tendies gs
  395.             | "fedora"     -> Items.fedora gs
  396.             | "medicine"   -> Items.medicine gs
  397.             | "girlfriend" -> Items.girlfriend gs
  398.             | "rich"       -> { gs with GBP = 999999999 } //cheat code
  399.             | _ -> printfn "I don't know that item."; gs
  400.         else
  401.             printfn "You don't have that!"
  402.             gs
  403.    
  404.     let rec mainInput gs =
  405.         printfn "\n[S]hop - [C]heck - [I]nventory - [U]se - [P]lay - [Q]uit:"
  406.         printf  ">"
  407.         let input = Console.ReadLine().ToLower()
  408.         match input with
  409.         | "shop"  | "s" ->
  410.             Store.storeInterface gs
  411.         | "quit"  | "q" ->
  412.             FileIO.write gs
  413.             printfn "\"%s\" was automatically saved." gs.manbabyName
  414.             printfn "Press any key to continue."
  415.             printfn "Goodbye!\n"
  416.             Console.ReadKey() |> ignore
  417.             exit 0; gs
  418.         | "check" | "c" ->
  419.             Manbabies.okaySmall ""
  420.             printfn "Name: %s" gs.manbabyName
  421.             printfn "Happiness: %i, Mental: %i, Physical: %i" gs.happiness gs.mentalHealth gs.physicalHealth
  422.             printf "Status: "
  423.             if gs.statusList.Length = 0 then
  424.                 printf "None"
  425.             else
  426.                 for i in 0 .. gs.statusList.Length - 1 do
  427.                     if i = gs.statusList.Length - 1 then
  428.                         printf "%s" gs.statusList.[i]
  429.                     else printf "%s, " gs.statusList.[i]
  430.             printf "\n"
  431.             gs
  432.         | "inventory" | "i" ->
  433.             Logic.getInv gs
  434.             printfn "\nGBP: %i" gs.GBP
  435.             gs
  436.         | "use" | "u" ->
  437.             useItemPrompt gs
  438.         | "play" | "p" ->
  439.             Manbabies.play gs
  440.         | "" | " " | "  " | "   " ->
  441.             gs
  442.         | _           ->
  443.             printfn "I didn't quite get that."
  444.             gs
  445.    
  446.     let rec update gs =
  447.         let ggs = Stats.updateStats gs
  448.         if ggs.isDead then
  449.             printfn " G A M E  O V E R"
  450.             FileIO.write ggs
  451.             Console.ReadKey() |> ignore
  452.             ggs
  453.         else
  454.             update (mainInput ggs)
  455.    
  456.     let rec private getName question =
  457.         printfn "What is %s?" question
  458.         printf  ">"
  459.         let name = Console.ReadLine().ToLower() |> Logic.uppercase
  460.         printfn "Is \"%s\" correct? (Y/N):" name
  461.         let ans = Console.ReadLine().ToLower()
  462.         match ans with
  463.         | "yes" | "y" -> name
  464.         | "no" | "n" | _ -> getName question
  465.        
  466.    
  467.     let beginFirstGame gs =
  468.         printfn "Thank you for adopting your first Manchild!"
  469.         let getplayerName = getName "YOUR NAME"
  470.         let getmanbabyName = getName "YOUR MANCHILD'S NAME"
  471.         printfn "Great! Lets get started...\n"
  472.         { gs with playerName = getplayerName; manbabyName = getmanbabyName }
  473.        
  474.  
  475. module Main =
  476.     [<EntryPoint>]
  477.     let main args =
  478.         let c = FileIO.chkfile ()
  479.         if c then
  480.             FileIO.write Stats.SeederState
  481.             let gs1 = Input.beginFirstGame Stats.SeederState
  482.             FileIO.write gs1
  483.             Manbabies.okaySmall ""
  484.             Input.update gs1 |> ignore
  485.         else
  486.             let gs1 = FileIO.read ()
  487.             if gs1.isDead then
  488.                 Manbabies.deadSmall "Mummy I only wanted to live."
  489.                 printfn "%s is dead. You murdered him, remember?" gs1.manbabyName
  490.                 printfn "Delete save.dm and try again, you heartless criminal.\n"
  491.                 printfn "Press any key to continue being a murderer..."
  492.                 Console.ReadKey() |> ignore
  493.                 printf  "\n"
  494.             else
  495.                 Manbabies.okaySmall ""
  496.                 printfn "Welcome back! %s missed you sortof." gs1.manbabyName
  497.                 Input.update gs1 |> ignore
  498.         0
  499.  
  500. //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement