Completed

This commit is contained in:
maxwes08
2025-10-20 10:00:51 +02:00
parent 3fe7224aaf
commit cc5b6125bb
7 changed files with 129 additions and 50 deletions

15
Box.cs
View File

@@ -1,15 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace TicTacToe
namespace TicTacToe
{
public class Box
{
public Action<int> Pressed;
public Action<int>? Pressed;
public int Index;
public bool BotOwned = false;
private Button _button;
@@ -23,9 +16,9 @@ namespace TicTacToe
_button.Text = "";
}
private void Clicked(object sender, EventArgs e)
private void Clicked(object? sender, EventArgs e)
{
Pressed.Invoke(Index);
Pressed?.Invoke(Index);
}
public void Destroy()

16
Form1.Designer.cs generated
View File

@@ -28,6 +28,7 @@
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
menuStrip1 = new MenuStrip();
fileToolStripMenuItem = new ToolStripMenuItem();
newGameToolStripMenuItem = new ToolStripMenuItem();
@@ -68,13 +69,13 @@
// newGameToolStripMenuItem
//
newGameToolStripMenuItem.Name = "newGameToolStripMenuItem";
newGameToolStripMenuItem.Size = new Size(270, 34);
newGameToolStripMenuItem.Size = new Size(199, 34);
newGameToolStripMenuItem.Text = "New game";
//
// exitToolStripMenuItem
//
exitToolStripMenuItem.Name = "exitToolStripMenuItem";
exitToolStripMenuItem.Size = new Size(270, 34);
exitToolStripMenuItem.Size = new Size(199, 34);
exitToolStripMenuItem.Text = "Exit";
//
// helpToolStripMenuItem
@@ -215,9 +216,10 @@
Controls.Add(grid_7);
Controls.Add(lbl_wins);
Controls.Add(menuStrip1);
Icon = (Icon)resources.GetObject("$this.Icon");
MainMenuStrip = menuStrip1;
Name = "Form1";
Text = "Form1";
Text = "Tic Tac Toe";
menuStrip1.ResumeLayout(false);
menuStrip1.PerformLayout();
ResumeLayout(false);
@@ -226,16 +228,9 @@
#endregion
private Button btn_restart;
private MenuStrip menuStrip1;
private ToolStripMenuItem fileToolStripMenuItem;
private ToolStripMenuItem helpToolStripMenuItem;
private Label label1;
private ToolStripMenuItem aboutToolStripMenuItem;
private Button button3;
private Button button4;
private Button button5;
private Button button8;
public Button grid_7;
public Button grid_5;
public Button grid_8;
@@ -249,5 +244,6 @@
public ToolStripMenuItem newGameToolStripMenuItem;
public Label lbl_loses;
public ToolStripMenuItem exitToolStripMenuItem;
public ToolStripMenuItem aboutToolStripMenuItem;
}
}

View File

@@ -120,4 +120,81 @@
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
AAABAAEAICAAAAEAIACoEAAAFgAAACgAAAAgAAAAQAAAAAEAIAAAAAAAABAAAAAAAAAAAAAAAAAAAAAA
AAD/////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////+/v7/6enp/7+/v/+qqqr/tbW1/9vb
2//7+/v////////////////////////////u7u7/tbW1/9ra2v//////////////////////////////
///7+/v/xMTE/8TExP/7+/v/////////////////////////////////8/Pz/5OTk/8vLy//CgoK/wIC
Av8GBgb/Hh4e/25ubv/e3t7//////////////////////4GBgf8CAgL/MDAw/8nJyf//////////////
/////////Pz8/5aWlv8RERH/FRUV/8PDw/////////////////////////////Pz8/9ra2v/BQUF/wAA
AP8AAAD/AQEB/wAAAP8AAAD/AAAA/zo6Ov/W1tb/////////////////gICA/wAAAP8AAAD/LS0t/8nJ
yf////////////z8/P+Wlpb/Dw8P/wAAAP8TExP/w8PD////////////////////////////k5OT/wUF
Bf8AAAD/Ghoa/3Jycv+ioqL/ioqK/zQ0NP8BAQH/AAAA/1RUVP/09PT////////////s7Oz/Xl5e/wIC
Av8AAAD/LS0t/8nJyf/9/f3/lpaW/w8PD/8AAAD/Dw8P/5aWlv/8/Pz//////////////////////+jo
6P8wMDD/AAAA/xoaGv+5ubn/////////////////4eHh/0VFRf8AAAD/CgoK/7a2tv//////////////
///r6+v/XV1d/wICAv8AAAD/MDAw/3Z2dv8RERH/AAAA/w8PD/+Wlpb//Pz8////////////////////
////////v7+//wsLC/8AAAD/cnJy////////////////////////////t7e3/woKCv8AAAD/eXl5////
///////////////////r6+v/XV1d/wICAv8AAAD/AQEB/wAAAP8PDw//lZWV//z8/P//////////////
//////////////////+pqan/AgIC/wEBAf+ioqL////////////////////////////d3d3/HR0d/wAA
AP9eXl7////////////////////////////m5ub/Nzc3/wAAAP8AAAD/AAAA/3V1df/8/Pz/////////
/////////////////////////////7S0tP8GBgb/AAAA/4qKiv///////////////////////////8vL
y/8SEhL/AAAA/2xsbP///////////////////////Pz8/5aWlv8QEBD/AAAA/wAAAP8AAAD/MDAw/8rK
yv//////////////////////////////////////29vb/x4eHv8AAAD/NTU1/+Hh4f//////////////
///5+fn/cXFx/wAAAP8CAgL/n5+f//////////////////z8/P+VlZX/Dw8P/wAAAP8SEhL/ODg4/wQE
BP8AAAD/LS0t/8nJyf/////////////////////////////////8/Pz/bGxs/wAAAP8BAQH/RkZG/7m5
uf/f39//zc3N/3Fxcf8LCwv/AAAA/zAwMP/j4+P////////////8/Pz/lpaW/w8PD/8AAAD/Dw8P/5eX
l//o6Oj/XV1d/wEBAf8AAAD/LS0t/8nJyf/////////////////////////////////c3Nz/Nzc3/wAA
AP8AAAD/CwsL/x0dHf8SEhL/AQEB/wAAAP8VFRX/rq6u/////////////////6Wlpf8ODg7/AAAA/w8P
D/+VlZX//Pz8///////r6+v/XV1d/wEBAf8AAAD/MDAw/9ra2v//////////////////////////////
///V1dX/UVFR/wkJCf8AAAD/AAAA/wAAAP8CAgL/Ly8v/66urv/9/f3/////////////////a2tr/wAA
AP8PDw//lZWV//z8/P/////////////////r6+v/XV1d/wEBAf8GBgb/tbW1////////////////////
///////////////////z8/P/tra2/3h4eP9dXV3/ampq/56env/j4+P/////////////////////////
///Q0ND/aWlp/6Wlpf/7+/v////////////////////////////q6ur/f39//4GBgf/u7u7/////////
//////////////////////////////////////////////7+/v//////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////v7+////////////////////
///////////////////////////////////u7u7/gYGB/39/f//q6ur/////////////////////////
///7+/v/pKSk/2pqav/Q0ND////////////////////////////j4+P/np6e/2pqav9dXV3/eXl5/7e3
t//z8/P//////////////////////////////////////7W1tf8GBgb/AQEB/11dXf/r6+v/////////
/////////Pz8/5WVlf8ODg7/AAAA/2xsbP/////////////////9/f3/rKys/y4uLv8CAgL/AAAA/wAA
AP8AAAD/CQkJ/1JSUv/W1tb/////////////////////////////////2tra/zAwMP8AAAD/AQEB/11d
Xf/r6+v///////z8/P+VlZX/Dg4O/wAAAP8PDw//paWl/////////////////6ysrP8TExP/AAAA/wEB
Af8SEhL/HR0d/wsLC/8AAAD/AAAA/zk5Of/d3d3/////////////////////////////////ycnJ/y0t
Lf8AAAD/AgIC/15eXv/o6Oj/lpaW/w8PD/8AAAD/Dw8P/5aWlv/8/Pz////////////j4+P/MDAw/wAA
AP8LCwv/cXFx/87Ozv/f39//uLi4/0ZGRv8AAAD/AAAA/2xsbP/8/Pz/////////////////////////
////////ycnJ/y0tLf8AAAD/BAQE/zg4OP8SEhL/AAAA/w8PD/+Wlpb//Pz8/////////////////5+f
n/8CAgL/AAAA/3Fxcf/5+fn/////////////////4eHh/zU1Nf8AAAD/Hh4e/9vb2///////////////
////////////////////////ycnJ/zAwMP8AAAD/AAAA/wAAAP8QEBD/l5eX//z8/P//////////////
////////bGxs/wAAAP8SEhL/zMzM////////////////////////////iYmJ/wAAAP8GBgb/tbW1////
///////////////////////////////////8/Pz/dXV1/wAAAP8AAAD/AAAA/zc3N//m5ub/////////
//////////////////9eXl7/AAAA/x4eHv/e3t7///////////////////////////+goKD/AAAA/wIC
Av+rq6v//////////////////////////////////Pz8/5WVlf8PDw//AAAA/wEBAf8AAAD/AgIC/11d
Xf/r6+v//////////////////////3h4eP8AAAD/CgoK/7i4uP///////////////////////////3Fx
cf8AAAD/DAwM/8HBwf////////////////////////////z8/P+Wlpb/Dw8P/wAAAP8RERH/dnZ2/zAw
MP8AAAD/AgIC/11dXf/r6+v/////////////////tbW1/woKCv8AAAD/R0dH/+Li4v//////////////
//+5ubn/Ghoa/wAAAP8yMjL/6urq///////////////////////8/Pz/lpaW/w8PD/8AAAD/Dw8P/5aW
lv/9/f3/ycnJ/y0tLf8AAAD/AgIC/15eXv/s7Oz////////////z8/P/UlJS/wAAAP8BAQH/NjY2/4uL
i/+jo6P/c3Nz/xsbG/8AAAD/BQUF/5WVlf///////////////////////////8PDw/8SEhL/AAAA/w8P
D/+Wlpb//Pz8////////////ycnJ/y0tLf8AAAD/AAAA/4GBgf/////////////////W1tb/ODg4/wAA
AP8AAAD/AAAA/wEBAf8AAAD/AAAA/wUFBf9tbW3/9PT0////////////////////////////w8PD/xUV
Ff8RERH/lpaW//z8/P//////////////////////ycnJ/zAwMP8CAgL/goKC////////////////////
///d3d3/bGxs/x4eHv8GBgb/AgIC/woKCv8wMDD/lJSU//Pz8///////////////////////////////
///7+/v/w8PD/8TExP/7+/v/////////////////////////////////2tra/7W1tf/u7u7/////////
///////////////////7+/v/3Nzc/7W1tf+qqqr/wMDA/+np6f//////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
</value>
</data>
</root>

26
Game.cs
View File

@@ -1,12 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Media;
using System.Text;
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;
namespace TicTacToe
namespace TicTacToe
{
public class Game
{
@@ -114,14 +106,14 @@ namespace TicTacToe
{
int[][] lines =
{
new[] {0, 1, 2},
new[] {3, 4, 5},
new[] {6, 7, 8},
new[] {0, 3, 6},
new[] {1, 4, 7},
new[] {2, 5, 8},
new[] {0, 4, 8},
new[] {2, 4, 6}
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
[0, 3, 6],
[1, 4, 7],
[2, 5, 8],
[0, 4, 8],
[2, 4, 6]
};
foreach (var line in lines)

View File

@@ -3,28 +3,33 @@ namespace TicTacToe
public static class Program
{
public static Form1 form = new Form1();
static Game game;
static Game game = new Game();
static int wins = 0;
static int loses = 0;
static void Main()
{
ApplicationConfiguration.Initialize();
game = new Game();
game.Start();
form.newGameToolStripMenuItem.Click += NewGame;
form.exitToolStripMenuItem.Click += Exit;
form.aboutToolStripMenuItem.Click += About;
Application.Run(form);
}
static void NewGame(object sender, EventArgs e)
static void NewGame(object? sender, EventArgs e)
{
game.Destroy();
game = new Game();
game.Start();
}
static void Exit(object sender, EventArgs e)
static void About(object? sender, EventArgs e)
{
MessageBox.Show("Tic Tac Toe med motst<73>ndare, kodat av Max Westerlund");
}
static void Exit(object? sender, EventArgs e)
{
Application.Exit();
}

View File

@@ -1,11 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</Project>
<!-- standalone exe -->
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<!-- optimization -->
<TrimMode>link</TrimMode>
<ReadyToRun>true</ReadyToRun>
<TieredCompilation>false</TieredCompilation>
<Optimize>true</Optimize>
<!-- icon -->
<ApplicationIcon>icon.ico</ApplicationIcon>
</PropertyGroup>
</Project>

BIN
icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB