public void AddLand(Land land) { if (Lands.Any(lnd => lnd.Equals(land))) { return; } Lands.Add(land); }
private void RecalculatePositions() { if (IsPointingUp) { Land[] landsFromUpperLeftCorner = { Lands[((int)RotateAngle / 120 + 0) % 3], Lands[((int)RotateAngle / 120 + 1) % 3], Lands[((int)RotateAngle / 120 + 2) % 3], }; if (IsOnOddRow) { landsFromUpperLeftCorner[0].X = CurrentPositionX + 1; landsFromUpperLeftCorner[0].Y = CurrentPositionY - 1; landsFromUpperLeftCorner[1].X = CurrentPositionX; landsFromUpperLeftCorner[1].Y = CurrentPositionY; landsFromUpperLeftCorner[2].X = CurrentPositionX + 1; landsFromUpperLeftCorner[2].Y = CurrentPositionY; } else { landsFromUpperLeftCorner[0].X = CurrentPositionX; landsFromUpperLeftCorner[0].Y = CurrentPositionY - 1; landsFromUpperLeftCorner[1].X = CurrentPositionX; landsFromUpperLeftCorner[1].Y = CurrentPositionY; landsFromUpperLeftCorner[2].X = CurrentPositionX + 1; landsFromUpperLeftCorner[2].Y = CurrentPositionY; } } else { Land[] landsFromUpperLeftCorner = { Lands[((int)RotateAngle / 120 + 1) % 3], Lands[((int)RotateAngle / 120 + 0) % 3], Lands[((int)RotateAngle / 120 + 2) % 3], }; if (IsOnOddRow) { landsFromUpperLeftCorner[0].X = CurrentPositionX; landsFromUpperLeftCorner[0].Y = CurrentPositionY - 1; landsFromUpperLeftCorner[1].X = CurrentPositionX + 1; landsFromUpperLeftCorner[1].Y = CurrentPositionY - 1; landsFromUpperLeftCorner[2].X = CurrentPositionX; landsFromUpperLeftCorner[2].Y = CurrentPositionY; } else { landsFromUpperLeftCorner[0].X = CurrentPositionX; landsFromUpperLeftCorner[0].Y = CurrentPositionY - 1; landsFromUpperLeftCorner[1].X = CurrentPositionX + 1; landsFromUpperLeftCorner[1].Y = CurrentPositionY - 1; landsFromUpperLeftCorner[2].X = CurrentPositionX + 1; landsFromUpperLeftCorner[2].Y = CurrentPositionY; } } if (State != PlayingTileStateEnum.Passive) { //If there is no board tile under every land, PROBLEM if (Lands.Any(p => m_Board.BoardMatrix[p.X, p.Y] == null)) { State = PlayingTileStateEnum.ActiveProblem; } //If every land would be at the same level, it's a good start else if (Lands.Select(p => m_Board.BoardMatrix[p.X, p.Y].Lands.Count).Distinct().Count() == 1) { //If spaces are empty under every land, there is a chance it would be good if (Lands.All(p => !m_Board.BoardMatrix[p.X, p.Y].Lands.Any())) { // If this is the first tile, it's clearly CORRECT if (m_Board.NbPlayingTiles == 1) { State = PlayingTileStateEnum.ActiveCorrect; } // If this is not the first tile, there are some placement rules else { //We need to find at least 1 land that is touching one already on board foreach (var p in Lands) { var pIsOnOddRow = p.Y % 2 == 0; var points = new List <Point> { new Point(p.X - 1, p.Y), new Point(p.X + 1, p.Y), new Point(p.X, p.Y - 1), new Point(p.X, p.Y + 1), new Point(pIsOnOddRow ? p.X + 1 : p.X - 1, p.Y + 1), new Point(pIsOnOddRow ? p.X + 1 : p.X - 1, p.Y - 1), }; //If there is one land already on board touching the land, CORRECT if (points.Any(q => m_Board.BoardMatrix[(int)q.X, (int)q.Y] != null && m_Board.BoardMatrix[(int)q.X, (int)q.Y].Lands.Any())) { State = PlayingTileStateEnum.ActiveCorrect; return; } } //There was no land touching one already on the board, PROBLEM State = PlayingTileStateEnum.ActiveProblem; } } //There is same level land under each land, but they're all from the same tile, PROBLEM else if (Lands.Select(p => m_Board.BoardMatrix[p.X, p.Y].Lands.Last().ParentTile).Distinct().Count() == 1) { State = PlayingTileStateEnum.ActiveProblem; } //There is same level land under each land, and they're not all from the same tile, it's a good start else { // If volcano is over another volcano, CORRECT, or else it's a PROBLEM State = m_Board.BoardMatrix[Volcano.X, Volcano.Y].Lands.Last().LandType == LandEnum.Volcano ? PlayingTileStateEnum.ActiveCorrect : PlayingTileStateEnum.ActiveProblem; } } //All the lands are not at the same level, PROBLEM else { State = PlayingTileStateEnum.ActiveProblem; } } PositionChanged(); }