 I made a TicTacToe game in Visual Studio - C#/XAML. https://ufile.io/h6hotxz1 The Xaml: <code> <Window.Resources> <Style TargetType="Button"> <Setter Property="Background" Value="White" /> <Setter Property="BorderThickness" Value="0.5" /> <Setter Property="FontSize" Value="70" /> </Style> </Window.Resources> <Grid x:Name="Container"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="*" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Button Click="Button_Click" x:Name= "Button0_0" Grid.Column="0" Grid.Row="0" Content="X" /> <Button Click="Button_Click" x:Name= "Button1_0" Grid.Column="1" Grid.Row="0" Content="X" /> <Button Click="Button_Click" x:Name= "Button2_0" Grid.Column="2" Grid.Row="0" Content="X" /> <Button Click="Button_Click" x:Name= "Button0_1" Grid.Column="0" Grid.Row="1" Content="X" /> <Button Click="Button_Click" x:Name= "Button1_1" Grid.Column="1" Grid.Row="1" Content="X" /> <Button Click="Button_Click" x:Name= "Button2_1" Grid.Column="2" Grid.Row="1" Content="X" /> <Button Click="Button_Click" x:Name= "Button0_2" Grid.Column="0" Grid.Row="2" Content="X" /> <Button Click="Button_Click" x:Name= "Button1_2" Grid.Column="1" Grid.Row="2" Content="X" /> <Button Click="Button_Click" x:Name= "Button2_2" Grid.Column="2" Grid.Row="2" Content="X" /> </Grid> </code> The C# Main file: <code>using System; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Media; namespace TicTacToe { /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { #region Private members /// /// Holds the current results of cells in the active game /// private MarkedType[] mResults; /// /// True if it is player 1's turn (x) or player 2's turn (o) /// private bool mPlayerTurn; /// /// Whether the game has ended or not /// private bool mGameEnded; #endregion #region Constructor /// /// Default Constructor /// public MainWindow() { InitializeComponent(); NewGame(); } #endregion #region NewGame /// /// Starts a new game /// private void NewGame() { // Create new blank array of free cells mResults = new MarkedType[9]; for (var i = 0; i < mResults.Length; i++) mResults[i] = MarkedType.Free; // Make sure P1 is current player mPlayerTurn = true; // Iterate every button on the grid Container.Children.Cast<Button>().ToList().ForEach(button => { // Set the content and colors to the default values button.Content = string.Empty; button.Background = Brushes.White; button.Foreground = Brushes.Blue; }); mGameEnded = false; } #endregion #region ButtonClick /// /// Handles a button click event /// /// <param name="sender">The button that was clicked</param> /// <param name="e">The events of the click</param> private void Button_Click(object sender, RoutedEventArgs e) { if (mGameEnded == true) { NewGame(); return; } // cast the sender to a button var button = (Button)sender; // Find the button's position in the array var column = Grid.GetColumn(button); var row = Grid.GetRow(button); var index = column + (row * 3); // check if the button is free and set the button to a new value (x) if (mResults[index] != MarkedType.Free) return; // Set the cell value based on which player's turn it is // and change the player's turn. if (mPlayerTurn) { mResults[index] = MarkedType.Cross; mPlayerTurn = false; button.Content = "X"; } else { mResults[index] = MarkedType.Nought; mPlayerTurn = true; button.Content = "O"; button.Foreground = Brushes.Green; } //Check for winner CheckForWinner(); } #endregion #region Check for winners and paint the background /// /// Checks for the winning condition /// private void CheckForWinner() { // Check for horizontal wins for (var i = 0; i <= 8; i += 3) { if (mResults[0 + i] != MarkedType.Free && (mResults[0 +i] & mResults[1+i] & mResults[2+i]) == mResults[0+i]) { //Highlighth winning cells if (i == 0) { Button0_0.Background = Button1_0.Background = Button2_0.Background = Brushes.Gold; } if (i == 3) { Button0_1.Background = Button1_1.Background = Button2_1.Background = Brushes.Gold; } if (i == 6) { Button0_2.Background = Button1_2.Background = Button2_2.Background = Brushes.Gold; } // game ended mGameEnded = true; } } // Check for vertical wins for (var i = 0; i <= 2; i++) { if (mResults[0 + i] != MarkedType.Free && (mResults[0 + i] & mResults[3 + i] & mResults[6 + i]) == mResults[0 + i]) { //Highlighth winning cells if (i == 0) { Button0_0.Background = Button0_1.Background = Button0_2.Background = Brushes.Gold; } if (i == 1) { Button1_0.Background = Button1_1.Background = Button1_2.Background = Brushes.Gold; } if (i == 2) { Button2_0.Background = Button2_1.Background = Button2_2.Background = Brushes.Gold; } // game ended mGameEnded = true; } } // Check for diagonal wins if (mResults[0] != MarkedType.Free && (mResults[0] & mResults[4] & mResults[8]) == mResults[0]) { //Highlighth winning cells Button0_0.Background = Button1_1.Background = Button2_2.Background = Brushes.Gold; // game ended mGameEnded = true; } if (mResults[2] != MarkedType.Free && (mResults[2] & mResults[4] & mResults[6]) == mResults[2]) { //Highlighth winning cells Button2_0.Background = Button1_1.Background = Button0_2.Background = Brushes.Gold; // game ended mGameEnded = true; } // End the game if no one wins and turn the background orange if (!mResults.Any(results => results == MarkedType.Free) && !mGameEnded) { mGameEnded = true; Container.Children.Cast<Button>().ToList().ForEach(button => { button.Background = Brushes.Orange; }); } } #endregion } } </code>
author | sulev |
---|---|
permlink | tictactoe |
category | coding |
json_metadata | {"tags":["coding","tictactoe","game","curate","region"],"image":["https://cdn.steemitimages.com/DQmUBUrMbQCsh5GoSSxS1DU9Caag1iNmFYh3HyPZGoQTeso/Untitled1.jpg"],"links":["https://ufile.io/h6hotxz1"],"app":"steemit/0.1","format":"markdown"} |
created | 2019-05-13 10:20:39 |
last_update | 2019-05-13 17:55:48 |
depth | 0 |
children | 3 |
last_payout | 2019-05-20 10:20:39 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 11.703 HBD |
curator_payout_value | 3.689 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 8,387 |
author_reputation | 315,005,876,598,228 |
root_title | TicTacToe |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 0 |
post_id | 84,768,961 |
net_rshares | 29,672,608,290,918 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
lafona-miner | 0 | 940,749,604,932 | 100% | ||
lafona5 | 0 | 952,732,198,147 | 100% | ||
dana-edwards | 0 | 271,230,169,490 | 100% | ||
kaylinart | 0 | 129,929,304,485 | 100% | ||
hitmeasap | 0 | 59,722,997,368 | 100% | ||
alao | 0 | 15,817,295,348 | 100% | ||
igster | 0 | 33,052,532,326 | 100% | ||
sergey44 | 0 | 27,449,690,437 | 100% | ||
ace108 | 0 | 307,690,300,309 | 18% | ||
alex2016 | 0 | 60,047,974 | 100% | ||
sulev | 0 | 2,449,946,617 | 100% | ||
freeinthought | 0 | 45,594,786,987 | 100% | ||
ocrdu | 0 | 4,526,359,539 | 100% | ||
sjennon | 0 | 159,442,998,298 | 100% | ||
trans-juanmi | 0 | 38,349,693,109 | 100% | ||
bekkababy | 0 | 12,392,126,769 | 100% | ||
meysam | 0 | 42,232,281,604 | 100% | ||
maninayton | 0 | 56,708,705,465 | 100% | ||
fede93g | 0 | 15,710,196,038 | 100% | ||
samuel-swinton | 0 | 36,148,520,768 | 100% | ||
motoengineer | 0 | 1,190,023,473,408 | 100% | ||
samhamou | 0 | 21,572,291,248 | 100% | ||
turtle-trader | 0 | 14,157,838,175 | 100% | ||
alinabarbu | 0 | 3,879,177,548 | 10% | ||
liberty-minded | 0 | 31,120,221,765 | 100% | ||
bargolis | 0 | 15,226,860,297 | 100% | ||
leyargoz | 0 | 27,199,778,398 | 100% | ||
freddyfish | 0 | 18,118,537,551 | 100% | ||
sustainablyyours | 0 | 36,168,328,294 | 100% | ||
bikergirl | 0 | 27,119,800,413 | 100% | ||
kouloumos | 0 | 37,242,022,321 | 100% | ||
booster | 0 | 13,180,509,717,104 | 31.19% | ||
bew | 0 | 19,203,808,099 | 100% | ||
ealbania | 0 | 17,195,486,565 | 100% | ||
finkistinger | 0 | 19,423,766,903 | 100% | ||
d-pend | 0 | 907,695,633,548 | 72% | ||
jstajok | 0 | 19,839,474,508 | 100% | ||
hardikv | 0 | 23,944,956,399 | 100% | ||
ragepeanut | 0 | 23,410,663,943 | 100% | ||
samotonakatoshi | 0 | 10,863,996,197 | 10% | ||
evgsk | 0 | 5,702,588,862 | 100% | ||
lisamalletart | 0 | 17,445,172,221 | 100% | ||
owner99 | 0 | 98,223,150,462 | 100% | ||
stayoutoftherz | 0 | 624,476,760,905 | 100% | ||
steemulator | 0 | 25,167,576,096 | 100% | ||
leaky20 | 0 | 17,161,799,125 | 100% | ||
teukumuhas | 0 | 84,138,863 | 5% | ||
onlineprds | 0 | 57,623,512,872 | 100% | ||
toxichustle | 0 | 25,369,970,592 | 100% | ||
hag228 | 0 | 18,387,872,726 | 100% | ||
chetanpadliya | 0 | 45,723,875,243 | 100% | ||
foruni73 | 0 | 72,372,820,669 | 100% | ||
devcoin | 0 | 19,865,096,374 | 100% | ||
jerrycheung | 0 | 38,802,618,404 | 100% | ||
franky4dita | 0 | 17,094,534,728 | 100% | ||
torico | 0 | 37,596,239,417 | 100% | ||
synace | 0 | 36,953,718,097 | 100% | ||
boatsports90 | 0 | 38,653,288,318 | 100% | ||
thedarkhorse | 0 | 186,585,259,103 | 100% | ||
littleboy | 0 | 141,252,850,277 | 100% | ||
luxbet | 0 | 81,765,262,506 | 10% | ||
joetravels | 0 | 15,623,248,877 | 100% | ||
halcyondaze | 0 | 19,234,077,372 | 100% | ||
macmaniac77 | 0 | 23,237,698,142 | 100% | ||
theprism | 0 | 13,840,147,588 | 100% | ||
goge-vandire | 0 | 66,690,414,909 | 100% | ||
silverwhale | 0 | 22,130,326,759 | 100% | ||
cryp2me | 0 | 13,869,115,952 | 100% | ||
joxus | 0 | 29,716,826,990 | 100% | ||
tony10 | 0 | 14,873,243,684 | 100% | ||
instatrashed | 0 | 23,192,207,380 | 100% | ||
gazbaz4000 | 0 | 48,833,107,634 | 100% | ||
fplacido | 0 | 17,854,403,468 | 100% | ||
gamingstation | 0 | 31,527,817,914 | 100% | ||
shanishah | 0 | 14,126,320,644 | 100% | ||
ribbitingscience | 0 | 22,725,224,689 | 100% | ||
sye54 | 0 | 19,347,711,476 | 100% | ||
nasrina.nasir | 0 | 19,548,202,206 | 100% | ||
piszozo | 0 | 18,414,036,313 | 100% | ||
mamaloves | 0 | 15,156,925,881 | 100% | ||
mineopoly | 0 | 42,381,407,195 | 100% | ||
jmotip | 0 | 31,171,771,018 | 100% | ||
calebleejl | 0 | 16,832,425,292 | 100% | ||
vvk | 0 | 19,755,345,017 | 100% | ||
wllmdnnd | 0 | 16,788,051,861 | 100% | ||
intrepidphotos | 0 | 512,678,761,947 | 100% | ||
biffybirdcam | 0 | 28,759,446,457 | 100% | ||
jakeybrown | 0 | 39,033,778,360 | 100% | ||
smartmarket | 0 | 355,242,547,372 | 3.14% | ||
petrescue | 0 | 14,489,170,390 | 100% | ||
jona12 | 0 | 19,935,830,507 | 100% | ||
yannh | 0 | 14,929,400,837 | 100% | ||
anjkara | 0 | 39,505,197,155 | 100% | ||
seandeanayao | 0 | 28,605,508,570 | 100% | ||
sv1rby | 0 | 39,207,556,560 | 100% | ||
nobyeni | 0 | 39,044,002,097 | 100% | ||
mshahabi | 0 | 178,534,776,084 | 45.2% | ||
unconditionalove | 0 | 202,625,500 | 36% | ||
imanisraelirick | 0 | 64,685,954,151 | 100% | ||
afrosiab | 0 | 30,392,233,315 | 100% | ||
steemitgifts | 0 | 22,023,551,269 | 100% | ||
earthnation-bot | 0 | 28,152,024,911 | 100% | ||
knackart | 0 | 41,104,952,953 | 100% | ||
cheema1 | 0 | 13,267,266,813 | 22.6% | ||
techchat | 0 | 39,864,860,801 | 100% | ||
timspawls | 0 | 16,309,906,542 | 100% | ||
babysloth | 0 | 19,671,112,910 | 100% | ||
ozphil | 0 | 408,430,197,507 | 100% | ||
jbrrd | 0 | 156,306,276 | 20% | ||
tamala | 0 | 19,462,850,981 | 100% | ||
ourdailyboard | 0 | 184,888,778,864 | 100% | ||
steemhelpinghand | 0 | 14,054,352,498 | 100% | ||
anamulhoque | 0 | 541,826,166 | 100% | ||
nathankaye | 0 | 20,540,925,690 | 100% | ||
emmyem84 | 0 | 20,560,653,123 | 100% | ||
scottcbusiness | 0 | 37,754,897,942 | 100% | ||
shakilkhan | 0 | 22,312,305,393 | 100% | ||
dragraff | 0 | 21,580,781,567 | 100% | ||
mwfiae | 0 | 25,351,423,120 | 100% | ||
javapoint | 0 | 15,199,337,035 | 100% | ||
sourcherry | 0 | 14,209,409,744 | 100% | ||
schreiblust | 0 | 30,513,817,714 | 100% | ||
pg-live-pt | 0 | 30,060,488,498 | 100% | ||
virtaco300cc | 0 | 269,468,194 | 50% | ||
skarnoze | 0 | 30,261,424,856 | 100% | ||
naim62 | 0 | 96,807,166 | 5% | ||
c0wtschpotato | 0 | 17,308,251,780 | 100% | ||
wordymouth | 0 | 17,939,197,983 | 100% | ||
scruffy23 | 0 | 37,889,291,530 | 100% | ||
johhnnyturbo20 | 0 | 17,585,178,548 | 100% | ||
theswissguy | 0 | 14,274,841,429 | 100% | ||
littleboys-faiz | 0 | 12,825,426,941 | 50% | ||
paraxs | 0 | 21,309,098,990 | 100% | ||
angelacs | 0 | 22,711,255,574 | 100% | ||
zapzap | 0 | 10,909,297,939 | 100% | ||
adept-forever | 0 | 460,420,745,339 | 100% | ||
thomasmore | 0 | 14,716,361,712 | 100% | ||
lanhange | 0 | 1,076,538,511,553 | 100% | ||
cryptopike | 0 | 15,608,696,068 | 100% | ||
syedshakil | 0 | 27,364,221,122 | 100% | ||
trisolaran | 0 | 33,757,863,549 | 100% | ||
letsbenomads | 0 | 17,542,989,952 | 100% | ||
uche-nna | 0 | 42,315,118,483 | 100% | ||
merlion | 0 | 78,987,191,154 | 100% | ||
swisswitness | 0 | 28,219,924,940 | 100% | ||
lazyman | 0 | 366,010,026,726 | 100% | ||
oliviackl | 0 | 19,272,178,743 | 100% | ||
vijbzabyss | 0 | 18,944,567,498 | 100% | ||
partiko | 0 | 263,647,074,729 | 3% | ||
gpcx86 | 0 | 63,883,728 | 25% | ||
kylealex | 0 | 38,151,254,008 | 100% | ||
tech4all | 0 | 17,986,024,621 | 100% | ||
emmyluluameh | 0 | 63,289,321 | 50% | ||
alexisdauliac | 0 | 16,755,836,473 | 100% | ||
eu-id | 0 | 285,572,057 | 5% | ||
ayanamirei | 0 | 885,389,891 | 3.01% | ||
lereve | 0 | 1,234,685,268 | 1% | ||
simmani | 0 | 1,214,080,503 | 95.14% | ||
general.guy | 0 | 15,805,846,048 | 100% | ||
devann | 0 | 417,073,782,087 | 100% | ||
synchronization | 0 | 132,521,783 | 36% | ||
iammightyflo | 0 | 392,708,690 | 100% | ||
beesknees | 0 | 29,256,937,379 | 100% | ||
steemtank | 0 | 2,439,252,126,541 | 100% | ||
igbotier | 0 | 6,979,588,518 | 100% | ||
we-are-steemians | 0 | 24,385,947,015 | 23.75% | ||
powerade | 0 | 65,554,996,895 | 100% | ||
lumencula | 0 | 25,117,792,742 | 100% | ||
luxiony | 0 | 288,833,389 | 100% | ||
wikita | 0 | 378,003,428 | 100% | ||
aninsidejob | 0 | 442,374,340,430 | 100% | ||
jkl65 | 0 | 31,907,267,171 | 100% |
I think your 2nd tag has a typo
author | ace108 |
---|---|
permlink | re-sulev-tictactoe-20190513t163618343z |
category | coding |
json_metadata | {"tags":["coding"],"app":"steemit/0.1"} |
created | 2019-05-13 16:36:15 |
last_update | 2019-05-13 16:36:15 |
depth | 1 |
children | 1 |
last_payout | 2019-05-20 16:36:15 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 31 |
author_reputation | 1,229,119,536,181,200 |
root_title | TicTacToe |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 84,786,309 |
net_rshares | 0 |
indeed
author | sulev |
---|---|
permlink | re-ace108-re-sulev-tictactoe-20190513t175534461z |
category | coding |
json_metadata | {"tags":["coding"],"app":"steemit/0.1"} |
created | 2019-05-13 17:55:33 |
last_update | 2019-05-13 17:55:33 |
depth | 2 |
children | 0 |
last_payout | 2019-05-20 17:55:33 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 6 |
author_reputation | 315,005,876,598,228 |
root_title | TicTacToe |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 0 |
post_id | 84,789,804 |
net_rshares | 0 |
Thank you so much for participating in the Partiko Delegation Plan Round 1! We really appreciate your support! As part of the delegation benefits, we just gave you a 3.00% upvote! Together, let’s change the world!
author | partiko |
---|---|
permlink | re-tictactoe-20190513t113021 |
category | coding |
json_metadata | "{"app": "partiko"}" |
created | 2019-05-13 11:30:24 |
last_update | 2019-05-13 11:30:24 |
depth | 1 |
children | 0 |
last_payout | 2019-05-20 11:30:24 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 213 |
author_reputation | 39,207,160,334,751 |
root_title | TicTacToe |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 84,772,267 |
net_rshares | 0 |