本文整理匯總了C#中Board.Contents方法的典型用法代碼示例。如果您正苦於以下問題:C# Board.Contents方法的具體用法?C# Board.Contents怎麽用?C# Board.Contents使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Board
的用法示例。
在下文中一共展示了Board.Contents方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Robbie_Can_Fail_To_Pickup_Rubbish
public void Robbie_Can_Fail_To_Pickup_Rubbish()
{
IDictionary<Situation, RobotAction> pickupStrategy = GetSimpleStrategy(RobotAction.PickUpCan);
Robot robbie = new Robot(pickupStrategy);
Board board = new Board(10, 10);
Point initialPos = new Point(0, 0);
board.AddElement(robbie, initialPos);
Assert.IsTrue(board.Contents(initialPos).Contains(robbie));
robbie.Act(board);
Assert.IsTrue(board.Contents(initialPos).Contains(robbie));
}
示例2: Element_Can_Be_Moved
public void Element_Can_Be_Moved()
{
var testElement = new TestBoardElement();
var board = new Board(10, 20);
Point position = new Point(5, 12);
board.AddElement(testElement, position);
board.Move(testElement, Board.Direction.North);
var expectedNewPosition = new Point(position.X - 1, position.Y);
Assert.IsFalse(board.Contents(position).Contains(testElement));
Assert.IsTrue(board.Contents(expectedNewPosition).Contains(testElement));
}
示例3: Robbie_Can_Do_Nothing
public void Robbie_Can_Do_Nothing()
{
IDictionary<Situation, RobotAction> stayPutStrategy = GetSimpleStrategy(RobotAction.StayPut);
Robot robbie = new Robot(stayPutStrategy);
Board board = new Board(10, 10);
Point initialPos = new Point(0, 0);
board.AddElement(robbie, initialPos);
Assert.IsTrue(board.Contents(initialPos).Contains(robbie));
robbie.Act(board);
Assert.IsTrue(board.Contents(initialPos).Contains(robbie));
}
示例4: BoardElement_Can_Be_Added_To_Board
public void BoardElement_Can_Be_Added_To_Board()
{
var testElement = new TestBoardElement();
var board = new Board(10, 20);
Point position = new Point(5, 12);
board.AddElement(testElement, position);
Assert.IsTrue(board.Contents(position).Contains(testElement));
}
示例5: BoardLitterer_Can_Randomly_Place_Rubbish_On_Board
public void BoardLitterer_Can_Randomly_Place_Rubbish_On_Board()
{
var board = new Board(100, 100);
var litterer = new BoardLitterer(0.5);
litterer.Litter(board);
int rubbishTotal = 0;
for (int x = 0; x < board.Width; x++)
for (int y = 0; y < board.Height; y++)
{
Assert.IsTrue(board.Contents(new Point(x, y)).Count() <= 1);
if (board.Contents(new Point(x,y)).Count() == 1)
{
++rubbishTotal;
}
}
Debug.Print("Rubbish count: {0}", rubbishTotal);
Assert.IsTrue(rubbishTotal > 4000 && rubbishTotal < 6000,
"Might fail on occasion, but is PROBABLY still working. Rerun test to check, if it failes.");
}
示例6: Robbie_Can_Hit_Wall
public void Robbie_Can_Hit_Wall()
{
IDictionary<Situation, RobotAction> moveNorthStrategy = GetSimpleStrategy(RobotAction.MoveNorth);
Robot robbie = new Robot(moveNorthStrategy);
Board board = new Board(10, 10);
Point initialPos = new Point(0, 0);
board.AddElement(robbie, initialPos);
robbie.Act(board);
Assert.IsTrue(board.Contents(initialPos).Contains(robbie));
}
示例7: NewBoard_Is_Correctly_Initialized
public void NewBoard_Is_Correctly_Initialized()
{
const int width = 70;
const int height = 80;
Board board = new Board(width, height);
Assert.AreEqual(width, board.Width);
Assert.AreEqual(height, board.Height);
for(int x=0; x<width; x++)
for (int y=0; y<height; y++)
Assert.IsTrue(board.Contents(new Point(x,y)).Count() == 0);
}
示例8: Robot_Can_Move
public void Robot_Can_Move()
{
IDictionary<Situation, RobotAction> alwaysMoveSouthStrategy = GetSimpleStrategy(RobotAction.MoveSouth);
Robot robbie = new Robot(alwaysMoveSouthStrategy);
Board board = new Board(10, 10);
Point initialPos = new Point(0, 0);
board.AddElement(robbie, initialPos);
robbie.Act(board);
Assert.IsFalse(board.Contents(initialPos).Contains(robbie));
Assert.IsTrue(board.Contents(initialPos + new Point(1, 0)).Contains(robbie));
}
示例9: GetContents
private Situation.BoardContents GetContents(Point pos, Board board)
{
if (!board.PointInsidePlayArea(pos)) return Situation.BoardContents.wall;
if (board.Contents(pos).OfType<Rubbish>().Any()) return Situation.BoardContents.can;
return Situation.BoardContents.empty;
}
示例10: TakeAction
private ActionResult TakeAction(RobotAction whatToDo, Board board)
{
try
{
switch (whatToDo)
{
case RobotAction.StayPut:
return ActionResult.DidNothing;
break;
case RobotAction.MoveEast:
{
board.Move(this, Board.Direction.East);
return ActionResult.SuccessfulMove;
break;
}
case RobotAction.MoveNorth:
{
board.Move(this, Board.Direction.North);
return ActionResult.SuccessfulMove;
break;
}
case RobotAction.MoveSouth:
{
board.Move(this, Board.Direction.South);
return ActionResult.SuccessfulMove;
break;
}
case RobotAction.MoveWest:
{
board.Move(this, Board.Direction.West);
return ActionResult.SuccessfulMove;
break;
}
case RobotAction.PickUpCan:
{
var pos = board.GetCurrentPosition(this);
var can = board.Contents(pos).OfType<Rubbish>().FirstOrDefault();
if (can == null) return ActionResult.TriedToPickupCanWhereThereWasNoCan;
Pickup(board, can);
return ActionResult.PickedUpCan;
break;
}
case RobotAction.MoveRandom:
{
var randomDirection = (Board.Direction) random.Next(0, 4);
board.Move(this, randomDirection);
return ActionResult.SuccessfulMove;
break;
}
default:
throw new ArgumentException("Nothing specified for action", "whatToDo");
}
} catch (InvalidMoveException e)
{
return ActionResult.HitWall;
}
}