Пример #1
0
 /// <summary>
 /// Permet de placer les pieces
 /// </summary>
 /// <param name="board">Le plateau</param>
 /// <param name="player">Le joueur</param>
 /// <param name="position">Position sur le plateau</param>
 protected override void placePiece(Board board, Player player, Position position)
 {
     if (position == Position.BAS)
     {
         board.getTile(0, board.SizeBoard / 2).Piece = new Piece(player);
         int cpt = board.SizeBoard - 3;
         place(0, cpt, player, board);
         cpt = 2;
         place(board.SizeBoard - 1, cpt, player, board);
     }
     else
     {
         for (int i = 0; i < board.SizeBoard; i++)
         {
             if (checkPlace(board, board.SizeBoard - 1, i))
             {
                 board.getTile(board.SizeBoard - 1, i).Piece = new Piece(player);
             }
             if (checkPlace(board, 0, i))
             {
                 board.getTile(0, i).Piece = new Piece(player);
             }
         }
     }
 }
Пример #2
0
        /// <summary>
        /// Verifie si un joueur a gagné
        /// </summary>
        /// <returns>
        ///     0 si pas de gagnant
        ///     1 si joueur 1 gagne
        ///     2 si joueuer 2 gagne
        /// </returns>
        public int verifyVictory()
        {
            int winner = 0;

            for (int i = 0; i < board.SizeBoard; i++)
            {
                if (board.getTile(0, i).hasPiece() && board.getTile(0, i).Piece.Player.Equals(p2) && board.getTile(0, i).Piece.hasBall())
                {
                    winner = 2;
                    break;
                }
            }

            if (winner == 0)
            {
                for (int i = 0; i < board.SizeBoard; i++)
                {
                    if (board.getTile(board.SizeBoard - 1, i).hasPiece() && board.getTile(board.SizeBoard - 1, i).Piece.Player.Equals(p1) && board.getTile(board.SizeBoard - 1, i).Piece.hasBall())
                    {
                        winner = 1;
                        break;
                    }
                }
            }
            if (winner != 0)
            {
                notifyEndGame(winner);
            }
            return(winner);
        }
Пример #3
0
        /// <summary>
        /// Permet de placer la balle
        /// </summary>
        /// <param name="board">Le plateau</param>
        /// <param name="player">Le joueur</param>
        /// <param name="position">Position sur le plateau</param>
        protected override void placeBall(Board board, Player player, Position position)
        {
            int    line = (position == Scenario.Position.HAUT) ? board.SizeBoard - 1 : 0;
            Random rand = new Random();

            board.getTile(line, rand.Next(board.SizeBoard)).Piece.Ball = player.Ball;
        }
Пример #4
0
        /// <summary>
        /// Place l'ensemble de pièces sur le plateau
        /// </summary>
        /// <param name="board">Le plateau</param>
        /// <param name="player">Le joueur</param>
        /// <param name="position">Position sur le plateau</param>
        protected override void placePiece(Board board, Player player, Position position)
        {
            int line = (position == Scenario.Position.HAUT) ? board.SizeBoard - 1 : 0;

            for (int i = 0; i < board.SizeBoard; i++)
            {
                board.getTile(line, i).Piece = new Piece(player);
            }
        }
Пример #5
0
        /// <summary>
        /// Met les Tiles possibles "Selected"
        /// </summary>
        /// <param name="board">Le plateau</param>
        /// <param name="move">Les coordonnées des destinations possibles de la balle</param>
        private void setSelectedPossibleTile(Board board, int[] move)
        {
            board.unSelectedAllTile();
            int i = 0;

            do
            {
                board.getTile(move[i], move[i + 1]).setSelected();
                i += 2;
            } while (i < 16 && move[i] != -1 && move[i] != -1);
        }
Пример #6
0
        /// <summary>
        /// Permet de jouer comme un humain
        /// </summary>
        /// <param name="board">Le plateau</param>
        private void playAsPlayer(Board board)
        {
            nbMove  = 0;
            canPlay = true;
            int[] moves = iaStrategy.play(board, this);
            int   i     = 0;

            while (i < Properties.NUMBERS_RES_API && moves[i] != -1)
            {
                Thread.Sleep(800);
                board.getTile(moves[i], moves[i + 1]).buildDecision();
                Thread.Sleep(800);
                board.getTile(moves[i + 2], moves[i + 3]).buildDecision();
                i = i + 4;
            }
            if (i < Properties.NUMBERS_RES_API)
            {
                endTurn();
            }
        }
Пример #7
0
        /// <summary>
        /// Placer des pieces sur une ligne dans les emplacements libres
        /// </summary>
        /// <param name="line">Ligne</param>
        /// <param name="cpt">Nombre de pieces</param>
        /// <param name="player">Joueur</param>
        /// <param name="board">Plateau</param>
        private void place(int line, int cpt, Player player, Board board)
        {
            Random rand = new Random();

            while (cpt != 0)
            {
                int col = rand.Next(board.SizeBoard);
                if (col != board.SizeBoard / 2 && checkPlace(board, line, col))
                {
                    board.getTile(line, col).Piece = new Piece(player);
                    cpt--;
                }
            }
        }
Пример #8
0
 /// <summary>
 /// Initialisation du board
 /// </summary>
 /// <param name="game">Le jeu</param>
 private void setUpBoard(Diaballik.Game game)
 {
     for (int i = 0; i < b.SizeBoard; i++)
     {
         for (int j = 0; j < b.SizeBoard; j++)
         {
             Tile     t  = b.getTile(i, j);
             TileView tV = new TileView(t, game);
             Grid.SetRow(tV, i);
             Grid.SetColumn(tV, j);
             this.gridBoard.Children.Add(tV);
         }
     }
 }
Пример #9
0
        /// <summary>
        /// Place la balle
        /// </summary>
        /// <param name="board">Le plateau.</param>
        /// <param name="player">Le joueur.</param>
        /// <param name="position">La position.<see cref="Diaballik.Scenario.Position"/></param>
        protected override void placeBall(Board board, Player player, Position position)
        {
            int line = (position == Scenario.Position.HAUT) ? board.SizeBoard - 1 : 0;

            board.getTile(line, board.SizeBoard / 2).Piece.Ball = player.Ball;
        }
Пример #10
0
 /// <summary>
 /// Verifie si une piece est sur l'emplacement
 /// </summary>
 /// <param name="board">Le plateau</param>
 /// <param name="line">La ligne</param>
 /// <param name="column">La colonne</param>
 /// <returns></returns>
 private bool checkPlace(Board board, int line, int column)
 {
     return(!board.getTile(line, column).hasPiece());
 }