本文整理汇总了C#中Playfield类的典型用法代码示例。如果您正苦于以下问题:C# Playfield类的具体用法?C# Playfield怎么用?C# Playfield使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Playfield类属于命名空间,在下文中一共展示了Playfield类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrintTable
public static void PrintTable(Playfield playfield)
{
string columnHeader = " ";
for (int i = 0; i < playfield.Width; i++)
{
columnHeader += i.ToString().PadLeft(3);
}
Console.WriteLine(columnHeader);
Console.WriteLine(" " + new String('-', playfield.Width * 3));
for (int row = 0; row < playfield.Height; row++)
{
Console.Write(row.ToString().PadLeft(2) + " | ");
for (int col = 0; col < playfield.Width; col++)
{
Console.Write(playfield.Field[row, col].ToString().PadLeft(2) + " ");
}
Console.WriteLine("| ");
}
Console.WriteLine(" " + new String('-', playfield.Width * 3));
}
示例2: TestRenderFieldGrid_PlayerAtStartPosition
public void TestRenderFieldGrid_PlayerAtStartPosition()
{
int[,] labyrinthGrid = new int[7, 7]
{
{0, 0, 1, 1, 0, 1, 1},
{1, 1, 1, 0, 0, 0, 1},
{0, 0, 0, 0, 1, 0, 0},
{1, 0, 1, 0, 1, 1, 1},
{1, 0, 0, 1, 0, 0, 0},
{1, 0, 1, 0, 0, 1, 1},
{1, 0, 0, 1, 0, 1, 0}
};
Playfield playfield = new Playfield(labyrinthGrid);
string actualOutput = Renderer.RenderField(playfield.LabyrinthGrid,
playfield.PlayerPosition.Row, playfield.PlayerPosition.Col);
StringBuilder expectedOutput = new StringBuilder();
expectedOutput.AppendLine("--XX-XX");
expectedOutput.AppendLine("XXX---X");
expectedOutput.AppendLine("----X--");
expectedOutput.AppendLine("X-X*XXX");
expectedOutput.AppendLine("X--X---");
expectedOutput.AppendLine("X-X--XX");
expectedOutput.AppendLine("X--X-X-");
bool areEqual = actualOutput == expectedOutput.ToString();
Assert.IsTrue(areEqual);
}
示例3: TestIsValidMove_CanMoveDown
public void TestIsValidMove_CanMoveDown()
{
int[,] labyrinthGrid = new int[7, 7]
{
{0, 1, 1, 0, 1, 1, 1},
{0, 0, 0, 0, 0, 0, 1},
{1, 0, 1, 0, 1, 0, 1},
{1, 0, 1, 0, 1, 0, 0},
{0, 1, 1, 1, 1, 1, 0},
{0, 0, 1, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0}
};
Playfield playfield = new Playfield(labyrinthGrid);
//Moving playerPosition at row=5 and col=2
playfield.PlayerPosition.MoveAtDirection(Direction.Up);
playfield.PlayerPosition.MoveAtDirection(Direction.Up);
playfield.PlayerPosition.MoveAtDirection(Direction.Right);
playfield.PlayerPosition.MoveAtDirection(Direction.Right);
playfield.PlayerPosition.MoveAtDirection(Direction.Down);
Direction directionDown = Direction.Down;
bool expected = true;
bool actual = MovesChecker.IsValidMove(playfield, directionDown);
Assert.AreEqual(expected, actual);
}
示例4: TestGetTopResults
public void TestGetTopResults()
{
Playfield playfield = new Playfield();
GameEngine engine = new GameEngine(playfield);
string expected = engine.GetTopResults();
string actual = new ScoreBoard().ShowScoreboard();
Assert.AreEqual(expected, actual);
}
示例5: TestInitializeField_IsCorrectStartPosition
public void TestInitializeField_IsCorrectStartPosition()
{
Playfield playfield = new Playfield();
playfield.InitializeField();
Position expected = new Position(3, 3);
Position actual = playfield.PlayerPosition;
Assert.AreEqual(expected.Row, actual.Row);
Assert.AreEqual(expected.Col, actual.Col);
}
示例6: TestProcessInput_OnWriteRestart
public void TestProcessInput_OnWriteRestart()
{
Playfield playfield = new Playfield();
GameEngine engine = new GameEngine(playfield);
AssignEvents(engine, engine.UserInput);
engine.UserInput.ProcessInput("restart");
int expected = 0;
int actual = engine.Score;
Assert.AreEqual(expected, actual);
}
示例7: TestProcessInput_OnWriteExit
public void TestProcessInput_OnWriteExit()
{
Playfield playfield = new Playfield();
GameEngine engine = new GameEngine(playfield);
AssignEvents(engine, engine.UserInput);
engine.UserInput.ProcessInput("exit");
bool expected = true;
bool actual = engine.HasGameQuit;
Assert.AreEqual(expected, actual);
}
示例8: TestMoveAtDirection_MoveAtUp
public void TestMoveAtDirection_MoveAtUp()
{
Playfield playfield = new Playfield();
GameEngine engine = new GameEngine(playfield);
engine.MoveAtDirection(Direction.Up, engine.MoveUp);
Position expected = new Position(2, 3);
Position actual = playfield.PlayerPosition;
Assert.AreEqual(expected.Row, actual.Row);
Assert.AreEqual(expected.Col, actual.Col);
}
示例9: TestInitializeNewGame_ScoreIsUpdated
public void TestInitializeNewGame_ScoreIsUpdated()
{
Playfield playfield = new Playfield();
GameEngine engine = new GameEngine(playfield);
engine.MoveAtDirection(Direction.Down, engine.MoveDown);
engine.InitializeNewGame();
int expected = 0;
int actual = engine.Score;
Assert.AreEqual(expected, actual);
}
示例10: TestProcessInput_OnWriteR
public void TestProcessInput_OnWriteR()
{
Playfield playfield = new Playfield();
GameEngine engine = new GameEngine(playfield);
AssignEvents(engine, engine.UserInput);
engine.UserInput.ProcessInput("R");
Position expected = new Position(3, 4);
Position actual = playfield.PlayerPosition;
Assert.AreEqual(expected.Row, actual.Row);
Assert.AreEqual(expected.Col, actual.Col);
}
示例11: TestInitializeField_IsClearPlayerPosition
public void TestInitializeField_IsClearPlayerPosition()
{
Playfield playfield = new Playfield();
playfield.InitializeField();
int expectedRow = 3;
int expectedCol = 3;
int actualRow = playfield.PlayerPosition.Row;
int actualCol = playfield.PlayerPosition.Col;
Position actual = playfield.PlayerPosition;
Assert.AreEqual(expectedRow, actualRow);
Assert.AreEqual(expectedCol, actualCol);
}
示例12: TestIsVictory_NorthEastCornerExit
public void TestIsVictory_NorthEastCornerExit()
{
int[,] labyrinthGrid = new int[7, 7]
{
{0, 0, 1, 1, 1, 1, 0},
{1, 1, 1, 1, 0, 0, 1},
{0, 0, 0, 1, 0, 1, 0},
{1, 0, 1, 0, 0, 1, 1},
{0, 1, 0, 1, 1, 0, 0},
{0, 0, 1, 0, 0, 0, 0},
{0, 0, 1, 0, 1, 0, 0}
};
Position customPosition = new Position(0, 6);
Playfield playfield = new Playfield(labyrinthGrid, customPosition);
bool expected = true;
bool actual = playfield.IsVictory();
Assert.AreEqual(expected, actual);
}
示例13: TestIsValidMove_CanMoveRight
public void TestIsValidMove_CanMoveRight()
{
int[,] labyrinthGrid = new int[7, 7]
{
{0, 0, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1},
{0, 0, 0, 0, 0, 0, 0},
{1, 0, 1, 0, 0, 1, 1},
{0, 1, 0, 1, 0, 0, 0},
{0, 0, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0}
};
Playfield playfield = new Playfield(labyrinthGrid);
Direction directionRight = Direction.Right;
bool expected = true;
bool actual = MovesChecker.IsValidMove(playfield, directionRight);
Assert.AreEqual(expected, actual);
}
示例14: TestRenderFieldGrid_PlayerAtOtherPosition
public void TestRenderFieldGrid_PlayerAtOtherPosition()
{
int[,] labyrinthGrid = new int[7, 7]
{
{0, 0, 1, 1, 0, 1, 1},
{1, 1, 1, 0, 0, 0, 1},
{0, 0, 0, 0, 1, 0, 0},
{1, 0, 1, 0, 1, 1, 1},
{1, 0, 0, 1, 0, 0, 0},
{1, 0, 1, 0, 0, 1, 1},
{1, 0, 0, 1, 0, 1, 0}
};
Playfield playfield = new Playfield(labyrinthGrid);
//Moving playerPosition at row=2 and col=6 (start index=0)
playfield.PlayerPosition.MoveAtDirection(Direction.Up);
playfield.PlayerPosition.MoveAtDirection(Direction.Up);
playfield.PlayerPosition.MoveAtDirection(Direction.Right);
playfield.PlayerPosition.MoveAtDirection(Direction.Right);
playfield.PlayerPosition.MoveAtDirection(Direction.Down);
playfield.PlayerPosition.MoveAtDirection(Direction.Right);
string actualOutput = Renderer.RenderField(playfield.LabyrinthGrid,
playfield.PlayerPosition.Row, playfield.PlayerPosition.Col);
StringBuilder expectedOutput = new StringBuilder();
expectedOutput.AppendLine("--XX-XX");
expectedOutput.AppendLine("XXX---X");
expectedOutput.AppendLine("----X-*");
expectedOutput.AppendLine("X-X-XXX");
expectedOutput.AppendLine("X--X---");
expectedOutput.AppendLine("X-X--XX");
expectedOutput.AppendLine("X--X-X-");
bool areEqual = actualOutput == expectedOutput.ToString();
Assert.IsTrue(areEqual);
}
示例15: CreatePlayfield
/// <summary>
/// Creates the playfield matrix with the balloons in it
/// </summary>
public override Playfield CreatePlayfield()
{
var largePlayfield = new Playfield(Width, Height);
return largePlayfield;
}