Skip to content

A very simple multiplayer tic-tac-toe game built with a java client and a node backend.

Notifications You must be signed in to change notification settings

wizard1238/network-tick-tac-toe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Getting Started with Server

First, create a .env file in the root directory of the repo with contents MONGOOSEURL = "<mongoose connection string>" Then, run yarn, then yarn dev.

API

Make requests to /game. The two parameters you can include are game and move To create a new game, make an emtpy post request. You will get an id back. To get the status of a game, include the id of the game in the game parameter. To make a move, include the id of the game, and in the move parameter include the position and the turn.

Example requests:

Getting status of a game:

{
    "game": "5fcae94a8468041e40388c7f" //Id of game
}

Making a move:

{
    "game": "5fcae94a8468041e40388c7f", //Id of game
    "move": {
        "position": "2",
        "turn": "Y"
    }
}

Getting Started with Client

Put Game.java into the same directory as your code. Add gson to the java project. Change the static String url in Game.java to the url of the server. Methods are listed here

  • startNewGame: Returns a string with the game code.
  • checkJoined: Returns void when another client has joined the same game. Takes string gameCode as a parameter.
  • myTurn: Runs callback when it is that client's turn. Takes char player, string gameCode, and a callback that returns a boolean true
    Game.myTurn('X', "<gameCode>", (callback) -> {
        //Run code here
    })
  • makeMove: Posts move to server. Takes string gameCode, int move, char player, char[] board. Returns void.
  • updateBoard: Gets board info from server. Takes string gameCode, char[] board, with an optional callback.

Example code is in the /example folder.

About

A very simple multiplayer tic-tac-toe game built with a java client and a node backend.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published