public void AttackPiece(GamePlayer player, List <GamePlayer> players, GameDice dice, int x) { if (x == 1) { foreach (GamePlayer thatPlayer in players) { if (thatPlayer.One.Position == player.One.Position && thatPlayer.Color != player.Color && thatPlayer.One.Position != 0 && thatPlayer.One.Position < 53) { thatPlayer.One.Position = 0; break; } else if (thatPlayer.Two.Position == player.One.Position && thatPlayer.Color != player.Color && thatPlayer.Two.Position != 0 && thatPlayer.Two.Position < 53) { thatPlayer.Two.Position = 0; break; } else if (thatPlayer.Three.Position == player.One.Position && thatPlayer.Color != player.Color && thatPlayer.Three.Position != 0 && thatPlayer.Three.Position < 53) { thatPlayer.Three.Position = 0; break; } else if (thatPlayer.Four.Position == player.One.Position && thatPlayer.Color != player.Color && thatPlayer.Four.Position != 0 && thatPlayer.Four.Position < 53) { thatPlayer.Four.Position = 0; break; } else if (thatPlayer.Two.Position == player.One.Position && thatPlayer.Color == player.Color && thatPlayer.Two.Position < 58) { if (player.One.Position == 40 && player.Color == "Red") { player.One.Position = 0; } else if (player.One.Position == 1 && player.Color == "Green") { player.One.Position = 0; } else if (player.One.Position == 14 && player.Color == "Blue") { player.One.Position = 0; } else if (player.One.Position == 27 && player.Color == "Yellow") { player.One.Position = 0; } else if (player.One.Position > 0) { player.One.Position -= dice.Value; } if (player.One.Position < 0) { player.One.Position = 0; } else if (player.One.Position == 0 && dice.Value == 6) { player.Turn = true; player.CanMove = true; player.CanThrow = false; break; } player.Turn = true; player.CanMove = true; player.CanThrow = false; break; } else if (thatPlayer.Three.Position == player.One.Position && thatPlayer.Color == player.Color && thatPlayer.Three.Position < 58) { if (player.One.Position == 40 && player.Color == "Red") { player.One.Position = 0; } else if (player.One.Position == 1 && player.Color == "Green") { player.One.Position = 0; } else if (player.One.Position == 14 && player.Color == "Blue") { player.One.Position = 0; } else if (player.One.Position == 27 && player.Color == "Yellow") { player.One.Position = 0; } else if (player.One.Position > 0) { player.One.Position -= dice.Value; } if (player.One.Position < 0) { player.One.Position = 0; } else if (player.One.Position == 0 && dice.Value == 6) { player.Turn = true; player.CanMove = true; player.CanThrow = false; break; } player.Turn = true; player.CanMove = true; player.CanThrow = false; break; } else if (thatPlayer.Four.Position == player.One.Position && thatPlayer.Color == player.Color && thatPlayer.Four.Position < 58) { if (player.One.Position == 40 && player.Color == "Red") { player.One.Position = 0; } else if (player.One.Position == 1 && player.Color == "Green") { player.One.Position = 0; } else if (player.One.Position == 14 && player.Color == "Blue") { player.One.Position = 0; } else if (player.One.Position == 27 && player.Color == "Yellow") { player.One.Position = 0; } else if (player.One.Position > 0) { player.One.Position -= dice.Value; } if (player.One.Position < 0) { player.One.Position = 0; } else if (player.One.Position == 0 && dice.Value == 6) { player.Turn = true; player.CanMove = true; player.CanThrow = false; break; } player.Turn = true; player.CanMove = true; player.CanThrow = false; break; } } } if (x == 2) { foreach (GamePlayer thatPlayer in players) { if (thatPlayer.One.Position == player.Two.Position && thatPlayer.Color != player.Color && thatPlayer.One.Position != 0 && thatPlayer.One.Position < 53) { thatPlayer.One.Position = 0; break; } else if (thatPlayer.Two.Position == player.Two.Position && thatPlayer.Color != player.Color && thatPlayer.Two.Position != 0 && thatPlayer.Two.Position < 53) { thatPlayer.Two.Position = 0; break; } else if (thatPlayer.Three.Position == player.Two.Position && thatPlayer.Color != player.Color && thatPlayer.Three.Position != 0 && thatPlayer.Three.Position < 53) { thatPlayer.Three.Position = 0; break; } else if (thatPlayer.Four.Position == player.Two.Position && thatPlayer.Color != player.Color && thatPlayer.Four.Position != 0 && thatPlayer.Four.Position < 53) { thatPlayer.Four.Position = 0; break; } else if (thatPlayer.One.Position == player.Two.Position && thatPlayer.Color == player.Color && thatPlayer.One.Position < 58) { if (player.Two.Position == 40 && player.Color == "Red") { player.Two.Position = 0; } else if (player.Two.Position == 1 && player.Color == "Green") { player.Two.Position = 0; } else if (player.Two.Position == 14 && player.Color == "Blue") { player.Two.Position = 0; } else if (player.Two.Position == 27 && player.Color == "Yellow") { player.Two.Position = 0; } else if (player.One.Position > 0) { player.Two.Position -= dice.Value; } if (player.Two.Position < 0) { player.Two.Position = 0; } else if (player.Two.Position == 0 && dice.Value == 6) { player.Turn = true; player.CanMove = true; player.CanThrow = false; break; } player.Turn = true; player.CanMove = true; player.CanThrow = false; break; } else if (thatPlayer.Three.Position == player.Two.Position && thatPlayer.Color == player.Color && thatPlayer.Three.Position < 58) { if (player.Two.Position == 40 && player.Color == "Red") { player.Two.Position = 0; } else if (player.Two.Position == 1 && player.Color == "Green") { player.Two.Position = 0; } else if (player.Two.Position == 14 && player.Color == "Blue") { player.Two.Position = 0; } else if (player.Two.Position == 27 && player.Color == "Yellow") { player.Two.Position = 0; } else if (player.One.Position > 0) { player.Two.Position -= dice.Value; } if (player.Two.Position < 0) { player.Two.Position = 0; } else if (player.Two.Position == 0 && dice.Value == 6) { player.Turn = true; player.CanMove = true; player.CanThrow = false; break; } player.Turn = true; player.CanMove = true; player.CanThrow = false; break; } else if (thatPlayer.Four.Position == player.Two.Position && thatPlayer.Color == player.Color && thatPlayer.Four.Position < 58) { if (player.Two.Position == 40 && player.Color == "Red") { player.Two.Position = 0; } else if (player.Two.Position == 1 && player.Color == "Green") { player.Two.Position = 0; } else if (player.Two.Position == 14 && player.Color == "Blue") { player.Two.Position = 0; } else if (player.Two.Position == 27 && player.Color == "Yellow") { player.Two.Position = 0; } else if (player.One.Position > 0) { player.Two.Position -= dice.Value; } if (player.Two.Position < 0) { player.Two.Position = 0; } else if (player.Two.Position == 0 && dice.Value == 6) { player.Turn = true; player.CanMove = true; player.CanThrow = false; break; } player.Turn = true; player.CanMove = true; player.CanThrow = false; break; } } } if (x == 3) { foreach (GamePlayer thatPlayer in players) { if (thatPlayer.One.Position == player.Three.Position && thatPlayer.Color != player.Color && thatPlayer.One.Position != 0 && thatPlayer.One.Position < 53) { thatPlayer.One.Position = 0; break; } else if (thatPlayer.Two.Position == player.Three.Position && thatPlayer.Color != player.Color && thatPlayer.Two.Position != 0 && thatPlayer.Two.Position < 53) { thatPlayer.Two.Position = 0; break; } else if (thatPlayer.Three.Position == player.Three.Position && thatPlayer.Color != player.Color && thatPlayer.Three.Position != 0 && thatPlayer.Three.Position < 53) { thatPlayer.Three.Position = 0; break; } else if (thatPlayer.Four.Position == player.Three.Position && thatPlayer.Color != player.Color && thatPlayer.Four.Position != 0 && thatPlayer.Four.Position < 53) { thatPlayer.Four.Position = 0; break; } else if (thatPlayer.One.Position == player.Three.Position && thatPlayer.Color == player.Color && thatPlayer.One.Position < 58) { if (player.Three.Position == 40 && player.Color == "Red") { player.Three.Position = 0; } else if (player.Three.Position == 1 && player.Color == "Green") { player.Three.Position = 0; } else if (player.Three.Position == 14 && player.Color == "Blue") { player.Three.Position = 0; } else if (player.Three.Position == 27 && player.Color == "Yellow") { player.Three.Position = 0; } else if (player.One.Position > 0) { player.Three.Position -= dice.Value; } if (player.Three.Position < 0) { player.Three.Position = 0; } else if (player.Three.Position == 0 && dice.Value == 6) { player.Turn = true; player.CanMove = true; player.CanThrow = false; break; } player.Turn = true; player.CanMove = true; player.CanThrow = false; break; } else if (thatPlayer.Two.Position == player.Three.Position && thatPlayer.Color == player.Color && thatPlayer.Two.Position < 58) { if (player.Three.Position == 40 && player.Color == "Red") { player.Three.Position = 0; } else if (player.Three.Position == 1 && player.Color == "Green") { player.Three.Position = 0; } else if (player.Three.Position == 14 && player.Color == "Blue") { player.Three.Position = 0; } else if (player.Three.Position == 27 && player.Color == "Yellow") { player.Three.Position = 0; } else if (player.One.Position > 0) { player.Three.Position -= dice.Value; } if (player.Three.Position < 0) { player.Three.Position = 0; } else if (player.Three.Position == 0 && dice.Value == 6) { player.Turn = true; player.CanMove = true; player.CanThrow = false; break; } player.Turn = true; player.CanMove = true; player.CanThrow = false; break; } else if (thatPlayer.Four.Position == player.Three.Position && thatPlayer.Color == player.Color && thatPlayer.Four.Position < 58) { if (player.Three.Position == 40 && player.Color == "Red") { player.Three.Position = 0; } else if (player.Three.Position == 1 && player.Color == "Green") { player.Three.Position = 0; } else if (player.Three.Position == 14 && player.Color == "Blue") { player.Three.Position = 0; } else if (player.Three.Position == 27 && player.Color == "Yellow") { player.Three.Position = 0; } else if (player.One.Position > 0) { player.Three.Position -= dice.Value; } if (player.Three.Position < 0) { player.Three.Position = 0; } else if (player.Three.Position == 0 && dice.Value == 6) { player.Turn = true; player.CanMove = true; player.CanThrow = false; break; } player.Turn = true; player.CanMove = true; player.CanThrow = false; break; } } } if (x == 4) { foreach (GamePlayer thatPlayer in players) { if (thatPlayer.One.Position == player.Four.Position && thatPlayer.Color != player.Color && thatPlayer.One.Position != 0 && thatPlayer.One.Position < 53) { thatPlayer.One.Position = 0; break; } else if (thatPlayer.Two.Position == player.Four.Position && thatPlayer.Color != player.Color && thatPlayer.Two.Position != 0 && thatPlayer.Two.Position < 53) { thatPlayer.Two.Position = 0; break; } else if (thatPlayer.Three.Position == player.Four.Position && thatPlayer.Color != player.Color && thatPlayer.Three.Position != 0 && thatPlayer.Three.Position < 53) { thatPlayer.Three.Position = 0; break; } else if (thatPlayer.Four.Position == player.Four.Position && thatPlayer.Color != player.Color && thatPlayer.Four.Position != 0 && thatPlayer.Four.Position < 53) { thatPlayer.Four.Position = 0; break; } else if (thatPlayer.One.Position == player.Four.Position && thatPlayer.Color == player.Color && thatPlayer.One.Position < 58) { if (player.Four.Position == 40 && player.Color == "Red") { player.Four.Position = 0; } else if (player.Four.Position == 1 && player.Color == "Green") { player.Four.Position = 0; } else if (player.Four.Position == 14 && player.Color == "Blue") { player.Four.Position = 0; } else if (player.Four.Position == 27 && player.Color == "Yellow") { player.Four.Position = 0; } else if (player.One.Position > 0) { player.Four.Position -= dice.Value; } if (player.Four.Position < 0) { player.Four.Position = 0; } else if (player.Four.Position == 0 && dice.Value == 6) { player.Turn = true; player.CanMove = true; player.CanThrow = false; break; } player.Turn = true; player.CanMove = true; player.CanThrow = false; break; } else if (thatPlayer.Two.Position == player.Four.Position && thatPlayer.Color == player.Color && thatPlayer.Two.Position < 58) { if (player.Four.Position == 40 && player.Color == "Red") { player.Four.Position = 0; } else if (player.Four.Position == 1 && player.Color == "Green") { player.Four.Position = 0; } else if (player.Four.Position == 14 && player.Color == "Blue") { player.Four.Position = 0; } else if (player.Four.Position == 27 && player.Color == "Yellow") { player.Four.Position = 0; } else if (player.One.Position > 0) { player.Four.Position -= dice.Value; } if (player.Four.Position < 0) { player.Four.Position = 0; } else if (player.Four.Position == 0 && dice.Value == 6) { player.Turn = true; player.CanMove = true; player.CanThrow = false; break; } player.Turn = true; player.CanMove = true; player.CanThrow = false; break; } else if (thatPlayer.Three.Position == player.Four.Position && thatPlayer.Color == player.Color && thatPlayer.Three.Position < 58) { if (player.Four.Position == 40 && player.Color == "Red") { player.Four.Position = 0; } else if (player.Four.Position == 1 && player.Color == "Green") { player.Four.Position = 0; } else if (player.Four.Position == 14 && player.Color == "Blue") { player.Four.Position = 0; } else if (player.Four.Position == 27 && player.Color == "Yellow") { player.Four.Position = 0; } else if (player.One.Position > 0) { player.Four.Position -= dice.Value; } if (player.Four.Position < 0) { player.Four.Position = 0; } else if (player.Four.Position == 0 && dice.Value == 6) { player.Turn = true; player.CanMove = true; player.CanThrow = false; break; } player.Turn = true; player.CanMove = true; player.CanThrow = false; break; } } } }
public GameRunner() { Dice = new GameDice(); Board = new GameBoard(); DbConnectionIsActive = true; }
public void MovePiece(GamePlayer player, GameDice dice, GamePiece piece) { if (player.Turn == true && player.CanMove == true) { if (player.Color == "Red") { if (piece.InPlay == true) { if (piece.Position == 0 && dice.Value == 6) { piece.Position = 40; } else if (piece.Position >= 40 && piece.Position <= 52) { piece.Position += dice.Value; if (piece.Position > 52) { int x = piece.Position - 52; piece.Position = 0; piece.Position += x; } } else if (piece.Position >= 1 && piece.Position <= 38) { piece.Position += dice.Value; if (piece.Position > 38) { int x = piece.Position - 38; piece.Position = 52; piece.Position += x; } } else if (piece.Position >= 53 && piece.Position <= 58) { piece.Position += dice.Value; } if (piece.Position > 58) { int x = ((piece.Position) - 58); piece.Position = (58 - x); } else if (piece.Position == 58) { //win condition piece.InPlay = false; } } } if (player.Color == "Green") { if (piece.InPlay == true) { if (piece.Position == 0 && dice.Value == 6) { piece.Position = 1; } else if (piece.Position >= 1 && piece.Position <= 51) { piece.Position += dice.Value; if (piece.Position >= 52) { int x = piece.Position - 51; piece.Position = 52; piece.Position += x; } } else if (piece.Position >= 53 && piece.Position <= 58) { piece.Position += dice.Value; } if (piece.Position > 58) { int x = ((piece.Position) - 58); piece.Position = (58 - x); } else if (piece.Position == 58) { //win condition piece.InPlay = false; } } } if (player.Color == "Yellow") { if (piece.InPlay == true) { if (piece.Position == 0 && dice.Value == 6) { piece.Position = 27; } else if (piece.Position >= 27 && piece.Position <= 52) { piece.Position += dice.Value; if (piece.Position > 52) { int x = piece.Position - 52; piece.Position = 0; piece.Position += x; } } else if (piece.Position >= 1 && piece.Position <= 25) { piece.Position += dice.Value; if (piece.Position > 25) { int x = piece.Position - 25; piece.Position = 52; piece.Position += x; } } else if (piece.Position >= 53 && piece.Position <= 58) { piece.Position += dice.Value; } if (piece.Position > 58) { int x = ((piece.Position) - 58); piece.Position = (58 - x); } else if (piece.Position == 58) { //win condition piece.InPlay = false; } } } if (player.Color == "Blue") { if (piece.InPlay == true) { if (piece.Position == 0 && dice.Value == 6) { piece.Position = 14; } else if (piece.Position >= 14 && piece.Position <= 52) { piece.Position += dice.Value; if (piece.Position > 52) { int x = piece.Position - 52; piece.Position = 0; piece.Position += x; } } else if (piece.Position >= 1 && piece.Position <= 12) { piece.Position += dice.Value; if (piece.Position > 12) { int x = piece.Position - 12; piece.Position = 52; piece.Position += x; } } else if (piece.Position >= 53 && piece.Position <= 58) { piece.Position += dice.Value; } if (piece.Position > 58) { int x = ((piece.Position) - 58); piece.Position = (58 - x); } else if (piece.Position == 58) { //win condition piece.InPlay = false; } } } } }