public void RequestMove(Card card) { var move = new GameMove(Player, card); lobbyWriter.Write((byte)NetMessageType.Data); lobbyWriter.Write((byte)MessageType.SendMove); move.Encode(lobbyWriter); }
/// <summary> /// Requests for a move to be made by this client /// </summary> /// <param name="card">The card to play</param> public void RequestMove(PlayingCard card) { if (IsConnected) { GameMove move = new GameMove(myKnownPlayers[myPlayerId], card); NetOutgoingMessage msg = myPeer.CreateMessage(); msg.Write((byte)MessageType.SendMove); move.Encode(msg); Send(msg); } }
/// <summary> /// Handles a player making a game move /// </summary> /// <param name="move"></param> private void HandleMove(GameMove move) { // define the reason string failReason = "Unknown"; Log("Player {0} wants to play {1}", move.Player.PlayerId, move.Move); // Iterate over each game rule for (int index = 0; index < myPlayRules.Count; index++) { // If the move is valid, continue, otherwise a rule was violated if (!myPlayRules[index].IsValidMove(this, move, ref failReason)) { // If the person who made the rule sucked at making rules, we catch their mistake if (failReason == "Unknown") { failReason = "Failed on " + myPlayRules[index].ReadableName; } // Notify the source user NotifyInvalidMove(move, failReason); if (LogLongRules) { Log("\tFailed rule \"{0}\": {1}", myPlayRules[index].ReadableName, failReason); } return; // Do not send to other clients, so break out of method } else if (LogLongRules) { Log("\tPassed rule \"{0}\"", myPlayRules[index].ReadableName); } } Log("Move played"); // Create the outgioing message NetOutgoingMessage outMsg = myServer.CreateMessage(); // Write the header and move to the message outMsg.Write((byte)MessageType.SucessfullMove); move.Encode(outMsg); // Send to all connected clients SendToAll(outMsg); // Update all the sucessfull move states for (int index = 0; index < Rules.MOVE_SUCCESS_RULES.Count; index++) { Rules.MOVE_SUCCESS_RULES[index].UpdateState(this, move); } }
/// <summary> /// Notifies a client that they made an invalid move /// </summary> /// <param name="move">The move that was determined to be invalid</param> /// <param name="reason">The reason that the move was invalid</param> private void NotifyInvalidMove(GameMove move, string reason) { // Create the message NetOutgoingMessage outMsg = myServer.CreateMessage(); // Write the header and the bad move to the packet outMsg.Write((byte)MessageType.InvalidMove); move.Encode(outMsg); outMsg.Write(reason); // Send the packet if (move.Player.Connection != null) { myServer.SendMessage(outMsg, move.Player.Connection, NetDeliveryMethod.ReliableOrdered); } }