상속: GameBase.AbstractStep
예제 #1
0
 public void ActivePlayerTest()
 {
     Register();
     Piece piece = new Piece(1, 1, 1, 1);
     QuartoStep step = new QuartoStep(0, 0, piece);
     DoStep(step, PlayerType.PlayerOne);
     QuartoStep step2 = new QuartoStep(1, 1, piece);
     DoStep(step, PlayerType.PlayerOne);
     Piece emptyPiece = new Piece();
     Assert.IsTrue((activeBoard.SelectedPiece).Equals(piece)  && activeBoard.CurrentPlayer == PlayerType.PlayerTwo && activeBoard.BBoard[1,1].Equals(emptyPiece));
 }
예제 #2
0
        public void GetAviableStepFull()
        {
            Register();

            Piece piece = new Piece(1, 0, 0, 0);

            QuartoStep step = new QuartoStep(1, 1, piece);

            DoStep(step, PlayerType.PlayerOne);

            IEnumerable<AbstractStep> lista = GetAvailableSteps(activeBoard);

            Assert.IsTrue(lista.ToList().Count == 16);
        }
예제 #3
0
        public void AfterWinStateInsertPieceTest()
        {
            Register();

            activeBoard.BBoard[0, 0].setPiece(1, 0, 1, 1);
            activeBoard.BBoard[0, 1].setPiece(1, 1, 0, 1);
            activeBoard.BBoard[1, 0].setPiece(1, 1, 1, 0);

            Piece piece = new Piece(1, 0, 0, 0);
            Piece piece2 = new Piece(0, 0, 0, 0);
            Piece emptyPiece = new Piece();

            QuartoStep step = new QuartoStep(1, 1, piece);
            QuartoStep step2 = new QuartoStep(2, 2, piece2);

            DoStep(step, PlayerType.PlayerOne);
            DoStep(step, PlayerType.PlayerTwo);
            DoStep(step2, PlayerType.PlayerTwo);
            DoStep(step2, PlayerType.PlayerOne);

            Assert.IsTrue(activeBoard.CurrentPlayer == PlayerType.NoOne && activeBoard.BBoard[2, 2].Equals(emptyPiece) && activeBoard.Winstate);
        }
예제 #4
0
        //A lehetséges lépések kiszámítása
        public override IEnumerable<AbstractStep> GetAvailableSteps(IState st)
        {
            try
            {
                Board  state = new Board((Board)st);
                List<QuartoStep> lista = new List<QuartoStep>();

                QuartoStep step;

                if (state.SelectedPiece != null )
                {
                    for (int j = 0; j < 4; j++)
                    {
                        for (int k = 0; k < 4; k++)
                        {
                            if (state.BBoard[j, k].color == 2)
                            {
                                step = new QuartoStep(j, k, state.SelectedPiece);
                                lista.Add(step);
                            }
                        }

                    }
                }
                else
                {
                    for (int i = 0; i < state.ActivePieces.Length; i++)
                    {
                        for (int j = 0; j < 4; j++)
                        {
                            for (int k = 0; k < 4; k++)
                            {
                                if (state.BBoard[j, k].color == 2)
                                {
                                    step = new QuartoStep(j, k, state.ActivePieces[i]);
                                    lista.Add(step);
                                }

                            }

                        }

                    }
                }

                return lista;
            }
            catch (Exception)
            {
                return new List<QuartoStep>();
            }
        }
예제 #5
0
        public void SimulateStepTest()
        {
            Register();

            Piece piece = new Piece(1, 0, 0, 0);
            QuartoStep step = new QuartoStep(1, 1, piece);

            IState st = SimulateStep(activeBoard, step);

            Assert.IsTrue(activeBoard.SelectedPiece == null && ((Board)st).SelectedPiece.Equals(piece));
        }
예제 #6
0
        public void InstertPieceTest()
        {
            Register();

            Piece piece = new Piece(1, 1, 1, 1);
            activeBoard.UpdateActivePieces(activeBoard.ActivePieces, piece);
            QuartoStep step = new QuartoStep(0, 0, piece);

            DoStep(step, PlayerType.PlayerOne);

             Assert.IsTrue(activeBoard.SelectedPiece == null && activeBoard.CurrentPlayer==PlayerType.PlayerOne);
        }
예제 #7
0
        public void InsertPieceNotEmptyFieldTest()
        {
            Register();

            Piece piece = new Piece(1, 1, 1, 1);
            Piece piece2 = new Piece(0, 0, 0, 0);

            QuartoStep step = new QuartoStep(0, 0, piece);
            QuartoStep step2 = new QuartoStep(1, 1, piece);
            QuartoStep step3 = new QuartoStep(1, 1, piece2);

            DoStep(step, PlayerType.PlayerOne);
            DoStep(step2, PlayerType.PlayerTwo);
            DoStep(step3, PlayerType.PlayerTwo);
            DoStep(step3, PlayerType.PlayerOne);

             Assert.IsTrue((activeBoard.SelectedPiece).Equals(piece2) && activeBoard.CurrentPlayer == PlayerType.PlayerOne && activeBoard.BBoard[1, 1].Equals(piece));
        }
        // Handles the clicks on the game area
        private void BtPut_Click(object sender, RoutedEventArgs e)
        {
            if (selection == -1) return;

            Button btn = (sender as Button);
            Image img = (btn.Content as Image);
            Int32 id = Convert.ToInt32(btn.Tag);
            img.Source = ImNext.Source;
            ImNext.Source = ImUnknown.Source;
            selection = -1;
            btn.IsEnabled = false;

            // Sends the step to the quatro object
            QuartoStep qs = new QuartoStep(id / 4, id % 4, null);
            quatro.DoStep(qs, iam);

            ShowNextEvent();

            foreach (Button b in area) { b.IsEnabled = false; }
            foreach (Button b in available) { b.IsEnabled = (b.Content as Image).Source != imageEmpty.Source; }
        }
        // Handles the clicks from the available pieces
        private void BtChoose_Click(object sender, RoutedEventArgs e)
        {
            if (selection != -1) return;

            Button btn = (sender as Button);
            Int32 id = Convert.ToInt32(btn.Tag);
            selection = id;
            ImNext.Source = (btn.Content as Image).Source;
            btn.Visibility = System.Windows.Visibility.Hidden;

            // Sends the step to the quatro object
            QuartoStep qs = new QuartoStep(0, 0, new Piece(id));
            quatro.DoStep(qs, iam);

            turns = 1 - turns;
            ShowNextEvent();

            foreach (Button b in area) { b.IsEnabled = false; }
            foreach (Button b in available) { b.IsEnabled = false; }
        }