コード例 #1
0
        //returns true if game is over
        public override bool Clicked(SeaSquare square, bool automated)
        {
            if (automated)
            {
                _humanPlayer.ZmienTure(_computerPlayer);
            }
            else
            {
                if (square.Type != TypPowierzchni.Unknown)
                {
                    MessageBox.Show("Please choose a new square");
                    return(false);
                }

                _humanPlayer.ZmienTure(square.Rzad, square.Kolumna, _computerPlayer);
            }

            if (_computerPlayer.NoShipsSadFace() && _computerPlayer.NoVehiclesSadFace() && _computerPlayer.NoPlanesSadFace())
            {
                MessageBox.Show("You win!");
                return(true);
            }
            else
            {
                _computerPlayer.ZmienGracza(_humanPlayer);
                if (_humanPlayer.NoShipsSadFace() && _humanPlayer.NoVehiclesSadFace() && _humanPlayer.NoPlanesSadFace())
                {
                    MessageBox.Show("You lose :(");
                    return(true);
                }
            }

            return(false);
        }
コード例 #2
0
ファイル: ComputerGridVM.cs プロジェクト: nisodic/battleship
        //returns true if game is over
        public override bool Clicked(SeaSquare square, bool automated)
        {
            if (automated)
            {
                _humanPlayer.TakeTurnAutomated(_computerPlayer);
            }
            else
            {
                if (square.Type != SquareType.Unknown)
                {
                    MessageBox.Show("Please choose a new square");
                    return(false);
                }

                _humanPlayer.TakeTurn(square.Row, square.Col, _computerPlayer);
            }

            if (_computerPlayer.NoShipsSadFace())
            {
                MessageBox.Show("You win!");
                return(true);
            }
            else
            {
                _computerPlayer.TakeTurn(_humanPlayer);
                if (_humanPlayer.NoShipsSadFace())
                {
                    MessageBox.Show("You lose :(");
                    return(true);
                }
            }

            return(false);
        }
コード例 #3
0
        private void Item_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            GridVMBase  vm      = this.DataContext as GridVMBase;
            ListBoxItem item    = sender as ListBoxItem;
            SeaSquare   content = item.Content as SeaSquare;

            //XXX sometimes if you click really fast you can end up clicking on what the debugger says is a "ListBoxItem {DisconnectedItem}
            //hunting down the exact cause would take ages, and might even be a bug in WPF or something
            if (content == null)
            {
                return;
            }

            vm.Clicked(content);
        }
コード例 #4
0
ファイル: HumanGridVM.cs プロジェクト: Przegrywer/NJPO2
 public override bool Clicked(SeaSquare content, bool automated)
 {
     return(false);
 }
コード例 #5
0
ファイル: GridVMBase.cs プロジェクト: Przegrywer/NJPO2
 public abstract bool Clicked(SeaSquare content, bool automated = false);