public ActionResult Saver(string ip, int port, int perSeconds, int seconds, string fileName) { // run the saving of the values in a new thread so the user won't wait for response new Thread(() => { // create a locator finding object PlaneLocator locator = new PlaneLocator(); List <PlanePos> list = new List <PlanePos>(); // get the valued as requested in the url for (int i = 0; i < perSeconds * seconds; i++) { PlanePos plane = locator.GetPlanePosition(ip, port); list.Add(plane); Thread.Sleep(1000 / perSeconds); } // create a serializer XmlSerializer serializer = new XmlSerializer(typeof(List <PlanePos>), new Type[] { typeof(PlanePos) }); // save the file to the location of the code string str = fileName + ".xml"; var dir = Server.MapPath("~/"); var file = Path.Combine(dir, fileName + ".xml"); FileStream stream = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.None); serializer.Serialize(stream, list); }).Start(); // send the values to the view ViewBag.seconds = seconds; ViewBag.ip = ip; ViewBag.port = port; ViewBag.perseconds = perSeconds; // show the view of the location of the plane return(View("~/Views/Saver.cshtml")); }
public ActionResult Location(string ip, int port) { // return a json that is the plane location PlaneLocator loc = new PlaneLocator(); PlanePos p = loc.GetPlanePosition(ip, port); return(Json(p, JsonRequestBehavior.AllowGet)); }
public void _GuessRequest(PlaneLocator planeLocator) { GuessRequest guessRequest = new GuessRequest(); guessRequest.Loc = planeLocator; Message message = new Message(); message.Type = BombplaneProto.Type.GuessRequest; message.Guessrequest = guessRequest; NetworkClient.Generate_Package(message); }
public static Plane.plane_direction GetDirection(PlaneLocator planeLocator) { // 上 if (planeLocator.Pos1.Y < planeLocator.Pos2.Y && planeLocator.Pos2.Y == planeLocator.Pos3.Y) { return(Plane.plane_direction.up); } // 下 else if (planeLocator.Pos1.Y > planeLocator.Pos2.Y && planeLocator.Pos2.Y == planeLocator.Pos3.Y) { return(Plane.plane_direction.down); } else if (planeLocator.Pos1.X < planeLocator.Pos2.X && planeLocator.Pos2.X == planeLocator.Pos3.X) { return(Plane.plane_direction.left); } else { return(Plane.plane_direction.right); } }
/// <summary> /// 向双方同时发送猜测结果 /// </summary> /// <param name="data"></param> private void _GuessResponse(Message message) { GuessResponse guessResponse = message.Guessresponse; bool destroyed = guessResponse.Destroyed; PlaneLocator planeLocator = guessResponse.Loc; List <ChessBoard.Chessboard_Point> points = GameUtils.PlaneLocator_To_Points(planeLocator); if (GameUtils.GetGameStatus() == ClientInfo.game_status.rival_guessing) { foreach (ChessBoard.Chessboard_Point point in points) { if (destroyed) { point.state = ChessBoard.point_state.destroy; } else { point.state = ChessBoard.point_state.miss; } ClientInfo.my_points.Enqueue(point); } GameUtils.SetGameStatus(ClientInfo.game_status.self_guessing); } else if (GameUtils.GetGameStatus() == ClientInfo.game_status.self_guessing) { foreach (ChessBoard.Chessboard_Point point in points) { if (destroyed) { point.state = ChessBoard.point_state.destroy; } else { point.state = ChessBoard.point_state.miss; } ClientInfo.rival_points.Enqueue(point); } GameUtils.SetGameStatus(ClientInfo.game_status.rival_guessing); } }
public static List <ChessBoard.Chessboard_Point> PlaneLocator_To_Points(PlaneLocator planeLocator) { List <ChessBoard.Chessboard_Point> chessboard_Points = new List <ChessBoard.Chessboard_Point>(); int center_x = 0, center_y = 0; Plane plane = new Plane(); Plane.plane_direction direction = GetDirection(planeLocator); plane.Direction = direction; switch (direction) { case Plane.plane_direction.down: center_x = planeLocator.Pos1.X; center_y = planeLocator.Pos1.Y - 1; break; case Plane.plane_direction.left: center_x = planeLocator.Pos1.X + 1; center_y = planeLocator.Pos1.Y; break; case Plane.plane_direction.up: center_x = planeLocator.Pos1.X; center_y = planeLocator.Pos1.Y + 1; break; case Plane.plane_direction.right: center_x = planeLocator.Pos1.X - 1; center_y = planeLocator.Pos1.Y; break; } for (int i = 0; i < 10; i++) { ChessBoard.Chessboard_Point point = new ChessBoard.Chessboard_Point(); point.x = center_x + plane.plane_shape[(int)plane.Direction][i].x; point.y = center_y + plane.plane_shape[(int)plane.Direction][i].y; chessboard_Points.Add(point); } return(chessboard_Points); }
private void Play_Ground_LeftMouseDown(object sender, MouseButtonEventArgs e) { Point clicked_point = e.GetPosition(Play_Ground); clicked_X = (int)(clicked_point.X / SINGLE_AREA_SIZE); clicked_Y = (int)(clicked_point.Y / SINGLE_AREA_SIZE); plane.Move_Plane(clicked_X, clicked_Y); if (plane.Is_Outbound(BLOCK_NUM - 1)) { return; } ClientInfo.game_status current_status = GameUtils.GetGameStatus(); if (current_status == ClientInfo.game_status.draw_plane) { max_selected_num = 3; if (selected_num < max_selected_num) { if (!Is_Overlapped()) { Show_Plane(clicked_X, clicked_Y, true); Set_Selected(); PlaneLocator planeLocator = new PlaneLocator(); Coordinate co1 = new Coordinate(); co1.X = clicked_X + plane.plane_shape[(int)plane.Direction][0].x; co1.Y = clicked_Y + plane.plane_shape[(int)plane.Direction][0].y; //Console.WriteLine("第一个坐标的x:" + co1.X.ToString() + ",第一个坐标的y:" + co1.Y.ToString()); Coordinate co2 = new Coordinate(); co2.X = clicked_X + plane.plane_shape[(int)plane.Direction][1].x; co2.Y = clicked_Y + plane.plane_shape[(int)plane.Direction][1].y; //Console.WriteLine("第二个坐标的x:" + co2.X.ToString() + ",第二个坐标的y:" + co2.Y.ToString()); Coordinate co3 = new Coordinate(); co3.X = clicked_X + plane.plane_shape[(int)plane.Direction][2].x; co3.Y = clicked_Y + plane.plane_shape[(int)plane.Direction][2].y; //Console.WriteLine("第三个坐标的x:" + co3.X.ToString() + ",第三个坐标的y:" + co3.Y.ToString()); planeLocator.Pos1 = co1; planeLocator.Pos2 = co2; planeLocator.Pos3 = co3; planeLocators.Add(planeLocator); selected_num++; if (selected_num == max_selected_num) { Submit_Button.Opacity = 1; Submit_Button.IsEnabled = true; } //Add_Plane_Chessboard(); } } // 已经选了三个飞机 else { MessageBox.Show("已经选完三架飞机的位置!"); return; } } else { return; } //bool send_status = network_model.Send_SingleCoordinate( // clicked_X, clicked_Y); }