Commit f780dd8c authored by fpeterfalvi's avatar fpeterfalvi
Browse files

Better layouts in observer.

Bug in calculateGuessQuestionWinner method corrected.
parent f69c048e
......@@ -96,6 +96,7 @@ public class AnsweredQuestionFragment extends Fragment {
for (int i=0;i<playerAnswers.size();i++) {
if (i != own_index) {
final TextView playerAnswerTextView = new TextView(getActivity());
playerAnswerTextView.setPadding(20, 0, 20, 0);
PlayerAnswer answer = playerAnswers.get(i);
if (answer.getValue() >= 0) {
playerAnswerTextView.setText(answer.getPlayerName() + ": "
......
......@@ -123,11 +123,11 @@ public class GameActivity extends AppCompatActivity implements MultipleChoiceFra
Date questionAnsweredDate = new Date();
double answerTime = (double)(questionAnsweredDate.getTime() - questionReceivedDate.getTime()) / 1000;
Log.d("A válasz: ", Integer.toString(answer) + " (" + Double.toString(answerTime) + "s)");
if (answer != -2) {
/*if (answer != -2) {
displayTextView.setText(answer + " (" + Double.toString(answerTime) + "s)");
} else {
displayTextView.setText("nem válaszolt");
}
}*/
new SendMessageToServerTask().execute(Integer.toString(answer) + "##" + Double.toString(answerTime));
}
......
......@@ -39,8 +39,8 @@ public class GuessQuestionResultPanel extends JPanel implements FontResizable {
this.add(questionTextArea);
JLabel correctAnswerLabel = new JLabel();
correctAnswerLabel.setFont(bigFont);
correctAnswerLabel.setHorizontalAlignment(JLabel.CENTER);
correctAnswerLabel.setText(Integer.toString(correctAnswer));
correctAnswerLabel.setText("Correct answer: " + Integer.toString(correctAnswer));
correctAnswerLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
this.add(correctAnswerLabel);
Gson gson = new Gson();
......@@ -51,10 +51,6 @@ public class GuessQuestionResultPanel extends JPanel implements FontResizable {
for (int i=0;i<playerAnswers.size();i++) {
JLabel playerAnswerLabel = new JLabel();
playerAnswerLabel.setFont(bigFont);
playerAnswerLabel.setMinimumSize(new Dimension((int) (10 * Main.fontSize), (int) (1.1 * Main.fontSize)));
playerAnswerLabel.setPreferredSize(new Dimension((int) (10 * Main.fontSize), (int) (1.1 * Main.fontSize)));
playerAnswerLabel.setMaximumSize(new Dimension((int) (10 * Main.fontSize), (int) (1.1 * Main.fontSize)));
playerAnswerLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
PlayerAnswer answer = playerAnswers.get(i);
if (answer.getValue() >= 0) {
......@@ -69,6 +65,7 @@ public class GuessQuestionResultPanel extends JPanel implements FontResizable {
Font boldFont = bigFont.deriveFont(Font.BOLD);
playerAnswerLabel.setFont(boldFont);
}
playerAnswerLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
this.add(playerAnswerLabel);
}
......
......@@ -10,20 +10,18 @@ import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import javax.jmdns.JmDNS;
import javax.jmdns.ServiceEvent;
import javax.jmdns.ServiceInfo;
import javax.jmdns.ServiceListener;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import com.google.gson.Gson;
import model.PlayerAnswer;
import model.ServerModel;
import java.util.List;
public class Main {
private String TAG = "Client";
......@@ -52,7 +50,7 @@ public class Main {
private static JPanel serverListPanel;
private static FontResizable actualFontResizable = null;
public static float fontSize = 60.0f;
public static float fontSize = 30.0f;
private static class SampleListener implements ServiceListener {
@Override
......@@ -117,20 +115,24 @@ public class Main {
threads = new ArrayList<Thread>();
frame = new JFrame("KvizObserver");
mainPanel = new JPanel(new BorderLayout());
mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
JPanel observerNamePanel = new JPanel();
observerNamePanel.setBorder(new EmptyBorder(20, 20, 20, 20));
observerNamePanel.setLayout(new BoxLayout(observerNamePanel, BoxLayout.Y_AXIS));
mainPanel.add(Box.createRigidArea(new Dimension(0,15)));
JLabel observerNameLabel = new JLabel("Observer name:");
observerNamePanel.add(observerNameLabel);
observerNameLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
mainPanel.add(observerNameLabel);
mainPanel.add(Box.createRigidArea(new Dimension(0,10)));
JTextField observerNameTextField = new JTextField();
observerNameTextField.setAlignmentX(Component.CENTER_ALIGNMENT);
observerNameTextField.setMaximumSize(new Dimension(200, 100));
observerNamePanel.add(observerNameTextField);
mainPanel.add(observerNameTextField);
mainPanel.add(Box.createRigidArea(new Dimension(0,10)));
JButton startSearchingButton = new JButton("Start searching servers");
startSearchingButton.setAlignmentX(Component.CENTER_ALIGNMENT);
startSearchingButton.addActionListener(new StartSearchingButtonListener(observerNameTextField));
observerNamePanel.add(startSearchingButton);
mainPanel.add(observerNamePanel);
mainPanel.add(startSearchingButton);
mainPanel.add(Box.createRigidArea(new Dimension(0,10)));
serverListPanel = new JPanel();
serverListPanel.setLayout(new BoxLayout(serverListPanel, BoxLayout.Y_AXIS));
......@@ -152,7 +154,7 @@ public class Main {
//teszteléshez
// MultipleChoiceQuestionPanel teszteléshez
/*
PlayerAnswer pla = new PlayerAnswer("játékos");
pla.setValue(2);
......@@ -176,6 +178,31 @@ public class Main {
mainPanel.revalidate();
mainPanel.repaint();
*/
// GuessQuestionResultPanel teszteléshez
/*
PlayerAnswer pla = new PlayerAnswer("játékos");
pla.setValue(4);
pla.setTime(2.3);
PlayerAnswer pla2 = new PlayerAnswer("játékos2");
pla2.setValue(2);
pla2.setTime(3.3);
PlayerAnswer pla3 = new PlayerAnswer("játékos3");
pla3.setValue(6);
pla3.setTime(3.7);
List<PlayerAnswer> plalist = new ArrayList<>();
plalist.add(pla);
plalist.add(pla2);
plalist.add(pla3);
Gson gson = new Gson();
GuessQuestionResultPanel gqrp = new GuessQuestionResultPanel("Hány szóból áll ez a kérdés?",
6, gson.toJson(plalist));
actualFontResizable = gqrp;
mainPanel.removeAll();
mainPanel.add(gqrp);
mainPanel.revalidate();
mainPanel.repaint();
*/
}
final static class StartSearchingButtonListener implements ActionListener {
......@@ -345,14 +372,16 @@ public class Main {
break;
case "GameStarted":
exit = false;
GuessQuestionPanel message = new GuessQuestionPanel("Game started", -1);
actualFontResizable = message;
mainPanel.removeAll();
mainPanel.add(message);
mainPanel.revalidate();
mainPanel.repaint();
//majd
break;
case "questionMC":
case "answerMC":
System.out.println("question vagy answer érkezett");
MultipleChoiceQuestionPanel mcqp = new MultipleChoiceQuestionPanel(params[1], params[2],
params[3], params[4], params[5], params[6], Integer.parseInt(params[7]),
Integer.parseInt(params[8]));
......
......@@ -100,11 +100,11 @@ public class GameActivity extends AppCompatActivity implements GameControlFragme
Thread newthread = new Thread(commThread);
newthread.start();
}
/*
for (int i=numberOfPlayers;i<outputs.size();i++) {
new SendMessageToClientTask().execute(Integer.toString(i), "GameStarted##normal");
}
*/
}
class CommunicationThread implements Runnable {
......@@ -171,8 +171,10 @@ public class GameActivity extends AppCompatActivity implements GameControlFragme
int indexOfBestAnswer = 0;
for (int i=1;i<playerAnswers.length;i++) {
PlayerAnswer ans = playerAnswers[i];
if (ans.getValue() >= 0 && ((bestAnswer.getValue() < 0) || (Math.abs(ans.getValue() - correctAnswer) <= Math.abs(bestAnswer.getValue() - correctAnswer)
&& ans.getTime() < bestAnswer.getTime()))) {
if (ans.getValue() >= 0 && ((bestAnswer.getValue() < 0) ||
(Math.abs(ans.getValue() - correctAnswer) < Math.abs(bestAnswer.getValue() - correctAnswer)) ||
((Math.abs(ans.getValue() - correctAnswer) == Math.abs(bestAnswer.getValue() - correctAnswer))
&& ans.getTime() < bestAnswer.getTime()))) {
bestAnswer = ans;
indexOfBestAnswer = i;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment