Tic-Tac-Toe - Part 3 - Multiplayer, with a Lobby

Favourite 32 favourites
Tutorial written by blackhornetOriginally published on 5th, May 2014 - 2 revisions

eGame Event Sheet

There isn't much here. Since there isn't much interaction in Tic-Tac-Toe, the few user events just call functions on the eCommunications event sheet to send messages to the other player. TileHiliting and board-tile-presses are sent.

eCommunications

Communications are broken up into outgoing Commands, and incoming Messages.
Commands
CmdTileHilite() - this builds up a hilite message of the X, Y, and hilite value for a tile.
If the message isn't the same as the last one, we send the TileHilite message, store the message to compare against next time, and call HiliteTile() to hilite the tile on our side.
CmdMakeMove() - we send the message to the other player of the X, Y, and move(X or O), call MarkTheMove() to mark the tile on our side, and then check for a winner. If the game isn't flaged as over, call SwitchPlayer() to switch who's turn it is.
CmdRestart() - this just resets everything to start the game over. We flip who starts first, and send a Restart message to the other player with who moves first.
Messages
These match what we just covered, only when we are the "other" player.
"TileHilite" message - decode the parameters, and call HiliteTile().
"MakeMove" - decode the parameters and MarkTheMove() and check for game over. Switch players as appropriate.
"Restart" - set the first move ID and go to the Game layout.

Share and Copy this Tutorial

You are free to copy, distribute, transmit and adapt this work with correct attribution. Click for more info.

Comments

2
Wsoukkachang 1,433 rep

Nice! Very useful!

Monday, May 05, 2014 at 4:19:32 AM
2
qu0y 3,151 rep

So considerate, thanks for being always so helpful!

Monday, May 05, 2014 at 2:29:55 PM
1
Scofano 2,693 rep

Thanks for sharing.

Monday, May 05, 2014 at 5:50:29 PM
1
Tedg 9,884 rep

Thanks for share this !)

Monday, May 05, 2014 at 6:53:22 PM
1
DUTOIT 12.7k rep

Oh, Wow, going to savour this one :) Looks fantastic.

Monday, May 05, 2014 at 7:54:54 PM
1
AbelaNET 14.8k rep

Thanks for sharing

Tuesday, May 06, 2014 at 8:22:39 AM
1
beardedeagle 2,020 rep

Multiplayer is the next thing I have to implement into my game and this will be very helpful to get me there. Thank you!

Monday, July 07, 2014 at 7:08:18 PM

Leave a comment

Everyone is welcome to leave their thoughts! Register a new account or login.