public void moveItem(GridSquare newGS) { //ensure that you are not jumping your own piece if ((new List<Status>() { Status.KingRed, Status.Red }.Contains(this.Occupied) && new List<Status>() { Status.KingRed, Status.Red }.Contains(newGS.Occupied)) || (new List<Status>() { Status.KingBlack, Status.Black }.Contains(this.Occupied) && new List<Status>() { Status.KingBlack, Status.Black }.Contains(newGS.Occupied))) { MessageBox.Show("You cannot Jump your own items"); } else { //change whos turn it will be Checkers.form.theGame.ColorTurn = this.Occupied == Status.Red || this.Occupied == Status.KingRed ? Game.Turn.BlackTurn : Game.Turn.RedsTurn; //make sure a red isnt landing on a red or a black isnt landing on a black if((new List<Status>() { Status.KingRed, Status.Red }.Contains(newGS.Occupied))){ if(newGS.Occupied == Status.KingRed) Checkers.form.theGame.BlackPoints += 2; else Checkers.form.theGame.BlackPoints++; doJump(newGS); } else if ((new List<Status>() { Status.KingBlack, Status.Black }.Contains(newGS.Occupied))) { if (newGS.Occupied == Status.KingBlack) Checkers.form.theGame.RedPoints += 2; else Checkers.form.theGame.RedPoints++; doJump(newGS); } else { newGS.Occupied = this.Occupied; this.Occupied = Status.Empty; } newGS.Draw(); this.Draw(); } }
public bool doJump(GridSquare newGS) { //place to object following the jump and change both the jumped and source square Point difference = new Point(this.Location.X - newGS.Location.X, this.Location.Y - newGS.Location.Y); Point newLocation = new Point(newGS.Location.X - difference.X, newGS.Location.Y - difference.Y); List<Control> allGS = Checkers.form.GetAll(Checkers.form, typeof(GridPanel)).ToList<Control>(); GridSquare discoveredGS = ((GridPanel)allGS.Where(x => (((GridPanel)x).GridSquareOwner).Location == newLocation).First() ).GridSquareOwner; if (discoveredGS.Occupied == Status.Empty) { //Form1.form.Controls.Remove(discoveredGS); discoveredGS.Occupied = getNewStatus(this.Occupied); this.Occupied = Status.Empty; newGS.Occupied = Status.Empty; //Form1.form.Controls.Add(discoveredGS); //check if landed on home, if so make king if (discoveredGS.Occupied == Status.Black && discoveredGS.Location.Y == defaultTileSize * (Checkers.gridSize - 1)) { discoveredGS.Occupied = Status.KingBlack; } else if (discoveredGS.Occupied == Status.Red && discoveredGS.Location.Y == 0) { discoveredGS.Occupied = Status.KingRed; } discoveredGS.Draw(); return true; } else { MessageBox.Show("You cannot jump a piece and land on another"); return false; } }