public Knight(Position pos, Side side, ChessField chessfield) : base(pos, side, chessfield) { FigureType = FigureTypes.Knight; movepolitics = new MovePolitics[] { chessfield.KnightMovePolitics}; }
public void ArrangeFigures(ChessField chessfield) { // расстановка на доске for (int i = 0; i < 8; i++) { alivefigures.Add(new Pawn(SidePosition(i, 1), side, chessfield)); } alivefigures.Add(new Rook(SidePosition(0, 0), side, chessfield)); alivefigures.Add(new Rook(SidePosition(7, 0), side, chessfield)); alivefigures.Add(new Knight(SidePosition(1, 0), side, chessfield)); alivefigures.Add(new Knight(SidePosition(6, 0), side, chessfield)); alivefigures.Add(new Bishop(SidePosition(2, 0), side, chessfield)); alivefigures.Add(new Bishop(SidePosition(5, 0), side, chessfield)); // король с ферзем ставяться зеркально Position pos = SidePosition(3, 0); // отображаем координату y если надо king = new King(new Position(4 + 1, pos.GetY()), side, chessfield); alivefigures.Add(king); alivefigures.Add(new Queen(new Position(3 + 1, pos.GetY()), side, chessfield)); foreach (Figure figure in alivefigures) { // устанавливаем обработчики figure.MoveEvent += chessfield.MoveFigureHandler; figure.KillEvent += KillFigureHandler; } this.chessfield = chessfield; shahsituation = false; }
public Pawn(Position pos, Side side, ChessField chessfield) : base(pos,side, chessfield) { FigureType = FigureTypes.Pawn; movepolitics = new MovePolitics[] { chessfield.VerticalMovePolitics}; attackpolitics = new MovePolitics[] { chessfield.DiagMovePolitics}; }
public Figure(Position pos, Side side, ChessField chessfield) { this.pos = pos; this.Side = side; this.chessfield = chessfield; hasmoved = false; }
public Bishop(Position pos, Side side, ChessField chessfield) : base(pos, side, chessfield) { FigureType = FigureTypes.Bishop; movepolitics = new MovePolitics[] { chessfield.DiagMovePolitics}; }
public void ArrangeFigures(ChessField chessfield) { // расстановка на доске for (int i = 0; i < 8; i++) alivefigures.Add(new Pawn(SidePosition(i, 1), side, chessfield)); alivefigures.Add(new Rook(SidePosition(0, 0), side, chessfield)); alivefigures.Add(new Rook(SidePosition(7, 0), side, chessfield)); alivefigures.Add(new Knight(SidePosition(1, 0), side, chessfield)); alivefigures.Add(new Knight(SidePosition(6, 0), side, chessfield)); alivefigures.Add(new Bishop(SidePosition(2, 0), side, chessfield)); alivefigures.Add(new Bishop(SidePosition(5, 0), side, chessfield)); // король с ферзем ставяться зеркально Position pos = SidePosition(3, 0); // отображаем координату y если надо king = new King(new Position(4 + 1, pos.GetY()), side, chessfield); alivefigures.Add(king); alivefigures.Add(new Queen(new Position(3+1, pos.GetY()), side, chessfield)); foreach (Figure figure in alivefigures) { // устанавливаем обработчики figure.MoveEvent += chessfield.MoveFigureHandler; figure.KillEvent += KillFigureHandler; } this.chessfield = chessfield; shahsituation = false; }
/// <summary> /// Новая игра /// </summary> public void NewGame() { gametype = GameType.LocalGame; this.player1 = CreateUser(view.GetUserName(Side.White), Side.White, player1); this.player2 = CreateUser(view.GetUserName(Side.Black), Side.Black, player2); //this.player1 = new Player("", Side.White); //this.player2 = new Player("", Side.Black); state = GameState.WaitWhite; Field = new ChessField(player1, player2); view.ClearLog(); view.ShowgbChessField(true); view.ShowrtbLog(true); view.EnableDefeat(true); view.EnableSave(true); view.EnableUndo(true); view.EnableNewGame(false); view.EnableNewLanGame(false); view.EnableLoad(false); view.ShowgbHUD(true); field.SetPawnSuperiousListener(PawnSuperiorityHandler); field.SetKingShahListener(KingShahHandler); field.SetKingStalemateListener(KingStalemateHandler); view.DrawField(); view.SetWhiteName(player1.Name); view.SetBlackName(player2.Name); view.WhiteCount(player1.GetCount()); view.BlackCount(player2.GetCount()); view.SetTurnText(); }
public Knight(Position pos, Side side, ChessField chessfield) : base(pos, side, chessfield) { FigureType = FigureTypes.Knight; movepolitics = new MovePolitics[] { chessfield.KnightMovePolitics }; }
public Bishop(Position pos, Side side, ChessField chessfield) : base(pos, side, chessfield) { FigureType = FigureTypes.Bishop; movepolitics = new MovePolitics[] { chessfield.DiagMovePolitics }; }
public Rook(Position pos, Side side, ChessField chessfield) : base(pos, side, chessfield) { FigureType = FigureTypes.Rook; movepolitics = new MovePolitics[] { chessfield.VerticalMovePolitics, chessfield.HorizontalMovePolitics}; }
public Rook(Position pos, Side side, ChessField chessfield) : base(pos, side, chessfield) { FigureType = FigureTypes.Rook; movepolitics = new MovePolitics[] { chessfield.VerticalMovePolitics, chessfield.HorizontalMovePolitics }; }
public List<Position> GetMoves(Figure figure, ChessField cf) { Position pos = figure.Position; List<Position> l = new List<Position>(); switch (figure.GetFigureType()) { case FigureTypes.King: { break; } } }
public List <Position> GetMoves(Figure figure, ChessField cf) { Position pos = figure.Position; List <Position> l = new List <Position>(); switch (figure.GetFigureType()) { case FigureTypes.King: { break; } } }
public MyList <Position> GetMoves(Figure figure, ChessField cf) { Position pos = figure.Position; MyList <Position> l = new MyList <Position>(); int x = pos.GetX(), y = pos.GetY(); try { l.Add(new Position(x + 1, y + 2)); } catch {} try { l.Add(new Position(x + 1, y + -2)); } catch { } try { l.Add(new Position(x - 1, y + 2)); } catch { } try { l.Add(new Position(x - 1, y - 2)); } catch { } try { l.Add(new Position(x + 2, y + 1)); } catch { } try { l.Add(new Position(x + 2, y - 1)); } catch { } try { l.Add(new Position(x - 2, y + 1)); } catch { } try { l.Add(new Position(x - 2, y - 1)); } catch { } return(l); }
public MyList<Position> GetMoves(Figure figure, ChessField cf) { Position pos = figure.Position; MyList<Position> l = new MyList<Position>(); int x = pos.GetX(), y = pos.GetY(); try { l.Add(new Position(x + 1, y + 2)); } catch{} try { l.Add(new Position(x + 1, y + -2)); } catch { } try { l.Add(new Position(x - 1, y + 2)); } catch { } try { l.Add(new Position(x - 1, y - 2)); } catch { } try { l.Add(new Position(x + 2, y + 1)); } catch { } try { l.Add(new Position(x + 2, y - 1)); } catch { } try { l.Add(new Position(x - 2, y +1)); } catch { } try { l.Add(new Position(x -2, y - 1)); } catch { } return l; }
public void NewServerGame() { gametype = GameType.ServerGame; this.player1 = CreateUser(view.GetUserName(Side.White), Side.White, player1); this.player2 = new Player("", Side.Black); //this.player1 = new Player("", Side.White); //this.player2 = new Player("", Side.Black); state = GameState.WaitWhite; Field = new ChessField(player1, player2); field.SetPawnSuperiousListener(PawnSuperiorityHandler); field.SetKingShahListener(KingShahHandler); field.SetKingStalemateListener(KingStalemateHandler); view.ClearLog(); server = new ServerThread(view, this); Thread thread = new Thread(server.Run); thread.Start(); thread.IsBackground = true; DialogResult dialogresult = view.ShowServerBanner(); if (dialogresult == DialogResult.Abort) { server.listener.Stop(); thread.Abort(); return; } //thread.Join(); view.ShowgbChessField(true); view.ShowrtbLog(true); view.EnableDefeat(true); view.EnableSave(true); view.EnableUndo(true); view.EnableNewGame(false); view.EnableNewLanGame(false); view.EnableLoad(false); view.ShowgbHUD(true); view.DrawField(); view.SetWhiteName(player1.Name); view.SetBlackName(player2.Name); view.WhiteCount(player1.GetCount()); view.BlackCount(player2.GetCount()); view.SetTurnText(); }
public MyList <Position> GetMoves(Figure figure, ChessField cf) { Position pos = figure.Position; MyList <Position> l = new MyList <Position>(); switch (figure.GetFigureType()) { case FigureTypes.King: { if (pos.GetX() > 1) { l.Add(new Position(pos.GetX() - 1, pos.GetY())); } if (pos.GetX() < 8) { l.Add(new Position(pos.GetX() + 1, pos.GetY())); } break; } default: // Bishop, Queen & etc. { // + for (int i = pos.GetX() + 1; i <= 8; i++) { l.Add(new Position(i, pos.GetY())); if (cf.GetFigureAt(new Position(i, pos.GetY())) != null) { break; } } // -- for (int i = pos.GetX() - 1; i > 0; i--) { l.Add(new Position(i, pos.GetY())); if (cf.GetFigureAt(new Position(i, pos.GetY())) != null) { break; } } break; } } return(l); }
public void NewClientGame() { gametype = GameType.ClientGame; this.player1 = new Player("", Side.White); this.player2 = CreateUser(view.GetUserName(Side.Black), Side.Black, player2); //this.player1 = new Player("", Side.White); //this.player2 = new Player("", Side.Black); state = GameState.WaitWhite; Field = new ChessField(player1, player2); field.SetPawnSuperiousListener(PawnSuperiorityHandler); field.SetKingShahListener(KingShahHandler); field.SetKingStalemateListener(KingStalemateHandler); view.ClearLog(); client = new ClientThread(view, this, view.GetServerAddress(), 12000); Thread thread = new Thread(client.Run); thread.Start(); thread.IsBackground = true; //thread.Join(); }
public MyList<Position> GetMoves(Figure figure, ChessField cf) { Position pos = figure.Position; MyList<Position> l = new MyList<Position>(); switch (figure.GetFigureType()) { case FigureTypes.King: { if (pos.GetX() >1) l.Add(new Position(pos.GetX()-1, pos.GetY())); if (pos.GetX() < 8) l.Add(new Position(pos.GetX()+1, pos.GetY())); break; } default: // Bishop, Queen & etc. { // + for (int i = pos.GetX() + 1; i <= 8; i++) { l.Add(new Position(i, pos.GetY())); if (cf.GetFigureAt(new Position(i, pos.GetY())) != null) break; } // -- for (int i = pos.GetX() - 1; i > 0; i--) { l.Add(new Position( i, pos.GetY())); if (cf.GetFigureAt(new Position( i, pos.GetY())) != null) break; } break; } } return l; }
public MyList <Position> GetMoves(Figure figure, ChessField cf) { Position pos = figure.Position, tmppos; MyList <Position> l = new MyList <Position>(); switch (figure.GetFigureType()) { case FigureTypes.Pawn: { if (figure.Side == Side.Black) { pos = figure.Reverse(pos); } if (pos.GetY() < 8) { if (pos.GetX() < 8) { tmppos = new Position(pos.GetX() + 1, pos.GetY() + 1); l.Add(figure.Side == Side.White ? tmppos : figure.Reverse(tmppos)); } if (pos.GetX() > 1) { tmppos = new Position(pos.GetX() - 1, pos.GetY() + 1); l.Add(figure.Side == Side.White ? tmppos : figure.Reverse(tmppos)); } } break; } case FigureTypes.King: { int x, y; x = pos.GetX(); y = pos.GetY(); if (x < 8) { if (y < 8) { l.Add(new Position(x + 1, y + 1)); } if (y > 1) { l.Add(new Position(x + 1, y - 1)); } } if (x > 1) { if (y < 8) { l.Add(new Position(x - 1, y + 1)); } if (y > 1) { l.Add(new Position(x - 1, y - 1)); } } break; } default: { for (int i = pos.GetX() + 1, j = pos.GetY() + 1; i <= 8 && j <= 8; i++, j++) { l.Add(new Position(i, j)); if (cf.GetFigureAt(new Position(i, j)) != null) { break; } } for (int i = pos.GetX() - 1, j = pos.GetY() - 1; i >= 1 && j >= 1; i--, j--) { l.Add(new Position(i, j)); if (cf.GetFigureAt(new Position(i, j)) != null) { break; } } for (int i = pos.GetX() + 1, j = pos.GetY() - 1; i <= 8 && j >= 1; i++, j--) { l.Add(new Position(i, j)); if (cf.GetFigureAt(new Position(i, j)) != null) { break; } } for (int i = pos.GetX() - 1, j = pos.GetY() + 1; i >= 1 && j <= 8; i--, j++) { l.Add(new Position(i, j)); if (cf.GetFigureAt(new Position(i, j)) != null) { break; } } break; } } return(l); }
public List <Position> GetMoves(Figure figure, ChessField cf) { throw new NotImplementedException(); }
public List<Position> GetMoves(Figure figure, ChessField cf) { throw new NotImplementedException(); }
public Pawn(Position pos, Side side, ChessField chessfield) : base(pos, side, chessfield) { FigureType = FigureTypes.Pawn; movepolitics = new MovePolitics[] { chessfield.VerticalMovePolitics }; attackpolitics = new MovePolitics[] { chessfield.DiagMovePolitics }; }
public MyList <Position> GetMoves(Figure figure, ChessField cf) { Position pos = figure.Position; Position tmppos; MyList <Position> l = new MyList <Position>(); switch (figure.GetFigureType()) { case FigureTypes.Pawn: { if (figure.Side == Side.Black) { pos = figure.Reverse(pos); } if (pos.GetY() == 2) { Position middlepos = new Position(pos.GetX(), pos.GetY() + 1); middlepos = figure.Side == Side.White ? middlepos : figure.Reverse(middlepos); if (cf.GetFigureAt(middlepos) == null) { tmppos = new Position(pos.GetX(), pos.GetY() + 2); l.Add(figure.Side == Side.White ? tmppos : figure.Reverse(tmppos)); } } int y = pos.GetY(); if (y + 1 < 9) { tmppos = new Position(pos.GetX(), y + 1); l.Add(figure.Side == Side.White ? tmppos : figure.Reverse(tmppos)); } break; } case FigureTypes.King: { if (pos.GetY() > 1) { l.Add(new Position(pos.GetX(), pos.GetY() - 1)); } if (pos.GetY() < 8) { l.Add(new Position(pos.GetX(), pos.GetY() + 1)); } break; } default: // Bishop, Queen & etc. { // + for (int i = pos.GetY() + 1; i <= 8; i++) { l.Add(new Position(pos.GetX(), i)); if (cf.GetFigureAt(new Position(pos.GetX(), i)) != null) { break; } } //-- for (int i = pos.GetY() - 1; i > 0; i--) { l.Add(new Position(pos.GetX(), i)); if (cf.GetFigureAt(new Position(pos.GetX(), i)) != null) { break; } } break; } } return(l); }
public MyList<Position> GetMoves(Figure figure, ChessField cf) { Position pos = figure.Position, tmppos; MyList<Position> l = new MyList<Position>(); switch (figure.GetFigureType()) { case FigureTypes.Pawn: { if (figure.Side == Side.Black) pos = figure.Reverse(pos); if (pos.GetY() < 8) { if (pos.GetX() < 8) { tmppos = new Position(pos.GetX()+1, pos.GetY()+1); l.Add(figure.Side == Side.White ? tmppos : figure.Reverse(tmppos)); } if (pos.GetX() > 1) { tmppos = new Position(pos.GetX()- 1, pos.GetY() + 1); l.Add(figure.Side == Side.White ? tmppos : figure.Reverse(tmppos)); } } break; } case FigureTypes.King: { int x,y; x = pos.GetX(); y = pos.GetY(); if (x<8) { if (y<8) l.Add(new Position(x+1,y+1)); if (y>1) l.Add(new Position(x+1,y-1)); } if (x>1) { if (y<8) l.Add(new Position(x-1,y+1)); if (y>1) l.Add(new Position(x-1, y-1)); } break; } default: { for (int i = pos.GetX()+1, j = pos.GetY()+1; i <= 8 && j <= 8; i++, j++) { l.Add(new Position(i, j)); if (cf.GetFigureAt(new Position(i, j)) != null) break; } for (int i = pos.GetX() - 1, j = pos.GetY() - 1; i >=1 && j >=1 ; i--, j--) { l.Add(new Position(i, j)); if (cf.GetFigureAt(new Position(i, j)) != null) break; } for (int i = pos.GetX() + 1, j = pos.GetY() - 1; i <= 8 && j >= 1; i++, j--) { l.Add(new Position(i, j)); if (cf.GetFigureAt(new Position(i, j)) != null) break; } for (int i = pos.GetX() -1, j = pos.GetY() + 1; i >= 1 && j <= 8; i--, j++) { l.Add(new Position(i, j)); if (cf.GetFigureAt(new Position(i, j)) != null) break; } break; } } return l; }
public MyList<Position> GetMoves(Figure figure, ChessField cf) { Position pos = figure.Position; Position tmppos; MyList<Position> l = new MyList<Position>(); switch (figure.GetFigureType()) { case FigureTypes.Pawn: { if (figure.Side == Side.Black) pos = figure.Reverse(pos); if (pos.GetY() == 2) { Position middlepos = new Position(pos.GetX(), pos.GetY()+1); middlepos = figure.Side == Side.White ? middlepos : figure.Reverse(middlepos); if (cf.GetFigureAt(middlepos) == null) { tmppos = new Position(pos.GetX(), pos.GetY() + 2); l.Add(figure.Side == Side.White ? tmppos : figure.Reverse(tmppos)); } } int y = pos.GetY(); if (y+1 <9) { tmppos = new Position(pos.GetX(), y+1); l.Add(figure.Side == Side.White ? tmppos : figure.Reverse(tmppos) ); } break; } case FigureTypes.King: { if (pos.GetY() >1) l.Add(new Position(pos.GetX(), pos.GetY()-1)); if (pos.GetY() < 8) l.Add(new Position(pos.GetX(), pos.GetY()+1)); break; } default: // Bishop, Queen & etc. { // + for (int i = pos.GetY() + 1; i <= 8; i++) { l.Add(new Position(pos.GetX(), i)); if (cf.GetFigureAt(new Position(pos.GetX(), i)) != null) break; } //-- for (int i = pos.GetY() - 1; i > 0; i--) { l.Add(new Position(pos.GetX(), i)); if (cf.GetFigureAt(new Position(pos.GetX(), i)) != null) break; } break; } } return l; }