Skip to content

Commit

Permalink
Conflit Res
Browse files Browse the repository at this point in the history
  • Loading branch information
jaypub2002 committed Apr 16, 2024
2 parents e2f0820 + b3f3cac commit 4ca7040
Show file tree
Hide file tree
Showing 10 changed files with 20,639 additions and 51 deletions.
35 changes: 16 additions & 19 deletions html/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,29 +213,27 @@ connection.onmessage = function(evt){

chatSocket.addEventListener('message', (event) => {
const message = JSON.parse(event.data);
displayMessage(this.name, this.message);
displayMessage(message.sender, message.content);
});

function sendMessage() {
const messageInput = document.getElementById('chatInput');
const mm = messageInput.value.trim();
message = mm;

if (message !== '') {
var chatMessage = {
code: 600, // Message code for chat messages
msg: message
};

chatSocket.send(JSON.stringify(chatMessage));
messageInput.value = ''; // Clear the input box after sending
function sendMessage() {
// Retrieve message content from the input field
const messageInput = document.getElementById('chatInput').value.trim();
if (messageInput !== '') {
const chatMessage = {
code: 600,
name: this.name,
message: messageInput
};
chatSocket.send(JSON.stringify(chatMessage));
document.getElementById('chatInput').value = '';
}
}
}

function displayMessage(sender, content) {
/// Display the received message
if (sender !== undefined && content !== undefined) {

function displayMessage(sender, content) {
// Check if both sender and content are defined
if (sender !== undefined && content !== undefined) {
const chatMessagesDiv = document.getElementById('chatMessages');
const messageDiv = document.createElement('div');
messageDiv.textContent = `${sender}: ${content}`;
Expand All @@ -244,7 +242,6 @@ function displayMessage(sender, content) {
}



//TO DO: set up functionality for validating the coords -> check slopes and stuff
// then send it to server for processing.
function scream(i,j){
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/uta/cse3310/Chat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package uta.cse3310;

import java.util.ArrayList;
import java.util.List;

public class Chat {
private String name;
private String message;

private List<Message> chatMessages;

public Chat() {
this.chatMessages = new ArrayList<>();
}

public void addMessage(String name, String message) {
Message newMessage = new Message(name, message);
chatMessages.add(newMessage);
}

public void displayMessages() {
for (Message msg : chatMessages) {
System.out.println(msg.getName() + ": " + msg.getMessage());
}
}

private class Message {
private String name;
private String message;

public Message(String name, String message) {
this.name = name;
this.message = message;
}

public String getName() {
return name;
}

public String getMessage() {
return message;
}
}
}
Loading

0 comments on commit 4ca7040

Please sign in to comment.