扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
清单 3
public class CSharpTicTacToe : Form {
public Player m_Player = Player.XPlayer;
TicTacToeBoard m_board = new TicTacToeBoard();
public CSharpTicTacToe() {
SetStyle(ControlStyles.Opaque, true);
Size = new Size(500, 500);
Text = "CSharp Tic Tac Toe";
m_board.Initialize();
//Finally add a button so that we can render to a bitmap
Button buttonRestart = new Button();
buttonRestart.Size=new Size(100,50);
buttonRestart.Location=new Point(300,100);
buttonRestart.Text="Restart";
buttonRestart.AddOnClick(new EventHandler(Restart));
this.Controls.Add(buttonRestart);
}
//Fired when the restart button is pressed
private void Restart(object sender, EventArgs e) {
m_Player = Player.XPlayer;
m_board.ClearBoard();
this.Invalidate();
}
protected override void OnMouseDown(MouseEventArgs e) {
base.OnMouseDown(e);
Positions position = m_board.HitTest(e.X, e.Y, m_Player);
if(position == Positions.Unknown) {
return;
}
if(m_Player == Player.XPlayer) {
m_Player = Player.OPlayer;
} else {
m_Player = Player.XPlayer;
}
this.Invalidate();
}
protected override void OnPaint(PaintEventArgs e) {
Graphics g = e.Graphics;
e.Graphics.SmoothingMode =
SmoothingMode.AntiAlias;
g.FillRectangle(new
SolidBrush(Color.FromARGB(250,
Color.White)), ClientRectangle);
m_board.Render(g);
}
public static void Main() {
Application.Run(new CSharpTicTacToe());
}
}
}
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者