If a ship occupies the square, then it takes a hit. In each round, each player shoots one square. After the ships have been positioned, the game proceeds in a series of rounds. On one grid each player arranges his/her ships. *Play Online via Game Center Multiplayer -against a random opponent -invite a friend *Single player mode: play against the computer *Achieve 8 ranks: from Seaman to Fleet Admiral *Chat and voice chat *Retina Display support *Be the leader in 3 Leaderboards & earn 18 tricky Achievements *Realistic sound effects Rules of the game: The goal of the game is to sink all of your opponent's ships first. If you are interested in the logic implementation you can check my GitHub repository as I will soon be finishing my implementation of the game, otherwise stay tuned for more interesting articles to come.Enjoy the classic Battleship game-guess where your opponent's ships are and destroy them! Play online with your friends or with random people from around the world, achieve ranks, use chat and voice chat, all for FREE! It's easy, fun and addictive to play. 3- decide what to do when receiving the request/message. The basics of server-client communication are: 1- setting up the connection. after that point, it is up to you what do you want to do and what logic do you want to implement. ConclusionĪs you can see, for us to set up a server and to start a connection between our client and that server is pretty easy and straightforward. I would stop here for now, as the rest would be more related to how to handle the game logic while using socket communication, and I want to keep this article focused on how to use socket and node. Socket.emit does send a message to a specific socket and it is used on both the client and the server sides, yet is used by the server and it sends a message to all connected sockets. The same goes for readiness and moves, the client emits the message, and the server processes it and returns responses. The first argument though is the event we are listening for and it is a text value sent by the other side using the emit function. Socket.on is a listening function with a callback method to handle what happens after being fired. Likewise, we need to communicate players' moves, hits, and misses.Ĭommunication will happen between client and server, in our case between server.js and app.js ConnectionĬonnection to the server is initiated by the client, in our case, it is initiated on click event of the button “Multiplayer” and it is as easy as calling the function io(). Knowing that the next step would be to handle those statuses in the game and to let players know when another player connects and when they are ready to play. Ready/Not Ready: a player is not ready until he places all his ships on the grid and presses the play button. Having two players requires us to monitor their status, what are the different statuses of a player?Ĭonnected: I wanted to keep the option of a single-player available for my users, so I added a button specifically for the multiplayer option and that’s when my player is considered connected.ĭisconnected: before a player joins the game / in our case before they load the app and choose the multiplayer option.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |