本文整理汇总了C#中Game.InitializeBoard方法的典型用法代码示例。如果您正苦于以下问题:C# Game.InitializeBoard方法的具体用法?C# Game.InitializeBoard怎么用?C# Game.InitializeBoard使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Game
的用法示例。
在下文中一共展示了Game.InitializeBoard方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GivenGameInitializes_WhenAPlayerPlays_ThenShouldCheckIfGameIsOver
public void GivenGameInitializes_WhenAPlayerPlays_ThenShouldCheckIfGameIsOver()
{
// Assign
var boardDisplayerMock = new Mock<IBoardDisplayer>();
var game = new Game(boardDisplayerMock.Object);
game.InitializeBoard();
// Act
var isOver = game.PlayAndCheck(Player.Player1);
// Assert
Assert.IsFalse(isOver);
}
示例2: GivenGameInitializes_WhenAPlayerPlays_ThenShouldDisplayBoard
public void GivenGameInitializes_WhenAPlayerPlays_ThenShouldDisplayBoard()
{
// Assign
var boardDisplayerMock = new Mock<IBoardDisplayer>();
var game = new Game(boardDisplayerMock.Object);
game.InitializeBoard();
// Act
game.PlayAndCheck(Player.Player1);
//Assert
boardDisplayerMock.Verify(b => b.DisplayBoard(game.Board), Times.Once);
}
示例3: GivenGameInitializes_WhenAPlayerNotWins_ThenShouldNotDisplayResult
public void GivenGameInitializes_WhenAPlayerNotWins_ThenShouldNotDisplayResult()
{
// Assign
var boardDisplayerMock = new Mock<IBoardDisplayer>();
var game = new Game(boardDisplayerMock.Object);
game.InitializeBoard();
game.MakeNextMove(Player.Player1, 0);
// Act
game.PlayAndCheck(Player.Player1);
// Assert
boardDisplayerMock.Verify(b => b.DisplayWinner(Player.Player1), Times.Never);
}
示例4: GivenGameInitializes_WhenAPlayerTicksWinningCombination_ThenPlayer1ShouldWin
public void GivenGameInitializes_WhenAPlayerTicksWinningCombination_ThenPlayer1ShouldWin()
{
// Assign
var game = new Game(new BoardDisplayer());
game.InitializeBoard();
game.MakeNextMove(Player.Player1, 0);
game.MakeNextMove(Player.Player1, 1);
game.MakeNextMove(Player.Player1, 2);
// Act
var hasPlayerWon = game.HasPlayerWon(Player.Player1);
// Assert
Assert.IsTrue(hasPlayerWon);
}
示例5: Main
static void Main(string[] args)
{
Game game = new Game();
var GameStatus = GameApp.Game.GameState.Ongoing;
String[,] gameBoard = new String[4,4];
game.InitializeBoard(gameBoard);
Console.WriteLine("Welcome To the Game 2048");
Console.WriteLine("Choose Moves: Right=a,Left=d,Up=w,Down=s, Q to quit");
DisplayBoard(gameBoard);
do
{
var inputKey = Console.ReadKey();
Console.WriteLine("");
if (inputKey.Key == System.ConsoleKey.W)
{
gameBoard = game.MoveUp(gameBoard);
GameStatus = GameStatus = game.CheckGameCondition(gameBoard);
if (GameStatus.Equals(GameApp.Game.GameState.Win) || GameStatus.Equals(GameApp.Game.GameState.Lost))
{
break;
}
gameBoard = game.GenerateNewSquareElement(gameBoard);
DisplayBoard(gameBoard);
}
else if (inputKey.Key == System.ConsoleKey.S)
{
gameBoard = game.MoveDown(gameBoard);
GameStatus = GameStatus = game.CheckGameCondition(gameBoard);
if (GameStatus.Equals(GameApp.Game.GameState.Win) || GameStatus.Equals(GameApp.Game.GameState.Lost))
{
break;
}
gameBoard = game.GenerateNewSquareElement(gameBoard);
DisplayBoard(gameBoard);
}
else if (inputKey.Key == System.ConsoleKey.A)
{
gameBoard = game.MoveLeft(gameBoard);
GameStatus = GameStatus = game.CheckGameCondition(gameBoard);
if (GameStatus.Equals(GameApp.Game.GameState.Win) || GameStatus.Equals(GameApp.Game.GameState.Lost))
{
break;
}
gameBoard = game.GenerateNewSquareElement(gameBoard);
DisplayBoard(gameBoard);
}
else if (inputKey.Key == System.ConsoleKey.D)
{
gameBoard = game.MoveRight(gameBoard);
GameStatus = GameStatus = game.CheckGameCondition(gameBoard);
if (GameStatus.Equals(GameApp.Game.GameState.Win) || GameStatus.Equals(GameApp.Game.GameState.Lost))
{
break;
}
gameBoard = game.GenerateNewSquareElement(gameBoard);
DisplayBoard(gameBoard);
}
else if (inputKey.Key == System.ConsoleKey.Q)
{
break;
}
else
{
Console.WriteLine("You entered an invalid key. Please Choose Moves: Right=a,Left=d,Up=w,Down=s or Q to quit");
}
} while (GameStatus.Equals(GameApp.Game.GameState.Ongoing));
DisplayBoard(gameBoard);
if (GameStatus.Equals(GameApp.Game.GameState.Lost))
Console.WriteLine("Well that sucks you lost");
else if(GameStatus.Equals(GameApp.Game.GameState.Win)){
Console.WriteLine("Saaweeeet you WON!!!!");
}else{
Console.WriteLine("You Gave up?");
}
do
{
var inputKey = Console.ReadKey();
if(inputKey.Key == System.ConsoleKey.Q)
{
break;
}
} while (true);
}
示例6: GivenGameInitializes_WhenPlayersUseAllTheCells_ThenGameShouldFinish
public void GivenGameInitializes_WhenPlayersUseAllTheCells_ThenGameShouldFinish()
{
// Assign
var game = new Game(new BoardDisplayer());
game.InitializeBoard();
for (var i = 0; i < game.Board.Cells.Count; i++)
{
game.MakeNextMove(Player.Player1, i);
}
// Act
bool isFinished = game.IsGameFinished();
// Assert
Assert.IsTrue(isFinished);
}
示例7: GivenGameInitializes_WhenPlayer1MakesAMove_ThenBoardShouldShowThis
public void GivenGameInitializes_WhenPlayer1MakesAMove_ThenBoardShouldShowThis()
{
// Assign
var game = new Game(new BoardDisplayer());
game.InitializeBoard();
var randomCell = new Random().Next(0, 8);
// Act
game.MakeNextMove(Player.Player1, randomCell);
// Assert
for (var i = 0; i < game.Board.Cells.Count; i++)
{
if (i == randomCell)
{
Assert.AreEqual(Player.Player1, game.Board.Cells[randomCell].Value);
continue;
}
Assert.IsFalse(game.Board.Cells[i].Value.HasValue);
}
}
示例8: GivenGameInitializes_WhenGameStarts_ThenShouldHaveEmptyBoard
public void GivenGameInitializes_WhenGameStarts_ThenShouldHaveEmptyBoard()
{
// Assign
var game = new Game(new BoardDisplayer());
// Act
game.InitializeBoard();
// Assert
Assert.AreEqual(9, game.Board.Cells.Count);
foreach (var cell in game.Board.Cells)
{
Assert.IsFalse(cell.Value.HasValue);
}
}
示例9: GivenGameInitializes_WhenGameStarts_ThenPlayersShouldPickRandomCells
public void GivenGameInitializes_WhenGameStarts_ThenPlayersShouldPickRandomCells()
{
// Assign
var game = new Game(new BoardDisplayer());
game.InitializeBoard();
// Act
var player1CellIndex = game.GetNextRandomAvailableCellIndex();
game.MakeNextMove(Player.Player1, player1CellIndex);
var player2Cell = game.GetNextRandomAvailableCellIndex();
game.MakeNextMove(Player.Player2, player2Cell);
// Assert
Assert.AreNotEqual(player1CellIndex, player2Cell);
}