/// <summary> /// Initializes a new instance of the <see cref="PlayerCheckers"/> class. /// </summary> /// <param name="color">The piece color.</param> /// <param name="gameboard">The gameboard.</param> public PlayerCheckers(IPieceColor color, Gameboard gameboard) : base(color) { IPiece newPiece; int offset = 0, startPos = 0; this.gameboard = gameboard; this.moveCounter = 0; this.selectedPiece = null; if (color == IPieceColor.White) { offset = 5; startPos = 1; } else if (color == IPieceColor.Black) { offset = 0; startPos = 0; } for (int j = 0; j < 3; j++) { startPos = (++startPos) % 2; for (int i = startPos; i < 8; i += 2) { newPiece = new Man(color, gameboard, new Position(i, j + offset)); newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent); this.PieceList.Add(newPiece); } } }
/// <summary> /// Initializes a new instance of the <see cref="PlayerChess"/> class. /// </summary> /// <param name="color">The piece color.</param> /// <param name="gameboard">The gameboard.</param> public PlayerChess(IPieceColor color, Gameboard gameboard) : base(color) { IPiece newPiece; int offset = 0; this.gameboard = gameboard; this.selectedPiece = null; if (color == IPieceColor.White) { offset = 7; } else if (color == IPieceColor.Black) { offset = 0; } for (int i = 0; i < 8; i++) { newPiece = new Pawn(color, gameboard, new Position(i, Math.Abs(offset - 1))); newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent); this.PieceList.Add(newPiece); } newPiece = new Rook(color, gameboard, new Position(0, offset)); newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent); this.PieceList.Add(newPiece); newPiece = new Rook(color, gameboard, new Position(7, offset)); newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent); this.PieceList.Add(newPiece); newPiece = new Knight(color, gameboard, new Position(1, offset)); newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent); this.PieceList.Add(newPiece); newPiece = new Knight(color, gameboard, new Position(6, offset)); newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent); this.PieceList.Add(newPiece); newPiece = new Bishop(color, gameboard, new Position(2, offset)); newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent); this.PieceList.Add(newPiece); newPiece = new Bishop(color, gameboard, new Position(5, offset)); newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent); this.PieceList.Add(newPiece); newPiece = new Queen(color, gameboard, new Position(3, offset)); newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent); this.PieceList.Add(newPiece); newPiece = new King(color, gameboard, new Position(4, offset)); newPiece.GameEvent += new PieceEvent(this.Piece_GameEvent); this.PieceList.Add(newPiece); this.King = newPiece; }
/// <summary> /// Initializes a new instance of the <see cref="Bishop"/> class. /// </summary> /// <param name="color">The piece color.</param> /// <param name="gameboard">The gameboard.</param> /// <param name="position">The starting position.</param> public Bishop(IPieceColor color, Gameboard gameboard, Position position) : base(color, gameboard, position) { if (color == IPieceColor.Black) { this.Image = (Brush)App.Current.FindResource("BlackBishop"); } else if (color == IPieceColor.White) { this.Image = (Brush)App.Current.FindResource("WhiteBishop"); } this.Gameboard.MovePiece(position, this); }
/// <summary> /// Initializes a new instance of the <see cref="Pawn"/> class. /// </summary> /// <param name="color">The piece color.</param> /// <param name="gameboard">The gameboard.</param> /// <param name="position">The starting position.</param> public Pawn(IPieceColor color, Gameboard gameboard, Position position) : base(color, gameboard, position) { if (color == IPieceColor.Black) { this.Image = (Brush)App.Current.FindResource("BlackPawn"); } else if (color == IPieceColor.White) { this.Image = (Brush)App.Current.FindResource("WhitePawn"); } this.firstMove = true; this.Gameboard.MovePiece(position, this); }
/// <summary> /// Updates the clock. /// </summary> /// <param name="pieceColor">Color of the piece.</param> private void UpdateClock(IPieceColor pieceColor) { if (this.isClockActive) { if (this.ClockMode == ClockMode.Stopwatch) { if (pieceColor == IPieceColor.White) { this.clock1.Time = this.time1; } else { this.clock2.Time = this.time2; } } else if (this.ClockMode == ClockMode.Timer) { if (pieceColor == IPieceColor.White) { this.clock1.Time = this.timeLimit.Subtract(this.time1); if (this.time1 == TimeSpan.FromTicks(0)) { this.HandleTimeout(); } else if (this.currentColor == pieceColor) { if (this.time1 < TimeSpan.FromMinutes(1) && !this.led1.Flashing) { this.led1.Flash(); } else if (this.time1 >= TimeSpan.FromMinutes(1)) { this.led1.TurnOn(); } } } else { this.clock2.Time = this.timeLimit.Subtract(this.time2); if (this.time2 == TimeSpan.FromTicks(0)) { this.HandleTimeout(); } else if (this.currentColor == pieceColor) { if (this.time2 < TimeSpan.FromMinutes(1) && !this.led2.Flashing) { this.led2.Flash(); } else if (this.time2 >= TimeSpan.FromMinutes(1)) { this.led2.TurnOn(); } } } } } }
/// <summary> /// Toggles the player. /// </summary> public void TogglePlayer() { if (this.currentColor == IPieceColor.White) { this.currentColor = IPieceColor.Black; if (this.isClockActive) { this.led1.TurnOff(); if (this.clockMode == ClockMode.Timer && this.time2 < TimeSpan.FromMinutes(1)) { this.led2.Flash(); } else { this.led2.TurnOn(); } } } else { this.currentColor = IPieceColor.White; if (this.isClockActive) { this.led2.TurnOff(); if (this.clockMode == ClockMode.Timer && this.time1 < TimeSpan.FromMinutes(1)) { this.led1.Flash(); } else { this.led1.TurnOn(); } } } }
/// <summary> /// Resets the clock. /// </summary> public void ResetClock() { if (!this.isClockActive) { this.SetTimeLimit(this.time1); this.led1.TurnOff(); this.led2.TurnOff(); this.currentColor = IPieceColor.White; this.flag1.Fill = (Brush)App.Current.FindResource("RedFlagDown"); this.flag2.Fill = (Brush)App.Current.FindResource("RedFlagDown"); this.moveCounter1.ResetCounter(); this.moveCounter2.ResetCounter(); } }
/// <summary> /// Initializes a new instance of the <see cref="ChessPiece"/> class. /// </summary> /// <param name="color">The piece color.</param> /// <param name="gameboard">The gameboard.</param> /// <param name="position">The starting position.</param> public ChessPiece(IPieceColor color, Gameboard gameboard, Position position) : base(color, gameboard, position) { }
/// <summary> /// Initializes a new instance of the <see cref="King"/> class. /// </summary> /// <param name="color">The piece color.</param> /// <param name="gameboard">The gameboard.</param> /// <param name="position">The starting position.</param> public King(IPieceColor color, Gameboard gameboard, Position position) : base(color, gameboard, position) { this.SetImage(color); this.Gameboard.MovePiece(position, this); }
/// <summary> /// Sets the image. /// </summary> /// <param name="color">The color.</param> private void SetImage(IPieceColor color) { if (color == IPieceColor.Black) { this.Image = (Brush)App.Current.FindResource("BlackDraughtsKing"); } else if (color == IPieceColor.White) { this.Image = (Brush)App.Current.FindResource("WhiteDraughtsKing"); } }
/// <summary> /// Initializes a new instance of the <see cref="PieceBase"/> class. /// </summary> /// <param name="color">The piece color.</param> /// <param name="gameboard">The gameboard.</param> /// <param name="position">The starting position.</param> public PieceBase(IPieceColor color, Gameboard gameboard, Position position) { this.color = color; this.gameboard = gameboard; this.position = position; }