1
\$\begingroup\$

I have put my whole code so far below, but what I am most interested in is how best to implement the map and utilise it. Any tips on organising my code and keeping it clean would also be greatly appreciated. Roomint is the function I am mostly worried about/ the room object.

type DamType=
    |Fire 
    |Ice 
    |Light 
    |Dark
    |General



type Monster={
    name:string;
    dVal:float;
    dType:DamType;
    hVal:float;
    info:string;
    dInfo:string;
    dCry:string;
    Special:bool;
    sItem:int;
 }        


type Armour={
    name:string;
    aVal:float;
    dType:DamType;
    info:string;
    iSpace:int;
}
type Weapon={
    name:string;
    dVal:float;
    dType:DamType;
    info:string;
    iSpace:int;
}

type Potion={
    name:string;
    pVal:float;
    info:string;
    iSpace:int;
}

type Bomb={
    name:string;
    bVal:float;
    dType: DamType;
    info:string;
    iSpace:int;
}

type User={
    name:string;
    Arm:Armour;
    Weap:Weapon;
    hVal:float;

}

An example of how weapon, armour, potion and bombs are formed and stored:

 let weap10 = {name="Legendary black blade";dVal=65.0;dType=General; 
 info="The blade that was thought to be
 lost in time, was here all along, with this, you may aswell be 
 unstoppable";iSpace=7 }

 let weapint =
     let weaplist =[weap1;weap2;weap3;weap4;weap5;weap6;weap7;weap8;weap9;weap10]
      weaplist

 let displayW (a:Weapon) =   
    a.name

And lastly, how my rooms are stored, its a bit odd, and I hope there is a better way to form the rooms:

let r60 = {id=60;item=m8;n=61;e=0;s=59;w=0;complete=false}
let r61 = {id=61;item=m9;n=0;e=0;s=60;w=0;complete=false}
let row12 = [r60;r61]

let roomlist = List.concat[row1;row2;row3;row4;row5;row6;row7;row8;row9;row10;row11;row12]


roomlist

When a user enters a new room, if the object in the room (r1, r2, etc) is a monster, they battle the monster, if any other object, they have the option to put it into their inventory or move on. They can then move NESW depending on the room, the next room is loaded using the int value of their selected direction and loading the room with that ID, however I don't know how to go about this! I am in my second year of university and am not so accustomed to F#.

\$\endgroup\$
  • 2
    \$\begingroup\$ Use arrays or lists instead of number-named variables. \$\endgroup\$ – Fyodor Soikin Dec 2 '17 at 16:04
  • \$\begingroup\$ how so?Isn't that what I'm doing already? \$\endgroup\$ – Daniel Peedah Dec 2 '17 at 16:07
  • \$\begingroup\$ When you copied and pasted your code it didn't work quite right. If you have tabs in your code they won't display correctly. The closing brace on each of your types is not in the code. Is there any way you can edit that and correct it? \$\endgroup\$ – pacmaninbw Dec 2 '17 at 16:11
  • 1
    \$\begingroup\$ No, it's not what you're doing already. You have a bunch of variables named row1, row2, row3, etc. These should be elements of an array. \$\endgroup\$ – Fyodor Soikin Dec 2 '17 at 16:26
  • \$\begingroup\$ The rows are lists of rooms themselves that are con-canted together to form a large list, i shall try to fix the code \$\endgroup\$ – Daniel Peedah Dec 2 '17 at 16:38

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.