1- import React from 'react'
21import axios from 'axios'
32
4- const registerUrl = 'localhost:8000/api/registration/'
53const registeredUser = `{"username":"CapKirk", "password1":"asswerd1", "password2":"asswerd1"}`
64const loginUser = `{"username":"CapKirk", "password":"asswerd1"}`
7- const loginUrl = 'localhost:8000/api/login/'
8- const url = `https://lambda-mud-test.herokuapp.com`
9- const direction = 'e'
10- const Token = ''
5+ const url = `https://lambda-beastmode.herokuapp.com`
116// const token = '284c818834f7c8c56561c73f840fc234a14e819b'
127
13-
148export const commands = {
159 register : ( ) => {
1610 try {
@@ -35,33 +29,56 @@ export const commands = {
3529 }
3630 } ,
3731 initialize : ( ) => {
38-
3932 try {
40- const token = `7619ce496e8495cb00909ac9c16612a3fdb70f5c` //localStorage.getItem("token")
41- console . log ( token )
42- const init = axios . get (
43- `https://lambda-beastmode.herokuapp.com/api/adv/init/` ,
44- { headers : { Authorization : `Token ${ token } ` } }
45- )
46- console . log ( init )
33+ const token = localStorage . getItem ( "token" )
34+ axios . get (
35+ `${ url } /api/adv/init/` ,
36+ { headers : { Authorization : `Token ${ token } ` } }
37+ ) . then ( ( res ) => {
38+ const room = res . data ;
39+ console . log ( `WELCOME TO SPACE ${ room . name } ` )
40+ console . log ( `You are currently located at: ${ room . x_coord } , ${ room . y_coord } - ${ room . title } ` )
41+ console . log ( `You see: ${ room . description } ` )
42+ const numPlayers = room . players . length
43+ if ( numPlayers > 0 ) {
44+ if ( numPlayers === 1 ) {
45+ console . log ( `You see a person: ${ room . players [ 0 ] } ` )
46+ } else {
47+ console . log ( `You see ${ numPlayers } : ${ room . players . reduce ( ( player , players ) => `${ player } , ${ players } ` ) } ` )
48+ }
49+ } else {
50+ console . log ( "You see no one" )
51+ }
52+ localStorage . setItem ( "room" , room ) ;
53+ } )
4754 } catch ( err ) {
4855 console . log ( err . stack )
4956 }
5057 } ,
51- move : ( ) => {
58+ move : ( args ) => {
59+ const direction = args [ 1 ]
60+ if ( ! [ "n" , "e" , "s" , "w" ] . includes ( direction ) ) {
61+ console . log ( "You must choose one of 4 directions: n s e w" )
62+ return
63+ }
5264 try {
5365 const token = localStorage . getItem ( "token" )
54- console . log ( token )
55- const mv2rm = axios . post (
56- `${ url } /` ,
57- { "direction" : `${ direction } ` } ,
58- { Authorization : `Token ${ token } ` }
59- )
60- console . log ( mv2rm )
61- } catch ( error ) {
62- console . log ( error . stack )
66+ axios . post (
67+ `${ url } /api/adv/move/` ,
68+ { "direction" : `${ direction } ` } ,
69+ { headers : {
70+ Authorization : `Token ${ token } ` ,
71+ "Content-Type" : "application/json"
72+ } }
73+ ) . then ( ( res ) => {
74+ const room = res . data
75+ console . log ( room )
76+ localStorage . setItem ( "room" , room ) ;
77+ } )
78+ } catch ( err ) {
79+ console . log ( err . stack )
6380 }
64- }
81+ } ,
6582 // say,
6683}
6784
0 commit comments