Results 1 to 1 of 1
- 07-07-2009, 06:22 AM #1
Member
- Join Date
- Jul 2009
- Posts
- 2
- Rep Power
- 0
Text Adventure Command Parser Exercise - Trying to do it the OOP way.
My code is below. It works, but I don't like it. What is the "best" way to create a text command parser for a text adventure game, from an object-oriented standpoint? Obviously opinions will differ, but opinions are what I'm looking for. I have had no classes or formal training and I don't want to develop bad habits. Also, note, none of these classes are finished, of course. Thanks in advance. If anyone needs to see the rest of the code, it is located here:
NOTE: I understand links are illegal for those with under 20 posts. I assume this is due to spamming concerns? I wasn't sure if this rule applied to text urls, so I removed the protocol and www parts to stop vB from automatically making them links. If this is against the rule I will correct my mistake immediately.
derrikc.com/java/SimpleGame/GameServer.java <-- this is the file the code below is from, but it won't compile without CharacterManager
and Character, and it's not really worth running without also using the client.
derrikc.com/java/SimpleGame/CharacterManager.java
derrikc.com/java/SimpleGame/Character.java
derrikc.com/java/SimpleGame/GameClient.java
Java Code:public void recieveCommands() { while(clientChar.getLoggedIn() == true) { // continue as long as the character is logged in String[] clientInput = null; clientInput = clientInput(); if (clientChar.getLoggedIn() == true) { // an extra check in case the character is logged out due to a recieved command if (clientInput[0].equals("hello")) { // handler for a "hello" message from the client clientOS.println(systemMessage("Hello, " + clientChar.getUsername() + ".")); } if (clientInput[0].equals("say")) { // handler for a "say" message from the client String chatMsg = ""; // rebuild a whole String out of the split up string including all text but the "say" command for (int i = 1; i < clientInput.length; i++) { chatMsg = chatMsg + clientInput[i] + " "; } // send the print command followed by the chat message to every authenticated client for (ClientServiceThread client : connectedList) { client.chatMessage(clientChar.getUsername(), chatMsg); } // end for } // end if } // end if } // end while } // end recieveCommands()
Similar Threads
-
String Exercise
By carlodelmundo in forum New To JavaReplies: 5Last Post: 03-06-2009, 12:59 PM -
[SOLVED] Text Parser
By karthik7974 in forum New To JavaReplies: 20Last Post: 04-22-2008, 10:18 AM -
I/O exercise
By Feldom in forum New To JavaReplies: 1Last Post: 10-28-2007, 04:48 PM -
help with exercise
By e_as're in forum New To JavaReplies: 3Last Post: 09-25-2007, 10:14 AM -
Unable to execute command line command in java
By LordSM in forum New To JavaReplies: 1Last Post: 08-08-2007, 12:23 AM
Bookmarks