How to implement the course of the computer (not in terms of the implementation of the logic of the course of the computer), namely, the logic of calling its course? Those. after the event of my move, the event (or method) of the computer should trigger, so I can not catch up with how to do it.
It looks like this. I have a marked 3 * 3 grid (like a playing field). when I click on a square, a mouse click event occurs and I run a check method (empty cell) and if it is empty, a cross or a zero is drawn.
Next, my property changes - who should walk and when it changes, the method works - the computer goes.
The problem is that the property changes in the event handler and, accordingly, the computer's running method works inside the event too (that is, the event has not yet worked). And when all this works, there is a drawing of a cross and a zero at the same time. And I want to do so, I clicked into the area, there was my move, I drew a cross. Then for example 2 seconds passed. (supposedly the computer thought) and began to walk the computer, i.e. drawn zero.
var timer = new DispatcherTimer() { Interval = new TimeSpan(0, 0, 2) }, which will process thetimer.Tick += (object sender, EventArgs e) => { timer.Stop(); AITurn(); SwapTurn(); }timer.Tick += (object sender, EventArgs e) => { timer.Stop(); AITurn(); SwapTurn(); }timer.Tick += (object sender, EventArgs e) => { timer.Stop(); AITurn(); SwapTurn(); }. - Alex Krass