Git Product home page Git Product logo

game.io's Introduction

Game.io is a multiplayer cli game that's based on the socket.io protocol.

Game server is implemented as a socket.io server that responds for specific events any client (web/cli) can send.

The game state is stored in a game object instantiated from a custom ES6 game class I wrote. I chose not to incorporate the socket communication functionality inside the game class so as to make it lean and with a single responsibility as much as possible. The other path I didn't take but thought of was to make the game class extend the Event Emitter class let the game object itself manage the communication with clients. But I didn't do that.

The game server API will be operating underhood using http long polling or websockets.

Communication will be all realtime between the different players.

The game object is visible throughout the flow of the game as long as the server is up and running. Server keeps state of the game in this game object.

I have written the game client using nodejs in the form of a cli-program that takes input from the users via the terminal.

To start the game, from within the project directory we first have to install dependencies by doing

npm install

Then next, we start the game server to be listening for connections from players by doing

npm run server

Now the server is up and listening for attempts of client connections on either port 5000 or a specified port in .env file. The maximum number of players accepted in a game is two players. More than two players, the server rejects the socket connection.

Players ask to connect to games by running

npm run client

Upon spinning up the game client, the program asks the user to input his/her name so that it can be registered as a player in the game.

When a user connects and no other user exists in the game lobby, the player is prompted Waiting for the other player to join...

Whenever the other player joins, server will set the game running and the latest player to join will be prompted to start the game.

A player starts the game by entering the initial number. I assumed the initially incepted number is actually input by the user because I couldn't get a clear idea about the requirement in this regard.

When the player incepts the first number, the terminal hangs after prompting the player Waiting for other player move...

At the same time, the other player is prompted to enter a move, Select a move from [-1, ,0, 1]:

And so forth, the game proceeds until the game class logic determines a winner after a specific move.

The following screenshot documents a flow of the game based on the examples pointed out in the requirements.

Alt text

game.io's People

Contributors

ramyfarid922 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.