BCS1110 1.0-RELEASE (GENERIC) bcs1110.ashish.nl/labs/lab-04/ [ Light ]
guest@bcs1110:~$ cat lab-04.md
# Lab 04 — Hello Chat

Objective

Enable, fix, and validate the player chat feature in JavaCraft.

Introduction

In this lab, you will work with the JavaCraft chat system. The chat functionality is included in the codebase (see the chat.java file on Canvas), but it is not working correctly by default. Your task is to:

  • Locate and review the chat code
  • Edit the code so it compiles and runs correctly
  • Integrate the chat code with your JavaCraft.java file
  • Communicate with your teammates through the chat

By the end of this lab, you will have a functioning chat system integrated into JavaCraft.

Instructions

1. Log into the Raspberry Pi

  1. Make sure your computer is connected to the same Wi-Fi network as the Raspberry Pi.
  2. Open a terminal and connect using SSH:
   ssh piNNNN@piNNNN

Replace NNNN with your group’s assigned number.

  1. Enter the password you created in the first lab.

2. Locate and Integrate the Chat Code

  1. Open the chat file and examine the existing logic. You should notice that the chat is not integrated with JavaCraft game.
  2. Integrate the chat logic with JavaCraft game.

3. Fix and Compile the Chat Code

  1. Edit the chat code so that it compiles without errors.

  2. Run JavaCraft to test whether the chat feature is now accessible.

4. Validate Messages with Your DFA/NFA

All chat messages must follow the pattern:

@[name]: [text]
  1. Design a DFA or NFA for this pattern and integrate it with your chat code.
    • Outgoing messages should only be sent if they match the pattern.
    • Incoming messages should be checked against the pattern before being displayed.
  2. If a message does not match the pattern, display an error or reject it.

5. Test Communication

  1. Connect at least two players to JavaCraft on the same network.

  2. Exchange at least ten messages in the correct format.

    • Examples:

      @Alice: Hello!
      @Bob: Hi Alice, how are you?
      
  3. Test at least two invalid messages (e.g., missing @ or :) and confirm that they are correctly rejected.

  4. Keep a log of your chat session for submission.

6. Shut Down the Raspberry Pi

When you are done, shut down the Raspberry Pi safely:

sudo shutdown -h now

Wait until the lights indicate the device has powered down, then unplug it.

Troubleshooting

  • If your code does not compile, double-check for:
    • Missing semicolons or braces
    • Incorrect class names or package declarations
  • If messages are not being validated correctly, print debug statements to confirm what your DFA/NFA is receiving.
  • If networking fails, confirm that all devices are on the same Wi-Fi and use the correct IP/hostname.

Example Chat Interaction

@Alice: Hello team!
@Bob: Hi Alice, good to see you.
@Charlie: Ready to test the game?

❌ Invalid messages should be rejected, e.g.:

Alice- Hello
This is broken

Lab Submission

  1. Demonstrate your working chat to the TA.
  2. Submit (with your final submission):
    • A log of at least ten valid messages and two invalid messages
    • Your modified chat code integrated into JavaCraft
    • Confirmation that your DFA/NFA (including the DFA/NFA itself) is being used to validate messages

Summary

By completing this lab, you have:

  • Fixed and enabled the chat logic in JavaCraft
  • Integrated your DFA/NFA for message validation
  • Successfully communicated between multiple players
  • Ensured that only correctly formatted messages are accepted