Exemple #1
0
        private void Play_Ground_Rival_MouseEnter(object sender, MouseEventArgs e)
        {
            mouse_is_left = false;
            Point reach_point = e.GetPosition(Play_Ground_Rival);
            int   reached_X   = (int)(reach_point.X / SINGLE_AREA_SIZE);
            int   reached_Y   = (int)(reach_point.Y / SINGLE_AREA_SIZE);

            current_X_Rival = reached_X;
            current_Y_Rival = reached_Y;
            ClientInfo.game_status current_status = GameUtils.GetGameStatus();
            if (current_status == ClientInfo.game_status.draw_plane)
            {
                return;
            }
            else if (current_status == ClientInfo.game_status.self_guessing)
            {
                if (is_bombing)
                {
                    Add_Block_Color(current_X_Rival, current_Y_Rival, Color.FromRgb(255, 0, 0), mouse_in_uid, false);
                }
                else
                {
                    plane.Move_Plane(current_X_Rival, current_Y_Rival);
                    Show_Plane(clicked_X_Rival, clicked_Y_Rival, false, false);
                }
            }
            else
            {
            }
        }
Exemple #2
0
        public MainWindow()
        {
            InitializeComponent();
            Left = SystemParameters.PrimaryScreenWidth - Width - 10;
            Top  = SystemParameters.PrimaryScreenHeight - Height - 80;
            WindowStartupLocation = WindowStartupLocation.CenterScreen;
            SINGLE_AREA_SIZE      = GAME_AREA_SIZE / BLOCK_NUM;
            PaintBoard(true);
            PaintBoard(false);
            InitPosition();

            Submit_Button.Opacity   = 0;
            Send_Button.Opacity     = 0;
            Submit_Button.IsEnabled = false;
            Send_Button.IsEnabled   = false;
            selected_uids.Add("selected_area_1");
            selected_uids.Add("selected_area_2");
            selected_uids.Add("selected_area_3");
            current_status = GameUtils.GetGameStatus();
            Thread gamestatus_listener = new Thread(Listen_Gamestatus_Change)
            {
                IsBackground = true
            };

            gamestatus_listener.Start();
            Thread chessboard_listener = new Thread(Listen_Chessboard)
            {
                IsBackground = true
            };

            chessboard_listener.Start();
            //int port = int.Parse(ConfigurationManager.AppSettings["network_port"]);
            //string ip = ConfigurationManager.AppSettings["network_ip"];
            //network_model = new NetworkModel(ip, port);
        }
Exemple #3
0
        private void MainWindow_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
            {
                // 游戏菜单
                EscPopup.IsOpen = !EscPopup.IsOpen;
            }
            if (e.Key == Key.R)
            {
                ClientInfo.game_status current_status = GameUtils.GetGameStatus();

                if (current_status == ClientInfo.game_status.draw_plane || (current_status == ClientInfo.game_status.self_guessing && !is_bombing))
                {
                    // 翻转飞机方向
                    plane.Rotate_Plane();
                    Refresh_Plane(mouse_is_left);
                }
            }
        }
Exemple #4
0
        private void Play_Ground_MouseEnter(object sender, MouseEventArgs e)
        {
            mouse_is_left = true;
            Point reach_point = e.GetPosition(Play_Ground);
            int   reached_X   = (int)(reach_point.X / SINGLE_AREA_SIZE);
            int   reached_Y   = (int)(reach_point.Y / SINGLE_AREA_SIZE);

            current_X = reached_X;
            current_Y = reached_Y;
            ClientInfo.game_status current_status = GameUtils.GetGameStatus();
            if (current_status == ClientInfo.game_status.draw_plane)
            {
                plane.Move_Plane(current_X, current_Y);
                Show_Plane(current_X, current_Y);
            }
            else
            {
                return;
            }
        }
Exemple #5
0
        private void Play_Ground_MouseMove(object sender, MouseEventArgs e)
        {
            Point reach_point = e.GetPosition(Play_Ground);
            int   reached_X   = (int)(reach_point.X / SINGLE_AREA_SIZE);
            int   reached_Y   = (int)(reach_point.Y / SINGLE_AREA_SIZE);

            if (reached_X == current_X && reached_Y == current_Y)
            {
                // 当前鼠标区域未发生改变
                return;
            }
            else
            {
                ClientInfo.game_status current_status = GameUtils.GetGameStatus();
                current_X = reached_X;
                current_Y = reached_Y;

                if (current_status == ClientInfo.game_status.draw_plane)
                {
                    plane.Move_Plane(current_X, current_Y);
                    Refresh_Plane();
                }
                //else if (current_status == ClientInfo.game_status.self_guessing)
                //{
                //    if (is_bombing)
                //    {
                //        Delete_Block_Color(mouse_in_uid);
                //        Add_Block_Color(current_X, current_Y, Color.FromRgb(255, 0, 0), mouse_in_uid);
                //    }
                //    else
                //    {
                //        plane.Move_Plane(current_X, current_Y);
                //        Refresh_Plane();
                //    }
                //}
                else
                {
                }
            }
        }
Exemple #6
0
 private void Play_Ground_Rival_MouseLeave(object sender, MouseEventArgs e)
 {
     ClientInfo.game_status current_status = GameUtils.GetGameStatus();
     if (current_status == ClientInfo.game_status.draw_plane)
     {
         return;
     }
     else if (current_status == ClientInfo.game_status.self_guessing)
     {
         if (is_bombing)
         {
             Delete_Block_Color(mouse_in_uid, false);
         }
         else
         {
             Delete_Plane(false);
         }
     }
     else
     {
     }
 }
Exemple #7
0
 private void Play_Ground_MouseLeave(object sender, MouseEventArgs e)
 {
     ClientInfo.game_status current_status = GameUtils.GetGameStatus();
     if (current_status == ClientInfo.game_status.draw_plane)
     {
         Delete_Plane();
     }
     //else if (current_status == ClientInfo.game_status.self_guessing)
     //{
     //    if (is_bombing)
     //    {
     //        Delete_Block_Color(mouse_in_uid);
     //    }
     //    else
     //    {
     //        Delete_Plane();
     //    }
     //}
     else
     {
     }
 }
Exemple #8
0
        private void Play_Ground_Rival_RightMouseDown(object sender, MouseButtonEventArgs e)
        {
            Point clicked_point = e.GetPosition(Play_Ground_Rival);

            clicked_X_Rival = (int)(clicked_point.X / SINGLE_AREA_SIZE);
            clicked_Y_Rival = (int)(clicked_point.Y / SINGLE_AREA_SIZE);
            plane.Move_Plane(clicked_X_Rival, clicked_Y_Rival);
            ClientInfo.game_status current_status = GameUtils.GetGameStatus();
            if (current_status == ClientInfo.game_status.self_guessing)
            {
                if (is_bombing)
                {
                    Delete_Block_Color(mouse_in_uid, false);
                    Show_Plane(clicked_X_Rival, clicked_Y_Rival, false, false);
                }
                else
                {
                    Delete_Plane(false);
                    Add_Block_Color(current_X_Rival, current_Y_Rival, Color.FromRgb(255, 0, 0), mouse_in_uid, false);
                }
                is_bombing = !is_bombing;
            }
        }
Exemple #9
0
 private bool is_game_starting(ClientInfo.game_status status)
 {
     if (current_status == ClientInfo.game_status.waiting_drawing && status == ClientInfo.game_status.self_guessing)
     {
         return(true);
     }
     else if (current_status == ClientInfo.game_status.draw_plane && status == ClientInfo.game_status.self_guessing)
     {
         return(true);
     }
     else if (current_status == ClientInfo.game_status.waiting_drawing && status == ClientInfo.game_status.rival_guessing)
     {
         return(true);
     }
     else if (current_status == ClientInfo.game_status.draw_plane && status == ClientInfo.game_status.rival_guessing)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #10
0
        private void Play_Ground_Rival_LeftMouseDown(object sender, MouseButtonEventArgs e)
        {
            Point clicked_point = e.GetPosition(Play_Ground_Rival);

            clicked_X_Rival = (int)((clicked_point.X) / SINGLE_AREA_SIZE);
            clicked_Y_Rival = (int)((clicked_point.Y) / SINGLE_AREA_SIZE);

            plane.Move_Plane(clicked_X_Rival, clicked_Y_Rival);


            ClientInfo.game_status current_status = GameUtils.GetGameStatus();
            if (current_status == ClientInfo.game_status.draw_plane)
            {
                return;
            }
            else if (current_status == ClientInfo.game_status.self_guessing)
            {
                if (is_bombing)
                {
                    //Delete_Block_Color(mouse_in_uid, false);
                    Delete_Plane(old_selected_guess_uids, false);
                    Delete_Block_Color(old_selected_bomb_uid, false);
                    Add_Block_Color(current_X_Rival, current_Y_Rival, Color.FromRgb(255, 0, 0), selected_uid, false);
                    old_selected_bomb_uid = selected_uid;
                    selected_coordinate.X = current_X_Rival;
                    selected_coordinate.Y = current_Y_Rival;
                    Send_Button.Opacity   = 1;
                    Send_Button.IsEnabled = true;
                }
                else
                {
                    if (plane.Is_Outbound(BLOCK_NUM - 1))
                    {
                        return;
                    }
                    //Delete_Plane(false);
                    Delete_Plane(old_selected_guess_uids, false);
                    Delete_Block_Color(old_selected_bomb_uid, false);
                    old_selected_guess_uids = Show_Plane(clicked_X_Rival, clicked_Y_Rival, true, false);
                    Coordinate co1 = new Coordinate();
                    co1.X = clicked_X_Rival + plane.plane_shape[(int)plane.Direction][0].x;
                    co1.Y = clicked_Y_Rival + 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_Rival + plane.plane_shape[(int)plane.Direction][1].x;
                    co2.Y = clicked_Y_Rival + 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_Rival + plane.plane_shape[(int)plane.Direction][2].x;
                    co3.Y = clicked_Y_Rival + plane.plane_shape[(int)plane.Direction][2].y;
                    //Console.WriteLine("第三个坐标的x:" + co3.X.ToString() + ",第三个坐标的y:" + co3.Y.ToString());
                    selected_planeLocator.Pos1 = co1;
                    selected_planeLocator.Pos2 = co2;
                    selected_planeLocator.Pos3 = co3;
                    Send_Button.Opacity        = 1;
                    Send_Button.IsEnabled      = true;
                }
            }
            else
            {
            }
            //bool send_status = network_model.Send_SingleCoordinate(
            //    clicked_X, clicked_Y);
        }
Exemple #11
0
        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);
        }
Exemple #12
0
        /// <summary>
        /// 根据本类存储的Chessboard和共有Chessboard的区别绘制棋盘
        /// </summary>
        /// <param name="is_left"></param>
        //public void Draw_Chessboard(bool is_left = true)
        //{
        //    if (is_left)
        //    {
        //        Thread.Sleep(100);
        //        //ChessBoard public_my_board = GameUtils.GetChessBoard(ChessBoard.whose_board.my_board);
        //        for (int i = 0; i < 10; i++)
        //        {
        //            for (int j = 0; j < 10; j++)
        //            {
        //                if (public_my_board.chessboard[i][j] != my_chessBoard.chessboard[i][j])
        //                {
        //                    my_chessBoard.chessboard[i][j] = public_my_board.chessboard[i][j];
        //                    Dispatcher.BeginInvoke(new Action(() =>
        //                    {
        //                        Draw_Point(j, i, public_my_board.chessboard[i][j], is_left);
        //                    }));
        //                }
        //            }
        //        }
        //    }
        //    else
        //    {
        //        Thread.Sleep(100);
        //        ChessBoard public_rival_board = GameUtils.GetChessBoard(ChessBoard.whose_board.rival_board);
        //        for (int i = 0; i < 10; i++)
        //        {
        //            for (int j = 0; j < 10; j++)
        //            {
        //                if (public_rival_board.chessboard[i][j] != my_chessBoard.chessboard[i][j])
        //                {
        //                    rival_chessBoard.chessboard[i][j] = public_rival_board.chessboard[i][j];
        //                    Dispatcher.BeginInvoke(new Action(() =>
        //                    {
        //                        Draw_Point(j, i, public_rival_board.chessboard[i][j], is_left);
        //                    }));
        //                }
        //            }
        //        }
        //    }
        //}
        /// <summary>
        /// 在一个单独的线程中监听游戏状态是否发生改变
        /// 控制某些UI发生改变
        /// </summary>
        private void Listen_Gamestatus_Change()
        {
            Console.WriteLine("监听游戏状态的线程已经开启...");
            while (true)
            {
                ClientInfo.game_status status = GameUtils.GetGameStatus();
                if (status == current_status)
                {
                    Thread.Sleep(500);
                    continue;
                }
                else
                {
                    Console.WriteLine("当前的游戏状态:" + status.ToString());
                    if (is_game_starting(status))
                    {
                        Dispatcher.BeginInvoke(new Action(() =>
                        {
                            Init_Game_Chessboard();
                        }));
                    }
                    current_status = status;

                    // 此处写状态改变后需要改变的UI
                    switch (status)
                    {
                    case ClientInfo.game_status.draw_plane:
                        Dispatcher.BeginInvoke(new Action(() =>
                        {
                            GameStatus.Text = "设定我方飞机位置";
                        }));
                        break;

                    case ClientInfo.game_status.rival_guessing:
                        Dispatcher.BeginInvoke(new Action(() =>
                        {
                            GameStatus.Text = "对方回合";
                        }));
                        break;

                    case ClientInfo.game_status.self_guessing:
                        Dispatcher.BeginInvoke(new Action(() =>
                        {
                            GameStatus.Text = "我方回合";
                        }));
                        break;

                    case ClientInfo.game_status.waiting:
                        Dispatcher.BeginInvoke(new Action(() =>
                        {
                            GameStatus.Text = "正在等待服务器响应";
                        }));
                        break;

                    case ClientInfo.game_status.waiting_drawing:
                        Dispatcher.BeginInvoke(new Action(() =>
                        {
                            GameStatus.Text = "等待对方指定飞机位置";
                        }));
                        break;

                    case ClientInfo.game_status.self_winning:
                        Dispatcher.BeginInvoke(new Action(() =>
                        {
                            GameStatus.Text = "我方获胜!";
                        }));
                        break;

                    case ClientInfo.game_status.rival_winning:
                        Dispatcher.BeginInvoke(new Action(() =>
                        {
                            GameStatus.Text = "对方获胜!";
                        }));
                        break;
                    }
                    Thread.Sleep(100);
                }
            }
        }
Exemple #13
0
        //public static void ClearChessBoard()
        //{

        //    ChessBoard clear_chessboard = new ChessBoard();
        //    ThreadPool.QueueUserWorkItem(delegate
        //    {
        //        SynchronizationContext.SetSynchronizationContext(new
        //          DispatcherSynchronizationContext(Application.Current.Dispatcher));
        //        SynchronizationContext.Current.Post(pl =>
        //        {
        //            //里面写真正的业务内容
        //            while (ClientInfo.my_chessboard.Count > 0)
        //                _ = ClientInfo.my_chessboard.TryDequeue(out _);
        //            while (ClientInfo.rival_chessboard.Count > 0)
        //                _ = ClientInfo.rival_chessboard.TryDequeue(out _);
        //            ClientInfo.my_chessboard.Enqueue(clear_chessboard);
        //            ClientInfo.rival_chessboard.Enqueue(clear_chessboard);
        //            //ClientInfo.my_chessboard.Clear();
        //            //ClientInfo.rival_chessboard.Clear();
        //            //ClientInfo.my_chessboard.Add(clear_chessboard);
        //            //ClientInfo.rival_chessboard.Add(clear_chessboard);
        //        }, null);
        //    });

        //}

        //public static void SetChessBoard(int x, int y, ChessBoard.whose_board whose, ChessBoard.point_state state, bool is_out = true)
        //{
        //    object thislock = new object();
        //    lock (thislock)
        //    {
        //        Console.WriteLine(x.ToString() + ":::" + y.ToString());
        //        if (whose == ChessBoard.whose_board.my_board)
        //        {
        //            ChessBoard chessBoard;
        //            if (ClientInfo.my_chessboard.Count == 0)
        //            {
        //                chessBoard = new ChessBoard();
        //            }
        //            else
        //                ClientInfo.my_chessboard.TryDequeue(out chessBoard);
        //            chessBoard.chessboard[y][x] = state;
        //            if (is_out)
        //                chessBoard.set_times++;
        //            ClientInfo.my_chessboard.Enqueue(chessBoard);
        //            Console.WriteLine("times: " + chessBoard.set_times.ToString());
        //        }
        //        else
        //        {
        //            ChessBoard chessBoard;
        //            if (ClientInfo.rival_chessboard.Count == 0)
        //                chessBoard = new ChessBoard();
        //            else
        //                ClientInfo.rival_chessboard.TryDequeue(out chessBoard);
        //            chessBoard.chessboard[y][x] = state;
        //            chessBoard.set_times++;
        //            ClientInfo.rival_chessboard.Enqueue(chessBoard);
        //            Console.WriteLine("times: " + chessBoard.set_times.ToString());
        //        }
        //    }

        //}

        //public static ChessBoard GetChessBoard(ChessBoard.whose_board whose)
        //{
        //    object thislock = new object();
        //    lock (thislock)
        //    {
        //        ChessBoard chessBoard;
        //        if (whose == ChessBoard.whose_board.my_board)
        //        {
        //            //while (ClientInfo.my_chessboard.Count == 0)
        //            //    Thread.Sleep(100);
        //            chessBoard = ClientInfo.my_chessboard.First();
        //            //ClientInfo.my_chessboard.TryDequeue(out chessBoard);
        //        }
        //        else
        //        {
        //            //while (ClientInfo.rival_chessboard.Count == 0)
        //            //    Thread.Sleep(100);
        //            chessBoard = ClientInfo.rival_chessboard.First();
        //        }
        //        return chessBoard;
        //    }

        //}

        public static void SetGameStatus(ClientInfo.game_status status)
        {
            _ = ClientInfo.current_gamestatus.TryDequeue(out _);
            ClientInfo.current_gamestatus.Enqueue(status);
        }