some of the game check is working

This commit is contained in:
2022-09-23 11:27:45 +02:00
23 changed files with 196 additions and 19 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1 +1 @@
<?xml version="1.0" encoding="utf-8"?><PipelineBuildEvent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><SourceFile>C:/dev/Tic-Tac-Toe/Tic-Tac-Toe/Tic-Tac-Toe/Content/Textures/X.png</SourceFile><SourceTime>2022-09-21T09:28:35.420606+02:00</SourceTime><DestFile>C:/dev/Tic-Tac-Toe/Tic-Tac-Toe/Tic-Tac-Toe/Content/bin/DesktopGL/Content/Textures/X.xnb</DestFile><DestTime>2022-09-21T09:41:34.4258436+02:00</DestTime><Importer>TextureImporter</Importer><ImporterTime>2022-07-26T13:44:56+02:00</ImporterTime><Processor>TextureProcessor</Processor><ProcessorTime>2022-07-26T13:44:56+02:00</ProcessorTime><Parameters><Key>ColorKeyColor</Key><Value>255,0,255,255</Value></Parameters><Parameters><Key>ColorKeyEnabled</Key><Value>True</Value></Parameters><Parameters><Key>GenerateMipmaps</Key><Value>False</Value></Parameters><Parameters><Key>PremultiplyAlpha</Key><Value>True</Value></Parameters><Parameters><Key>ResizeToPowerOfTwo</Key><Value>False</Value></Parameters><Parameters><Key>MakeSquare</Key><Value>False</Value></Parameters><Parameters><Key>TextureFormat</Key><Value>Color</Value></Parameters><Dependencies /><BuildAsset /><BuildOutput /></PipelineBuildEvent> <?xml version="1.0" encoding="utf-8"?><PipelineBuildEvent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><SourceFile>C:/dev/Tic-Tac-Toe/Tic-Tac-Toe/Tic-Tac-Toe/Content/Textures/X.png</SourceFile><SourceTime>2022-09-21T09:28:35.420606+02:00</SourceTime><DestFile>C:/dev/Tic-Tac-Toe/Tic-Tac-Toe/Tic-Tac-Toe/Content/bin/DesktopGL/Content/Textures/X.xnb</DestFile><DestTime>2022-09-23T08:49:01.067381+02:00</DestTime><Importer>TextureImporter</Importer><ImporterTime>2022-07-26T13:44:56+02:00</ImporterTime><Processor>TextureProcessor</Processor><ProcessorTime>2022-07-26T13:44:56+02:00</ProcessorTime><Parameters><Key>ColorKeyColor</Key><Value>255,0,255,255</Value></Parameters><Parameters><Key>ColorKeyEnabled</Key><Value>True</Value></Parameters><Parameters><Key>GenerateMipmaps</Key><Value>False</Value></Parameters><Parameters><Key>PremultiplyAlpha</Key><Value>True</Value></Parameters><Parameters><Key>ResizeToPowerOfTwo</Key><Value>False</Value></Parameters><Parameters><Key>MakeSquare</Key><Value>False</Value></Parameters><Parameters><Key>TextureFormat</Key><Value>Color</Value></Parameters><Dependencies /><BuildAsset /><BuildOutput /></PipelineBuildEvent>

View File

@@ -1 +1 @@
<?xml version="1.0" encoding="utf-8"?><PipelineBuildEvent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><SourceFile>C:/dev/Tic-Tac-Toe/Tic-Tac-Toe/Tic-Tac-Toe/Content/Textures/circle.png</SourceFile><SourceTime>2022-09-21T09:27:30.8441469+02:00</SourceTime><DestFile>C:/dev/Tic-Tac-Toe/Tic-Tac-Toe/Tic-Tac-Toe/Content/bin/DesktopGL/Content/Textures/circle.xnb</DestFile><DestTime>2022-09-21T09:41:34.2979772+02:00</DestTime><Importer>TextureImporter</Importer><ImporterTime>2022-07-26T13:44:56+02:00</ImporterTime><Processor>TextureProcessor</Processor><ProcessorTime>2022-07-26T13:44:56+02:00</ProcessorTime><Parameters><Key>ColorKeyColor</Key><Value>255,0,255,255</Value></Parameters><Parameters><Key>ColorKeyEnabled</Key><Value>True</Value></Parameters><Parameters><Key>GenerateMipmaps</Key><Value>False</Value></Parameters><Parameters><Key>PremultiplyAlpha</Key><Value>True</Value></Parameters><Parameters><Key>ResizeToPowerOfTwo</Key><Value>False</Value></Parameters><Parameters><Key>MakeSquare</Key><Value>False</Value></Parameters><Parameters><Key>TextureFormat</Key><Value>Color</Value></Parameters><Dependencies /><BuildAsset /><BuildOutput /></PipelineBuildEvent> <?xml version="1.0" encoding="utf-8"?><PipelineBuildEvent xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><SourceFile>C:/dev/Tic-Tac-Toe/Tic-Tac-Toe/Tic-Tac-Toe/Content/Textures/circle.png</SourceFile><SourceTime>2022-09-21T09:27:30.8441469+02:00</SourceTime><DestFile>C:/dev/Tic-Tac-Toe/Tic-Tac-Toe/Tic-Tac-Toe/Content/bin/DesktopGL/Content/Textures/circle.xnb</DestFile><DestTime>2022-09-23T08:49:00.8300161+02:00</DestTime><Importer>TextureImporter</Importer><ImporterTime>2022-07-26T13:44:56+02:00</ImporterTime><Processor>TextureProcessor</Processor><ProcessorTime>2022-07-26T13:44:56+02:00</ProcessorTime><Parameters><Key>ColorKeyColor</Key><Value>255,0,255,255</Value></Parameters><Parameters><Key>ColorKeyEnabled</Key><Value>True</Value></Parameters><Parameters><Key>GenerateMipmaps</Key><Value>False</Value></Parameters><Parameters><Key>PremultiplyAlpha</Key><Value>True</Value></Parameters><Parameters><Key>ResizeToPowerOfTwo</Key><Value>False</Value></Parameters><Parameters><Key>MakeSquare</Key><Value>False</Value></Parameters><Parameters><Key>TextureFormat</Key><Value>Color</Value></Parameters><Dependencies /><BuildAsset /><BuildOutput /></PipelineBuildEvent>

View File

@@ -7,8 +7,12 @@ namespace Tic_Tac_Toe {
public class Game1 : Game { public class Game1 : Game {
private GraphicsDeviceManager _graphics; private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch; private SpriteBatch _spriteBatch;
private Texture2D Circle, X;
private RectangleF[,] rectArray; private RectangleF[,] rectArray;
private int[] CircleXPostion; private int[,] CircleXPostion;
private int lineThickness = 5;
private int playerWon = 0; //1 is circle 2 is x
private bool isCircleNext = false;
public Game1() { public Game1() {
_graphics = new GraphicsDeviceManager(this); _graphics = new GraphicsDeviceManager(this);
@@ -20,12 +24,13 @@ namespace Tic_Tac_Toe {
// TODO: Add your initialization logic here // TODO: Add your initialization logic here
//Setting Resolution //Setting Resolution
this._graphics.PreferredBackBufferWidth = 800; _graphics.PreferredBackBufferWidth = 800;
this._graphics.PreferredBackBufferHeight = 600; _graphics.PreferredBackBufferHeight = 600;
this._graphics.ApplyChanges(); _graphics.ApplyChanges();
//For field //For field
rectArray = new RectangleF[3,3]; rectArray = new RectangleF[3,3];
CircleXPostion = new int[3, 3]; //0 is free space, 1 is circle, 2 is X
base.Initialize(); base.Initialize();
} }
@@ -34,33 +39,85 @@ namespace Tic_Tac_Toe {
_spriteBatch = new SpriteBatch(GraphicsDevice); _spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here // TODO: use this.Content to load your game content here
Circle = Content.Load<Texture2D>("Textures/circle");
X = Content.Load<Texture2D>("Textures/X");
} }
protected override void Update(GameTime gameTime) { protected override void Update(GameTime gameTime) {
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit(); Exit();
System.Console.WriteLine("TEST KIIRAS");
// TODO: Add your update logic here // TODO: Add your update logic here
if (playerWon == 0) {
var mouse = Mouse.GetState();
for (int i = 0; i < rectArray.GetLength(0); i++) {
for (int j = 0; j < rectArray.GetLength(1); j++) {
mouse = Mouse.GetState();
if (isCircleNext) {
if (rectArray[i, j].Contains(new Point(mouse.X, mouse.Y)) && mouse.LeftButton == ButtonState.Pressed && CircleXPostion[i, j] == 0) {
CircleXPostion[i, j] = 1; //eltároljuk a kör pozicióját
isCircleNext = false;
//System.Threading.Thread.Sleep(250);
}
} else {
if (rectArray[i, j].Contains(new Point(mouse.X, mouse.Y)) && mouse.LeftButton == ButtonState.Pressed && CircleXPostion[i, j] == 0) {
CircleXPostion[i, j] = 2; //eltaroljuk az x poziciojat
isCircleNext = true;
//System.Threading.Thread.Sleep(250);
}
}
}
}
}
CheckGameCondition();
base.Update(gameTime); base.Update(gameTime);
} }
protected override void Draw(GameTime gameTime) { protected override void Draw(GameTime gameTime) {
GraphicsDevice.Clear(Color.Black); GraphicsDevice.Clear(Color.CadetBlue);
// TODO: Add your drawing code here // TODO: Add your drawing code here
var mouse = Mouse.GetState();
_spriteBatch.Begin(); _spriteBatch.Begin();
DrawTicTacToeFieldRect(rectArray, Color.White); DrawTicTacToeFieldRect(rectArray, Color.LightGray);
//checking if mouse is in a rect
for (int i = 0; i < rectArray.GetLength(0); i++) { for (int i = 0; i < rectArray.GetLength(0); i++) {
for (int j = 0; j < rectArray.GetLength(1); j++) { for (int j = 0; j < rectArray.GetLength(1); j++) {
var mouse = Mouse.GetState(); mouse = Mouse.GetState();
if (rectArray[i, j].Contains(new Point(mouse.X, mouse.Y))) { if (isCircleNext) { //Circle player highlight
DrawSingleRect(rectArray, Color.Red, i, j); if (rectArray[i, j].Contains(new Point(mouse.X, mouse.Y))) {
DrawSingleRect(rectArray, Color.Red, i, j);
}
} else { //X player highlight
if (rectArray[i, j].Contains(new Point(mouse.X, mouse.Y))) {
DrawSingleRect(rectArray, Color.Green, i, j);
}
} }
} }
} }
for (int i = 0; i < CircleXPostion.GetLength(0); i++) {
for (int j = 0; j < CircleXPostion.GetLength(1); j++) {
mouse = Mouse.GetState();
if (CircleXPostion[i,j] == 1) { //Circle player highlight
_spriteBatch.Draw(Circle, new Rectangle(200 * i + 100, 200*j, 200, 200), Color.White);
} else if (CircleXPostion[i, j] == 2) { //X player highlight
_spriteBatch.Draw(X, new Rectangle(200 * i + 100, 200*j, 200, 200), Color.White);
}
}
}
//loop through circle pos arr to draw the texture
/*_spriteBatch.Draw(Circle, new Rectangle(100, 0, 200, 200), Color.White);
_spriteBatch.Draw(X, new Rectangle(300, 0, 200, 200), Color.White);*/
_spriteBatch.End(); _spriteBatch.End();
base.Draw(gameTime); base.Draw(gameTime);
@@ -69,11 +126,11 @@ namespace Tic_Tac_Toe {
public void DrawTicTacToeField() { public void DrawTicTacToeField() {
//drawing the field //drawing the field
//Vertical Lines //Vertical Lines
_spriteBatch.DrawLine(250, 0, 250, _graphics.PreferredBackBufferHeight, Color.White, 10, 0); _spriteBatch.DrawLine(250, 0, 250, _graphics.PreferredBackBufferHeight, Color.White, lineThickness, 0);
_spriteBatch.DrawLine(550, 0, 550, _graphics.PreferredBackBufferHeight, Color.White, 10, 0); _spriteBatch.DrawLine(550, 0, 550, _graphics.PreferredBackBufferHeight, Color.White, lineThickness, 0);
//Horizontal Lines //Horizontal Lines
_spriteBatch.DrawLine(0, 200, _graphics.PreferredBackBufferWidth, 200, Color.White, 10, 0); _spriteBatch.DrawLine(0, 200, _graphics.PreferredBackBufferWidth, 200, Color.White, lineThickness, 0);
_spriteBatch.DrawLine(0, 400, _graphics.PreferredBackBufferWidth, 400, Color.White, 10, 0); _spriteBatch.DrawLine(0, 400, _graphics.PreferredBackBufferWidth, 400, Color.White, lineThickness, 0);
} }
private void DrawTicTacToeFieldRect(RectangleF[,] rectArray, Color color) { private void DrawTicTacToeFieldRect(RectangleF[,] rectArray, Color color) {
@@ -83,13 +140,104 @@ namespace Tic_Tac_Toe {
for (int i = 0; i < rectArray.GetLength(0); i++) { for (int i = 0; i < rectArray.GetLength(0); i++) {
for (int j = 0; j < rectArray.GetLength(1); j++) { for (int j = 0; j < rectArray.GetLength(1); j++) {
rectArray[i, j] = new RectangleF(size * i + 100, size*j, size, size); //+100 is offset rectArray[i, j] = new RectangleF(size * i + 100, size*j, size, size); //+100 is offset
_spriteBatch.DrawRectangle(rectArray[i, j], color, 10, 0); _spriteBatch.DrawRectangle(rectArray[i, j], color, lineThickness, 0);
} }
} }
} }
private void DrawSingleRect(RectangleF[,] rectArray, Color color, int x, int y) { private void DrawSingleRect(RectangleF[,] rectArray, Color color, int indexX, int indexY) {
_spriteBatch.DrawRectangle(rectArray[x, y], color, 10, 0); _spriteBatch.DrawRectangle(rectArray[indexX, indexY], color, lineThickness, 0);
}
private void CheckGameCondition() {
//vertical
//circle
for (int i = 0; i < CircleXPostion.GetLength(0); i++) {
int count = 0;
for (int j = 0; j < CircleXPostion.GetLength(1); j++) {
if(CircleXPostion[i, j] == 1) {
count++;
}
}
if(count == 3) {
playerWon = 1;
return;
}
}
//x
for (int i = 0; i < CircleXPostion.GetLength(0); i++) {
int count = 0;
for (int j = 0; j < CircleXPostion.GetLength(1); j++) {
if (CircleXPostion[i, j] == 2) {
count++;
}
}
if (count == 3) {
playerWon = 2;
return;
}
}
//horizontal
//circle
for (int i = 0; i < CircleXPostion.GetLength(0); i++) {
int count = 0;
for (int j = 0; j < CircleXPostion.GetLength(1); j++) {
if (CircleXPostion[j, i] == 1) {
count++;
}
}
if (count == 3) {
playerWon = 1;
return;
}
}
//x
for (int i = 0; i < CircleXPostion.GetLength(0); i++) {
int count = 0;
for (int j = 0; j < CircleXPostion.GetLength(1); j++) {
if (CircleXPostion[j, i] == 2) {
count++;
}
}
if (count == 3) {
playerWon = 2;
return;
}
}
//diagonal
//circle
for (int i = 0; i < CircleXPostion.GetLength(0); i++) {
int count = 0;
if (CircleXPostion[i, i] == 1) {
count++;
}
if (count == 3) {
playerWon = 1;
return;
}
}
//x
for (int i = 0; i < CircleXPostion.GetLength(0); i++) {
int count = 0;
if (CircleXPostion[i, i] == 2) {
count++;
}
if (count == 3) {
playerWon = 2;
return;
}
}
//reverse diagonal
} }
} }
} }

View File

@@ -27,3 +27,32 @@ C:\dev\Tic-Tac-Toe\Tic-Tac-Toe\Tic-Tac-Toe\bin\Debug\net6.0\Content\Textures\cir
C:\dev\Tic-Tac-Toe\Tic-Tac-Toe\Tic-Tac-Toe\bin\Debug\net6.0\Content\Textures\X.xnb C:\dev\Tic-Tac-Toe\Tic-Tac-Toe\Tic-Tac-Toe\bin\Debug\net6.0\Content\Textures\X.xnb
C:\dev\Tic-Tac-Toe\Tic-Tac-Toe\Tic-Tac-Toe\bin\Debug\net6.0\MonoGame.Extended.dll C:\dev\Tic-Tac-Toe\Tic-Tac-Toe\Tic-Tac-Toe\bin\Debug\net6.0\MonoGame.Extended.dll
C:\dev\Tic-Tac-Toe\Tic-Tac-Toe\Tic-Tac-Toe\bin\Debug\net6.0\Newtonsoft.Json.dll C:\dev\Tic-Tac-Toe\Tic-Tac-Toe\Tic-Tac-Toe\bin\Debug\net6.0\Newtonsoft.Json.dll
C:\dev\TicTacToe\Tic-Tac-Toe\bin\Debug\net6.0\Content\Textures\circle.xnb
C:\dev\TicTacToe\Tic-Tac-Toe\bin\Debug\net6.0\Content\Textures\X.xnb
C:\dev\TicTacToe\Tic-Tac-Toe\bin\Debug\net6.0\Tic-Tac-Toe.exe
C:\dev\TicTacToe\Tic-Tac-Toe\bin\Debug\net6.0\Tic-Tac-Toe.deps.json
C:\dev\TicTacToe\Tic-Tac-Toe\bin\Debug\net6.0\Tic-Tac-Toe.runtimeconfig.json
C:\dev\TicTacToe\Tic-Tac-Toe\bin\Debug\net6.0\Tic-Tac-Toe.dll
C:\dev\TicTacToe\Tic-Tac-Toe\bin\Debug\net6.0\Tic-Tac-Toe.pdb
C:\dev\TicTacToe\Tic-Tac-Toe\bin\Debug\net6.0\MonoGame.Extended.dll
C:\dev\TicTacToe\Tic-Tac-Toe\bin\Debug\net6.0\MonoGame.Framework.dll
C:\dev\TicTacToe\Tic-Tac-Toe\bin\Debug\net6.0\Newtonsoft.Json.dll
C:\dev\TicTacToe\Tic-Tac-Toe\bin\Debug\net6.0\runtimes\linux-x64\native\libSDL2-2.0.so.0
C:\dev\TicTacToe\Tic-Tac-Toe\bin\Debug\net6.0\runtimes\linux-x64\native\libopenal.so.1
C:\dev\TicTacToe\Tic-Tac-Toe\bin\Debug\net6.0\runtimes\osx\native\libSDL2.dylib
C:\dev\TicTacToe\Tic-Tac-Toe\bin\Debug\net6.0\runtimes\osx\native\libopenal.1.dylib
C:\dev\TicTacToe\Tic-Tac-Toe\bin\Debug\net6.0\runtimes\win-x64\native\SDL2.dll
C:\dev\TicTacToe\Tic-Tac-Toe\bin\Debug\net6.0\runtimes\win-x64\native\soft_oal.dll
C:\dev\TicTacToe\Tic-Tac-Toe\bin\Debug\net6.0\runtimes\win-x86\native\SDL2.dll
C:\dev\TicTacToe\Tic-Tac-Toe\bin\Debug\net6.0\runtimes\win-x86\native\soft_oal.dll
C:\dev\TicTacToe\Tic-Tac-Toe\obj\Debug\net6.0\Tic-Tac-Toe.csproj.AssemblyReference.cache
C:\dev\TicTacToe\Tic-Tac-Toe\obj\Debug\net6.0\Tic-Tac-Toe.GeneratedMSBuildEditorConfig.editorconfig
C:\dev\TicTacToe\Tic-Tac-Toe\obj\Debug\net6.0\Tic-Tac-Toe.AssemblyInfoInputs.cache
C:\dev\TicTacToe\Tic-Tac-Toe\obj\Debug\net6.0\Tic-Tac-Toe.AssemblyInfo.cs
C:\dev\TicTacToe\Tic-Tac-Toe\obj\Debug\net6.0\Tic-Tac-Toe.csproj.CoreCompileInputs.cache
C:\dev\TicTacToe\Tic-Tac-Toe\obj\Debug\net6.0\Tic-Tac-Toe.csproj.CopyComplete
C:\dev\TicTacToe\Tic-Tac-Toe\obj\Debug\net6.0\Tic-Tac-Toe.dll
C:\dev\TicTacToe\Tic-Tac-Toe\obj\Debug\net6.0\refint\Tic-Tac-Toe.dll
C:\dev\TicTacToe\Tic-Tac-Toe\obj\Debug\net6.0\Tic-Tac-Toe.pdb
C:\dev\TicTacToe\Tic-Tac-Toe\obj\Debug\net6.0\Tic-Tac-Toe.genruntimeconfig.cache
C:\dev\TicTacToe\Tic-Tac-Toe\obj\Debug\net6.0\ref\Tic-Tac-Toe.dll