private void RenderCountryInformation(CountryInfo country, string color) { var start = country.StateSpace.TopLeft; var end = country.StateSpace.BottomRight; var width = end.Column - start.Column + 1; var height = end.Row - start.Row; var infoComponents = Regex.Split(country.Name.ToString(), @"(?<!^)(?=[A-Z])").ToList(); // Regex splits by capital letter infoComponents[0] = $"{(int)country.Name}. {infoComponents[0]}"; infoComponents.Add($"{'\u2694'} {country.Armies.ToString().PadLeft(2, '0')}"); Console.ForegroundColor = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), color); var informationStart = new CoOrdinate ( start.Row + ((height + 1) / 2) - (infoComponents.Count / 2), start.Column + ((width - infoComponents.Max(e => e.Length)) / 2) ); foreach (var component in infoComponents) { Console.SetCursorPosition(informationStart.Column, informationStart.Row + infoComponents.FindIndex(e => e == component)); Console.Write(component); } // Consider handling this outside of the Render() method country.StateSpace.ArmyPosition = new CoOrdinate(Console.CursorTop, informationStart.Column + 2); }
public Piece Get(PieceType type, Color color, CoOrdinate coOrdinate) { switch (type) { case PieceType.Bishop: return(new Bishop(color, coOrdinate)); case PieceType.King: return(new King(color, coOrdinate)); case PieceType.Knight: return(new Knight(color, coOrdinate)); case PieceType.Pawn: return(new Pawn(color, coOrdinate)); case PieceType.Queen: return(new Queen(color, coOrdinate)); case PieceType.Rook: return(new Rook(color, coOrdinate)); default: throw new ArgumentException("Invalid type", type.GetType().Name); } }
private static void OffSetGridPosition(CoOrdinate coOrd, int xpos, int ypos, bool includeGridStart = true) { var x = GridLeftPos + (includeGridStart ? 1 : 0) + (coOrd.XCord * CellXOffset) + xpos; var y = GridTopPos + (includeGridStart ? 1 : 0) + (coOrd.YCord * CellYOffset) + ypos; Console.SetCursorPosition(x, y); }
public void TestExtremes() { CoOrdinate first = new CoOrdinate(0, 0); CoOrdinate last = new CoOrdinate(4, 4); Assert.IsTrue(first.Equals(CoOrdinate.FromIndex(0))); Assert.IsTrue(last.Equals(CoOrdinate.FromIndex(24))); }
public void TestCoordinate() { CoOrdinate co = new CoOrdinate(2, 2); Assert.AreEqual(12, co.Index); CoOrdinate co2 = new CoOrdinate(2, 2); Assert.IsTrue(co.Equals(co2)); Assert.IsTrue(co.Equals(CoOrdinate.FromIndex(12))); }
public void InitHandlers() { CoOrdinate currentRoom = new CoOrdinate(3, 3); RobotHardware.IHardwareRobot cleaningRobot = new RobotHardware.Hardware(currentRoom.X, currentRoom.Y); IRobotVisitMonitor robotVisitMonitor = RobotVisitMonitorFactory.CreateRobotVisitMonitor( RobotVisitMonitorType.RobotVisitMonitorWithConsoleOutput, cleaningRobot); Room room = new SimpleRoom(); _algorithmEssentials = new AlgorithmEssentials(room, cleaningRobot, robotVisitMonitor); _firstObstacleHandler = new ObstacleHandler(_algorithmEssentials); _obstacleHandlerWithCellRevisit = new ObstacleHandler(_algorithmEssentials, true); }
private void OnSecondClick(PieceButton currentPosition) { CoOrdinate toCoOrdinate = CoOrdinate.GetCoOrdinate(currentPosition.Name); //If the location to be moved is not empty or is not a valid move if (!_game.PlayTurn(_currentPlayerTurn, _currentSelectedPiece.Piece, toCoOrdinate)) { _messageFlashTimer.Enabled = false; MessageBox.Show(this, errorWrongMove); } else { RefreshChessBoard(); UpdateStateHistory(); CheckGameStatus(); } }
public void CircularCleaningAlgorithmOnSquareShapeTest() { // Define the min and max co-ordinate for the room _currentRoom = new CoOrdinate(3, 3); // Create the Robot _cleaningRobot = new RobotHardware.Hardware(_currentRoom.X, _currentRoom.Y); // Create the required robot visit monitor. Current visit monitor can print the robot path to console _robotVisitMonitor = RobotVisitMonitorFactory.CreateRobotVisitMonitor( RobotVisitMonitorType.RobotVisitMonitorWithConsoleOutput, _cleaningRobot); // Create a simple room _room = new SimpleRoom(); // Create the algorithm essentials with the above robot, visit monitor and room. _algorithmEssentials = new AlgorithmEssentials(_room, _cleaningRobot, _robotVisitMonitor); // Ask the CleaningAlgorithmFactory to create the CleaningAlgorithm instance by passing the required // required CleaningAlgorithmType _cleaningAlgorithm = CleaningAlgorithmFactory.CreateCleaningAlgorithm( CleaningAlgorithmType.CircularCleaningAlgorithm, _algorithmEssentials); Assert.AreEqual(CleanStatus.Complete, _cleaningAlgorithm.Clean()); Assert.AreEqual("Turn Left", _algorithmEssentials.RobotVisitMonitor.GetPathAt(0)); Assert.AreEqual("Turn Right", _algorithmEssentials.RobotVisitMonitor.GetPathAt(1)); Assert.AreEqual("Move Forward", _algorithmEssentials.RobotVisitMonitor.GetPathAt(2)); Assert.AreEqual("Move Forward", _algorithmEssentials.RobotVisitMonitor.GetPathAt(3)); Assert.AreEqual("Turn Right", _algorithmEssentials.RobotVisitMonitor.GetPathAt(4)); Assert.AreEqual("Move Forward", _algorithmEssentials.RobotVisitMonitor.GetPathAt(5)); Assert.AreEqual("Move Forward", _algorithmEssentials.RobotVisitMonitor.GetPathAt(6)); Assert.AreEqual("Turn Right", _algorithmEssentials.RobotVisitMonitor.GetPathAt(7)); Assert.AreEqual("Move Forward", _algorithmEssentials.RobotVisitMonitor.GetPathAt(8)); Assert.AreEqual("Move Forward", _algorithmEssentials.RobotVisitMonitor.GetPathAt(9)); Assert.AreEqual("Turn Right", _algorithmEssentials.RobotVisitMonitor.GetPathAt(10)); Assert.AreEqual("Move Forward", _algorithmEssentials.RobotVisitMonitor.GetPathAt(11)); Assert.AreEqual("Turn Right", _algorithmEssentials.RobotVisitMonitor.GetPathAt(12)); Assert.AreEqual("Move Forward", _algorithmEssentials.RobotVisitMonitor.GetPathAt(13)); Assert.AreEqual("Turn Right", _algorithmEssentials.RobotVisitMonitor.GetPathAt(14)); Assert.AreEqual("Turn Right", _algorithmEssentials.RobotVisitMonitor.GetPathAt(15)); Assert.AreEqual("Turn Right", _algorithmEssentials.RobotVisitMonitor.GetPathAt(16)); }
private void DrawChessBoard(History boardState) { ChessBoard.Controls.Clear(); for (int row = 0; row < this.ChessBoard.ColumnCount; row++) { for (int column = 0; column < this.ChessBoard.RowCount; column++) { CoOrdinate key = new CoOrdinate(row, column); PieceButton cellButton = CreateButton(row, column); Piece piece; if (boardState.LayOut.TryGetValue(key, out piece)) { cellButton.Image = piece.Image; } cellButton.Piece = piece; this.ChessBoard.Controls.Add(cellButton, row, column); } } }
public void CreateGrid(Grid grid) { GameObject CardsRoot = new GameObject("CardsRoot"); var cards = grid.GetCards(); //todo rework int x = 1, y = 1; for (int i = 0; i < columnLength * rowLength; i++) { var pos = new Vector3(x_Start + (x_space * (i % columnLength)), 0, y_start + (-y_space * (i / columnLength))); var cardObject = Instantiate(CardPrefab, pos, Quaternion.identity); CoOrdinate current = new CoOrdinate(x, y); cardObject.GetComponent <CardController>().RegisterCard(cards[current]); if (y == columnLength) { x++; y = 0; } y++; cardObject.transform.parent = CardsRoot.transform; } }
public void YouHitABombMessage(CoOrdinate coOrd) { DrawGrid(); OffSetGridPosition(new CoOrdinate(0, _sweeper.Height), 0, 5); Console.WriteLine("Oh NO it's a BOMB, hash tag Minesweep Fail!"); }
public GameCell(int xCord, int yCord) { CoOrd = new CoOrdinate(xCord, yCord); }