private static async Task ConsumeOneAsync(CancellationToken token) { Console.Write($"Starting {nameof(ConsumeOneAsync)} scenario"); var channel = new Channel("localhost", 10000, ChannelCredentials.Insecure); var client = new ClientImpl(channel); BombResponse r = await client.ConsumeOne(token); Console.WriteLine($"Recieved response: code='{r.Code}' detail='{r.Detail}'"); }
public async Task ConsumeMany(CancellationToken token) { try { while (!token.IsCancellationRequested) { foreach (BombRequest request in this.GenerateMortarRequest(token)) { this.Log($"Sending message {request.SecurityKey} with {request.Payload.ToStringUtf8()}"); var options = new CallOptions(cancellationToken: token); BombResponse response = await this.bombingClient.SupportRequestAsync(request, options); this.Log(FormatResponse(response)); } } } catch (RpcException e) { this.Log($"RPC failed: {e}"); } }
private static string FormatResponse(BombResponse resp) => FormatResponse(resp.GetType().Name, resp.Code.ToString(), resp.Detail);
/// <summary> /// 向双方同时发送轰炸结果 /// </summary> /// <param name="data"></param> private void _BombResponse(Message message) { BombResponse bombResponse = message.Bombresponse; BombResponse.Types.BOMB_RESULT result = bombResponse.Res; int x = bombResponse.Pos.X; int y = bombResponse.Pos.Y; Console.WriteLine("result: " + result.ToString()); ChessBoard.Chessboard_Point point = new ChessBoard.Chessboard_Point(); point.x = x; point.y = y; if (GameUtils.GetGameStatus() == ClientInfo.game_status.rival_guessing) { //Console.WriteLine("network_count0: " + ClientInfo.my_chessboard.Count()); switch (result) { case BombResponse.Types.BOMB_RESULT.Destoryed: point.state = ChessBoard.point_state.destroy; ClientInfo.my_points.Enqueue(point); //GameUtils.SetChessBoard(x, y, ChessBoard.whose_board.my_board, ChessBoard.point_state.destroy); break; case BombResponse.Types.BOMB_RESULT.Hit: point.state = ChessBoard.point_state.hit; ClientInfo.my_points.Enqueue(point); //GameUtils.SetChessBoard(x, y, ChessBoard.whose_board.my_board, ChessBoard.point_state.hit); break; case BombResponse.Types.BOMB_RESULT.Miss: point.state = ChessBoard.point_state.miss; ClientInfo.my_points.Enqueue(point); //GameUtils.SetChessBoard(x, y, ChessBoard.whose_board.my_board, ChessBoard.point_state.miss); break; } GameUtils.SetGameStatus(ClientInfo.game_status.self_guessing); } else if (GameUtils.GetGameStatus() == ClientInfo.game_status.self_guessing) { //Console.WriteLine("network_count0: " + ClientInfo.my_chessboard.Count()); switch (result) { case BombResponse.Types.BOMB_RESULT.Destoryed: //GameUtils.SetChessBoard(x, y, ChessBoard.whose_board.rival_board, ChessBoard.point_state.destroy); point.state = ChessBoard.point_state.destroy; ClientInfo.rival_points.Enqueue(point); break; case BombResponse.Types.BOMB_RESULT.Hit: point.state = ChessBoard.point_state.hit; ClientInfo.rival_points.Enqueue(point); //GameUtils.SetChessBoard(x, y, ChessBoard.whose_board.rival_board, ChessBoard.point_state.hit); break; case BombResponse.Types.BOMB_RESULT.Miss: point.state = ChessBoard.point_state.miss; ClientInfo.rival_points.Enqueue(point); //GameUtils.SetChessBoard(x, y, ChessBoard.whose_board.rival_board, ChessBoard.point_state.miss); break; } GameUtils.SetGameStatus(ClientInfo.game_status.rival_guessing); } //Thread.Sleep(1000); //Console.WriteLine("network_count: " + ClientInfo.my_chessboard.Count()); }