Skip to content

Assignment #2

Magnus Gudmundsson edited this page Apr 1, 2016 · 18 revisions

Yowsa.

Thanks for the HangMan hack. I talked to my Son about it over lunch, and he wasn't that impressed... So I asked him for advice, and he started mumbling on about adventures and ecafés and dungeons and fantasy books yada yada yada.
Anyways, I did some digging of my own, and found a webpage all about something they call adventure games. I think that is the direction we should be heading towards. I'm thinking like MineCraft, but more basic! A text adventure where everyone can create their own rooms, how cool is that?
I talked to a friend of Jamie Duct Tape, goes by the name of Matt from Earth. He says he's going to give you an IPA later today, but that you were to build a new component, a form for the Adventure game. He sent me some specs.

Hi, 
this the JSON for a room. Tell him to begin with a form that posts that JSON.
I haven't done any validation on the server yet, (it's on my list, 
I will probably get to it next week.) 
So I need him to do all validation on the client side. 
for now, hard code dungeonId to 56ec088f68057ee424aed1db
name and description are required,
the image url is not required, but it should be valid http, 
bonus if he can check that the suffix is correct
 (jpeg, gif or png I guess.)  
Of course Exits should only lead to existing rooms, 
but he needs to mockup a list of like 4-8 rooms to choose from. 
An async validation of the uniqueness of the name would be nice,
can he fake that with a service call that saves to local storage? 
All rooms should have at least one exit.  
Type should be one of indoors/outdoors/under water/in space / other
the code does not have to bother with the actions for now. 


Ciao , 
Matt from Earth
{ 
   "name": "string",
   "dungeonId": "string",
   "picture": "string",    ///path to url image
   "description": "string",
   "exits":  [{
      "name":"string", 
       "leadsToRoomId": "string"} ], // bson objectId
   "type":"string"; 
  "actions": [ {
        "verb" : "string", 
        "conditionResults": [
           "conditions": [
           {
               "artifactId": "string", //Bson objectID
               "flag": "string", 
               "operator": "string"
           }], 
        "results": [{
           "command": "string", 
           "artifactId": "string", 
           "flag": "string", 
           "value": "mixed" 
      }]] 
      }], 
  "flags": [
     { 
        "name": "string", 
        "type": "string", 
        "value": "mixed"
     }
     ];

JSON FKTW Tell him you only do MEDEA! 🎱


Forms forms forms.

Some tips from the coach : Earlier on in the project the templates where inlined in the component. This time I think we should keep it in a separate file. The html could get pretty hairy.
Speaking of pretty, focus on getting it working first, make it pretty later.

Create a html file called room.component.html and reference it in the component like this: templateUrl:'room.component.html'

Have you heard about the Elvis operator? Unlike Angular when showing values, Angular 2 gets upset if the value is null or undefined,
and it will throw an error right into your console.
so they came up with the Elvis operator, it looks like this ?.

{{room?.name}} 

means if there is a room, it will display the name, otherwise nothing will be displayed.

Here are some good resources on forms:

https://angular.io/docs/ts/latest/guide/forms.html

A plunker demonstrating usage of formbuilder
http://plnkr.co/edit/6RkM0eRftf3KQpoDCktz?p=preview

As you are going to mock the fetching of other rooms, I think that warrants a service, call it room.service.ts
😆

Bonus Round -

  • In the form, always present North, South, East and West as viable exists, but make it possible for user to create another exit that is more freeform.

Home

[Setup, Startup](Setup, Startup)

Typescript

[Assignment #1] (Assignment-%231)

[Assignment #2] (Assignment-%232)

[Assignment #3] (Assignment-%233)

[Links] (Links)

[Slide Shows] (Slide Shows)

Clone this wiki locally