nus-cs2030 / 2021-s1

28 stars 48 forks source link

PE2 LEVEL 6 #353

Open patriciafzy opened 3 years ago

patriciafzy commented 3 years ago

Hi, can i check for one of the testcases:

jshell> r3.tick(takeSword).back().tick(killTroll).tick(dropSword) --> You have taken sword. --> Troll is killed. --> You have dropped sword. $.. ==> @dining Sword is shimmering.

Why do we still have "Sword is shimmering." altho the sword is already dropped?

Screenshot 2020-11-14 at 5 49 40 PM
calvenjs commented 3 years ago

Because you dropped the sword at @dining. And you are @dining. For me i made no changes when i go back except if the sword is taken i will get it to previous room list of things... so it will show "Sword is shimmering".

patriciafzy commented 3 years ago

Ahh okay now I see it! I think my method and yours is largely similar where my back method is implemented like: i get the prev room to be the new room and tick(), and then if this current room i took the sword, i will add it to the prev room.

However, I still dont see the "Sword is shimmering" part..

enqiilim commented 3 years ago

when you drop the sword, you should only change the status of the sword to be not taken, but the sword is still in the current room, so for me I had my status of the sword in a list and when i drop the sword i edit the status of the sword only, it doesnt change the items inside the room

tien87chun commented 3 years ago

@patriciafzy did you add it to a temp list and return the temp list in the new Room? If you had added it into the prevRoom's list and you return a new room, it would not have showed up. If you had you may want to check on the immutability of your rooms. I guess it might have something to do with that since your logic seems to be fine

limyingying2000 commented 3 years ago

When we drop the Sword, the Sword is still in the room, hence "Sword is shimmering" is printed in the dining room, but we are no longer holding the sword, i.e "You have taken sword."

rickyaandrew commented 3 years ago

tbh for this problem just need to make sure that you remove the sword from the previous room at go() function if you are holding the sword. Then add the sword into the new room. If this is done properly i think it can resolve most problems