I am looking forward for designing a real time multiplayer game like QuizUp in android. I understand the UI and the database part of it , but I am not able to gauge the complexity involved to write the server logic.
So some features that I am looking for are as follows :
Can some one please highlight the building blocks on the Server that will be required to achieve the above use cases?
Probable building blocks/ modules that i can think of are :
please point out any missing block on the Server not Database and UI from your experience Thanks
I think what you need in server is a real-time web application framework though I've never played QuizUp. With such stuff, you can easily deal with your business logic.
The following pseudo code is written in Cettia. It's a real-time web application framework I authored but since only Java server and JavaScript client are provided, you can't use it for Android for now. Neverthelss, I think it would help you when writing your business logic roughly and finding such framework in terms of evaluating features you need.
Server server = new DefaultServer();
Queue<ServerSocket> waitings = new ConcurrentLinkedQueue<>();
server.onsocket(socket -> {
// Find the counterpart from the waiting queue
// This is #1
ServerSocket counterpart = waitings.poll();
// If no one waits, adds the socket to the queue
// Remaining logic will be executed when other socket, the socket's counterpart, is connected
if (counterpart == null) {
waitings.offer(socket);
// Make sure evicts the socket when it's closed
socket.onclose(() -> waitings.remove(socket));
return;
}
// Now we have two registered users - socket and counterpart
// Find a quiz which is a set of 5 questions from database or somewhere
// Assumes quiz has a randomly generated id property
Quiz quiz = Quiz.random();
// Create a report to evaluate socket and counterpart's answer
Report report = new Report();
// Make a group for socket and counterpart for convenience
socket.tag(quiz.id());
counterpart.tag(quiz.id());
// Find a group whose name is quiz.id(), one we've just created
server.byTag(quiz.id())
// and send the quiz to sockets in the group
.send("quiz", quiz)
// and add an event listener which will be called by each client
// This is #2
.on("quiz", qa -> {
// Every time (total 5 times) client answers to each question,
// this listener will be executed and 'qa' contains information about question and answer
// Evaluates if answer is right
boolean right = Quiz.evaluate(qa.question(), qa.answer());
// Adds a final information to the report
report.add(qa.user(), qa.question(), qa.answer(), right);
});
// Initiate timeout timer
new Timer().schedule(() -> {
// Notifies socket and counterpart of timeout
server.byTag(quiz.id()).send("timeout");
// It's time to evalute the report which contains a result of this game
// Analyze who answers more accurately in less time and give him/her some points
// This is #3
report...
}, 60 * 1000).run();
});