Difference between revisions of "DT 8025 2016 Practical 3"

From CERES
Jump to: navigation, search
 
(20 intermediate revisions by one user not shown)
Line 11: Line 11:
  
 
== Instructions ==
 
== Instructions ==
 
  
 
Start with a list of scenarios (use-cases) that the following application should be able to deal with:  
 
Start with a list of scenarios (use-cases) that the following application should be able to deal with:  
Line 26: Line 25:
  
  
== ESPoodle for Android! ==
+
== Rock Paper Scissors Online Game for Android! ==
  
 
=== Overview ===
 
=== Overview ===
  
The goal of this project is to implement a simplified version of [http://doodle.com/ Doodle] app for Android.
+
The goal of this project is to implement a simple Android app for a Rock Paper Scissors online game.
The only part of functionality that we adopt in our practical is to:
+
The functionalities that we adopt in our practical is to:
  
* Connect to an [[media:doodleServer.zip|ESPoodle server]],
+
* Connect to an [[media:DT8025_RPSServer.zip | RPS server]],
  
* Specify a new meeting request, its participants and 3 options for its time-slot
+
* Register on the server: ready to play (available),
  
* Fetch one of the meeting requests for the participant and choose a preferred time-slot,
+
* Read the list of available players,
  
* Close a meeting request by selecting one of the time slots if all participants have made their choices, and
+
* Send/Discard a play request with another player,
  
* Viewing the closed meetings in which a participant is involved.
+
* Accept/reject a play request from another player,
 +
 
 +
* Fetch the list of play requests either from or to the current player,
 +
 
 +
* Make a choice (Rock/Paper/Scissors) and fetch the choice of the other player
 +
 
 +
* Leave a game session, and
 +
 
 +
* Exit.
  
 
=== Starting up ===
 
=== Starting up ===
  
To achieve this, you will be given an IP address of an [[media:doodleServer.zip|ESPoodle server]] implemented and installed on a computer.  
+
During the development, you run the server on your own computer and use it as the RPS Server. In any case, your app should get the IP from the user and the IP should not be hard coded.
 +
 
 +
To compile the java code for the server, go to the folder containing the source and execute (assuming JDK has already been installed and configured)
 +
 
 +
javac RPSServer.java
 +
 
 +
and, then run the server by executing the following command (you may not need to use '-cp .').
 +
 
 +
java -cp . RPSServer
 +
 
 +
The server will now be started and listen on port 4444. You will see 'Started server on port 4444' message on the terminal.
 +
 
 +
=== The Application  ===
 +
 
 +
To achieve this, you will be given an IP address of an [[media:DT8025_RPSServer.zip|RPS server]] implemented and installed on a computer.  
 
The server listens on port 4444.  
 
The server listens on port 4444.  
Your app should first allow the user to enter this IP address and a unique ID which is to be used in meeting requests;
+
 
 +
Your app should first allow the user to enter this IP address and a unique ID which is to be used in requests;
 
use your HH account login name as the unique ID throughout this practical.  
 
use your HH account login name as the unique ID throughout this practical.  
  
Line 53: Line 75:
 
(while providing sufficient information as toast messages).  
 
(while providing sufficient information as toast messages).  
 
If successful, the client will receive the following tag from the server  
 
If successful, the client will receive the following tag from the server  
 
  
 
  <Accepted connection from  id +/>
 
  <Accepted connection from  id +/>
 
  
 
where id is the unique identifier (account name) provided by the client.  
 
where id is the unique identifier (account name) provided by the client.  
 +
Then, the client needs to send the ready to play command to the server to be visible by others
 +
 +
<ReadyToPlay/>
 +
 +
It will then receive the following tag from the server (in case of no error)
 +
 +
<Welcome to Rock Paper Scissors Online Game!/>
 +
 +
 
Then, the app will provide three possible options:
 
Then, the app will provide three possible options:
  
* to create a new meeting request,   
+
* view online players (to send play request to),   
  
* to check for open meeting requests, and  
+
* view pending play requests to be answered, and
  
* to  check for closed meeting requests.
+
* view sent play requests (waiting/accepted/rejected).
  
=== Creating a new request ===
 
  
The app shows a layout in which the user can enter a unique meeting Id, a number of time-slots (for simplicity we assume that all meetings take one hour and hence, it suffices to mention the starting time), and identifiers of three participants.
+
=== View Online Players  ===
When the user presses the submit button,
+
the client sends the following structure to the server
+
  
<OpenMeeting>
+
The app shows a layout in which the list of online players and their status (idle/busy/waiting) is shown. To fetch the list of online players the client sends the following request
    <MeetingId "5"/>
+
    <Message text = "Please select a time for the coming meeting."/>
+
        <time = "8:00"/>
+
        <time = "10:00"/>
+
        <time = "9:00"/>
+
    <Participant numberOfParticipant ="3">
+
        <name = "clientParticipantA"/>
+
        <name = "clientParticipantB"/>
+
        <name = "clientParticipantC"/>
+
      </Participant>
+
<OpenMeeting/>
+
  
The serve will reply to the meeting scheduler
+
<OnlinePlayers/>
  
  <Request to start meeting is accepted/>
+
The server sends the list of online players one by one like
 +
 
 +
  <OnlinePlayer name="Masoumeh" status="waiting"/>
 +
<OnlinePlayer name="Mahsa" status="idle"/>
 +
<OnlinePlayer name="Sebastian" status="busy"/>
 +
 
 +
=== Send Play Request ===
 +
The user can select one of the idle players to send a play request to. When the user selects the player (e.g., Mahsa) the client sends the following structure to the server
 +
 
 +
<PlayRequest Mahsa/>
 +
 
 +
The serve will reply to the request
 +
 
 +
<Play request was sent to Mahsa!/>
  
 
This is shown by a toast message and the app will return to the main menu.
 
This is shown by a toast message and the app will return to the main menu.
  
=== Checking for open requests ===
+
=== View Play Request For X  ===
  
The user may ask whether there has been any meeting request in which the current user is mentioned as a participant.  
+
The user may ask whether there has been any play request to be .  
 
In this case, after this option is selected from the main menu, the client  
 
In this case, after this option is selected from the main menu, the client  
end open meeting request like
+
send the following command
  
   <CheckOpenMeeting/>
+
   <PlayRequestsForMe/>
  
The server send all open meetings for the participant one by one like  
+
The server sends all pending requests for the participant one by one like  
  
  <OpenMeeting>
+
  <PlayRequest From="Masoumeh" With="Mahsa" status="pending"/>
      <For "+clientParticipant+"/>
+
      <MeetingId "5"/>
+
      <Message text = "Please select a time for the coming meeting."/>
+
      <time = "8:00"/>
+
      <time = "10:00"/>
+
      <time = "13:00"/>
+
<OpenMeeting/>
+
  
 +
=== Accept/Reject Play Request ===
 +
The user may select one of the requests for him/her and accept/reject the request.
 +
 +
  <AcceptPlayRequest Masoumeh/>
  
 +
or
  
The participant fetches one of the meeting requests for the participant and chooses a preferred time-slot and send
+
   <RejectPlayRequest Masoumeh/>  
+
   <SelectedTime>
+
      <MeetingId "5"/>
+
      <time = "10:00"/>
+
  <SelectedTime/>  
+
  
The server will store the selected time immediately and send
+
The server will then update the status of the request to 'accepted' and 'rejected' respectively, and send back
  
    <reply>
+
<PlayRequest From="Masoumeh" With="Mahsa" status="accepted/rejected"/>
        <SelectedTime>
+
            <MeetingId "5"/>
+
            <time = "10:00"/>
+
        <SelectedTime/>
+
    </reply>
+
  
=== Closing meeting requests ===
+
If the user accepts a request the app automatically moves to the play game view in which the user starts to play.
  
 +
=== View Sent Play Request  ===
 +
The user may ask for the play requests sent by him/her.
 +
In this case, after this option is selected from the main menu, the client
 +
send the following command
 +
 +
  <MyPlayRequests/>
 +
 +
The server sends all requests from him/her one by one like
 +
 +
<PlayRequest From="Masoumeh" With="Mahsa" status="pending/accepted/rejected/discarded"/>
 +
 +
An accepted play request shows on active (ongoing) game session. The user can select an accepted request and starts to play. (note: a user can participate at most in one game at a same time).
 +
 +
=== Discard Play Request ===
 +
The user may decide to discard one of his/her request by select on the pending (not accepted or rejected) requests and send the following command
 +
 +
  <DiscardPlayRequest Mahsa/>
  
When this option is selected, the app will first ask the user to fill in the meeting identifier and then will fetch the meetings to which all participants have responded.
+
The server will then update the status of the correspondent request to 'discarded' and send back
This is done by first sending the following message to the server:
+
  
  <CheckMeetingRespond>
+
<PlayRequest From="Masoumeh" With="Mahsa" status="discarded"/>
    <MeetingId "5"/>
+
  <CheckMeetingRespond/>
+
  
then the server will send the name of the participants and the selected times to the meeting scheduler one by one as
+
=== Play Rock Paper Scissors ===
 +
The game happens in the play view. In this view, the user makes his/her choice (rock/paper/scissors) and also sees the choice of the other player (obviously not before making his/her choice!). When the user makes the choice, the client sends the following command
  
  <SelectedTime>
+
  <Choice Rock/Paper/Scissors/>
      <MeetingId "5"/>
+
      <name = "ParticipantName"/>
+
      <time = "10:00"/>
+
  <SelectedTime/>  
+
    ...
+
and the number of participants who respond for the meeting
+
  
  <NumberOfRespond "No"/>
+
To fetch the status of the game (choices), the client sends the check status request
  
Then user can select one of the time-slots and close the meeting by sending the following message:
+
  <CheckGameStatus/>
  
  <CloseMeeting>
+
=== Leave Game Session ===
    <MeetingId "5"/><SelectedTime time = "10:00">
+
The user may leave a game session by sending this command
  <CloseMeeting/>
+
  
=== Checking for closed meeting requests ===
+
  <LeaveSession/>
  
 +
This option is available in the play view.
  
Participants can check closed meetings by
+
=== Exit Game ===
  <CheckClosedMeeting/>
+
To exit the game the client sends
  
the server will send
+
<Exit/>
  
  <ClosedMeeting>
+
== NOTE ==
      <MeetingId "5"/>
+
''' Please check the source code of the RPSServer for the complete list of commands and error messages.
      <SelectedTime time = "10:00">
+
    <ClosedMeeting/>
+
  
 
===[[DT_8025_2016 |Back to Course Page]]===
 
===[[DT_8025_2016 |Back to Course Page]]===

Latest revision as of 10:17, 25 October 2016

Objectives

There are three main objectives for this practical:

  • Learn about and use the concept of service in Android
  • Learn about and use the concepts related to network programming in Android
  • Integrated several concepts and techniques learned in this course to implement an Android application


Instructions

Start with a list of scenarios (use-cases) that the following application should be able to deal with: the scenarios should specify what kind of interactions the app should support in which order so as to realize users' requirements. Subsequently make an architectural design (preferably, but necessarily, using notations such as UML Class Diagrams an Sequence Diagrams) to show how the application should be decomposed into a number of activities and services. For each activity design the layout beforehand. Then, start programming. After you are doing, update the scenarios and design to reflect what you have actually implemented; use the scenarios as test-cases and make sure that the app does what it is supposed to.

Submit a single .zip file on blackboard with two folders: the first containing a single pdf reporting on the scenarios, design, test-cases and their outcomes, and the other containing the Eclipse project.


Rock Paper Scissors Online Game for Android!

Overview

The goal of this project is to implement a simple Android app for a Rock Paper Scissors online game. The functionalities that we adopt in our practical is to:

  • Register on the server: ready to play (available),
  • Read the list of available players,
  • Send/Discard a play request with another player,
  • Accept/reject a play request from another player,
  • Fetch the list of play requests either from or to the current player,
  • Make a choice (Rock/Paper/Scissors) and fetch the choice of the other player
  • Leave a game session, and
  • Exit.

Starting up

During the development, you run the server on your own computer and use it as the RPS Server. In any case, your app should get the IP from the user and the IP should not be hard coded.

To compile the java code for the server, go to the folder containing the source and execute (assuming JDK has already been installed and configured)

javac RPSServer.java 

and, then run the server by executing the following command (you may not need to use '-cp .').

java -cp . RPSServer

The server will now be started and listen on port 4444. You will see 'Started server on port 4444' message on the terminal.

The Application

To achieve this, you will be given an IP address of an RPS server implemented and installed on a computer. The server listens on port 4444.

Your app should first allow the user to enter this IP address and a unique ID which is to be used in requests; use your HH account login name as the unique ID throughout this practical.

Then the app tries to connect to the server; if unsuccessful it will make three attempts with a 10 second delay in between (while providing sufficient information as toast messages). If successful, the client will receive the following tag from the server

<Accepted connection from  id +/>

where id is the unique identifier (account name) provided by the client. Then, the client needs to send the ready to play command to the server to be visible by others

<ReadyToPlay/>

It will then receive the following tag from the server (in case of no error)

<Welcome to Rock Paper Scissors Online Game!/>


Then, the app will provide three possible options:

  • view online players (to send play request to),
  • view pending play requests to be answered, and
  • view sent play requests (waiting/accepted/rejected).


View Online Players

The app shows a layout in which the list of online players and their status (idle/busy/waiting) is shown. To fetch the list of online players the client sends the following request

<OnlinePlayers/>

The server sends the list of online players one by one like

<OnlinePlayer name="Masoumeh" status="waiting"/>
<OnlinePlayer name="Mahsa" status="idle"/>
<OnlinePlayer name="Sebastian" status="busy"/>

Send Play Request

The user can select one of the idle players to send a play request to. When the user selects the player (e.g., Mahsa) the client sends the following structure to the server

<PlayRequest Mahsa/>

The serve will reply to the request

<Play request was sent to Mahsa!/>

This is shown by a toast message and the app will return to the main menu.

View Play Request For X

The user may ask whether there has been any play request to be . In this case, after this option is selected from the main menu, the client send the following command

 <PlayRequestsForMe/>

The server sends all pending requests for the participant one by one like

<PlayRequest From="Masoumeh" With="Mahsa" status="pending"/>

Accept/Reject Play Request

The user may select one of the requests for him/her and accept/reject the request.

  <AcceptPlayRequest Masoumeh/> 

or

  <RejectPlayRequest Masoumeh/> 

The server will then update the status of the request to 'accepted' and 'rejected' respectively, and send back

<PlayRequest From="Masoumeh" With="Mahsa" status="accepted/rejected"/>

If the user accepts a request the app automatically moves to the play game view in which the user starts to play.

View Sent Play Request

The user may ask for the play requests sent by him/her. In this case, after this option is selected from the main menu, the client send the following command

 <MyPlayRequests/>

The server sends all requests from him/her one by one like

<PlayRequest From="Masoumeh" With="Mahsa" status="pending/accepted/rejected/discarded"/>

An accepted play request shows on active (ongoing) game session. The user can select an accepted request and starts to play. (note: a user can participate at most in one game at a same time).

Discard Play Request

The user may decide to discard one of his/her request by select on the pending (not accepted or rejected) requests and send the following command

  <DiscardPlayRequest Mahsa/> 

The server will then update the status of the correspondent request to 'discarded' and send back

<PlayRequest From="Masoumeh" With="Mahsa" status="discarded"/>

Play Rock Paper Scissors

The game happens in the play view. In this view, the user makes his/her choice (rock/paper/scissors) and also sees the choice of the other player (obviously not before making his/her choice!). When the user makes the choice, the client sends the following command

  <Choice Rock/Paper/Scissors/>

To fetch the status of the game (choices), the client sends the check status request

 <CheckGameStatus/>

Leave Game Session

The user may leave a game session by sending this command

 <LeaveSession/>

This option is available in the play view.

Exit Game

To exit the game the client sends

<Exit/>

NOTE

Please check the source code of the RPSServer for the complete list of commands and error messages.

Back to Course Page