Exemplo n.º 1
0
 public void WrongPlayer()
 {
     try
     {
         Game.Instance.Start("White Player", "Black Player", Board.BoardSize.Tournament);
         PiecePosition position = new PiecePosition(1, 2);
         Game.Instance.PutPiece(position, "Black Player", null);
         Assert.Fail();
     }
     catch(GameException exception)
     {
         Assert.AreEqual("You are not the current player.", exception.Message);
     }
     Game.Instance.Stop();
 }
Exemplo n.º 2
0
 public WhitePieceRepresentation(PiecePosition position, PictureBox gameBoard)
     : base(position, gameBoard)
 {
 }
Exemplo n.º 3
0
 public void FirstPosition()
 {
     position = new PiecePosition(1, 2);
     Assert.AreEqual(1, position.Row);
     Assert.AreEqual(2, position.Column);
 }
Exemplo n.º 4
0
 public PieceRepresentation(PiecePosition position, PictureBox gameBoard)
 {
     Size = new Size(19, 19);
     Location = new Point(5 + position.Row * 19, 5 + position.Column * 19);
     BackColor = Color.Transparent;
     this.gameBoard = gameBoard;
 }
Exemplo n.º 5
0
 // Constructors
 public Piece(GoInterface.PieceRepresentation pieceRepresentation, Army army, PiecePosition position)
 {
     this.army = army;
     this.pieceRepresentation = pieceRepresentation;
     this.position = position;
     if(army.LastPlay == position)
     {
         throw new PieceException(this, "Invalid place.");
     }
     int liberties = CheckNeighbours();
     if(!IsValidPosition(liberties))
     {
         RollbackChanges();
         throw new PieceException(this, "Invalid place.");
     }
     CommitChanges(liberties);
     army.LastPlay = position;
 }
Exemplo n.º 6
0
 public void PutPiece(PiecePosition position, String playerName, GoInterface.PieceRepresentation pieceRepresentation)
 {
     if(!started)
     {
         throw new GameException("Game is not started. Please start game before playing.");
     }
     if(!active.Name.Equals(playerName))
     {
         throw new GameException("You are not the current player.");
     }
     try
     {
         new Piece(pieceRepresentation, active.Army, position);
         active = (active == white? black: white);
     }
     catch(PieceException exception)
     {
         throw new GameException(exception.Message, exception);
     }
 }
Exemplo n.º 7
0
 public bool IsValidPosition(PiecePosition position)
 {
     return position.Row >= 0 && position.Row < board.GetLength(0) && position.Column >= 0 && position.Column < board.GetLength(1);
 }
Exemplo n.º 8
0
 // Properties
 public Piece this[PiecePosition position]
 {
     get { return board[position.Row, position.Column]; }
     set { board[position.Row, position.Column] = value; }
 }