Skip to content

Peer-to-peer rock/paper/scissors game. Very awesome.

Notifications You must be signed in to change notification settings

johanmickos/ropasci

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ropasci

Ropasci is a P2P application for playing the ROck-PAper-SCIssors game among peers.

Animated GIF of gameplay

How to Plav

Rock beats scissors. Scissors beat paper. Paper covers rock.

Press the buttons to make your move.

Implementation

This game is written in Java and relies on JavaFX for the GUI. Internally, the game logic is maintained separately from the multithreaded GUI and networking code and responds to events generated by them. Thus, the GUI drives events being pushed to the peers, and the networking code bubbles up the P2P state changes.

Networking

Peers connect to each other and gossip their own connected peers to build a fully-connected P2P topology. In each gameplay round, only the connected participants contributeto the game's progress.

Each peer spins up a NetworkManager responsible for orchestrating events between the P2P network and the GUI. A simple TCP-based ServerSocket listens for connecting peers, with new peers being added to a thread-safe list contained in a Supervisor.

Protocol

A simple handshake-based binary protocol is used. When two peers connect, they exchange a length-prefixed payload containing a handshake byte and their peer ID. Upon successful handshaking, the two peers can communicate their usernames to each other and commence sending game state updates.

Each subsequent message is a length-prefixed snippet of the message type followed by an optional data segment, depending on the message type.

When messages are successfully decoded from their binary format into their Java representations, they're bubbled up to the UI and game state logic.

About

Peer-to-peer rock/paper/scissors game. Very awesome.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages