Let's imagine a more entertaining version of what we want to achieve TTT (this is the most important feature of most games). For example, a variant of TTT allows a player to occupy only 3 squares at a time, removing the first step in the fourth step, removing the second step in the next fifth step, and so on. To implement this variant, we need to keep track of each step sequentially-we can take advantage of the Playmover class, as in example 5-20.
Example 5-20
namespace TicTacToe {
public class PlayerMove {
private string playerName;
public string PlayerName {
get { return playerName; }
set { playerName = value; }
}
private int moveNumber;
public int MoveNumber {
get { return moveNumber; }
set { moveNumber = value; }
}
public PlayerMove(string playerName, int moveNumber) {
this.playerName = playerName;
this.moveNumber = moveNumber;
}
}
}
Now, instead of using a simple string for the content of each button object, we will show such a change in a playmover instance in example 5-20.
Example 5-21
namespace TicTacToe {
public partial class Window1 : Window {
int moveNumber;
void NewGame( ) {
this.moveNumber = 0;
}
void cell_Click(object sender, RoutedEventArgs e) {
// Set button content
//button.Content = this.CurrentPlayer;
button.Content =
new PlayerMove(this.CurrentPlayer, ++this.moveNumber);
}
}
}