Docstoc

Multiplayer Enhanced Make Square Game in the Net

Document Sample
Multiplayer Enhanced Make Square Game in the Net Powered By Docstoc
					                                                                 (IJCSIS) International Journal of Computer Science and Information Security,
                                                                                                                Vol. 8, No. 9, December 2010

 Multiplayer Enhanced Make Square Game in the Net
           Md. Ekramul Hamid                                    Sudip Saha                                       Mohammed Qayyum
    Department of network Engineering                         Software Engineer                           Department of Computer Engineering
      College of Computer Science                           Protocom Technology                              College of Computer Science
         King Khalid University                              Sydney, NSW-2000                                   King Khalid University
     Abha, Kingdom of Saudi Arabia                                Australia.                                Abha, Kingdom of Saudi Arabia
    e-mail:ekram_hamid@yahoo.com

Abstract— In this work, the authors attempt to create a successful            Make Square is shown in the figure 1. Basically, the nodes in
Java socket program to implement the “Make Square” game in                    the board are made of filled circles.
the net. The game is very popular among the children. Even
though this game is for kids, this one can also be played by an
adult because it can be quite tricky, require concentration and a
little bit of intelligence. The goal in this game is to make more
small squares. A player will win the game, if he can complete
maximum number of squares after the game is over. Here
client/server technology is used to implement socket
programming. Since the game is implemented by java, so it is
platform independent and portable. Many players in many
different groups can play the game on the net. To make the game
more interesting we enhance its feature by adding hidden lines.
This makes the game more attractive and challenging. The Java                                Figure 1. Playing Board (m x n Matrix of nodes)
features like Networking, Graphics, Layout Management,
Package and Interface, Exception Handling, I/O, Applets, AWT
Controls and Event handling etc. [2-4] are used to create the                 A. General Rules of the Game
game. The Make Square game consists of more than 1700 lines of
                                                                                  A player connects two nodes with a line in his turn. Once
code in 12 classes. Five of these classes are part of the server side
and rest seven is part of the client side. The Make Square game is
                                                                              he puts the line, his turn is over, and next players turn is start
running properly in a network.                                                and so on. In this way, the game goes on in a round robin
                                                                              fashion until all the squares are completed. A player will win
   Keywords-component;    Make       Square,      node,    socket             the game, if he can complete maximum number of squares after
programming, AWT, 3D object, GUI, client/server technology                    the game is over.

                        I.    INTRODUCTION                                        Let two players A and B are playing the game. In The first
                                                                              turn, player A puts his first move A(1,1) and B puts his first
    There are so many games like the “Make Square” that are                   move B(1,1) as shown in figure 2. Here, each player’s turn
really silly and funny. But not all of them are like this that                represented by PLAYER (i,j), where i and j are turn and move
require concentration and a little bit of intelligence. These are             of PLAYER respectively.
the puzzle games. The controls for these games are very simple
and usually need to use only the mouse. Player can click on
different objects on the screen to trigger all sorts of actions.
Here in this paper we propose the development of online games
using Java. We use Applets because everyone has an Internet
browser, so everyone is able to play this game without
installing the JDK!
    Java is a multiplatform, object-oriented programming
language created by Sun Microsystems. Creating games on
Java is simple than creating games on languages such as C++
due to the advantages of the Swing library that comes as part of                    Figure 2. Turns of A and B            Figure 3. B wins a square
the Java API.
    The “Make Square” is a very popular game played on paper
                                                                                  The player who puts the last line to form a complete square
by drawing a board layout as figure 1. Here, the authors
                                                                              — wins the square. Figure 3 shows B wins a square. When no
attempt to implement tele-playing version of the game in the
                                                                              more square is remaining, the game is over and the player who
network [1]. To play the game, each player connects to server
                                                                              completes more squares is the winner. To make the game more
using client program. It does not need any third party server
                                                                              interesting we enhance its feature by adding hidden lines. This
software to play the game.
                                                                              makes the game more attractive and challenging.
   The Make Square playing board consists of nodes, where
nodes are arranged as a m x n matrix. A typical board of a




                                                                        216                                  http://sites.google.com/site/ijcsis/
                                                                                                             ISSN 1947-5500
                                                                   (IJCSIS) International Journal of Computer Science and Information Security,
                                                                                                                  Vol. 8, No. 9, December 2010
B. Enhanced Rules of the Game                                                information is passed to the server and the server broadcast the
Rule1: One player (say A) can hide one line, which is not                    update player list. The user then see a list of all available
visible to others. He cannot put another hidden line until his               players and any one from the group can start the game by
hidden line is disclosed to all.                                             clicking the start button.

Rule2: A player (let A) can put a line, there are two possible
places,
1. Where no line exists
    If this line makes a complete square with hidden line(s), he
wins the square. Since he (A) disclosed the hidden line(s), he
will get another chance to put a new line. Figure 4 shows A and
B put hidden lines (indicated by dashed line) and figure 5
shows A disclosed the hidden lines in the next move and wins
the square.




       Figure 4. Hidden lines        Figure 5. Disclosed hidden line



2. On another existing hidden line, which is not visible to him
(A), then the hidden line will disclosed only to him (A) and get
a chance to put a new line.
Rule3: A player (let A) can put a hidden line in two possible
places
1. Where no line exists, then it will visible to that player (A)
only and invisible to others.
2. On another existing hidden line, which is not visible to him
(A), then this line will also consider as a hidden line. In this
case a player can’t win the square even though that hidden line
makes a complete square.                                                     C. Different Buttons and Windows
                                                                             Buttons:
                          II.   GAME SETUP
                                                                                      start    : allows to start the games
The Make Square game setup is very simple because of its
strong Graphical User Interface (GUI). One player can setup                           message : allows to send messages to others
the game either in solo mode or multi-player mode.                                    exit     : quitting the game
A. Solo Mode                                                                          pass     : to skip a turn
   One player can play Make Square in Solo mode. Here his
opponent may be an intelligent agent. He has to enter his name,              Windows:
choose his pen color and game size (number of nodes in the                   Waiting list window: shows the player list in the queue.
row and column) and start the game.
                                                                             Score Board window: shows player name and score of that
B. Multi-Player Mode                                                         player. The player, who wins a square, gets 1 point.
    In this mode, many players can play the game. Here some                  Message window : at any time during the play, players may
players (max. 4) together make a group where one player is                   converse using this window.
leader and others are members. Each player has to enter his
name, pen color and choose status (as a leader/member). If he                   The game-playing environment is shown in the figure 7.
joins as group leader, he has to select game size. Otherwise he
has to choice group number to play (Figure 6). This




                                                                       217                              http://sites.google.com/site/ijcsis/
                                                                                                        ISSN 1947-5500
                                                             (IJCSIS) International Journal of Computer Science and Information Security,
                                                                                                            Vol. 8, No. 9, December 2010
D. Features of the Game
        •   Easy game setup
        •   Attractive board layout
        •   Hidden line option
        •   Chatting facility
        •   Descriptive score board
        •   Multi-group support
        •   Durability (against system crash)


              III.   ROLE OF CLIENT/SERVER
    The client–server computing is a distributed application
structure that partitions tasks between the providers of a
resource, called servers, and service requesters, called clients.
Often clients and servers communicate over a computer
network on separate hardware, but both client and server may
reside in the same system. A server machine is a host that is
running one or more server programs which share their
resources with clients. A client does not share any of its
resources, but requests a server's content or service function.
Clients therefore initiate communication sessions with servers
which await incoming requests. Figure 8 shows the
client/server communication.
A. Role of Client
• Client provides GUI as per the requirements of the game.
•   Client facilitates the player to start a new game by
    invoking start option.
•   Client shows the players name, group id in a list.
•   Client updates each player, screens and sends correct
    messages.
                                                                                       IV.   DATA STRUCTURES USED
                                                                          A. Server Side
B. Role of Server
                                                                          Data Structure for Player Handling
• Server provides multiple client connections so that many
   players can play.                                                         The data structure for player handling in the server side is
                                                                          shown in the figure 9.
•   Server continuously listens to the different requests from
    the multiple clients.                                                     When a client initially connects to server, it assigns a
                                                                          temporary id (tid) to the client until he becomes a member of
•   Server maintains all the clients information.                         the game. In figure 9, socket indicates the socket address from
•   Server maintains the play sequence and notifies the player            which the client connects. After getting the membership, each
    about his turn                                                        players information such as group id (gid), players id (pid),
                                                                          socket number (socket), players name (name), number of rows
                                                                          and columns (row, col) in the playing board will be stored in
                                                                          the following structure as shown in the figure 10.




                                                                    218                              http://sites.google.com/site/ijcsis/
                                                                                                     ISSN 1947-5500
                                                            (IJCSIS) International Journal of Computer Science and Information Security,
                                                                                                           Vol. 8, No. 9, December 2010




                                                                         The center (C) bit structure in Figure 13 is maintained in the
                                                                         center cell of each square. The bit positions 1,2, and 4 in the
                                                                         center integer that represents the total lines around the center.
                                                                         Bit no 1 represents One (1) Line, Bit no 2 represents Two(2)
                                                                         Lines and Bit no 4 represents Three(3) Lines around the center.
                                                                         Remaining Bit positions 64, 32, 16 and 8 represent Line
                                                                         positions. If Bit position 1, 2, 4 contain 1 then Remaining Bit
                                                                         position 64, 32, 16 and 8 represents the Player id.

•   Server maintains an array of linked list for different
    playing groups, each group have one linked list [6].
•   First node in the linked list contain the leader information
    remaining nodes contain members information.
•   In the array of linked list there may have two types of
    group, waiting group and playing group.
•   Server differentiates between playing group and waiting
    group using the row in the leader node. If it is –1, implies
    the group is playing.
•   When a group’s game is over, then its corresponding list
    will be free.
B. Client Side
Data Structure for Player Handling
   The data structure for player handling in the client side is
shown in the figure 11. In the figure 11, each client holds all
players information such as group id (gid), player id (pid),
player name (name), Score, hidden line.




Data Structure for the Playing Board
                                                                             In the TLBR bit structure in figure 14, bit position 1
    Figure 12 represents the playing board structure, which is a         represents the Line status (1 for existence). Bit positions 2
2 X 2 matrix. In the matrix each element (other than nodes)              represents whether the line is a hidden or not. Bit position 3
store an integer value. The elements (i , 2j+1) [where                   represents whether the Line is Visible or not. Remaining Bit
i=1,3,5…… and j=0,1,2,3…..] store the CENTER value and                   position 64, 32, 16 and 8 represents Player id that put the line.
others store the TLBR (Top/Left/Bottom/Right) value.




                                                                   219                              http://sites.google.com/site/ijcsis/
                                                                                                    ISSN 1947-5500
                                                              (IJCSIS) International Journal of Computer Science and Information Security,
                                                                                                             Vol. 8, No. 9, December 2010
                    V.     THE GAME CODE
    The Make Square game consists of more than 1700 lines of
code in 12 classes [1-4]. Five of these classes are part of the
server side and rest seven is part of the client side. Most of the                                               Display
classes and its functions are given in appendix -I.                                                            initform

                 VI.     ACTIVITY DIAGRAM
    Activity diagram are use to model the dynamic aspects of a                                         N          Is            Y
system. With the help of this diagram one can show the flow of                                                   mult
an object as it moves from state to state at different points in a
system [7].                                                                               Display solo                          Connect to
                                                                                                                                  server


                                                                                           Game setup                                 is         N
                                                                                                                                    conn
                         Create server socket                                                                                       ected
                       & waiting for request                                                                                                     Y
                                                                                             Start game
                                                                                                                               Display mult
                                                                                                                                  form
                                    Is              N
                                client                                                    Display board
                                                                                                                                Send player
                               request
                                                                                                                              info. To server


                                             Close socket                                 Check for turn
                                      Y                                                                                          Get update
                                                                                                                                 player list
                              Allocate a
                              socket                                                      Update board
                                                                                                                                 Start game



                           Create thread                                                         Is                               Display
                                                                                                over                           playing board

                                                                                                           N
                  Figure 15. Activity diagram (server side)
                                                                                           Y                                   Get turn from
                                                                                                                                  server


                                                                                                                                Send board
                                                                                                                              status to server

                                                                                                                                                 EXIT
                                                                                                                             N        Is
                                                                                                                                     over

                                                                                                                                    Y
                                                                                                                                 Disconnect
                                                                                                                                   server

                                                                                      EXIT
                                                                                                                                 Display end



                                                                           Figure 16. Activity diagram (client side)

                                                                     220                               http://sites.google.com/site/ijcsis/
                                                                                                       ISSN 1947-5500
                                                                      (IJCSIS) International Journal of Computer Science and Information Security,
                                                                                                                     Vol. 8, No. 9, December 2010
              VII.    RESULTS AND DISCUSSIONS                                      •   public void init()
    The Make Square game is running properly in a network.                             init function displays a screen where user choice modes
The playing board updates real-time. The game can survive                          either solo or multi.
from system crash, media failure and power failure of clients.
The Make Square game is very popular to us because it is quite                     •   public void mousePressed (MouseEvent me)
easy to play. The game is intended for entertainment purpose                          When a mouse button is clicked this function call select line
and net version of it makes it more interesting. It can be market                  method of the board class.
as a commercial product like other games.
                                                                                   •   public void MessageHandeler()
                                                                                   This method handles the message sent by server.
                        VIII. CONCLUSION
                                                                                   •   public void BoardMng (int r,int c,int iMouseBtn,int
    In this Project work, we have created an applet represents a                       Pid)
complete client/server, multi-player board game “Make
Square” using Java programming. Almost all the important                               It manages the playing board. Whether player turn is active
java concepts are implemented here. The motivating objective                       or his turn is over and accordingly informs the server.
is to develop a basic understanding of java programming in the
network environment.                                                               •   public void actionPerformed (ActionEvent ae)

    In the future the following improvements to the software                          When a particular button is clicked this function takes
are recommended:                                                                   appropriate action.

•     More efficient GUI                                                           •   private void MultForm()
                                                                                   This form provides users information to the server.
•     Make computer logic more intelligent as a player
                                                                                   •   private void OpenForm()
                                                                                      It shows a player the update list of players and update the
                             REFERENCES                                            waiting player list.
[1]   M. E. Hamid and S. Saha, “Make Square”, MCS 2nd semester project,
      Department. of Computer Science, Fergusson College, University of            •   private void BoardForm()
      Pune, India, June 2001.
[2]   H. Schildt, The Complete Reference, Tata McGraw-Hill Publishing
                                                                                   It shows playing board.
      Company Limited, New Delhi, 2001.
                                                                                   •   public void UpdateScoreBoard(int pid, boolean Bright,
[3]   E. Bruce, Thinking in Java , Prentice Hall PTR, 1999.                            int score)
[4]   S. C. Horsrmann, Core Java, Volume-I&II, Sun MicroSystem Inc. 2000.
[5]   E. Balagurusamy, Programming in Java, Tata McGraw-Hill Publishing                It updates the score board and other information’s (playing
      Limited, New Delhi, 1995.                                                    or waiting and hidden status)
[6]   L. Yedidyah, J. Moshe, M. T. Aaron, Data Structures using C and C++,
      Prentice-Hall of India Private Limited, New Delhi 110001, 1998.              •   public Color SelectPenColor(int pen, boolean Bright)
[7]   B. Grady. R. James, The Unified Modeling Language User Guide, Person            It selects a pen color according to pen provided by
      Education Asia, New Delhi 2001.
                                                                                   argument (pen).
                                                                                   3) class INITform
                              APPENDICES
                                                                                   •   public void ShowInitForm()
APPENDIX-I
                                                                                   This function show the initial form of the applet.
1) class CONNECTtoSERVER extends Thread
                                                                                   4) class SOLOfrom
   This class connects client to server and creates a thread for
continually listening the server information using following                       •   ShowSoloFrom()
functions:                                                                         This function shows a form in solo mode.
•     public int ConnectToServer()                                                 5) class PCData
   It connects client to server. If successful, return a message,                      This class is used for storing information of players in client
otherwise –1                                                                       side. Informations are player id, group id, pen, score, hidden,
•     public void run()                                                            name,
   It continuously listens server information and call message                     •   interface CONSTANTSlist
handler.                                                                           Here all constants are declared.
2) public class MakeSquare extends Applet
         This class makes user interface.



                                                                             221                               http://sites.google.com/site/ijcsis/
                                                                                                               ISSN 1947-5500
                                                               (IJCSIS) International Journal of Computer Science and Information Security,
                                                                                                              Vol. 8, No. 9, December 2010
6) class BOARD implements CONSTANTSlist                                        It is used to broadcast message to client. Its category
                                                                            parameter implies:
•    public void DisplayBoard()
                                                                            0 → to all client connected to server.
This function displays the board of the game.
                                                                            1 → to all waiting and playing player.
•    public void DrawLine(int r, int c, int Pid)
                                                                            2 → to all waiting except a particular player.
    It draws a line according to row, column and player id
(using pid’s pen color).                                                    3 → to all player in a group.
•    public void UpdateMatrix(int r, int c, int iMouseBtn,                  4 → to all player except a particular player.
     int Pid)
                                                                            5 → to all waiting player.
  It updates matrix (board) according to the row, column,
mouse, and pid.                                                             6 → to all waiting player except a particular player.
•    public void ModifyCenter(int r, int c, byte TLRBid, int                10→ to a particular player.
     Pid)                                                                   •   synchronized public int ProcessClientMsg()
•    public void ModifyCenter(int r, int c, int iMouseBtn,                  To process clients messages.
     int Pid)
                                                                            12) class CREATEclient extends Thread
Modify the center bit structure.
                                                                                This class creates an instance that listens a particular client
•    public void ModifyTLRB(int r, int c, byte TLRBid, int                  information.
     Pid)
It updates top, left, right, botton bit structure.
                                                                                                 AUTHORS PROFILE
•    public void SelectLine(MouseEvent me)
    It selects line according to mouse click. left button for solid                           Md. Ekramul Hamid received his B.Sc
line and right button for hidden line.                                                        and M.Sc degree from the Department
7) class Object3D                                                                             of Applied Physics and Electronics,
                                                                                              Rajshahi University, Bangladesh. After
•    Object3D(int Rl, int Gl, int Bl,Applet app)                                              that he obtained the Masters of
    This function shows 3D balls according to color provided                                  Computer Science degree from Pune
by its argument.                                                            University, India. He received his PhD degree from
                                                                            Shizuoka University, Japan. During 1997-2000, he was a
•    public void Draw3DBall(Graphics gc, int x, int y, int r)               lecturer in the Department of Computer Science and
   Draw a ball according to the arguments (radius, xy                       Technology, Rajshahi University. Since 2007, he has been
position)                                                                   serving as an associate professor in the same department.
                                                                            He is currently working as an assistant professor in the
8) public class Server5                                                     college of computer science at King Khalid University,
   This class creates a server socket according to specified                Abha, KSA. His research interests include Software
address and waiting for client.                                             development, speech enhancement, and speech signal
                                                                            processing.
9) class PSData
    This class is used for storing information of players in
server side. Information’s are player id, group id, socket,
name, row, and column.
10) class Tdata
     It stores temporary information of players like temporary                             Sudip Saha received his B.C.S and M.C.S
id, and socket.                                                             degree from Pune University, India. He received Post
11) class CLIENTmng                                                         Graduation Diploma in Information Technology from
                                                                            University of New England, Australia. He is currently working
•    synchronized public void AddClient()                                   as a software engineer in Protocom Technology, Sydney,
    This is used to add a new client and provide a temporary id             Australia. His research interests include telecommunication
to the user.                                                                and mobile technologies.

•    public void BroadCast(int cata,int gid,int pid ,String
     msg)




                                                                      222                                 http://sites.google.com/site/ijcsis/
                                                                                                          ISSN 1947-5500
                                                        (IJCSIS) International Journal of Computer Science and Information Security,
                                                                                                       Vol. 8, No. 9, December 2010




                 Mohammed Qayyum, Currently working as
Lecturer in the Department of Computer Engineering at King
Khalid University, Kingdom of Saudi Arabia. Before joining
at KKU, he worked as a Assistant Professor under the
Department of Computer Science and Engineering at MJCET,
Hydarabad, India. Prior to that, He also worked as a Systems
Engineer with designation as Member Technical Staff for
Ikanos Communications Inc. Bangalore, India. He completed
his Master of Technology degree in Software Engineering
from JNT University, Hydarabad, India. He is keen and
desperate for research in Data Replication Techniques of
Mobile Adhoc Networks with Database issues.




                                                               223                           http://sites.google.com/site/ijcsis/
                                                                                             ISSN 1947-5500

				
DOCUMENT INFO
Description: The International Journal of Computer Science and Information Security (IJCSIS) is a well-established publication venue on novel research in computer science and information security. The year 2010 has been very eventful and encouraging for all IJCSIS authors/researchers and IJCSIS technical committee, as we see more and more interest in IJCSIS research publications. IJCSIS is now empowered by over thousands of academics, researchers, authors/reviewers/students and research organizations. Reaching this milestone would not have been possible without the support, feedback, and continuous engagement of our authors and reviewers. Field coverage includes: security infrastructures, network security: Internet security, content protection, cryptography, steganography and formal methods in information security; multimedia systems, software, information systems, intelligent systems, web services, data mining, wireless communication, networking and technologies, innovation technology and management. ( See monthly Call for Papers) We are grateful to our reviewers for providing valuable comments. IJCSIS December 2010 issue (Vol. 8, No. 9) has paper acceptance rate of nearly 35%. We wish everyone a successful scientific research year on 2011. Available at http://sites.google.com/site/ijcsis/ IJCSIS Vol. 8, No. 9, December 2010 Edition ISSN 1947-5500 � IJCSIS, USA.