private void SynchornizeWithGameGrid() { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { string marker = Gamegrid.ValueAt(i, j); switch (marker) { case "x": DrawX(i, j); break; case "o": DrawO(i, j); break; default: DrawBlank(i, j); break; } } } }
public visual_grid() { InitializeComponent(); Gamegrid.InitializeGrid(); imageCells[0, 0] = cell_0_0; imageCells[0, 1] = cell_0_1; imageCells[0, 2] = cell_0_2; imageCells[1, 0] = cell_1_0; imageCells[1, 1] = cell_1_1; imageCells[1, 2] = cell_1_2; imageCells[2, 0] = cell_2_0; imageCells[2, 1] = cell_2_1; imageCells[2, 2] = cell_2_2; SynchornizeWithGameGrid(); /* * for( int i = 0; i < 3; i++) * { * for( int j = 0; j < 3; j++) * { * DrawBlank(i, j); * } * } */ }
private void CellMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { Image i = sender as Image; string [] s = i.Name.Split('_'); int x = Convert.ToInt32(s[1]); int y = Convert.ToInt32(s[2]); Gamegrid.PlaceMarker(x, y, Gamegrid.WhoseTurn()); SynchornizeWithGameGrid(); bool isGameOver = Gamegrid.HasTeamWon("x") || Gamegrid.HasTeamWon("o") || Gamegrid.numberOfTurns == 9; if (isGameOver) { string winningTeam = ""; if (Gamegrid.HasTeamWon("x")) { winningTeam = "x"; } else if (Gamegrid.HasTeamWon("o")) { winningTeam = "o"; } victory_screen vs = new victory_screen(winningTeam); this.Content = vs; } }