本文整理匯總了C#中Board.DrawBoard方法的典型用法代碼示例。如果您正苦於以下問題:C# Board.DrawBoard方法的具體用法?C# Board.DrawBoard怎麽用?C# Board.DrawBoard使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Board
的用法示例。
在下文中一共展示了Board.DrawBoard方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
static void Main(string[] args)
{
Match newMatch = new Match();
Match thisMatch = newMatch.SetupMatch();
Board gameBoard = new Board();
Player players = new Player();
var homeTeamHand = thisMatch.HomeTeam.Hand();
var awayTeamHand = thisMatch.AwayTeam.Hand();
gameBoard.DrawBoard(thisMatch);
//Turn loop
for (int turn = 1; turn <= 9; turn++)
{
Console.WriteLine();
Console.WriteLine("Start of turn {0}", turn);
//Assign orders to all players in the Home match
players.GiveOrders(thisMatch.HomeTeam, homeTeamHand);
//Assign orders to all players in the away team
players.GiveOrders(thisMatch.AwayTeam, awayTeamHand);
//Execute Orders
players.ExecuteOrders(thisMatch);
//Find encounters - doesn't seem to work
List<Coordinate> engagements = thisMatch.CompairePlayersCoordinates(thisMatch);
Rolls roll = new Rolls();
//Roll for all engagements
foreach (Coordinate coordinate in engagements)
{
Console.WriteLine("Engagement at {0},{1}", coordinate.X, coordinate.Y);
roll.RollForEngagement(coordinate, thisMatch);
}
Console.WriteLine("!-----New Turn------!");
gameBoard.DrawBoard(thisMatch);
}
}
示例2: Main
static int Main(string[] args)
{
Program p = new Program();
char gameOn = 'y';//keeps track if game is ongoing
int input;//variable to keep track of players choice of boardsize
while (gameOn == 'y')
{
// get the size of the board that the user wants
Console.Write("\nWelcome to Tic-Tac-Toe!\n\n");
Console.Write("1. 3x3 (Standard)\n");
Console.Write("2. 5x5\n");
Console.Write("\nWhat size do you want on the board? (3 or 5): ");
input = Convert.ToInt32(Console.ReadLine());
// set the board size, based on the user's input
if (input == 3 || input == 5)
{
p.boardWidth = input;
p.boardSize = p.boardWidth * p.boardWidth;
}
else
{
Console.WriteLine("\nYou entered an invalid size!Try again! \n\n");
continue;
}
// Array for the board
char[] board = new char[p.boardSize];
// Set all of the board items to empty
for (int i = 0; i < p.boardSize; i++)
board[i] = empty;
bool win = false;
int size = p.boardSize;//Varibles for the boardssize to pass as parameters in methodcallings
int width = p.boardWidth;//pass as parameters in methodcallings
Console.WriteLine("\nChoose opponent\n");
Console.WriteLine("1. Human opponent");
Console.WriteLine("2. Computer ");
int chosenOpponent = int.Parse(Console.ReadLine());//Player input if they want to play
//against another human or the computerplayer
// Draw the board
Console.WriteLine();
Console.Write(@"The board looks like this and you choose your position by entering the number
representing the position you want:");
Player play = new Player(size,width);
Board b = new Board(size, width);
ComputerPlayer cp = new ComputerPlayer(size,width);
// reset moveCount
play.moveCount = 0;
b.DrawBoard(board, true);
Console.WriteLine("\n\n");
while (win == false)//While there is no winner
{
// Ask player1 for a move
play.AskForMove(board,player1);
// Draw the board
b.DrawBoard(board, false);
// Check to see if player 1 has won
win = false;
win = play.IsWinner(board, player1, size);
if (win == true)
{
Console.WriteLine("\n\nPlayer X has won!\n\n");
break;
}
// Check for a draw
if (play.IsDraw())
{
Console.WriteLine("\n\nIt's a draw!\n\n");
break;
}
// Ask player2 for a move
if (chosenOpponent == 2 && input == 3)//If player wanted computer opponent and a 3x3board
cp.AskForComputerMoveThree(board,player2);
else if (chosenOpponent == 2 && input == 5)//If player wanted computer opponent and a 5x5 board
cp.AskForComputerMoveFive(board, player2);
else
play.AskForMove(board, player2);//If player wanted human opponent
// Draw board again
b.DrawBoard(board, false);
// Check to see if player 2 has won
win = false;
win = play.IsWinner(board, player2, size);
if (win == true)
{
//.........這裏部分代碼省略.........
示例3: Main
static void Main()
{
// Setting the size of the console window
Console.SetWindowSize(50, 26);
Console.SetBufferSize(50, 26);
// Starts off by sending players to UserGreeting.AskNames method, saving playernames in a string array
string[] Names = UserGreeting.AskNames();
// Creates a new board
Board MyBoard = new Board();
// Creates 2 new players, where we fetch the names from the array,
// originally inherited from the UserGreeting.AskNames method
Player Player1 = new Player(Names[0], "X", MyBoard);
Player Player2 = new Player(Names[1], "O", MyBoard);
MyBoard.DrawBoard();
while (MyBoard.SpaceLeft())
{
Player1.MakeMove();
if (!MyBoard.SpaceLeft()) break;
MyBoard.CheckWinner();
if (MyBoard.Winner) break;
Player2.MakeMove();
if (!MyBoard.SpaceLeft()) break;
MyBoard.CheckWinner();
if (MyBoard.Winner) break;
}
}