本文整理汇总了C#中IBoard.Update方法的典型用法代码示例。如果您正苦于以下问题:C# IBoard.Update方法的具体用法?C# IBoard.Update怎么用?C# IBoard.Update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IBoard
的用法示例。
在下文中一共展示了IBoard.Update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FSM_SinglePlayer
/// <summary>
/// Single player mode
/// </summary>
/// <param name="gameLogic"></param>
/// <param name="models"></param>
/// <param name="gameSettings"></param>
#region private static void FSM_SinglePlayer(...)
private static void FSM_SinglePlayer(Connect4Game gameLogic, GameSettings gameSettings, IBoard board)
{
switch (gameLogic.GameState)
{
case GameSettings.GAMESTATE.S_BeforeGame:
{
if (gameLogic.STARTING_PLAYER == gameSettings.RED_PLAYER)
{
gameLogic.GameState = GameSettings.GAMESTATE.S_Player1Move;
gameLogic.HUMAN_PLAYER = gameSettings.RED_PLAYER;
}
else
{
gameLogic.GameState = GameSettings.GAMESTATE.S_WaitForCPU;
gameLogic.HUMAN_PLAYER = gameSettings.YELLOW_PLAYER;
}
break;
}
case GameSettings.GAMESTATE.S_Player1Move:
{
//HandleMouseInput(gameSettings, gameLogic);
//HandleKeyInput(gameSettings, gameLogic);
break;
}
case GameSettings.GAMESTATE.S_DropPlayerStone:
{
if (board.DropStone(gameLogic))
{
if (board.Bounce())
gameLogic.GameState = GameSettings.GAMESTATE.S_SwitchPlayer;
}
break;
}
case GameSettings.GAMESTATE.S_SwitchPlayer:
{
// Change player
gameLogic.SwitchPlayer();
gameLogic.CheckIfFinished();
if (gameLogic.NextGameState == GameSettings.GAMESTATE.S_GameFinished)
{
gameLogic.GameState = GameSettings.GAMESTATE.S_GameFinished;
}
else
{
board.SwitchStones(gameLogic);
if (gameLogic.activePlayer == gameSettings.RED_PLAYER)
{
// Reset stone position for the next new stone
gameLogic.SetNextPlayerStone();
gameLogic.GameState = GameSettings.GAMESTATE.S_Player1Move;
}
else
{
gameLogic.GameState = GameSettings.GAMESTATE.S_WaitForCPU;
}
}
break;
}
case GameSettings.GAMESTATE.S_WaitForCPU:
{
// Start the AI
if (!gameLogic.AIStarted)
{
gameLogic.CPUMove();
}
if (gameLogic.NextGameState == GameSettings.GAMESTATE.S_DropCPUStone)
{
gameLogic.AbortAI();
board.Update(gameLogic.column * board.ColumnDistance);
gameLogic.GameState = GameSettings.GAMESTATE.S_DropCPUStone;
}
break;
}
case GameSettings.GAMESTATE.S_DropCPUStone:
{
if (board.DropStone(gameLogic))
{
if (board.Bounce())
gameLogic.GameState = GameSettings.GAMESTATE.S_SwitchPlayer;
}
//.........这里部分代码省略.........
示例2: HandleKeyInput
public static void HandleKeyInput(GameSettings gameSettings, Connect4Game gameLogic, KeyboardState keyboardState, IBoard board)
{
if(gameLogic.GameState != GameSettings.GAMESTATE.S_Player1Move)
return;
#region Right key
if (!flagRight && !flagDown)
{
if (keyboardState.IsKeyDown(Keys.Right))
{
flagRight = true;
if (gameLogic.column < gameSettings.COLUMNS - 1)
{
// Update gamefield information
gameLogic.column++;
gameLogic.SetRow(gameLogic.column);
}
else
{
// Update gamefield information
gameLogic.column = 0;
gameLogic.SetRow(gameLogic.column);
}
board.Update(gameLogic.column * board.ColumnDistance);
}
}
#endregion
#region Left key
if (!flagLeft && !flagDown)
{
if (keyboardState.IsKeyDown(Keys.Left))
{
flagLeft = true;
if (gameLogic.column > 0)
{
// Update gamefield information
gameLogic.column--;
gameLogic.SetRow(gameLogic.column);
}
else
{
// Update gamefield information
gameLogic.column = gameSettings.COLUMNS - 1;
gameLogic.SetRow(gameLogic.column);
}
board.Update(gameLogic.column * board.ColumnDistance);
}
}
#endregion
#region Down key
if (!flagDown)
{
if (keyboardState.IsKeyDown(Keys.Down) && gameLogic.row != -1)
{
flagDown = true;
gameLogic.SetRow(gameLogic.column);
gameLogic.AddRowElement(gameLogic.column, gameLogic.row);
// Update game field
gameLogic.UpdateGameField();
// Drop player stone
gameLogic.GameState = GameSettings.GAMESTATE.S_DropPlayerStone;
}
}
#endregion
// Reset flags
if (!keyboardState.IsKeyDown(Keys.Right))
flagRight = false;
if (!keyboardState.IsKeyDown(Keys.Left))
flagLeft = false;
if (!keyboardState.IsKeyDown(Keys.Down))
flagDown = false;
}