Hi everyone. I'm back😆.
For today lab session, we need to do our own text adventure game and I cannot wait to do it! We need to write a program to get the user instructions so that the player can move from one room to another by typing in commands of direction. The adventure game should has at least ten rooms to explore and two ways for the game to end. The objective is that we can practice how to use multi-way and nested selection statement to specify alternative paths of a program's execution.
I plan to do a game where a player needs to find a mystic flower by choosing correct paths. It is quite easy to do the program at first but I cannot run it when it comes to Room 1. I mean I still can run it but after I put a direction, there is no instruction come out after that. Then I use "direction.equals (west)" instead of "directions = west" and change "String direction1 =input1.next();" to "String direction1 = input.nextLine();".
The next() method can read the input only till space or in other words, it cannot read two words separated by a space. It also places the cursor in the same line after reading the input. While the nextLine() method reads everything including space between the words until the end of the line. Once the input is read it places the cursor in the next line.
After that, I try to run it again and success except for the last part where it non-stop shows "Argon:Congratulations! You have found the flower." repeatedly till my laptop hang for awhile. Therefore, I put a "break" to solve the problem.
So yeah, I have finished my own adventure game with a lot of hassle😠but at least I am satisfied with my work. See you guys again in my next lab session. Bye~~
Henny Abigailwillyen Sinjus
183640
SSK3100 (Group 15)Next blog: nurnadhirahzulkepli.blogspot.com
No comments:
Post a Comment