} // Istance of a figure //payload for chooser response public Payload(bool error, string action, Figure f, coord pos) { this.startPos = pos; this.action = action; this.error = error; this.figure = f; }
//payload for chooser response public Payload(bool error, string action, Figure f, coord pos) { this.startPos = pos; this.action = action; this.error = error; this.figure = f; }
// Method that move figures in search of possible move private bool isDraw(Player player, coord start) { coord end = new coord(); if (this.getFieldFigureColor(start) == player.ToString()) { for (end.x = 0; end.x < this.size.x; end.x++) { for (end.y = 0; end.y < this.size.y; end.y++) { //move eache figure to each field if ((doEnPassant(player, start, end, true)) || (checkMove(player, start, end) && !isCheck(player, start, end))) { //Found possible move return(false); } } } } if (start.x < this.size.x - 1) { return(isDraw(player, new coord(start.x + 1, start.y))); } else if (start.y < this.size.y - 1) { return(isDraw(player, new coord(0, start.y + 1))); } return(true); }
// Method for En Passant private bool doEnPassant(Player player, coord start, coord end, bool tryOnly) { int direction; if (player.ToString() == "white") { direction = 1; } else { direction = -1; } if (this.getFieldFigureName(start) == "Pawn" && this.fields [start.x, start.y].color == player.ToString() && (start.x + 1 == end.x || start.x - 1 == end.x) && start.y + direction == end.y && this.getFieldFigureName(end.x, start.y) == "Pawn" && ((Pawn)this.fields [end.x, start.y]).justMoved && (this.getFieldFigureName(end.x, end.y) == "Empty")) { if (!tryOnly) { //do actual move this.removedFigures.Add(this.fields [end.x, end.y - direction]); this.fields [end.x, end.y - direction] = new Empty(); this.fields [end.x, end.y] = this.fields [start.x, start.y]; this.fields [start.x, start.y] = new Empty(); } return(true); } return(false); }
// Method that check if the player is in checkmate private bool isCheckMate(Player player, coord start) { bool res = true; for (int x = 0; x < this.size.x && res; x++) { for (int y = 0; y < this.size.y && res; y++) { coord end = new coord(x, y); if (checkMove(player, start, end)) { res = isCheck(player, start, end); //if res == false means that there is a possible move } } } if (res) { if (start.x < this.size.x - 1) { res = isCheckMate(player, new coord(start.x + 1, start.y)); } else if (start.y < this.size.y - 1) { res = isCheckMate(player, new coord(0, start.y + 1)); } } return(res); }
//payload for move command public Payload(bool error, string action, coord start, coord end) { this.startPos = start; this.endPos = end; this.action = action; this.error = error; }
/* Method for the movement of the bishop*/ public override bool move(Board board, coord start, coord end) { if (Math.Abs (start.x - end.x) == Math.Abs (start.y - end.y)) { coord tmp = start; while (!tmp.Equals (end)) { // Until tmp isn't equal to end coordinates: if (board.getFieldFigureName (tmp) != "Empty" && !tmp.Equals(start)) // If there is an object along trajectory return false; // movement isn't permitted if (tmp.x > end.x && tmp.y > end.y) { // If temp.x and temp.y are major than their end tmp.x--; //Decrement both tmp.y--; } if (tmp.x > end.x && tmp.y < end.y) { // or temp.x is major and temp.x is minor tmp.x--; // decrement x tmp.y++; // increment y } if (tmp.x < end.x && tmp.y > end.y) { // or temp.x is minor and temp.y is major tmp.x++; // increment x tmp.y--; // decrement y } if (tmp.x < end.x && tmp.y < end.y) { // or temp.x is minor and temp.y is minor tmp.x++; // Increment both tmp.y++; } } return true; // movement is allowed if there isn't an object along trajectory } return false; // If the movement isn't diagonal it isn't permitted }
// Method that describe what happen when a tile is clicked private void onTileClicked(object obj, ButtonPressEventArgs args) { if (((Gdk.EventButton)args.Event).Type == Gdk.EventType.ButtonPress) { TileWidget tile = (TileWidget)obj; //Console.WriteLine (tile.position.x + ", " + tile.position.y + " " + tile.color + " " + tile.figure); if (!this.clicked) { this.clickedPosition = new coord (tile.position.x, tile.position.y); if (this.callback (this.clickedPosition, this.clickedPosition)) { this.clicked = true; Fixed f = (Fixed)(tile.Child); Image circle = tile.loadCircle (this.tileSize); f.Add (circle); f.ShowAll (); } } else { //remove the ring whenn the user clicks agen on the same tile if (this.callback (this.clickedPosition, tile.position) && this.clickedPosition.Equals (tile.position)) { Fixed f = (Fixed)(tile.Child); if (f.Children.Length > 1) f.Remove (f.Children [1]); } this.clicked = false; } } }
// Method that describe what happen when a tile is clicked private void onTileClicked(object obj, ButtonPressEventArgs args) { if (((Gdk.EventButton)args.Event).Type == Gdk.EventType.ButtonPress) { TileWidget tile = (TileWidget)obj; //Console.WriteLine (tile.position.x + ", " + tile.position.y + " " + tile.color + " " + tile.figure); if (!this.clicked) { this.clickedPosition = new coord(tile.position.x, tile.position.y); if (this.callback(this.clickedPosition, this.clickedPosition)) { this.clicked = true; Fixed f = (Fixed)(tile.Child); Image circle = tile.loadCircle(this.tileSize); f.Add(circle); f.ShowAll(); } } else { //remove the ring whenn the user clicks agen on the same tile if (this.callback(this.clickedPosition, tile.position) && this.clickedPosition.Equals(tile.position)) { Fixed f = (Fixed)(tile.Child); if (f.Children.Length > 1) { f.Remove(f.Children [1]); } } this.clicked = false; } } }
private coord tileSize; // Size of a tile // Constructor public GridWidget(Game game, Cb callback, int scale) : base((uint)game.getSize().x, (uint)game.getSize().y, true) { this.callback = callback; this.clicked = false; this.game = game; this.tileSize = new coord(10 * scale, 10 * scale); }
/* Method for the movement of pawn */ public override bool move(Board board, coord start, coord end) { int direction; /* Int value for direction of movement */ /* If the color is white we have an increment of y(positive direction) else a decrement */ if (this.color == "white") { direction = 1; } else { direction = -1; } if (!this.hasMoved && start.x == end.x && start.y + (2 * direction) == end.y && board.getFieldFigureName (start.x, start.y + direction) == "Empty" && board.getFieldFigureName (start.x, start.y + (2 * direction)) == "Empty") return true; if (start.x == end.x && start.y + direction == end.y && board.getFieldFigureName (start.x, start.y + direction) == "Empty") return true; if ((start.x + 1 == end.x || start.x - 1 == end.x) && start.y + direction == end.y && board.getFieldFigureName (end) != "Empty") { return true; } return false; /* If the value of x and y are not corresponding to the rule the movement isn't allowed */ }
/* Method for the movement of knight */ public override bool move(Board board, coord start, coord end) { coord rule = new coord (1, 2); int x = rule.x; // x is setted to 1 int y = rule.y; // y is setted to 2 for (int i = 0; i < 2; i++) { if (i == 1) { // When i is equal to 1 x = rule.y; // x is setted to 2 y = rule.x; // and y is setted to 1 } if (start.x + x == end.x) { // If the movement on x is equal to starting position plus x if (start.y + y == end.y) { // and the movement on y is equal to starting position plus y return true; // movement is permitted } } if (start.x - x == end.x) { // If the movement on x is equal to starting position minus x if (start.y - y == end.y) { // and the movement on y is equal to starting position minus y return true; // movement is permitted } } if (start.x - x == end.x) { // If the movement on x is equal to starting position minus x if (start.y + y == end.y) { // and the movement on y is equal to starting position plus y return true; // movement is permitted } } if (start.x + x == end.x) { // If the movement on x is equal to starting position plus x if (start.y - y == end.y) { // and the movement on y is equal to starting position minus y return true; // movement is permitted } } } return false; // Other movement aren't permitted }
} // Instance of a figure // constructor public TileWidget(string colorBg, string figure, string color, coord size) { string imgName; if (color != "" && figure != "" && figure.ToLower() != "empty") { if (figure.ToLower() != "knight") { imgName = color.ToLower() [0].ToString() + figure.ToUpper() [0].ToString(); } else { imgName = color.ToLower() [0].ToString() + "N"; } Image img = loadSvg(imgName, size); Fixed f = new Fixed(); f.Add(img); f.ShowAll(); this.Add(f); this.Show(); } if (colorBg != "") { Gdk.Color col = new Gdk.Color(); Gdk.Color.Parse(colorBg, ref col); this.ModifyBg(StateType.Normal, col); } this.figure = figure; this.color = color; }
// Method for loading of the circle that inscribe the figure when it is clicked public Gtk.Image loadCircle(coord size) { string basePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase).Substring(5); Gdk.Pixbuf display = new Gdk.Pixbuf(basePath + @"/img/circle.svg", size.x, size.y); return(new Gtk.Image(display)); }
private coord tileSize; // Size of a tile #endregion Fields #region Constructors // Constructor public GridWidget(Game game, Cb callback, int scale) : base((uint)game.getSize ().x, (uint)game.getSize ().y, true) { this.callback = callback; this.clicked = false; this.game = game; this.tileSize = new coord (10 * scale, 10 * scale); }
private coord tileSize; // Size of tile #endregion Fields #region Constructors // Constructor public SidebarWidget(List<Figure> removedFigures, string color, int scale) { this.removedFigures = removedFigures; this.color = color; // Color of the sidebar's admitted figures updateSidebar (); this.WidthRequest = 5 * scale; this.tileSize = new coord (5 * scale, 5 * scale); }
/* Method for the movement of king */ public override bool move(Board board, coord start, coord end) { for (int x = (start.x == 0) ? 0 : start.x - 1; x <= start.x + 1; x++) { /* If the movement on x is between -1 and 1(included) */ for (int y = (start.y == 0) ? 0 : start.y - 1; y <= start.y + 1; y++) { /* if the movement on y is between -1 and 1(included) */ if (end.Equals (new coord (x, y))) /* and the end coordinates are updated */ return true; /* this method return a true value */ } } return false; /* If the value of x and y are not corresponding to the rule the movement isn't allowed */ }
private coord tileSize; // Size of tile // Constructor public SidebarWidget(List <Figure> removedFigures, string color, int scale) { this.removedFigures = removedFigures; this.color = color; // Color of the sidebar's admitted figures updateSidebar(); this.WidthRequest = 5 * scale; this.tileSize = new coord(5 * scale, 5 * scale); }
// Method for the movement of rock public override bool move(Board board, coord start, coord end) { // int x = this.rule.x; // int y = this.rule.y; if (start.x == end.x) // Check for the vertical movement { if (start.y < end.y) // If the end position is major than the starting position { for (int i = start.y + 1; i < end.y; i++) // Check for an object in this trajectory { if (board.getFieldFigureName(start.x, i) != "Empty") { return(false); // If there is one (not empty) movement isn't allowed } } } else // If the end position is minor than the starting position { for (int i = start.y - 1; i > end.y; i--) // Check for an object in this trajectory { if (board.getFieldFigureName(start.x, i) != "Empty") { return(false); // If there is one (not empty) movement isn't allowed } } } return(true); // If there aren't object movement is permitted } else if (start.y == end.y) // Check for the horizontal movement { if (start.x < end.x) // If the end position is major than the starting position { for (int i = start.x + 1; i < end.x; i++) // Check for an object in this trajectory { if (board.getFieldFigureName(i, start.y) != "Empty") { return(false); // If there is one (not empty) movement isn't allowed } } } else // If the end position is minor than the starting position { for (int i = start.x - 1; i > end.x; i--) // Check for an object in this trajectory { if (board.getFieldFigureName(i, start.y) != "Empty") { return(false); // If there is one (not empty) movement isn't allowed } } } return(true); // If there aren't object along trajectory movement is permitted } return(false); // If the movement isn't vertical or horizontal it isn't permitted }
//returns true if the move is possible //retruns false if the move is not possible private bool checkMove(Player player, coord start, coord end) { if ((this.fields [start.x, start.y].GetType().Name == "Empty") || (this.fields [start.x, start.y].color != player.ToString()) || (this.fields [end.x, end.y].color == player.ToString())) { return(false); } return(this.fields [start.x, start.y].move(this, start, end)); }
// Method for the opening of popup public void open(Player player, coord position) { close (); foreach (Figure fig in this.figures) { TileWidget tile = new TileWidget ("", fig.name (), player.ToString (), this.tileSize); tile.position = position; fig.color = player.ToString (); box.PackStart (tile); tile.ButtonPressEvent += onTileClicked; } this.ShowAll (); }
// Method that load images of figures public Gtk.Image loadSvg(string file, coord size) { Gdk.Pixbuf display; string basePath = System.IO.Path.GetDirectoryName (System.Reflection.Assembly.GetExecutingAssembly ().GetName ().CodeBase).Substring (5); try { display = new Gdk.Pixbuf (basePath + @"/img/cburnett/" + file + ".svg", size.x, size.y); } catch (GLib.GException e) { Console.WriteLine (e); display = null; } return (new Gtk.Image (display)); }
// Method for the opening of popup public void open(Player player, coord position) { close(); foreach (Figure fig in this.figures) { TileWidget tile = new TileWidget("", fig.name(), player.ToString(), this.tileSize); tile.position = position; fig.color = player.ToString(); box.PackStart(tile); tile.ButtonPressEvent += onTileClicked; } this.ShowAll(); }
// Method that load images of figures public Gtk.Image loadSvg(string file, coord size) { Gdk.Pixbuf display; string basePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase).Substring(5); try { display = new Gdk.Pixbuf(basePath + @"/img/cburnett/" + file + ".svg", size.x, size.y); } catch (GLib.GException e) { Console.WriteLine(e); display = null; } return(new Gtk.Image(display)); }
// constructor public Popup(Window parent, Figure[] f, Action <Figure, coord> callback, int scale) : base(Gtk.WindowType.Toplevel) { this.TransientFor = parent; this.SetPosition(Gtk.WindowPosition.CenterOnParent); this.Decorated = false; this.tileSize = new coord(10 * scale, 10 * scale); this.callback = callback; this.Title = "choose"; this.figures = f; this.box = new HBox(); this.Add(this.box); }
// Method for handling the click public bool clickHandler(coord start, coord end) { Message msg; if (start.Equals (end)) { msg = this.game.call(new Payload (false, "checkSelection", start)); } else { msg = this.game.call(new Payload(false, "move", start, end)); if (msg.action == "chooser") { this.chooser.open (msg.player, end); } updateGui (msg); } return !msg.error; }
// constructor public Popup(Window parent, Figure[] f, Action<Figure, coord> callback, int scale) : base(Gtk.WindowType.Toplevel) { this.TransientFor = parent; this.SetPosition (Gtk.WindowPosition.CenterOnParent); this.Decorated = false; this.tileSize = new coord (10 * scale, 10 * scale); this.callback = callback; this.Title = "choose"; this.figures = f; this.box = new HBox (); this.Add (this.box); }
/* Method for the movement of king */ public override bool move(Board board, coord start, coord end) { for (int x = (start.x == 0) ? 0 : start.x - 1; x <= start.x + 1; x++) /* If the movement on x is between -1 and 1(included) */ { for (int y = (start.y == 0) ? 0 : start.y - 1; y <= start.y + 1; y++) /* if the movement on y is between -1 and 1(included) */ { if (end.Equals(new coord(x, y))) /* and the end coordinates are updated */ { return(true); /* this method return a true value */ } } } return(false); /* If the value of x and y are not corresponding to the rule the movement isn't allowed */ }
//check if the king will be in check after this move and don't allow it if it is private bool isCheck(Player player, coord start, coord end) { coord king = new coord(); bool noKing = true; Figure removedObj = new Figure(); bool res = false; //move the figure to the new position if the new positon is not the same as the old if (!start.Equals(end)) { removedObj = this.fields [end.x, end.y]; this.fields [end.x, end.y] = this.fields [start.x, start.y]; this.fields [start.x, start.y] = new Empty(); } //search for the king on the board for (int x = 0; x < this.size.x; x++) { for (int y = 0; y < this.size.y; y++) { if (this.fields [x, y].color == player.ToString() && getFieldFigureName(new coord(x, y)) == "King") { king = new coord(x, y); noKing = false; } } } //if a king was found, try to move all figures to the position of the king,if that is possibile it means that the king is in check if (!noKing) { for (int x = 0; x < this.size.x && !res; x++) { for (int y = 0; y < this.size.y && !res; y++) { //if a move is posiblie means the king is checked if (checkMove(player.next(), new coord(x, y), king)) { res = true; } } } } //revert the move so that the state of the board is the same as at the start of this function if (!start.Equals(end)) { this.fields [start.x, start.y] = this.fields [end.x, end.y]; this.fields [end.x, end.y] = removedObj; } return(res); }
// Method for switching figures on the board public Message switchFigures(Figure figure, coord position) { Player player = new Player(getFieldFigureColor(position)); Message result = new Message(false, "", "", player); this.fields [position.x, position.y] = figure; if (isCheck(player.next())) { result.msg = "check"; if (isCheckMate(player.next(), new coord(0, 0))) { result.msg = "checkmate"; } } return(result); }
/* Method for the movement of knight */ public override bool move(Board board, coord start, coord end) { coord rule = new coord(1, 2); int x = rule.x; // x is setted to 1 int y = rule.y; // y is setted to 2 for (int i = 0; i < 2; i++) { if (i == 1) // When i is equal to 1 { x = rule.y; // x is setted to 2 y = rule.x; // and y is setted to 1 } if (start.x + x == end.x) // If the movement on x is equal to starting position plus x { if (start.y + y == end.y) // and the movement on y is equal to starting position plus y { return(true); // movement is permitted } } if (start.x - x == end.x) // If the movement on x is equal to starting position minus x { if (start.y - y == end.y) // and the movement on y is equal to starting position minus y { return(true); // movement is permitted } } if (start.x - x == end.x) // If the movement on x is equal to starting position minus x { if (start.y + y == end.y) // and the movement on y is equal to starting position plus y { return(true); // movement is permitted } } if (start.x + x == end.x) // If the movement on x is equal to starting position plus x { if (start.y - y == end.y) // and the movement on y is equal to starting position minus y { return(true); // movement is permitted } } } return(false); // Other movement aren't permitted }
// Method for handling the click public bool clickHandler(coord start, coord end) { Message msg; if (start.Equals(end)) { msg = this.game.call(new Payload(false, "checkSelection", start)); } else { msg = this.game.call(new Payload(false, "move", start, end)); if (msg.action == "chooser") { this.chooser.open(msg.player, end); } updateGui(msg); } return(!msg.error); }
// Constructor method public Board() { removedFigures = new List <Figure> (); int lineNumber = 1; // is 1 because the last line dosen't have a \n int lineLength = 0; for (int i = 0; i < layout.Length; i++) { if (layout [i] == '\n') { lineNumber++; } else { lineLength++; } }// End for lineLength /= lineNumber; //create array with the right size this.fields = new Figure[lineLength, lineNumber]; //save size this.size = new coord(lineLength, lineNumber); //fill up the array with the right figures int c = 0; for (int y = 0; y < lineNumber; y++) { for (int x = 0; x < lineLength; x++) { if (layout [c] == '\n') { c++; } this.fields [x, y] = figureLookup(layout [c]); c++; } // End second for } // End first for this.chooseableFigures = createChooseableFigures(); } // End board class
// Method for the movement of rock public override bool move(Board board, coord start, coord end) { // int x = this.rule.x; // int y = this.rule.y; if (start.x == end.x) { // Check for the vertical movement if (start.y < end.y) { // If the end position is major than the starting position for (int i = start.y + 1; i < end.y; i++) { // Check for an object in this trajectory if (board.getFieldFigureName (start.x, i) != "Empty") { return false; // If there is one (not empty) movement isn't allowed } } } else { // If the end position is minor than the starting position for (int i = start.y - 1; i > end.y; i--) { // Check for an object in this trajectory if (board.getFieldFigureName (start.x, i) != "Empty") { return false; // If there is one (not empty) movement isn't allowed } } } return true; // If there aren't object movement is permitted } else if (start.y == end.y) { // Check for the horizontal movement if (start.x < end.x) { // If the end position is major than the starting position for (int i = start.x + 1; i < end.x; i++) { // Check for an object in this trajectory if (board.getFieldFigureName (i, start.y) != "Empty") { return false; // If there is one (not empty) movement isn't allowed } } } else { // If the end position is minor than the starting position for (int i = start.x - 1; i > end.x; i--) { // Check for an object in this trajectory if (board.getFieldFigureName (i, start.y) != "Empty") { return false; // If there is one (not empty) movement isn't allowed } } } return true; // If there aren't object along trajectory movement is permitted } return false; // If the movement isn't vertical or horizontal it isn't permitted }
/* Method for the movement of the bishop*/ public override bool move(Board board, coord start, coord end) { if (Math.Abs(start.x - end.x) == Math.Abs(start.y - end.y)) { coord tmp = start; while (!tmp.Equals(end)) // Until tmp isn't equal to end coordinates: { if (board.getFieldFigureName(tmp) != "Empty" && !tmp.Equals(start)) // If there is an object along trajectory { return(false); // movement isn't permitted } if (tmp.x > end.x && tmp.y > end.y) // If temp.x and temp.y are major than their end { tmp.x--; //Decrement both tmp.y--; } if (tmp.x > end.x && tmp.y < end.y) // or temp.x is major and temp.x is minor { tmp.x--; // decrement x tmp.y++; // increment y } if (tmp.x < end.x && tmp.y > end.y) // or temp.x is minor and temp.y is major { tmp.x++; // increment x tmp.y--; // decrement y } if (tmp.x < end.x && tmp.y < end.y) // or temp.x is minor and temp.y is minor { tmp.x++; // Increment both tmp.y++; } } return(true); // movement is allowed if there isn't an object along trajectory } return(false); // If the movement isn't diagonal it isn't permitted }
// constructor public TileWidget(string colorBg, string figure, string color, coord size) { string imgName; if (color != "" && figure != "" && figure.ToLower () != "empty") { if (figure.ToLower () != "knight") { imgName = color.ToLower () [0].ToString () + figure.ToUpper () [0].ToString (); } else { imgName = color.ToLower () [0].ToString () + "N"; } Image img = loadSvg (imgName, size); Fixed f = new Fixed (); f.Add (img); f.ShowAll (); this.Add (f); this.Show (); } if (colorBg != "") { Gdk.Color col = new Gdk.Color (); Gdk.Color.Parse (colorBg, ref col); this.ModifyBg (StateType.Normal, col); } this.figure = figure; this.color = color; }
/* Method for the movement of pawn */ public override bool move(Board board, coord start, coord end) { int direction; /* Int value for direction of movement */ /* If the color is white we have an increment of y(positive direction) else a decrement */ if (this.color == "white") { direction = 1; } else { direction = -1; } if (!this.hasMoved && start.x == end.x && start.y + (2 * direction) == end.y && board.getFieldFigureName(start.x, start.y + direction) == "Empty" && board.getFieldFigureName(start.x, start.y + (2 * direction)) == "Empty") { return(true); } if (start.x == end.x && start.y + direction == end.y && board.getFieldFigureName(start.x, start.y + direction) == "Empty") { return(true); } if ((start.x + 1 == end.x || start.x - 1 == end.x) && start.y + direction == end.y && board.getFieldFigureName(end) != "Empty") { return(true); } return(false); /* If the value of x and y are not corresponding to the rule the movement isn't allowed */ }
// Method for handling the chooser public void handleChooser(Figure figure, coord position) { updateGui(this.game.call(new Payload(false, "switchFigures", figure, position))); }
// Method for loading of the circle that inscribe the figure when it is clicked public Gtk.Image loadCircle(coord size) { string basePath = System.IO.Path.GetDirectoryName (System.Reflection.Assembly.GetExecutingAssembly ().GetName ().CodeBase).Substring (5); Gdk.Pixbuf display = new Gdk.Pixbuf (basePath + @"/img/circle.svg", size.x, size.y); return (new Gtk.Image (display)); }
/* Method for the movement of the queen */ public override bool move(Board board, coord start, coord end) { // Diagonal movement if (Math.Abs (start.x - end.x) == Math.Abs (start.y - end.y)) { coord tmp = start; while (!tmp.Equals (end)) { // Until tmp isn't equal to end coordinates: if (board.getFieldFigureName (tmp) != "Empty" && !tmp.Equals(start)) // If there is an object along trajectory return false; // movement isn't permitted if (tmp.x > end.x && tmp.y > end.y) { // If temp.x and temp.y are major than their end tmp.x--; //Decrement both tmp.y--; } if (tmp.x > end.x && tmp.y < end.y) { // or temp.x is major and temp.x is minor tmp.x--; // decrement x tmp.y++; // increment y } if (tmp.x < end.x && tmp.y > end.y) { // or temp.x is minor and temp.y is major tmp.x++; // increment x tmp.y--; // decrement y } if (tmp.x < end.x && tmp.y < end.y) { // or temp.x is minor and temp.y is minor tmp.x++; // Increment both tmp.y++; } } return true; // movement is allowed if there isn't an object along trajectory } // Vertical and horizontal movement if (start.x == end.x) { // Check for the vertical movement if (start.y < end.y) { // If the end position is major than the starting position for (int i = start.y + 1; i < end.y; i++) { // Check for an object in this trajectory if (board.getFieldFigureName (start.x, i) != "Empty") { return false; // If there is one (not empty) movement isn't allowed } } } else { // If the end position is minor than the starting position for (int i = start.y - 1; i > end.y; i--) { // Check for an object in this trajectory if (board.getFieldFigureName (start.x, i) != "Empty") { return false; // If there is one (not empty) movement isn't allowed } } } return true; // If there aren't object movement is permitted } else if (start.y == end.y) { // Check for the horizontal movement if (start.x < end.x) { // If the end position is major than the starting position for (int i = start.x + 1; i < end.x; i++) { // Check for an object in this trajectory if (board.getFieldFigureName (i, start.y) != "Empty") { return false; // If there is one (not empty) movement isn't allowed } } } else { // If the end position is minor than the starting position for (int i = start.x - 1; i > end.x; i--) { // Check for an object in this trajectory if (board.getFieldFigureName (i, start.y) != "Empty") { return false; // If there is one (not empty) movement isn't allowed } } } return true; // If there aren't object along trajectory movement is permitted } return false; // Any other case different from movements horizontal,diagonal or vertical aren't permitted }
/* Method for the movement of the figure on the board */ public virtual bool move(Board board, coord start, coord end) { return true; }
// Method that get the color of the figure public string getFieldFigureColor(coord c) { return(getField(c).color); }
// Method for handling the chooser public void handleChooser(Figure figure, coord position) { updateGui (this.game.call (new Payload (false, "switchFigures", figure, position))); }
// Method that get the fields x and y from a coord object public Figure getField(coord c) { return(this.fields [c.x, c.y]); }
// Method for adding a figure to game private void addFigure(Widget w, coord pos) { this.Attach(w, (uint)pos.x, (uint)pos.x + 1, (uint)pos.y, (uint)pos.y + 1); }
// Method for adding a figure to game private void addFigure(Widget w, coord pos) { this.Attach (w, (uint)pos.x, (uint)pos.x + 1, (uint)pos.y, (uint)pos.y + 1); }
/* Method for the movement of the queen */ public override bool move(Board board, coord start, coord end) { // Diagonal movement if (Math.Abs(start.x - end.x) == Math.Abs(start.y - end.y)) { coord tmp = start; while (!tmp.Equals(end)) // Until tmp isn't equal to end coordinates: { if (board.getFieldFigureName(tmp) != "Empty" && !tmp.Equals(start)) // If there is an object along trajectory { return(false); // movement isn't permitted } if (tmp.x > end.x && tmp.y > end.y) // If temp.x and temp.y are major than their end { tmp.x--; //Decrement both tmp.y--; } if (tmp.x > end.x && tmp.y < end.y) // or temp.x is major and temp.x is minor { tmp.x--; // decrement x tmp.y++; // increment y } if (tmp.x < end.x && tmp.y > end.y) // or temp.x is minor and temp.y is major { tmp.x++; // increment x tmp.y--; // decrement y } if (tmp.x < end.x && tmp.y < end.y) // or temp.x is minor and temp.y is minor { tmp.x++; // Increment both tmp.y++; } } return(true); // movement is allowed if there isn't an object along trajectory } // Vertical and horizontal movement if (start.x == end.x) // Check for the vertical movement { if (start.y < end.y) // If the end position is major than the starting position { for (int i = start.y + 1; i < end.y; i++) // Check for an object in this trajectory { if (board.getFieldFigureName(start.x, i) != "Empty") { return(false); // If there is one (not empty) movement isn't allowed } } } else // If the end position is minor than the starting position { for (int i = start.y - 1; i > end.y; i--) // Check for an object in this trajectory { if (board.getFieldFigureName(start.x, i) != "Empty") { return(false); // If there is one (not empty) movement isn't allowed } } } return(true); // If there aren't object movement is permitted } else if (start.y == end.y) // Check for the horizontal movement { if (start.x < end.x) // If the end position is major than the starting position { for (int i = start.x + 1; i < end.x; i++) // Check for an object in this trajectory { if (board.getFieldFigureName(i, start.y) != "Empty") { return(false); // If there is one (not empty) movement isn't allowed } } } else // If the end position is minor than the starting position { for (int i = start.x - 1; i > end.x; i--) // Check for an object in this trajectory { if (board.getFieldFigureName(i, start.y) != "Empty") { return(false); // If there is one (not empty) movement isn't allowed } } } return(true); // If there aren't object along trajectory movement is permitted } return(false); // Any other case different from movements horizontal,diagonal or vertical aren't permitted }
/* Method for the movement of the figure on the board */ public virtual bool move (Board board, coord start, coord end) { return true; }
// Method for getting the color of the figure public string getFieldFigureColor(coord coord) { return(this.board.getFieldFigureColor(coord)); }