diff options
64 files changed, 3185 insertions, 1635 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2d8a974 --- /dev/null +++ b/.gitignore @@ -0,0 +1,362 @@ +## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+##
+## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
+
+# User-specific files
+*.rsuser
+*.suo
+*.user
+*.userosscache
+*.sln.docstates
+
+# User-specific files (MonoDevelop/Xamarin Studio)
+*.userprefs
+
+# Mono auto generated files
+mono_crash.*
+
+# Build results
+[Dd]ebug/
+[Dd]ebugPublic/
+[Rr]elease/
+[Rr]eleases/
+x64/
+x86/
+[Ww][Ii][Nn]32/
+[Aa][Rr][Mm]/
+[Aa][Rr][Mm]64/
+bld/
+[Bb]in/
+[Oo]bj/
+[Ll]og/
+[Ll]ogs/
+
+# Visual Studio 2015/2017 cache/options directory
+.vs/
+# Uncomment if you have tasks that create the project's static files in wwwroot
+#wwwroot/
+
+# Visual Studio 2017 auto generated files
+Generated\ Files/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+# NUnit
+*.VisualState.xml
+TestResult.xml
+nunit-*.xml
+
+# Build Results of an ATL Project
+[Dd]ebugPS/
+[Rr]eleasePS/
+dlldata.c
+
+# Benchmark Results
+BenchmarkDotNet.Artifacts/
+
+# .NET Core
+project.lock.json
+project.fragment.lock.json
+artifacts/
+
+# ASP.NET Scaffolding
+ScaffoldingReadMe.txt
+
+# StyleCop
+StyleCopReport.xml
+
+# Files built by Visual Studio
+*_i.c
+*_p.c
+*_h.h
+*.ilk
+*.meta
+*.obj
+*.iobj
+*.pch
+*.pdb
+*.ipdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*_wpftmp.csproj
+*.log
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.svclog
+*.scc
+
+# Chutzpah Test files
+_Chutzpah*
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opendb
+*.opensdf
+*.sdf
+*.cachefile
+*.VC.db
+*.VC.VC.opendb
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+*.sap
+
+# Visual Studio Trace Files
+*.e2e
+
+# TFS 2012 Local Workspace
+$tf/
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+*.DotSettings.user
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# AxoCover is a Code Coverage Tool
+.axoCover/*
+!.axoCover/settings.json
+
+# Coverlet is a free, cross platform Code Coverage Tool
+coverage*.json
+coverage*.xml
+coverage*.info
+
+# Visual Studio code coverage results
+*.coverage
+*.coveragexml
+
+# NCrunch
+_NCrunch_*
+.*crunch*.local.xml
+nCrunchTemp_*
+
+# MightyMoose
+*.mm.*
+AutoTest.Net/
+
+# Web workbench (sass)
+.sass-cache/
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.[Pp]ublish.xml
+*.azurePubxml
+# Note: Comment the next line if you want to checkin your web deploy settings,
+# but database connection strings (with potential passwords) will be unencrypted
+*.pubxml
+*.publishproj
+
+# Microsoft Azure Web App publish settings. Comment the next line if you want to
+# checkin your Azure Web App publish settings, but sensitive information contained
+# in these scripts will be unencrypted
+PublishScripts/
+
+# NuGet Packages
+*.nupkg
+# NuGet Symbol Packages
+*.snupkg
+# The packages folder can be ignored because of Package Restore
+**/[Pp]ackages/*
+# except build/, which is used as an MSBuild target.
+!**/[Pp]ackages/build/
+# Uncomment if necessary however generally it will be regenerated when needed
+#!**/[Pp]ackages/repositories.config
+# NuGet v3's project.json files produces more ignorable files
+*.nuget.props
+*.nuget.targets
+
+# Microsoft Azure Build Output
+csx/
+*.build.csdef
+
+# Microsoft Azure Emulator
+ecf/
+rcf/
+
+# Windows Store app package directories and files
+AppPackages/
+BundleArtifacts/
+Package.StoreAssociation.xml
+_pkginfo.txt
+*.appx
+*.appxbundle
+*.appxupload
+
+# Visual Studio cache files
+# files ending in .cache can be ignored
+*.[Cc]ache
+# but keep track of directories ending in .cache
+!?*.[Cc]ache/
+
+# Others
+ClientBin/
+~$*
+*~
+*.dbmdl
+*.dbproj.schemaview
+*.jfm
+*.pfx
+*.publishsettings
+orleans.codegen.cs
+
+# Including strong name files can present a security risk
+# (https://github.com/github/gitignore/pull/2483#issue-259490424)
+#*.snk
+
+# Since there are multiple workflows, uncomment next line to ignore bower_components
+# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
+#bower_components/
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file
+# to a newer Visual Studio version. Backup files are not needed,
+# because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+ServiceFabricBackup/
+*.rptproj.bak
+
+# SQL Server files
+*.mdf
+*.ldf
+*.ndf
+
+# Business Intelligence projects
+*.rdl.data
+*.bim.layout
+*.bim_*.settings
+*.rptproj.rsuser
+*- [Bb]ackup.rdl
+*- [Bb]ackup ([0-9]).rdl
+*- [Bb]ackup ([0-9][0-9]).rdl
+
+# Microsoft Fakes
+FakesAssemblies/
+
+# GhostDoc plugin setting file
+*.GhostDoc.xml
+
+# Node.js Tools for Visual Studio
+.ntvs_analysis.dat
+node_modules/
+
+# Visual Studio 6 build log
+*.plg
+
+# Visual Studio 6 workspace options file
+*.opt
+
+# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
+*.vbw
+
+# Visual Studio LightSwitch build output
+**/*.HTMLClient/GeneratedArtifacts
+**/*.DesktopClient/GeneratedArtifacts
+**/*.DesktopClient/ModelManifest.xml
+**/*.Server/GeneratedArtifacts
+**/*.Server/ModelManifest.xml
+_Pvt_Extensions
+
+# Paket dependency manager
+.paket/paket.exe
+paket-files/
+
+# FAKE - F# Make
+.fake/
+
+# CodeRush personal settings
+.cr/personal
+
+# Python Tools for Visual Studio (PTVS)
+__pycache__/
+*.pyc
+
+# Cake - Uncomment if you are using it
+# tools/**
+# !tools/packages.config
+
+# Tabs Studio
+*.tss
+
+# Telerik's JustMock configuration file
+*.jmconfig
+
+# BizTalk build output
+*.btp.cs
+*.btm.cs
+*.odx.cs
+*.xsd.cs
+
+# OpenCover UI analysis results
+OpenCover/
+
+# Azure Stream Analytics local run output
+ASALocalRun/
+
+# MSBuild Binary and Structured Log
+*.binlog
+
+# NVidia Nsight GPU debugger configuration file
+*.nvuser
+
+# MFractors (Xamarin productivity tool) working folder
+.mfractor/
+
+# Local History for Visual Studio
+.localhistory/
+
+# BeatPulse healthcheck temp database
+healthchecksdb
+
+# Backup folder for Package Reference Convert tool in Visual Studio 2017
+MigrationBackup/
+
+# Ionide (cross platform F# VS Code tools) working folder
+.ionide/
+
+# Fody - auto-generated XML schema
+FodyWeavers.xsd
diff --git a/.vs/Chess/v16/.suo b/.vs/Chess/v16/.suo Binary files differdeleted file mode 100644 index dc29f3f..0000000 --- a/.vs/Chess/v16/.suo +++ /dev/null @@ -1,6 +1,6 @@ -<?xml version="1.0" encoding="utf-8" ?> -<configuration> - <startup> - <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> - </startup> +<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <startup>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
+ </startup>
</configuration>
\ No newline at end of file diff --git a/BoardTile.cs b/BoardTile.cs index e58cbc6..7cea5a9 100644 --- a/BoardTile.cs +++ b/BoardTile.cs @@ -1,66 +1,163 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Chess -{ - public enum BoardTileColor - { - White, - Black, - } - - public class BoardTile - { - public int X; - public int Y; - public BoardTileColor Color; - public ChessPiece OccupyingPiece; - - public BoardTile(int x, int y) - { - X = x; - Y = y; - - Color = BoardTileColor.White; - if (y % 2 == 0) - { - if (x % 2 != 0) Color = BoardTileColor.Black; - } - else - { - if (x % 2 == 0) Color = BoardTileColor.Black; - } - - OccupyingPiece = null; - } - - public bool CanMoveTo(ChessBoard board, BoardTile tile) - { - if (OccupyingPiece != null) return OccupyingPiece.CanMoveTo(board, this, tile); - - return false; - } - - internal void Draw(Graphics graphics, float tileWidth, float tileHeight, bool active) - { - graphics.FillRectangle(new SolidBrush(this.Color == BoardTileColor.White ? System.Drawing.Color.FromArgb(235, 236, 208) : System.Drawing.Color.FromArgb(137, 163, 105)), - new RectangleF(X * tileWidth, Y * tileHeight, tileWidth, tileHeight)); - - OccupyingPiece?.Draw(graphics, X, Y, tileWidth, tileHeight); - - if (active) - { - float marginw = tileWidth / 3; - float marginh = tileHeight / 3; - int padding = 3; - graphics.FillEllipse(new SolidBrush(System.Drawing.Color.FromArgb(150, 50, 50, 50)), X * tileWidth + marginw, Y * tileHeight + marginh, tileWidth - marginw * 2, tileHeight - marginh * 2); - graphics.FillEllipse(new SolidBrush(System.Drawing.Color.FromArgb(150, 255, 200, 200)), X * tileWidth + marginw + padding, Y * tileHeight + marginh + padding, tileWidth - (marginw + padding) * 2, tileHeight - (marginh + padding) * 2); - } - } - } -} +using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Chess
+{
+ [Flags]
+ public enum TileState
+ {
+ /// <summary>
+ /// Default state.
+ /// </summary>
+ Normal = 1,
+
+ /// <summary>
+ /// Selected by user.
+ /// </summary>
+ Selected = 2,
+
+ /// <summary>
+ /// Possible target for selected piece.
+ /// </summary>
+ Targeted = 4,
+
+ /// <summary>
+ /// Involved in latest piece movement.
+ /// </summary>
+ Latest = 8,
+ }
+
+ public enum BoardTileColor
+ {
+ White,
+ Black,
+ }
+
+ public class BoardTile
+ {
+ public int X;
+ public int Y;
+ public BoardTileColor Color;
+ public ChessPiece OccupyingPiece;
+ public TileState State;
+
+ public BoardTile(int x, int y)
+ {
+ X = x;
+ Y = y;
+
+ Color = BoardTileColor.White;
+ if (y % 2 == 0)
+ {
+ if (x % 2 != 0) Color = BoardTileColor.Black;
+ }
+ else
+ {
+ if (x % 2 == 0) Color = BoardTileColor.Black;
+ }
+
+ State = TileState.Normal;
+ OccupyingPiece = null;
+ }
+
+ public override string ToString()
+ {
+ return (((char)('a' + (char)X)).ToString() + (ChessBoard.BoardSize - Y).ToString()).ToString().ToUpper();
+ }
+
+ public bool CanMoveTo(ChessBoard board, BoardTile tile)
+ {
+ // By putting this code here we check whether or not the king will be attacked if we move,
+ // and also checks what spots we CAN move to when the king is under attack.
+ if (OccupyingPiece.WillKingBeAttackedIfMovedTo(board, this, tile))
+ {
+ return false;
+ }
+
+ if (OccupyingPiece != null) return OccupyingPiece.CanMoveTo(board, this, tile);
+
+ return false;
+ }
+
+ private System.Drawing.Color GetColor()
+ {
+ return this.Color == BoardTileColor.White ? System.Drawing.Color.FromArgb(235, 236, 208) : System.Drawing.Color.FromArgb(137, 163, 105);
+ }
+
+ private void DrawIdentifier(Graphics graphics, float tileWidth, float tileHeight)
+ {
+ Font drawFont = new Font("Arial", (tileWidth < tileHeight) ? tileWidth / 6 : tileHeight / 6, FontStyle.Bold);
+
+ float marginw = tileWidth / 30;
+ float marginh = tileHeight / 30;
+
+ // row number
+ if (X == 0)
+ {
+ graphics.DrawString((ChessBoard.BoardSize - Y).ToString(), drawFont,
+ new SolidBrush(System.Drawing.Color.FromArgb(200, 0, 0, 0)),
+ X * tileWidth + marginw, Y * tileHeight + marginh);
+ }
+
+ // col letter
+ if (Y + 1 == ChessBoard.BoardSize)
+ {
+ StringFormat format = new StringFormat();
+ format.LineAlignment = StringAlignment.Far;
+
+ graphics.DrawString(((char)('a' + (char)X)).ToString(), drawFont,
+ new SolidBrush(System.Drawing.Color.FromArgb(200, 0, 0, 0)),
+ X * tileWidth + marginw, Y * tileHeight + tileHeight - marginh, format);
+ }
+
+ drawFont.Dispose();
+ }
+
+ internal void Draw(Graphics graphics, float tileWidth, float tileHeight)
+ {
+ if (State.HasFlag(TileState.Latest))
+ {
+ graphics.FillRectangle(new SolidBrush(System.Drawing.Color.FromArgb(247, 180, 86)),
+ new RectangleF(X * tileWidth, Y * tileHeight, tileWidth, tileHeight));
+ }
+ else if (State.HasFlag(TileState.Selected))
+ {
+ graphics.FillRectangle(new SolidBrush(System.Drawing.Color.FromArgb(247, 97, 86)),
+ new RectangleF(X * tileWidth, Y * tileHeight, tileWidth, tileHeight));
+
+ }
+ else if (State.HasFlag(TileState.Normal))
+ {
+ graphics.FillRectangle(new SolidBrush(GetColor()), new RectangleF(X * tileWidth, Y * tileHeight, tileWidth, tileHeight));
+ }
+
+ DrawIdentifier(graphics, tileWidth, tileHeight);
+
+ OccupyingPiece?.Draw(graphics, X, Y, tileWidth, tileHeight);
+
+ float marginw = tileWidth / 3;
+ float marginh = tileHeight / 3;
+
+ if (State.HasFlag(TileState.Targeted))
+ {
+ int padding = 3;
+ graphics.FillEllipse(new SolidBrush(System.Drawing.Color.FromArgb(200, 50, 50, 50)),
+ X * tileWidth + marginw,
+ Y * tileHeight + marginh,
+ tileWidth - marginw * 2,
+ tileHeight - marginh * 2);
+
+ graphics.FillEllipse(new SolidBrush(System.Drawing.Color.FromArgb(247, 97, 86)),
+ X * tileWidth + marginw + padding,
+ Y * tileHeight + marginh + padding,
+ tileWidth - (marginw + padding) * 2,
+ tileHeight - (marginh + padding) * 2);
+ }
+ }
+ }
+}
diff --git a/Chess.csproj b/Chess.csproj index 86ed7b9..1d4ddc4 100644 --- a/Chess.csproj +++ b/Chess.csproj @@ -1,136 +1,153 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> - <PropertyGroup> - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <ProjectGuid>{CBF01088-874A-442B-867D-2456BED50DC0}</ProjectGuid> - <OutputType>WinExe</OutputType> - <RootNamespace>Chess</RootNamespace> - <AssemblyName>Chess</AssemblyName> - <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> - <FileAlignment>512</FileAlignment> - <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> - <Deterministic>true</Deterministic> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - <PlatformTarget>AnyCPU</PlatformTarget> - <DebugSymbols>true</DebugSymbols> - <DebugType>full</DebugType> - <Optimize>false</Optimize> - <OutputPath>bin\Debug\</OutputPath> - <DefineConstants>DEBUG;TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> - <PlatformTarget>AnyCPU</PlatformTarget> - <DebugType>pdbonly</DebugType> - <Optimize>true</Optimize> - <OutputPath>bin\Release\</OutputPath> - <DefineConstants>TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - </PropertyGroup> - <ItemGroup> - <Reference Include="System" /> - <Reference Include="System.Core" /> - <Reference Include="System.Xml.Linq" /> - <Reference Include="System.Data.DataSetExtensions" /> - <Reference Include="Microsoft.CSharp" /> - <Reference Include="System.Data" /> - <Reference Include="System.Deployment" /> - <Reference Include="System.Drawing" /> - <Reference Include="System.Net.Http" /> - <Reference Include="System.Windows.Forms" /> - <Reference Include="System.Xml" /> - </ItemGroup> - <ItemGroup> - <Compile Include="BoardTile.cs" /> - <Compile Include="ChessBoard.cs" /> - <Compile Include="ChessPiece.cs" /> - <Compile Include="ImageHelper.cs" /> - <Compile Include="MainForm.cs"> - <SubType>Form</SubType> - </Compile> - <Compile Include="MainForm.Designer.cs"> - <DependentUpon>MainForm.cs</DependentUpon> - </Compile> - <Compile Include="Pieces\Bishop.cs" /> - <Compile Include="Pieces\King.cs" /> - <Compile Include="Pieces\Knight.cs" /> - <Compile Include="Pieces\Pawn.cs" /> - <Compile Include="Pieces\Queen.cs" /> - <Compile Include="Pieces\Rook.cs" /> - <Compile Include="Program.cs" /> - <Compile Include="Properties\AssemblyInfo.cs" /> - <EmbeddedResource Include="MainForm.resx"> - <DependentUpon>MainForm.cs</DependentUpon> - </EmbeddedResource> - <EmbeddedResource Include="Properties\Resources.resx"> - <Generator>ResXFileCodeGenerator</Generator> - <LastGenOutput>Resources.Designer.cs</LastGenOutput> - <SubType>Designer</SubType> - </EmbeddedResource> - <Compile Include="Properties\Resources.Designer.cs"> - <AutoGen>True</AutoGen> - <DependentUpon>Resources.resx</DependentUpon> - <DesignTime>True</DesignTime> - </Compile> - <None Include="Properties\Settings.settings"> - <Generator>SettingsSingleFileGenerator</Generator> - <LastGenOutput>Settings.Designer.cs</LastGenOutput> - </None> - <Compile Include="Properties\Settings.Designer.cs"> - <AutoGen>True</AutoGen> - <DependentUpon>Settings.settings</DependentUpon> - <DesignTimeSharedInput>True</DesignTimeSharedInput> - </Compile> - </ItemGroup> - <ItemGroup> - <None Include="App.config" /> - </ItemGroup> - <ItemGroup> - <None Include="Resources\b_bishop_png_shadow_256px.png" /> - </ItemGroup> - <ItemGroup> - <None Include="Resources\b_king_png_shadow_256px.png" /> - </ItemGroup> - <ItemGroup> - <None Include="Resources\b_knight_png_shadow_256px.png" /> - </ItemGroup> - <ItemGroup> - <None Include="Resources\b_pawn_png_shadow_256px.png" /> - </ItemGroup> - <ItemGroup> - <None Include="Resources\b_queen_png_shadow_256px.png" /> - </ItemGroup> - <ItemGroup> - <None Include="Resources\b_rook_png_shadow_256px.png" /> - </ItemGroup> - <ItemGroup> - <None Include="Resources\w_bishop_png_shadow_256px.png" /> - </ItemGroup> - <ItemGroup> - <None Include="Resources\w_king_png_shadow_256px.png" /> - </ItemGroup> - <ItemGroup> - <None Include="Resources\w_knight_png_shadow_256px.png" /> - </ItemGroup> - <ItemGroup> - <None Include="Resources\w_pawn_png_shadow_256px.png" /> - </ItemGroup> - <ItemGroup> - <None Include="Resources\w_queen_png_shadow_256px.png" /> - </ItemGroup> - <ItemGroup> - <None Include="Resources\w_rook_png_shadow_256px.png" /> - </ItemGroup> - <ItemGroup> - <None Include="Resources\square brown light_png_shadow_256px.png" /> - </ItemGroup> - <ItemGroup> - <None Include="Resources\square gray light _png_shadow_256px.png" /> - </ItemGroup> - <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> +<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{CBF01088-874A-442B-867D-2456BED50DC0}</ProjectGuid>
+ <OutputType>WinExe</OutputType>
+ <RootNamespace>Chess</RootNamespace>
+ <AssemblyName>Chess</AssemblyName>
+ <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+ <Deterministic>true</Deterministic>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+ <HintPath>packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Deployment" />
+ <Reference Include="System.Drawing" />
+ <Reference Include="System.Net.Http" />
+ <Reference Include="System.Windows.Forms" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="BoardTile.cs" />
+ <Compile Include="ChessBoard.cs" />
+ <Compile Include="ChessPiece.cs" />
+ <Compile Include="Events\GameFinishedEvent.cs" />
+ <Compile Include="Events\RoundFinishedEvent.cs" />
+ <Compile Include="Extensions\GraphicsExtensions.cs" />
+ <Compile Include="Extensions\UdpClientExtensions.cs" />
+ <Compile Include="Game.cs" />
+ <Compile Include="ImageHelper.cs" />
+ <Compile Include="MainForm.cs">
+ <SubType>Form</SubType>
+ </Compile>
+ <Compile Include="MainForm.Designer.cs">
+ <DependentUpon>MainForm.cs</DependentUpon>
+ </Compile>
+ <Compile Include="Networking\INetworkMessage.cs" />
+ <Compile Include="Networking\NetworkManager.cs" />
+ <Compile Include="Pieces\Bishop.cs" />
+ <Compile Include="Pieces\King.cs" />
+ <Compile Include="Pieces\Knight.cs" />
+ <Compile Include="Pieces\Pawn.cs" />
+ <Compile Include="Pieces\Queen.cs" />
+ <Compile Include="Pieces\Rook.cs" />
+ <Compile Include="Player.cs" />
+ <Compile Include="PlayerMove.cs" />
+ <Compile Include="Program.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <EmbeddedResource Include="MainForm.resx">
+ <DependentUpon>MainForm.cs</DependentUpon>
+ <SubType>Designer</SubType>
+ </EmbeddedResource>
+ <EmbeddedResource Include="Properties\Resources.resx">
+ <Generator>ResXFileCodeGenerator</Generator>
+ <LastGenOutput>Resources.Designer.cs</LastGenOutput>
+ <SubType>Designer</SubType>
+ </EmbeddedResource>
+ <Compile Include="Properties\Resources.Designer.cs">
+ <AutoGen>True</AutoGen>
+ <DependentUpon>Resources.resx</DependentUpon>
+ <DesignTime>True</DesignTime>
+ </Compile>
+ <None Include="packages.config" />
+ <None Include="Properties\Settings.settings">
+ <Generator>SettingsSingleFileGenerator</Generator>
+ <LastGenOutput>Settings.Designer.cs</LastGenOutput>
+ </None>
+ <Compile Include="Properties\Settings.Designer.cs">
+ <AutoGen>True</AutoGen>
+ <DependentUpon>Settings.settings</DependentUpon>
+ <DesignTimeSharedInput>True</DesignTimeSharedInput>
+ </Compile>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="App.config" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Resources\b_bishop_png_shadow_256px.png" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Resources\b_king_png_shadow_256px.png" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Resources\b_knight_png_shadow_256px.png" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Resources\b_pawn_png_shadow_256px.png" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Resources\b_queen_png_shadow_256px.png" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Resources\b_rook_png_shadow_256px.png" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Resources\w_bishop_png_shadow_256px.png" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Resources\w_king_png_shadow_256px.png" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Resources\w_knight_png_shadow_256px.png" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Resources\w_pawn_png_shadow_256px.png" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Resources\w_queen_png_shadow_256px.png" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Resources\w_rook_png_shadow_256px.png" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Resources\square brown light_png_shadow_256px.png" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Resources\square gray light _png_shadow_256px.png" />
+ </ItemGroup>
+ <ItemGroup>
+ <Content Include="TODO.txt" />
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file @@ -1,25 +1,25 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30406.217 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chess", "Chess.csproj", "{CBF01088-874A-442B-867D-2456BED50DC0}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {CBF01088-874A-442B-867D-2456BED50DC0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CBF01088-874A-442B-867D-2456BED50DC0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CBF01088-874A-442B-867D-2456BED50DC0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CBF01088-874A-442B-867D-2456BED50DC0}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {879B9B2D-8E15-4746-92A9-45F6CDD2463A} - EndGlobalSection -EndGlobal +
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.30406.217
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chess", "Chess.csproj", "{CBF01088-874A-442B-867D-2456BED50DC0}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {CBF01088-874A-442B-867D-2456BED50DC0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {CBF01088-874A-442B-867D-2456BED50DC0}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {CBF01088-874A-442B-867D-2456BED50DC0}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {CBF01088-874A-442B-867D-2456BED50DC0}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {879B9B2D-8E15-4746-92A9-45F6CDD2463A}
+ EndGlobalSection
+EndGlobal
diff --git a/ChessBoard.cs b/ChessBoard.cs index 487ec29..d594d22 100644 --- a/ChessBoard.cs +++ b/ChessBoard.cs @@ -1,163 +1,455 @@ -using Chess.Pieces; -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Drawing.Drawing2D; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace Chess -{ - public class ChessBoard - { - const int boardSize = 8; - - private float tileWidth; - private float tileHeight; - - internal BoardTile[,] tiles; - private PictureBox container; - - private BoardTile selectedTile = null; - - private bool screenInvalidated = true; - - public ChessBoard(PictureBox container) - { - this.container = container; - - GenerateBoard(); - GeneratePieces(); - - DrawGame(); - } - - public void HandleResize() - { - DrawGame(); - } - - public void GeneratePieces() - { - tiles[0, 0].OccupyingPiece = new Rook(false); - tiles[0, 1].OccupyingPiece = new Knight(false); - tiles[0, 2].OccupyingPiece = new Bishop(false); - tiles[4,4].OccupyingPiece = new Queen(false); - tiles[0, 4].OccupyingPiece = new King(false); - tiles[0, 5].OccupyingPiece = new Bishop(false); - tiles[0, 6].OccupyingPiece = new Knight(false); - tiles[0, 7].OccupyingPiece = new Rook(false); - - for (int x = 0; x < boardSize; x++) - tiles[1, x].OccupyingPiece = new Pawn(false); - - for (int x = 0; x < boardSize; x++) - tiles[6, x].OccupyingPiece = new Pawn(true); - - tiles[7, 0].OccupyingPiece = new Rook(true); - tiles[7, 1].OccupyingPiece = new Knight(true); - tiles[7, 2].OccupyingPiece = new Bishop(true); - tiles[4,5].OccupyingPiece = new Queen(true); - tiles[3, 3].OccupyingPiece = new King(true); - tiles[7, 5].OccupyingPiece = new Bishop(true); - tiles[7, 6].OccupyingPiece = new Knight(true); - tiles[7, 7].OccupyingPiece = new Rook(true); - } - - public ChessPiece PieceAt(int x, int y) - { - if (x >= 0 && y >= 0 && x < boardSize && y < boardSize) - { - return tiles[y, x].OccupyingPiece; - } - - return null; - } - - public void GenerateBoard() - { - tiles = new BoardTile[boardSize, boardSize]; - - for (int y = 0; y < boardSize; y++) - { - for (int x = 0; x < boardSize; x++) - { - tiles[y, x] = new BoardTile(x, y); - } - } - } - - public void DrawTile(Point point) - { - if (point.X >= 0 && point.X < boardSize && point.Y >= 0 && point.Y < boardSize) - { - var tile = tiles[point.Y, point.X]; - - using (Graphics g = (screenInvalidated ? Graphics.FromImage(container.Image) : container.CreateGraphics())) - { - tile.Draw(g, tileWidth, tileHeight, (selectedTile != null && selectedTile.CanMoveTo(this, tile))); - } - } - } - - public void DrawGame() - { - screenInvalidated = true; - - if (container.Image != null) - container.Image.Dispose(); - - container.Image = new Bitmap(container.Size.Width, container.Size.Height); - - tileWidth = container.Size.Width / (float)boardSize; - tileHeight = container.Size.Height / (float)boardSize; - - for (int y = 0; y < boardSize; y++) - { - for (int x = 0; x < boardSize; x++) - { - DrawTile(new Point(x, y)); - } - } - - screenInvalidated = false; - } - - public Point MouseToTilePosition(int x, int y) - { - return new Point((int)(x / tileWidth), (int)(y / tileHeight)); - } - - private void MoveSelectedPieceTo(BoardTile tile) - { - if (selectedTile.CanMoveTo(this, tile)) - { - tile.OccupyingPiece = selectedTile.OccupyingPiece; - selectedTile.OccupyingPiece = null; - } - } - - public void SelectTile(Point point) - { - var clickedTile = tiles[point.Y, point.X]; - - if (selectedTile != clickedTile) - { - if (selectedTile != null) - { - MoveSelectedPieceTo(clickedTile); - } - - selectedTile = clickedTile; - } - else - { - selectedTile = null; - } - - DrawGame(); - } - } -} +using Chess.Events;
+using Chess.Pieces;
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Drawing.Drawing2D;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace Chess
+{
+ public class ChessBoard
+ {
+ public const int BoardSize = 8;
+
+ private float tileWidth;
+ private float tileHeight;
+
+ private MainForm container = null;
+ private bool screenInvalidated = true;
+ private List<BoardTile> latestTiles = new List<BoardTile>();
+ private RoundFinishedEvent currentRountData = new RoundFinishedEvent(1);
+ private int movesMadeWithoutProgress = 60;
+
+ public BoardTile[,] Tiles;
+ public BoardTile SelectedTile = null;
+
+ /// <summary>
+ /// Event that is evoked when the game has ended.
+ /// </summary>
+ public event EventHandler<GameFinishedEvent> OnGameFinished;
+
+ /// <summary>
+ /// Event that is evoked after drawing the board.
+ /// </summary>
+ public event EventHandler OnDraw;
+
+ /// <summary>
+ /// Event that is evoked after a round has been played.
+ /// </summary>
+ public event EventHandler<RoundFinishedEvent> OnRoundFinished;
+
+ public ChessBoard(MainForm container)
+ {
+ this.container = container;
+
+ GenerateBoard();
+ GeneratePieces();
+
+ DrawGame();
+ }
+
+ /// <summary>
+ /// Handle the window resize event.
+ /// </summary>
+ public void HandleResize()
+ {
+ DrawGame();
+ }
+
+ /// <summary>
+ /// Generate the pieces.
+ /// </summary>
+ public void GeneratePieces()
+ {
+#if false
+ Tiles[0, 0].OccupyingPiece = new Rook(false);
+ Tiles[0, 1].OccupyingPiece = new Knight(false);
+ Tiles[0, 2].OccupyingPiece = new Bishop(false);
+ Tiles[0, 3].OccupyingPiece = new Queen(false);
+ Tiles[0, 4].OccupyingPiece = new King(false);
+ Tiles[0, 5].OccupyingPiece = new Bishop(false);
+ Tiles[0, 6].OccupyingPiece = new Knight(false);
+ Tiles[0, 7].OccupyingPiece = new Rook(false);
+
+ for (int x = 0; x < BoardSize; x++)
+ Tiles[1, x].OccupyingPiece = new Pawn(false);
+
+ for (int x = 0; x < BoardSize; x++)
+ Tiles[6, x].OccupyingPiece = new Pawn(true);
+
+ Tiles[7, 0].OccupyingPiece = new Rook(true);
+ Tiles[7, 1].OccupyingPiece = new Knight(true);
+ Tiles[7, 2].OccupyingPiece = new Bishop(true);
+ Tiles[7, 3].OccupyingPiece = new Queen(true);
+ Tiles[7, 4].OccupyingPiece = new King(true);
+ Tiles[7, 5].OccupyingPiece = new Bishop(true);
+ Tiles[7, 6].OccupyingPiece = new Knight(true);
+ Tiles[7, 7].OccupyingPiece = new Rook(true);
+#endif
+#if false
+ Tiles[0, 7].OccupyingPiece = new King(false);
+
+ Tiles[1, 4].OccupyingPiece = new Queen(true);
+ Tiles[2, 6].OccupyingPiece = new King(true);
+#endif
+#if true
+ Tiles[0, 4].OccupyingPiece = new King(false);
+
+ Tiles[1, 1].OccupyingPiece = new Pawn(true);
+ Tiles[7, 4].OccupyingPiece = new King(true);
+#endif
+ }
+
+ /// <summary>
+ /// Get the piece at the given tile location.
+ /// </summary>
+ /// <param name="point"></param>
+ /// <returns></returns>
+ public ChessPiece PieceAt(Point point)
+ {
+ return PieceAt(point.X, point.Y);
+ }
+
+ /// <summary>
+ /// Get the piece at the given tile location.
+ /// </summary>
+ /// <param name="x"></param>
+ /// <param name="y"></param>
+ /// <returns></returns>
+ public ChessPiece PieceAt(int x, int y)
+ {
+ if (x >= 0 && y >= 0 && x < BoardSize && y < BoardSize)
+ {
+ return Tiles[y, x].OccupyingPiece;
+ }
+
+ return null;
+ }
+
+ /// <summary>
+ /// Get tiles by the given type of the occupying type and color.
+ /// </summary>
+ /// <param name="piece"></param>
+ /// <param name="isWhite"></param>
+ /// <returns></returns>
+ public List<BoardTile> TilesByPieceType(Type piece, bool isWhite)
+ {
+ List<BoardTile> result = new List<BoardTile>();
+
+ for (int y = 0; y < ChessBoard.BoardSize; y++)
+ {
+ for (int x = 0; x < ChessBoard.BoardSize; x++)
+ {
+ var found = PieceAt(x, y);
+
+ if (found != null && found.GetType() == piece && found.IsWhite == isWhite)
+ {
+ result.Add(Tiles[y, x]);
+ }
+ }
+ }
+
+ return result;
+ }
+
+ /// <summary>
+ /// Get a piece by the given type and color.
+ /// </summary>
+ /// <param name="piece"></param>
+ /// <param name="isWhite"></param>
+ /// <returns></returns>
+ public ChessPiece PieceByType(Type piece, bool isWhite)
+ {
+ for (int y = 0; y < ChessBoard.BoardSize; y++)
+ {
+ for (int x = 0; x < ChessBoard.BoardSize; x++)
+ {
+ var found = PieceAt(x, y);
+ if (found != null && found.GetType() == piece && found.IsWhite == isWhite)
+ {
+ return found;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /// <summary>
+ /// Generate the chess board.
+ /// </summary>
+ public void GenerateBoard()
+ {
+ Tiles = new BoardTile[BoardSize, BoardSize];
+
+ for (int y = 0; y < BoardSize; y++)
+ {
+ for (int x = 0; x < BoardSize; x++)
+ {
+ Tiles[y, x] = new BoardTile(x, y);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Draw the tile at the given point.
+ /// </summary>
+ /// <param name="point"></param>
+ public void DrawTile(Point point)
+ {
+ if (point.X >= 0 && point.X < BoardSize && point.Y >= 0 && point.Y < BoardSize)
+ {
+ var tile = Tiles[point.Y, point.X];
+
+ using (Graphics g = (screenInvalidated ? Graphics.FromImage(container.chessBoardBitmap.Image) : container.chessBoardBitmap.CreateGraphics()))
+ {
+ tile.State = TileState.Normal;
+
+ if (latestTiles.Contains(tile))
+ tile.State |= TileState.Latest;
+
+ if (SelectedTile != null && SelectedTile.CanMoveTo(this, tile))
+ tile.State |= TileState.Targeted;
+
+ if (tile == SelectedTile)
+ tile.State |= TileState.Selected;
+
+ tile.Draw(g, tileWidth, tileHeight);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Invalidate the current frame and draw + display a new frame.
+ /// </summary>
+ public void DrawGame()
+ {
+ screenInvalidated = true;
+
+ if (container.chessBoardBitmap.Image != null)
+ container.chessBoardBitmap.Image.Dispose();
+
+ container.chessBoardBitmap.Image = new Bitmap(container.chessBoardBitmap.Size.Width, container.chessBoardBitmap.Size.Height);
+
+ tileWidth = container.chessBoardBitmap.Size.Width / (float)BoardSize;
+ tileHeight = container.chessBoardBitmap.Size.Height / (float)BoardSize;
+
+ for (int y = 0; y < BoardSize; y++)
+ {
+ for (int x = 0; x < BoardSize; x++)
+ {
+ DrawTile(new Point(x, y));
+ }
+ }
+
+ OnDraw?.Invoke(this, null);
+
+ screenInvalidated = false;
+ }
+
+ /// <summary>
+ /// Convert mouse position relative to window to tile coordinates.
+ /// </summary>
+ /// <param name="x">Mouse X</param>
+ /// <param name="y">Mouse Y</param>
+ /// <returns></returns>
+ public Point MouseToTilePosition(int x, int y)
+ {
+ return new Point((int)(x / tileWidth), (int)(y / tileHeight));
+ }
+
+ /// <summary>
+ /// Checks whether the given piece can move to any spot.
+ /// </summary>
+ /// <param name="tile"></param>
+ /// <returns></returns>
+ private bool CanMoveToAnything(BoardTile tile)
+ {
+ for (int y = 0; y < BoardSize; y++)
+ {
+ for (int x = 0; x < BoardSize; x++)
+ {
+ if (tile.OccupyingPiece != null && tile.CanMoveTo(this, Tiles[y, x]))
+ {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ private bool IsCheckmate(Player player)
+ {
+ bool kingUnderAttack = false;
+ bool canMove = false;
+ var king = TilesByPieceType(typeof(King), !player.IsWhite).FirstOrDefault();
+
+ for (int y = 0; y < BoardSize; y++)
+ {
+ for (int x = 0; x < BoardSize; x++)
+ {
+ if (Tiles[y, x].OccupyingPiece?.IsWhite == player.IsWhite)
+ {
+ if (Tiles[y, x].OccupyingPiece != null && Tiles[y, x].CanMoveTo(this, king))
+ {
+ kingUnderAttack = true;
+ }
+ }
+ else if (CanMoveToAnything(Tiles[y, x])) canMove = true;
+ }
+ }
+
+ return kingUnderAttack && !canMove;
+ }
+
+ private bool IsStalemate(bool moveMadeByWhite)
+ {
+ if (IsKingAlone(!moveMadeByWhite))
+ {
+ if (!CanMoveToAnything(TilesByPieceType(typeof(King), !moveMadeByWhite).FirstOrDefault())) return true;
+ }
+
+ return false;
+ }
+
+ private bool IsKingAlone(bool isWhite)
+ {
+ if (PieceByType(typeof(Pawn), isWhite) != null) return false;
+ if (PieceByType(typeof(Rook), isWhite) != null) return false;
+ if (PieceByType(typeof(Knight), isWhite) != null) return false;
+ if (PieceByType(typeof(Bishop), isWhite) != null) return false;
+ if (PieceByType(typeof(Queen), isWhite) != null) return false;
+
+ return true;
+ }
+
+ private bool EnoughMaterialOnBoard()
+ {
+ if (IsKingAlone(true) && IsKingAlone(false)) return false;
+
+ return true;
+ }
+
+ /// <summary>
+ /// Try to move the currently selected piece to the given board tile.
+ /// </summary>
+ /// <param name="tile"></param>
+ /// <returns>Returns true if movement was successfull.</returns>
+ private bool MoveSelectedPieceTo(BoardTile tile, Player player)
+ {
+ if (SelectedTile.CanMoveTo(this, tile))
+ {
+ // Check if current move is a castling move
+ if (SelectedTile.OccupyingPiece != null && SelectedTile.OccupyingPiece.GetType() == typeof(King) &&
+ tile.OccupyingPiece != null && tile.OccupyingPiece.GetType() == typeof(Rook) &&
+ tile.OccupyingPiece.IsWhite == SelectedTile.OccupyingPiece.IsWhite)
+ {
+ var rookDestination = ((Rook)tile.OccupyingPiece).GetCastleLocation(this, tile);
+ rookDestination.OccupyingPiece = tile.OccupyingPiece;
+ tile.OccupyingPiece = null;
+
+ tile = ((King)SelectedTile.OccupyingPiece).GetCastleLocation(this, SelectedTile, tile);
+ }
+
+ currentRountData.AddMove(new PlayerMove(player, SelectedTile, tile));
+
+ latestTiles.Clear();
+ latestTiles.Add(tile);
+ latestTiles.Add(SelectedTile);
+
+ if (tile.OccupyingPiece == null && SelectedTile.OccupyingPiece.GetType() != typeof(Pawn))
+ {
+ movesMadeWithoutProgress++;
+ }
+ else
+ {
+ movesMadeWithoutProgress = 0;
+ }
+
+ tile.OccupyingPiece = SelectedTile.OccupyingPiece;
+ SelectedTile.OccupyingPiece.PostMovementEvent(tile);
+ SelectedTile.OccupyingPiece = null;
+
+ if (IsCheckmate(player))
+ {
+ OnGameFinished?.Invoke(this, new GameFinishedEvent(player, GameFinishedReason.CheckMate));
+ }
+ else if (!EnoughMaterialOnBoard())
+ {
+ OnGameFinished?.Invoke(this, new GameFinishedEvent(null, GameFinishedReason.InsufficientMaterial));
+ }
+ else if (IsStalemate(player.IsWhite))
+ {
+ OnGameFinished?.Invoke(this, new GameFinishedEvent(null, GameFinishedReason.Stalemate));
+ }
+ else if (movesMadeWithoutProgress >= 75)
+ {
+ OnGameFinished?.Invoke(this, new GameFinishedEvent(null, GameFinishedReason.Move75));
+ }
+
+ if (currentRountData.IsDone)
+ {
+ OnRoundFinished?.Invoke(this, currentRountData);
+ currentRountData = new RoundFinishedEvent(currentRountData.Round + 1);
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /// <summary>
+ /// Select a tile.
+ /// </summary>
+ /// <param name="point"></param>
+ /// <returns>Returns true if the turn should be ended for current player.</returns>
+ public bool SelectTile(Point point, Player player)
+ {
+ bool result = false;
+
+ var clickedTile = Tiles[point.Y, point.X];
+
+ if (SelectedTile != clickedTile)
+ {
+ if (SelectedTile != null)
+ {
+ if (MoveSelectedPieceTo(clickedTile, player))
+ {
+ SelectedTile = null;
+ result = true;
+ }
+ else
+ {
+ // Only allow selection if player's own pieces.
+ if (player.IsWhite == clickedTile.OccupyingPiece?.IsWhite)
+ SelectedTile = clickedTile;
+ else
+ SelectedTile = null;
+ }
+ }
+ else
+ {
+ // Only allow selection if player's own pieces.
+ if (player.IsWhite == clickedTile.OccupyingPiece?.IsWhite)
+ SelectedTile = clickedTile;
+ else
+ SelectedTile = null;
+ }
+ }
+ else
+ {
+ SelectedTile = null;
+ }
+
+ DrawGame();
+
+ return result;
+ }
+ }
+}
diff --git a/ChessPiece.cs b/ChessPiece.cs index 5a27177..4ae9232 100644 --- a/ChessPiece.cs +++ b/ChessPiece.cs @@ -1,175 +1,223 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Drawing; -using System.Drawing.Drawing2D; -using System.Drawing.Imaging; - -namespace Chess -{ - internal enum MoveCheckResult - { - CanMove, - CantMove, - ContinueCheck, - } - - public abstract class ChessPiece - { - internal Bitmap PieceImage; - internal bool IsWhite; - - public ChessPiece(bool isWhite) - { - IsWhite = isWhite; - } - - internal MoveCheckResult CanMoveUpLeft(ChessBoard board, BoardTile currentTile, BoardTile destinationTile, int count = 8) - { - for (int t = 1; t <= count; t++) - { - Point p1 = new Point(currentTile.X - t, currentTile.Y - t); - - var enemy = board.PieceAt(p1.X, p1.Y); - if ((p1.X == destinationTile.X && p1.Y == destinationTile.Y) && (enemy == null)) return MoveCheckResult.CanMove; - if ((p1.X == destinationTile.X && p1.Y == destinationTile.Y) && (enemy != null && enemy.IsWhite != this.IsWhite)) return MoveCheckResult.CanMove; - if (enemy != null && enemy != this) return MoveCheckResult.ContinueCheck; - } - - return MoveCheckResult.ContinueCheck; - } - - internal MoveCheckResult CanMoveUpRight(ChessBoard board, BoardTile currentTile, BoardTile destinationTile, int count = 8) - { - for (int t = 1; t <= count; t++) - { - Point p1 = new Point(currentTile.X + t, currentTile.Y - t); - - var enemy = board.PieceAt(p1.X, p1.Y); - if ((p1.X == destinationTile.X && p1.Y == destinationTile.Y) && (enemy == null)) return MoveCheckResult.CanMove; - if ((p1.X == destinationTile.X && p1.Y == destinationTile.Y) && (enemy != null && enemy.IsWhite != this.IsWhite)) return MoveCheckResult.CanMove; - if (enemy != null && enemy != this) return MoveCheckResult.ContinueCheck; - } - - return MoveCheckResult.ContinueCheck; - } - - - internal MoveCheckResult CanMoveDownRight(ChessBoard board, BoardTile currentTile, BoardTile destinationTile, int count = 8) - { - for (int t = 1; t <= count; t++) - { - Point p1 = new Point(currentTile.X + t, currentTile.Y + t); - - var enemy = board.PieceAt(p1.X, p1.Y); - if ((p1.X == destinationTile.X && p1.Y == destinationTile.Y) && (enemy == null)) return MoveCheckResult.CanMove; - if ((p1.X == destinationTile.X && p1.Y == destinationTile.Y) && (enemy != null && enemy.IsWhite != this.IsWhite)) return MoveCheckResult.CanMove; - if (enemy != null && enemy != this) return MoveCheckResult.ContinueCheck; - } - - return MoveCheckResult.ContinueCheck; - } - - internal MoveCheckResult CanMoveDownLeft(ChessBoard board, BoardTile currentTile, BoardTile destinationTile, int count = 8) - { - for (int t = 1; t <= count; t++) - { - Point p1 = new Point(currentTile.X - t, currentTile.Y + t); - - var enemy = board.PieceAt(p1.X, p1.Y); - if ((p1.X == destinationTile.X && p1.Y == destinationTile.Y) && (enemy == null)) return MoveCheckResult.CanMove; - if ((p1.X == destinationTile.X && p1.Y == destinationTile.Y) && (enemy != null && enemy.IsWhite != this.IsWhite)) return MoveCheckResult.CanMove; - if (enemy != null && enemy != this) return MoveCheckResult.ContinueCheck; - } - - return MoveCheckResult.ContinueCheck; - } - - internal MoveCheckResult CanMoveLeft(ChessBoard board, BoardTile currentTile, BoardTile destinationTile, int count = 8) - { - if (currentTile.Y != destinationTile.Y) return MoveCheckResult.ContinueCheck; - - if (destinationTile.X < currentTile.X) - { - for (int t = 1; t <= count; t++) - { - var enemy = board.PieceAt(currentTile.X - t, currentTile.Y); - if (currentTile.X - t == destinationTile.X && (enemy == null)) return MoveCheckResult.CanMove; - if (currentTile.X - t == destinationTile.X && (enemy != null && enemy.IsWhite != this.IsWhite)) return MoveCheckResult.CanMove; - if (enemy != null && enemy != this) return MoveCheckResult.ContinueCheck; - } - } - - return MoveCheckResult.ContinueCheck; - } - - internal MoveCheckResult CanMoveRight(ChessBoard board, BoardTile currentTile, BoardTile destinationTile, int count = 8) - { - if (currentTile.Y != destinationTile.Y) return MoveCheckResult.ContinueCheck; - - if (destinationTile.X > currentTile.X) - { - for (int t = 1; t <= count; t++) - { - var enemy = board.PieceAt(currentTile.X + t, currentTile.Y); - if (currentTile.X + t == destinationTile.X && (enemy == null)) return MoveCheckResult.CanMove; - if (currentTile.X + t == destinationTile.X && (enemy != null && enemy.IsWhite != this.IsWhite)) return MoveCheckResult.CanMove; - if (enemy != null && enemy != this) return MoveCheckResult.ContinueCheck; - } - } - - return MoveCheckResult.ContinueCheck; - } - - internal MoveCheckResult CanMoveDown(ChessBoard board, BoardTile currentTile, BoardTile destinationTile, int count = 8) - { - if (currentTile.X != destinationTile.X) return MoveCheckResult.ContinueCheck; - - if (destinationTile.Y > currentTile.Y) - { - for (int t = 1; t <= count; t++) - { - var enemy = board.PieceAt(currentTile.X, currentTile.Y + t); - if (currentTile.Y + t == destinationTile.Y && (enemy == null)) return MoveCheckResult.CanMove; - if (currentTile.Y + t == destinationTile.Y && (enemy != null && enemy.IsWhite != this.IsWhite)) return MoveCheckResult.CanMove; - if (enemy != null && enemy != this) return MoveCheckResult.ContinueCheck; - } - } - - return MoveCheckResult.ContinueCheck; - } - - internal MoveCheckResult CanMoveUp(ChessBoard board, BoardTile currentTile, BoardTile destinationTile, int count = 8) - { - if (currentTile.X != destinationTile.X) return MoveCheckResult.ContinueCheck; - - if (destinationTile.Y < currentTile.Y) - { - for (int t = 1; t <= count; t++) - { - var enemy = board.PieceAt(currentTile.X, currentTile.Y - t); - if (currentTile.Y - t == destinationTile.Y && (enemy == null)) return MoveCheckResult.CanMove; - if (currentTile.Y - t == destinationTile.Y && (enemy != null && enemy.IsWhite != this.IsWhite)) return MoveCheckResult.CanMove; - if (enemy != null && enemy != this) return MoveCheckResult.ContinueCheck; - } - } - - return MoveCheckResult.ContinueCheck; - } - - public abstract bool CanMoveTo(ChessBoard board, BoardTile currentTile, BoardTile destinationTile); - public void Draw(Graphics graphics, float x, float y, float tileWidth, float tileHeight) - { - if (PieceImage != null) - { - var image = ImageHelper.ResizeImage(PieceImage, (int)tileWidth, (int)tileHeight); - - graphics.DrawImage(image, new PointF(x * tileWidth + (tileWidth/ 40), y * tileHeight + (tileWidth / 40))); - - image.Dispose(); - } - } - } -} +using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Drawing;
+using System.Drawing.Drawing2D;
+using System.Drawing.Imaging;
+
+namespace Chess
+{
+ internal enum MoveCheckResult
+ {
+ CanMove,
+ CantMove,
+ ContinueCheck,
+ }
+
+ public abstract class ChessPiece
+ {
+ internal Bitmap PieceImage;
+ internal bool IsWhite;
+
+ public ChessPiece(bool isWhite)
+ {
+ IsWhite = isWhite;
+ }
+
+ internal virtual MoveCheckResult CanMoveUpLeft(ChessBoard board, BoardTile currentTile, BoardTile destinationTile, int count = ChessBoard.BoardSize)
+ {
+ for (int t = 1; t <= count; t++)
+ {
+ Point p1 = new Point(currentTile.X - t, currentTile.Y - t);
+
+ var enemy = board.PieceAt(p1.X, p1.Y);
+ if ((p1.X == destinationTile.X && p1.Y == destinationTile.Y) && (enemy == null)) return MoveCheckResult.CanMove;
+ if ((p1.X == destinationTile.X && p1.Y == destinationTile.Y) && (enemy != null && enemy.IsWhite != this.IsWhite)) return MoveCheckResult.CanMove;
+ if (enemy != null && enemy != this) return MoveCheckResult.ContinueCheck;
+ }
+
+ return MoveCheckResult.ContinueCheck;
+ }
+
+ internal virtual MoveCheckResult CanMoveUpRight(ChessBoard board, BoardTile currentTile, BoardTile destinationTile, int count = ChessBoard.BoardSize)
+ {
+ for (int t = 1; t <= count; t++)
+ {
+ Point p1 = new Point(currentTile.X + t, currentTile.Y - t);
+
+ var enemy = board.PieceAt(p1.X, p1.Y);
+ if ((p1.X == destinationTile.X && p1.Y == destinationTile.Y) && (enemy == null)) return MoveCheckResult.CanMove;
+ if ((p1.X == destinationTile.X && p1.Y == destinationTile.Y) && (enemy != null && enemy.IsWhite != this.IsWhite)) return MoveCheckResult.CanMove;
+ if (enemy != null && enemy != this) return MoveCheckResult.ContinueCheck;
+ }
+
+ return MoveCheckResult.ContinueCheck;
+ }
+
+
+ internal virtual MoveCheckResult CanMoveDownRight(ChessBoard board, BoardTile currentTile, BoardTile destinationTile, int count = ChessBoard.BoardSize)
+ {
+ for (int t = 1; t <= count; t++)
+ {
+ Point p1 = new Point(currentTile.X + t, currentTile.Y + t);
+
+ var enemy = board.PieceAt(p1.X, p1.Y);
+ if ((p1.X == destinationTile.X && p1.Y == destinationTile.Y) && (enemy == null)) return MoveCheckResult.CanMove;
+ if ((p1.X == destinationTile.X && p1.Y == destinationTile.Y) && (enemy != null && enemy.IsWhite != this.IsWhite)) return MoveCheckResult.CanMove;
+ if (enemy != null && enemy != this) return MoveCheckResult.ContinueCheck;
+ }
+
+ return MoveCheckResult.ContinueCheck;
+ }
+
+ internal virtual MoveCheckResult CanMoveDownLeft(ChessBoard board, BoardTile currentTile, BoardTile destinationTile, int count = ChessBoard.BoardSize)
+ {
+ for (int t = 1; t <= count; t++)
+ {
+ Point p1 = new Point(currentTile.X - t, currentTile.Y + t);
+
+ var enemy = board.PieceAt(p1.X, p1.Y);
+ if ((p1.X == destinationTile.X && p1.Y == destinationTile.Y) && (enemy == null)) return MoveCheckResult.CanMove;
+ if ((p1.X == destinationTile.X && p1.Y == destinationTile.Y) && (enemy != null && enemy.IsWhite != this.IsWhite)) return MoveCheckResult.CanMove;
+ if (enemy != null && enemy != this) return MoveCheckResult.ContinueCheck;
+ }
+
+ return MoveCheckResult.ContinueCheck;
+ }
+
+ internal virtual MoveCheckResult CanMoveLeft(ChessBoard board, BoardTile currentTile, BoardTile destinationTile, int count = ChessBoard.BoardSize)
+ {
+ if (currentTile.Y != destinationTile.Y) return MoveCheckResult.ContinueCheck;
+
+ if (destinationTile.X < currentTile.X)
+ {
+ for (int t = 1; t <= count; t++)
+ {
+ var enemy = board.PieceAt(currentTile.X - t, currentTile.Y);
+ if (currentTile.X - t == destinationTile.X && (enemy == null)) return MoveCheckResult.CanMove;
+ if (currentTile.X - t == destinationTile.X && (enemy != null && enemy.IsWhite != this.IsWhite)) return MoveCheckResult.CanMove;
+ if (enemy != null && enemy != this) return MoveCheckResult.ContinueCheck;
+ }
+ }
+
+ return MoveCheckResult.ContinueCheck;
+ }
+
+ internal virtual MoveCheckResult CanMoveRight(ChessBoard board, BoardTile currentTile, BoardTile destinationTile, int count = ChessBoard.BoardSize)
+ {
+ if (currentTile.Y != destinationTile.Y) return MoveCheckResult.ContinueCheck;
+
+ if (destinationTile.X > currentTile.X)
+ {
+ for (int t = 1; t <= count; t++)
+ {
+ var enemy = board.PieceAt(currentTile.X + t, currentTile.Y);
+ if (currentTile.X + t == destinationTile.X && (enemy == null)) return MoveCheckResult.CanMove;
+ if (currentTile.X + t == destinationTile.X && (enemy != null && enemy.IsWhite != this.IsWhite)) return MoveCheckResult.CanMove;
+ if (enemy != null && enemy != this) return MoveCheckResult.ContinueCheck;
+ }
+ }
+
+ return MoveCheckResult.ContinueCheck;
+ }
+
+ internal virtual MoveCheckResult CanMoveDown(ChessBoard board, BoardTile currentTile, BoardTile destinationTile, int count = ChessBoard.BoardSize)
+ {
+ if (currentTile.X != destinationTile.X) return MoveCheckResult.ContinueCheck;
+
+ if (destinationTile.Y > currentTile.Y)
+ {
+ for (int t = 1; t <= count; t++)
+ {
+ var enemy = board.PieceAt(currentTile.X, currentTile.Y + t);
+ if (currentTile.Y + t == destinationTile.Y && (enemy == null)) return MoveCheckResult.CanMove;
+ if (currentTile.Y + t == destinationTile.Y && (enemy != null && enemy.IsWhite != this.IsWhite)) return MoveCheckResult.CanMove;
+ if (enemy != null && enemy != this) return MoveCheckResult.ContinueCheck;
+ }
+ }
+
+ return MoveCheckResult.ContinueCheck;
+ }
+
+ internal virtual MoveCheckResult CanMoveUp(ChessBoard board, BoardTile currentTile, BoardTile destinationTile, int count = ChessBoard.BoardSize)
+ {
+ if (currentTile.X != destinationTile.X) return MoveCheckResult.ContinueCheck;
+
+ if (destinationTile.Y < currentTile.Y)
+ {
+ for (int t = 1; t <= count; t++)
+ {
+ var enemy = board.PieceAt(currentTile.X, currentTile.Y - t);
+ if (currentTile.Y - t == destinationTile.Y && (enemy == null)) return MoveCheckResult.CanMove;
+ if (currentTile.Y - t == destinationTile.Y && (enemy != null && enemy.IsWhite != this.IsWhite)) return MoveCheckResult.CanMove;
+ if (enemy != null && enemy != this) return MoveCheckResult.ContinueCheck;
+ }
+ }
+
+ return MoveCheckResult.ContinueCheck;
+ }
+
+ internal bool WillKingBeAttackedIfMovedTo(ChessBoard board, BoardTile currentTile, BoardTile destinationTile)
+ {
+ bool result = false;
+
+ var friendlyKingTile = board.TilesByPieceType(typeof(Chess.Pieces.King), this.IsWhite).FirstOrDefault();
+
+ // Temporarely move piece to destination to check if king will be attacked.
+ ChessPiece tempHolder = destinationTile.OccupyingPiece;
+ destinationTile.OccupyingPiece = currentTile.OccupyingPiece;
+
+ if (currentTile != destinationTile)
+ currentTile.OccupyingPiece = null;
+
+ if (this.GetType() == typeof(Chess.Pieces.King))
+ {
+ friendlyKingTile = destinationTile;
+ }
+
+ for (int y = 0; y < ChessBoard.BoardSize; y++)
+ {
+ for (int x = 0; x < ChessBoard.BoardSize; x++)
+ {
+ var tileToCheck = board.Tiles[y, x];
+
+ if (tileToCheck.OccupyingPiece != null && tileToCheck.OccupyingPiece != this && tileToCheck.OccupyingPiece.CanMoveTo(board, tileToCheck, friendlyKingTile))
+ {
+ result = true;
+ break;
+ }
+ }
+ }
+
+ // Move pieces back.
+ currentTile.OccupyingPiece = destinationTile.OccupyingPiece;
+ destinationTile.OccupyingPiece = tempHolder;
+
+ return result;
+ }
+
+ public virtual void PostMovementEvent(BoardTile tile)
+ {
+
+ }
+
+ public abstract bool CanMoveTo(ChessBoard board, BoardTile currentTile, BoardTile destinationTile);
+
+ public void Draw(Graphics graphics, float x, float y, float tileWidth, float tileHeight)
+ {
+ if (PieceImage != null)
+ {
+ int imgW = (int)(tileWidth / 1.3);
+ int imgH = (int)(tileHeight / 1.3);
+
+ var image = ImageHelper.ResizeImage(PieceImage, imgW, imgH);
+
+ graphics.DrawImage(image, new PointF(x * tileWidth + (tileWidth / 2) - (imgW / 2), y * tileHeight + (tileHeight / 2) - (imgH / 2)));
+
+ image.Dispose();
+ }
+ }
+ }
+}
diff --git a/Events/GameFinishedEvent.cs b/Events/GameFinishedEvent.cs new file mode 100644 index 0000000..22cf26a --- /dev/null +++ b/Events/GameFinishedEvent.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Chess.Events +{ + public enum GameFinishedReason + { + CheckMate, + InsufficientMaterial, + Stalemate, + + /// <summary> + /// Not implemented from here on. + /// </summary> + Resignation, + Move75, + Repetition, + Agreement, + } + + public class GameFinishedEvent : EventArgs + { + public Player Winner { get; } + public GameFinishedReason Reason { get; set; } + + public GameFinishedEvent(Player winner, GameFinishedReason reason) + { + Winner = winner; + Reason = reason; + } + + public string GetWinnerName() + { + if (Winner != null) + { + return Winner.IsWhite ? "White" : "Black"; + } + + return ""; + } + + public string GetFinishReason() + { + return Reason.ToString(); + } + } +} diff --git a/Events/RoundFinishedEvent.cs b/Events/RoundFinishedEvent.cs new file mode 100644 index 0000000..061b31d --- /dev/null +++ b/Events/RoundFinishedEvent.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Chess.Events +{ + public class RoundFinishedEvent : EventArgs + { + public int Round { get; } + public PlayerMove Move1 { get; private set; } + public PlayerMove Move2 { get; private set; } + + public bool IsDone { get { return Move1 != null && Move2 != null; } } + + public RoundFinishedEvent(int round) + { + Round = round; + } + + public void AddMove(PlayerMove move) + { + if (Move1 == null) Move1 = move; + else Move2 = move; + } + } +} diff --git a/Extensions/GraphicsExtensions.cs b/Extensions/GraphicsExtensions.cs new file mode 100644 index 0000000..acf73cd --- /dev/null +++ b/Extensions/GraphicsExtensions.cs @@ -0,0 +1,218 @@ +using System; +using System.Drawing; +using System.Drawing.Drawing2D; + +namespace Chess.Extensions +{ + public static class GraphicsExtensions + { + private static GraphicsPath GenerateRoundedRectangle( + this Graphics graphics, + RectangleF rectangle, + float radius) + { + float diameter; + GraphicsPath path = new GraphicsPath(); + if (radius <= 0.0F) + { + path.AddRectangle(rectangle); + path.CloseFigure(); + return path; + } + else + { + if (radius >= (Math.Min(rectangle.Width, rectangle.Height)) / 2.0) + return graphics.GenerateCapsule(rectangle); + diameter = radius * 2.0F; + SizeF sizeF = new SizeF(diameter, diameter); + RectangleF arc = new RectangleF(rectangle.Location, sizeF); + path.AddArc(arc, 180, 90); + arc.X = rectangle.Right - diameter; + path.AddArc(arc, 270, 90); + arc.Y = rectangle.Bottom - diameter; + path.AddArc(arc, 0, 90); + arc.X = rectangle.Left; + path.AddArc(arc, 90, 90); + path.CloseFigure(); + } + return path; + } + + private static GraphicsPath GenerateCapsule( + this Graphics graphics, + RectangleF baseRect) + { + float diameter; + RectangleF arc; + GraphicsPath path = new GraphicsPath(); + try + { + if (baseRect.Width > baseRect.Height) + { + diameter = baseRect.Height; + SizeF sizeF = new SizeF(diameter, diameter); + arc = new RectangleF(baseRect.Location, sizeF); + path.AddArc(arc, 90, 180); + arc.X = baseRect.Right - diameter; + path.AddArc(arc, 270, 180); + } + else if (baseRect.Width < baseRect.Height) + { + diameter = baseRect.Width; + SizeF sizeF = new SizeF(diameter, diameter); + arc = new RectangleF(baseRect.Location, sizeF); + path.AddArc(arc, 180, 180); + arc.Y = baseRect.Bottom - diameter; + path.AddArc(arc, 0, 180); + } + else path.AddEllipse(baseRect); + } + catch { path.AddEllipse(baseRect); } + finally { path.CloseFigure(); } + return path; + } + + /// <summary> + /// Draws a rounded rectangle specified by a pair of coordinates, a width, a height and the radius + /// for the arcs that make the rounded edges. + /// </summary> + /// <param name="brush">System.Drawing.Pen that determines the color, width and style of the rectangle.</param> + /// <param name="x">The x-coordinate of the upper-left corner of the rectangle to draw.</param> + /// <param name="y">The y-coordinate of the upper-left corner of the rectangle to draw.</param> + /// <param name="width">Width of the rectangle to draw.</param> + /// <param name="height">Height of the rectangle to draw.</param> + /// <param name="radius">The radius of the arc used for the rounded edges.</param> + public static void DrawRoundedRectangle( + this Graphics graphics, + Pen pen, + float x, + float y, + float width, + float height, + float radius) + { + RectangleF rectangle = new RectangleF(x, y, width, height); + GraphicsPath path = graphics.GenerateRoundedRectangle(rectangle, radius); + SmoothingMode old = graphics.SmoothingMode; + graphics.SmoothingMode = SmoothingMode.AntiAlias; + graphics.DrawPath(pen, path); + graphics.SmoothingMode = old; + } + + + /// <summary> + /// Draws a rounded rectangle specified by a pair of coordinates, a width, a height and the radius + /// for the arcs that make the rounded edges. + /// </summary> + /// <param name="brush">System.Drawing.Pen that determines the color, width and style of the rectangle.</param> + /// <param name="x">The x-coordinate of the upper-left corner of the rectangle to draw.</param> + /// <param name="y">The y-coordinate of the upper-left corner of the rectangle to draw.</param> + /// <param name="width">Width of the rectangle to draw.</param> + /// <param name="height">Height of the rectangle to draw.</param> + /// <param name="radius">The radius of the arc used for the rounded edges.</param> + public static void DrawRoundedRectangle( + this Graphics graphics, + Pen pen, + int x, + int y, + int width, + int height, + int radius) + { + graphics.DrawRoundedRectangle( + pen, + Convert.ToSingle(x), + Convert.ToSingle(y), + Convert.ToSingle(width), + Convert.ToSingle(height), + Convert.ToSingle(radius)); + } + + /// <summary> + /// Fills the interior of a rounded rectangle specified by a pair of coordinates, a width, a height + /// and the radius for the arcs that make the rounded edges. + /// </summary> + /// <param name="brush">System.Drawing.Brush that determines the characteristics of the fill.</param> + /// <param name="x">The x-coordinate of the upper-left corner of the rectangle to fill.</param> + /// <param name="y">The y-coordinate of the upper-left corner of the rectangle to fill.</param> + /// <param name="width">Width of the rectangle to fill.</param> + /// <param name="height">Height of the rectangle to fill.</param> + /// <param name="radius">The radius of the arc used for the rounded edges.</param> + public static void FillRoundedRectangle( + this Graphics graphics, + Brush brush, + float x, + float y, + float width, + float height, + float radius) + { + RectangleF rectangle = new RectangleF(x, y, width, height); + GraphicsPath path = graphics.GenerateRoundedRectangle(rectangle, radius); + SmoothingMode old = graphics.SmoothingMode; + graphics.SmoothingMode = SmoothingMode.AntiAlias; + graphics.FillPath(brush, path); + graphics.SmoothingMode = old; + } + + /// <summary> + /// Fills the interior of a rounded rectangle specified by a pair of coordinates, a width, a height + /// and the radius for the arcs that make the rounded edges. + /// </summary> + /// <param name="brush">System.Drawing.Brush that determines the characteristics of the fill.</param> + /// <param name="x">The x-coordinate of the upper-left corner of the rectangle to fill.</param> + /// <param name="y">The y-coordinate of the upper-left corner of the rectangle to fill.</param> + /// <param name="width">Width of the rectangle to fill.</param> + /// <param name="height">Height of the rectangle to fill.</param> + /// <param name="radius">The radius of the arc used for the rounded edges.</param> + public static void FillRoundedRectangle( + this Graphics graphics, + Brush brush, + int x, + int y, + int width, + int height, + int radius) + { + graphics.FillRoundedRectangle( + brush, + Convert.ToSingle(x), + Convert.ToSingle(y), + Convert.ToSingle(width), + Convert.ToSingle(height), + Convert.ToSingle(radius)); + } + + public static void DrawParagraph(this Graphics graphics, string s, Font font, Brush brush, float x, float y) + { + graphics.DrawParagraph(s, font, brush, x, y, StringFormat.GenericDefault); + } + + public static void DrawParagraph(this Graphics graphics, string s, Font font, Brush brush, float x, float y, StringFormat format) + { + string[] split = s.Split(new string[] { "\n" }, StringSplitOptions.None); + int dy = (int)font.GetHeight(graphics) * 1; + + int offy = 0; + foreach (var str in split) + { + graphics.DrawString(str, font, brush, x, y + offy, format); + offy += dy; + } + } + + public static int ParagraphHeight(this Graphics graphics, string s, Font font) + { + string[] split = s.Split(new string[] { "\n" }, StringSplitOptions.None); + int dy = (int)font.GetHeight(graphics) * 1; + + int offy = 0; + foreach (var str in split) + { + offy += dy; + } + + return offy; + } + } +}
\ No newline at end of file diff --git a/Extensions/UdpClientExtensions.cs b/Extensions/UdpClientExtensions.cs new file mode 100644 index 0000000..23278db --- /dev/null +++ b/Extensions/UdpClientExtensions.cs @@ -0,0 +1,21 @@ +using Chess.Networking; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Sockets; +using System.Text; +using System.Threading.Tasks; + +namespace Chess.Extensions +{ + public static class UdpClientExtensions + { + private static int Send(this UdpClient client, INetworkMessage message, IPEndPoint ep) + { + var msg = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message)); + return client.Send(msg, msg.Length, ep); + } + } +} @@ -0,0 +1,132 @@ +using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using Chess.Events;
+using Chess.Extensions;
+
+namespace Chess
+{
+ public enum GameState
+ {
+ Playing,
+ Ended,
+ }
+
+ public class Game
+ {
+ List<Player> Players = new List<Player>();
+
+ private ChessBoard board = null;
+ private MainForm container;
+ private GameState state;
+ private GameFinishedEvent gameFinishData;
+
+ public Game(MainForm container)
+ {
+ this.state = GameState.Playing;
+ this.container = container;
+
+ Players.Add(new Player(true, true));
+ Players.Add(new Player(false, false));
+
+ board = new ChessBoard(container);
+
+ board.OnGameFinished += Board_OnGameFinished;
+ board.OnDraw += Board_OnDraw;
+ board.OnRoundFinished += Board_OnRoundFinished;
+ }
+
+ private void Board_OnRoundFinished(object sender, RoundFinishedEvent e)
+ {
+ this.container.moveList.Items.Add(new ListViewItem(new string[] { e.Round.ToString(), e.Move1.ToString(), e.Move2.ToString() }));
+ }
+
+ private void Board_OnDraw(object sender, EventArgs e)
+ {
+ if (state == GameState.Ended)
+ {
+ using (Graphics g = Graphics.FromImage(container.chessBoardBitmap.Image))
+ {
+ Font drawFont = new Font("Arial", 28, FontStyle.Bold);
+
+ string endingName = "";
+ if (gameFinishData.Winner == null) endingName = "Game tied\n";
+ else endingName = gameFinishData.GetWinnerName() + " won\n";
+ endingName += "by " + gameFinishData.GetFinishReason();
+
+ int w = 350;
+ int ph = g.ParagraphHeight(endingName, drawFont);
+ int h = ph + 80;
+
+ g.FillRoundedRectangle(new SolidBrush(Color.FromArgb(80, 80, 80)), (this.container.chessBoardBitmap.Width / 2) - (w / 2), (this.container.chessBoardBitmap.Height / 2) - (h / 2), w, h, 20);
+
+ StringFormat format = new StringFormat();
+ format.Alignment = StringAlignment.Center;
+
+ Color textColor = Color.FromArgb(245, 245, 245);
+
+ g.DrawParagraph(endingName, drawFont,
+ new SolidBrush(textColor), (this.container.chessBoardBitmap.Width / 2), (this.container.chessBoardBitmap.Height / 2) - (ph / 2), format);
+ }
+ }
+ }
+
+ private void Board_OnGameFinished(object sender, Events.GameFinishedEvent e)
+ {
+ state = GameState.Ended;
+ gameFinishData = e;
+ }
+
+ public void HandleResize()
+ {
+ board.HandleResize();
+ }
+
+ private Player NextPlayer(Player p)
+ {
+ bool isNext = false;
+ foreach (var player in Players)
+ {
+ if (isNext)
+ {
+ return player;
+ }
+
+ if (p == player) isNext = true;
+ }
+
+ if (Players.Count != 0)
+ return Players.ElementAt(0);
+ else
+ return null;
+ }
+
+ public void HandleClick(int x, int y)
+ {
+ if (state != GameState.Playing) return;
+
+ Point clickedTileCoords = board.MouseToTilePosition(x, y);
+
+ foreach (var player in Players)
+ {
+ if (player.IsPlayersTurn)
+ {
+ bool endTurn = board.SelectTile(clickedTileCoords, player);
+
+ if (endTurn)
+ {
+ player.IsPlayersTurn = false;
+ Player nextPlayer = NextPlayer(player);
+
+ if (nextPlayer != null)
+ nextPlayer.IsPlayersTurn = true;
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/ImageHelper.cs b/ImageHelper.cs index 3ad91a6..fbfd501 100644 --- a/ImageHelper.cs +++ b/ImageHelper.cs @@ -1,39 +1,39 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Drawing.Drawing2D; -using System.Drawing.Imaging; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Chess -{ - public class ImageHelper - { - public static Bitmap ResizeImage(Image image, int width, int height) - { - var destRect = new Rectangle(0, 0, width, height); - var destImage = new Bitmap(width, height); - - destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution); - - using (var graphics = Graphics.FromImage(destImage)) - { - graphics.CompositingMode = CompositingMode.SourceCopy; - graphics.CompositingQuality = CompositingQuality.HighQuality; - graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; - graphics.SmoothingMode = SmoothingMode.HighQuality; - graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; - - using (var wrapMode = new ImageAttributes()) - { - wrapMode.SetWrapMode(WrapMode.TileFlipXY); - graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode); - } - } - - return destImage; - } - } -} +using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Drawing.Drawing2D;
+using System.Drawing.Imaging;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Chess
+{
+ public class ImageHelper
+ {
+ public static Bitmap ResizeImage(Image image, int width, int height)
+ {
+ var destRect = new Rectangle(0, 0, width, height);
+ var destImage = new Bitmap(width, height);
+
+ destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);
+
+ using (var graphics = Graphics.FromImage(destImage))
+ {
+ graphics.CompositingMode = CompositingMode.SourceCopy;
+ graphics.CompositingQuality = CompositingQuality.HighQuality;
+ graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
+ graphics.SmoothingMode = SmoothingMode.HighQuality;
+ graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
+
+ using (var wrapMode = new ImageAttributes())
+ {
+ wrapMode.SetWrapMode(WrapMode.TileFlipXY);
+ graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
+ }
+ }
+
+ return destImage;
+ }
+ }
+}
diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index f8268fc..1f63434 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -1,65 +1,122 @@ -namespace Chess -{ - partial class MainForm - { - /// <summary> - /// Required designer variable. - /// </summary> - private System.ComponentModel.IContainer components = null; - - /// <summary> - /// Clean up any resources being used. - /// </summary> - /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// <summary> - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// </summary> - private void InitializeComponent() - { - this.chessBoardBitmap = new System.Windows.Forms.PictureBox(); - ((System.ComponentModel.ISupportInitialize)(this.chessBoardBitmap)).BeginInit(); - this.SuspendLayout(); - // - // chessBoardBitmap - // - this.chessBoardBitmap.Location = new System.Drawing.Point(254, 61); - this.chessBoardBitmap.Name = "chessBoardBitmap"; - this.chessBoardBitmap.Size = new System.Drawing.Size(173, 146); - this.chessBoardBitmap.TabIndex = 0; - this.chessBoardBitmap.TabStop = false; - this.chessBoardBitmap.MouseClick += new System.Windows.Forms.MouseEventHandler(this.chessBoardBitmap_MouseClick); - // - // MainForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(784, 761); - this.Controls.Add(this.chessBoardBitmap); - this.MinimumSize = new System.Drawing.Size(200, 200); - this.Name = "MainForm"; - this.Text = "Chess Xtreme"; - this.Load += new System.EventHandler(this.MainForm_Load); - this.Resize += new System.EventHandler(this.MainForm_Resize); - ((System.ComponentModel.ISupportInitialize)(this.chessBoardBitmap)).EndInit(); - this.ResumeLayout(false); - - } - - #endregion - - private System.Windows.Forms.PictureBox chessBoardBitmap; - } -} - +namespace Chess
+{
+ partial class MainForm
+ {
+ /// <summary>
+ /// Required designer variable.
+ /// </summary>
+ private System.ComponentModel.IContainer components = null;
+
+ /// <summary>
+ /// Clean up any resources being used.
+ /// </summary>
+ /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ /// <summary>
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ /// </summary>
+ private void InitializeComponent()
+ {
+ this.chessBoardBitmap = new System.Windows.Forms.PictureBox();
+ this.gameControlPanel = new System.Windows.Forms.Panel();
+ this.moveList = new System.Windows.Forms.ListView();
+ this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+ this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+ this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
+ ((System.ComponentModel.ISupportInitialize)(this.chessBoardBitmap)).BeginInit();
+ this.gameControlPanel.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // chessBoardBitmap
+ //
+ this.chessBoardBitmap.Location = new System.Drawing.Point(254, 61);
+ this.chessBoardBitmap.Name = "chessBoardBitmap";
+ this.chessBoardBitmap.Size = new System.Drawing.Size(173, 146);
+ this.chessBoardBitmap.TabIndex = 0;
+ this.chessBoardBitmap.TabStop = false;
+ this.chessBoardBitmap.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chessBoardBitmap_MouseDown);
+ //
+ // gameControlPanel
+ //
+ this.gameControlPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.gameControlPanel.Controls.Add(this.moveList);
+ this.gameControlPanel.Location = new System.Drawing.Point(685, -1);
+ this.gameControlPanel.Name = "gameControlPanel";
+ this.gameControlPanel.Size = new System.Drawing.Size(200, 661);
+ this.gameControlPanel.TabIndex = 1;
+ //
+ // moveList
+ //
+ this.moveList.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.moveList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
+ this.columnHeader1,
+ this.columnHeader2,
+ this.columnHeader3});
+ this.moveList.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
+ this.moveList.HideSelection = false;
+ this.moveList.Location = new System.Drawing.Point(5, 5);
+ this.moveList.MultiSelect = false;
+ this.moveList.Name = "moveList";
+ this.moveList.ShowGroups = false;
+ this.moveList.Size = new System.Drawing.Size(190, 390);
+ this.moveList.TabIndex = 0;
+ this.moveList.UseCompatibleStateImageBehavior = false;
+ this.moveList.View = System.Windows.Forms.View.Details;
+ //
+ // columnHeader1
+ //
+ this.columnHeader1.Text = "#";
+ //
+ // columnHeader2
+ //
+ this.columnHeader2.Text = "";
+ this.columnHeader2.Width = 67;
+ //
+ // columnHeader3
+ //
+ this.columnHeader3.Text = "";
+ this.columnHeader3.Width = 58;
+ //
+ // MainForm
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(884, 661);
+ this.Controls.Add(this.gameControlPanel);
+ this.Controls.Add(this.chessBoardBitmap);
+ this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
+ this.MaximizeBox = false;
+ this.MaximumSize = new System.Drawing.Size(900, 700);
+ this.MinimumSize = new System.Drawing.Size(600, 400);
+ this.Name = "MainForm";
+ this.Text = "Chess Xtreme";
+ this.Load += new System.EventHandler(this.MainForm_Load);
+ this.Resize += new System.EventHandler(this.MainForm_Resize);
+ ((System.ComponentModel.ISupportInitialize)(this.chessBoardBitmap)).EndInit();
+ this.gameControlPanel.ResumeLayout(false);
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+ private System.Windows.Forms.Panel gameControlPanel;
+ public System.Windows.Forms.ColumnHeader columnHeader1;
+ private System.Windows.Forms.ColumnHeader columnHeader2;
+ private System.Windows.Forms.ColumnHeader columnHeader3;
+ public System.Windows.Forms.PictureBox chessBoardBitmap;
+ public System.Windows.Forms.ListView moveList;
+ }
+}
+
diff --git a/MainForm.cs b/MainForm.cs index 724f259..012b47f 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -1,45 +1,50 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace Chess -{ - public partial class MainForm : Form - { - private ChessBoard board; - - public MainForm() - { - InitializeComponent(); - } - - private void FitBoardContainerToScreen() - { - this.chessBoardBitmap.Location = new Point(0, 0); - this.chessBoardBitmap.Size = new Size(this.ClientSize.Width, this.ClientSize.Height); - } - - private void MainForm_Load(object sender, EventArgs e) - { - FitBoardContainerToScreen(); - this.board = new ChessBoard(this.chessBoardBitmap); - } - - private void MainForm_Resize(object sender, EventArgs e) - { - FitBoardContainerToScreen(); - this.board.HandleResize(); - } - - private void chessBoardBitmap_MouseClick(object sender, MouseEventArgs e) - { - this.board.SelectTile(this.board.MouseToTilePosition(e.X, e.Y)); - } - } -} +using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace Chess
+{
+ public partial class MainForm : Form
+ {
+ private Game game;
+
+ public MainForm()
+ {
+ InitializeComponent();
+ }
+
+ private void FitBoardContainerToScreen()
+ {
+ this.columnHeader1.Width = 30;
+
+ this.chessBoardBitmap.Location = new Point(0, 0);
+ this.chessBoardBitmap.Size = new Size(this.ClientSize.Width - this.gameControlPanel.Width, this.ClientSize.Height);
+ }
+
+ private void MainForm_Load(object sender, EventArgs e)
+ {
+ FitBoardContainerToScreen();
+ this.game = new Game(this);
+ }
+
+ private void MainForm_Resize(object sender, EventArgs e)
+ {
+ var form = sender as MainForm;
+ if (form.WindowState == FormWindowState.Minimized) return;
+
+ FitBoardContainerToScreen();
+ this.game.HandleResize();
+ }
+
+ private void chessBoardBitmap_MouseDown(object sender, MouseEventArgs e)
+ {
+ this.game.HandleClick(e.X, e.Y);
+ }
+ }
+}
diff --git a/MainForm.resx b/MainForm.resx index 1af7de1..29dcb1b 100644 --- a/MainForm.resx +++ b/MainForm.resx @@ -1,120 +1,120 @@ -<?xml version="1.0" encoding="utf-8"?> -<root> - <!-- - Microsoft ResX Schema - - Version 2.0 - - The primary goals of this format is to allow a simple XML format - that is mostly human readable. The generation and parsing of the - various data types are done through the TypeConverter classes - associated with the data types. - - Example: - - ... ado.net/XML headers & schema ... - <resheader name="resmimetype">text/microsoft-resx</resheader> - <resheader name="version">2.0</resheader> - <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> - <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> - <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> - <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> - <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> - <value>[base64 mime encoded serialized .NET Framework object]</value> - </data> - <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> - <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> - <comment>This is a comment</comment> - </data> - - There are any number of "resheader" rows that contain simple - name/value pairs. - - Each data row contains a name, and value. The row also contains a - type or mimetype. Type corresponds to a .NET class that support - text/value conversion through the TypeConverter architecture. - Classes that don't support this are serialized and stored with the - mimetype set. - - The mimetype is used for serialized objects, and tells the - ResXResourceReader how to depersist the object. This is currently not - extensible. For a given mimetype the value must be set accordingly: - - Note - application/x-microsoft.net.object.binary.base64 is the format - that the ResXResourceWriter will generate, however the reader can - read any of the formats listed below. - - mimetype: application/x-microsoft.net.object.binary.base64 - value : The object must be serialized with - : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter - : and then encoded with base64 encoding. - - mimetype: application/x-microsoft.net.object.soap.base64 - value : The object must be serialized with - : System.Runtime.Serialization.Formatters.Soap.SoapFormatter - : and then encoded with base64 encoding. - - mimetype: application/x-microsoft.net.object.bytearray.base64 - value : The object must be serialized into a byte array - : using a System.ComponentModel.TypeConverter - : and then encoded with base64 encoding. - --> - <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> - <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> - <xsd:element name="root" msdata:IsDataSet="true"> - <xsd:complexType> - <xsd:choice maxOccurs="unbounded"> - <xsd:element name="metadata"> - <xsd:complexType> - <xsd:sequence> - <xsd:element name="value" type="xsd:string" minOccurs="0" /> - </xsd:sequence> - <xsd:attribute name="name" use="required" type="xsd:string" /> - <xsd:attribute name="type" type="xsd:string" /> - <xsd:attribute name="mimetype" type="xsd:string" /> - <xsd:attribute ref="xml:space" /> - </xsd:complexType> - </xsd:element> - <xsd:element name="assembly"> - <xsd:complexType> - <xsd:attribute name="alias" type="xsd:string" /> - <xsd:attribute name="name" type="xsd:string" /> - </xsd:complexType> - </xsd:element> - <xsd:element name="data"> - <xsd:complexType> - <xsd:sequence> - <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> - <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> - </xsd:sequence> - <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> - <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> - <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> - <xsd:attribute ref="xml:space" /> - </xsd:complexType> - </xsd:element> - <xsd:element name="resheader"> - <xsd:complexType> - <xsd:sequence> - <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> - </xsd:sequence> - <xsd:attribute name="name" type="xsd:string" use="required" /> - </xsd:complexType> - </xsd:element> - </xsd:choice> - </xsd:complexType> - </xsd:element> - </xsd:schema> - <resheader name="resmimetype"> - <value>text/microsoft-resx</value> - </resheader> - <resheader name="version"> - <value>2.0</value> - </resheader> - <resheader name="reader"> - <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> - </resheader> - <resheader name="writer"> - <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> - </resheader> +<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
</root>
\ No newline at end of file diff --git a/Networking/INetworkMessage.cs b/Networking/INetworkMessage.cs new file mode 100644 index 0000000..155ae6b --- /dev/null +++ b/Networking/INetworkMessage.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Chess.Networking +{ + internal interface INetworkMessage + { + string Message { get; } + } +} diff --git a/Networking/NetworkManager.cs b/Networking/NetworkManager.cs new file mode 100644 index 0000000..2d2525e --- /dev/null +++ b/Networking/NetworkManager.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Sockets; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Chess.Networking +{ + public static class NetworkManager + { + private static int udpPort = 42069; + private static UdpClient client; + private static Thread networkingThread; + + public static void Initialize() + { + try + { + client = new UdpClient(udpPort, AddressFamily.InterNetwork); + client.EnableBroadcast = true; + } + catch(Exception ex) + { + client = null; + } + + networkingThread = new Thread(new ThreadStart(StartNetworkingThread)); + networkingThread.Start(); + } + + private static void StartNetworkingThread() + { + if (client == null) return; + + //client.Send(RequestData, new IPEndPoint(IPAddress.Broadcast, udpPort)); + DateTime timestamp = DateTime.UtcNow; + + while (true) + { + var senderEndpoint = new IPEndPoint(IPAddress.Any, 0); + var rawData = client.Receive(ref senderEndpoint); + + var parsedData = Encoding.ASCII.GetString(rawData); + + // handle message here + + // client.Send(RequestData, RequestData.Length, new IPEndPoint(IPAddress.Broadcast, udpPort)); + + // client.Send(RequestData, RequestData.Length, new IPEndPoint(IPAddress.Broadcast, udpPort)); + } + } + } +} diff --git a/Pieces/Bishop.cs b/Pieces/Bishop.cs index 10d1537..6e509ca 100644 --- a/Pieces/Bishop.cs +++ b/Pieces/Bishop.cs @@ -1,42 +1,42 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Chess.Pieces -{ - class Bishop : ChessPiece - { - public Bishop(bool isWhite) : base(isWhite) - { - PieceImage = new Bitmap(!isWhite ? Chess.Properties.Resources.b_bishop_png_shadow_256px : Chess.Properties.Resources.w_bishop_png_shadow_256px); - } - - public override bool CanMoveTo(ChessBoard board, BoardTile currentTile, BoardTile destinationTile) - { - MoveCheckResult result; - - result = CanMoveDownLeft(board, currentTile, destinationTile); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - - result = CanMoveDownRight(board, currentTile, destinationTile); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - - result = CanMoveUpLeft(board, currentTile, destinationTile); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - - result = CanMoveUpRight(board, currentTile, destinationTile); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - - return false; - } - - - } -} +using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Chess.Pieces
+{
+ class Bishop : ChessPiece
+ {
+ public Bishop(bool isWhite) : base(isWhite)
+ {
+ PieceImage = new Bitmap(!isWhite ? Chess.Properties.Resources.b_bishop_png_shadow_256px : Chess.Properties.Resources.w_bishop_png_shadow_256px);
+ }
+
+ public override bool CanMoveTo(ChessBoard board, BoardTile currentTile, BoardTile destinationTile)
+ {
+ MoveCheckResult result;
+
+ result = CanMoveDownLeft(board, currentTile, destinationTile);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ result = CanMoveDownRight(board, currentTile, destinationTile);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ result = CanMoveUpLeft(board, currentTile, destinationTile);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ result = CanMoveUpRight(board, currentTile, destinationTile);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ return false;
+ }
+
+
+ }
+}
diff --git a/Pieces/King.cs b/Pieces/King.cs index 945c476..0a98597 100644 --- a/Pieces/King.cs +++ b/Pieces/King.cs @@ -1,58 +1,123 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Chess.Pieces -{ - class King : ChessPiece - { - public King(bool isWhite) : base(isWhite) - { - PieceImage = new Bitmap(!isWhite ? Chess.Properties.Resources.b_king_png_shadow_256px : Chess.Properties.Resources.w_king_png_shadow_256px); - } - - public override bool CanMoveTo(ChessBoard board, BoardTile currentTile, BoardTile destinationTile) - { - MoveCheckResult result; - - result = CanMoveDown(board, currentTile, destinationTile, 1); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - - result = CanMoveUp(board, currentTile, destinationTile, 1); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - - result = CanMoveLeft(board, currentTile, destinationTile, 1); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - - result = CanMoveRight(board, currentTile, destinationTile, 1); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - - // diagonal - - result = CanMoveDownLeft(board, currentTile, destinationTile, 1); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - - result = CanMoveDownRight(board, currentTile, destinationTile, 1); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - - result = CanMoveUpLeft(board, currentTile, destinationTile, 1); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - - result = CanMoveUpRight(board, currentTile, destinationTile, 1); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - - return false; - } - } -} +using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Chess.Pieces
+{
+ class King : ChessPiece
+ {
+ bool isInInitialPosition = true;
+
+ public King(bool isWhite) : base(isWhite)
+ {
+ PieceImage = new Bitmap(!isWhite ? Chess.Properties.Resources.b_king_png_shadow_256px : Chess.Properties.Resources.w_king_png_shadow_256px);
+ }
+
+ public override void PostMovementEvent(BoardTile tile)
+ {
+ isInInitialPosition = false;
+
+ base.PostMovementEvent(tile);
+ }
+
+ internal override MoveCheckResult CanMoveLeft(ChessBoard board, BoardTile currentTile, BoardTile destinationTile, int count = 8)
+ {
+ MoveCheckResult result = base.CanMoveLeft(board, currentTile, destinationTile, count);
+
+ // Check for legal castling move
+ if (isInInitialPosition)
+ {
+ var rooks = board.TilesByPieceType(typeof(Rook), this.IsWhite);
+
+ foreach(var rook in rooks)
+ {
+ if (rook != destinationTile) continue;
+
+ if (rook.OccupyingPiece is Rook piece)
+ {
+ if (piece.IsInInitialPosition)
+ {
+ if (rook.X == 0)
+ {
+ // check right path
+ if (board.Tiles[currentTile.Y, currentTile.X - 1].OccupyingPiece == null && rook.CanMoveTo(board, board.Tiles[currentTile.Y, currentTile.X - 1]))
+ {
+ result = MoveCheckResult.CanMove;
+ }
+ }
+ else if (rook.X == 7)
+ {
+ // check left path
+ if (board.Tiles[currentTile.Y, currentTile.X + 1].OccupyingPiece == null && rook.CanMoveTo(board, board.Tiles[currentTile.Y, currentTile.X + 1]))
+ {
+ result = MoveCheckResult.CanMove;
+ }
+ }
+ }
+ }
+ }
+
+ }
+
+ return result;
+ }
+
+ public override bool CanMoveTo(ChessBoard board, BoardTile currentTile, BoardTile destinationTile)
+ {
+ MoveCheckResult result;
+
+ result = CanMoveDown(board, currentTile, destinationTile, 1);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ result = CanMoveUp(board, currentTile, destinationTile, 1);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ result = CanMoveLeft(board, currentTile, destinationTile, 1);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ result = CanMoveRight(board, currentTile, destinationTile, 1);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ // diagonal
+
+ result = CanMoveDownLeft(board, currentTile, destinationTile, 1);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ result = CanMoveDownRight(board, currentTile, destinationTile, 1);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ result = CanMoveUpLeft(board, currentTile, destinationTile, 1);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ result = CanMoveUpRight(board, currentTile, destinationTile, 1);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ return false;
+ }
+
+ internal BoardTile GetCastleLocation(ChessBoard board, BoardTile currentTile, BoardTile destinationTile)
+ {
+ if (destinationTile.X < currentTile.X)
+ {
+ return board.Tiles[currentTile.Y, currentTile.X - 2];
+ }
+ else if (destinationTile.X > currentTile.X)
+ {
+ return board.Tiles[currentTile.Y, currentTile.X + 2];
+ }
+
+ return destinationTile;
+ }
+ }
+}
diff --git a/Pieces/Knight.cs b/Pieces/Knight.cs index 5a0aea7..cd6db72 100644 --- a/Pieces/Knight.cs +++ b/Pieces/Knight.cs @@ -1,46 +1,46 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Chess.Pieces -{ - class Knight : ChessPiece - { - public Knight(bool isWhite) : base(isWhite) - { - PieceImage = new Bitmap(!isWhite ? Chess.Properties.Resources.b_knight_png_shadow_256px : Chess.Properties.Resources.w_knight_png_shadow_256px); - } - - public override bool CanMoveTo(ChessBoard board, BoardTile currentTile, BoardTile destinationTile) - { - Point[] pointsToCheck = { - new Point(currentTile.X - 2, currentTile.Y - 1), - new Point(currentTile.X - 2, currentTile.Y + 1), - - new Point(currentTile.X + 2, currentTile.Y - 1), - new Point(currentTile.X + 2, currentTile.Y + 1), - - new Point(currentTile.X + 1, currentTile.Y - 2), - new Point(currentTile.X - 1, currentTile.Y - 2), - - new Point(currentTile.X + 1, currentTile.Y + 2), - new Point(currentTile.X - 1, currentTile.Y + 2), - }; - - foreach(var point in pointsToCheck) - { - if (!(destinationTile.Y == point.Y && destinationTile.X == point.X)) continue; - - var enemy = board.PieceAt(point.X, point.Y); - if (enemy == null) return true; - if (enemy != null && enemy.IsWhite != this.IsWhite) return true; - if (enemy != null && enemy != this) continue; - } - - return false; - } - } -} +using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Chess.Pieces
+{
+ class Knight : ChessPiece
+ {
+ public Knight(bool isWhite) : base(isWhite)
+ {
+ PieceImage = new Bitmap(!isWhite ? Chess.Properties.Resources.b_knight_png_shadow_256px : Chess.Properties.Resources.w_knight_png_shadow_256px);
+ }
+
+ public override bool CanMoveTo(ChessBoard board, BoardTile currentTile, BoardTile destinationTile)
+ {
+ Point[] pointsToCheck = {
+ new Point(currentTile.X - 2, currentTile.Y - 1),
+ new Point(currentTile.X - 2, currentTile.Y + 1),
+
+ new Point(currentTile.X + 2, currentTile.Y - 1),
+ new Point(currentTile.X + 2, currentTile.Y + 1),
+
+ new Point(currentTile.X + 1, currentTile.Y - 2),
+ new Point(currentTile.X - 1, currentTile.Y - 2),
+
+ new Point(currentTile.X + 1, currentTile.Y + 2),
+ new Point(currentTile.X - 1, currentTile.Y + 2),
+ };
+
+ foreach(var point in pointsToCheck)
+ {
+ if (!(destinationTile.Y == point.Y && destinationTile.X == point.X)) continue;
+
+ var enemy = board.PieceAt(point.X, point.Y);
+ if (enemy == null) return true;
+ if (enemy != null && enemy.IsWhite != this.IsWhite) return true;
+ if (enemy != null && enemy != this) continue;
+ }
+
+ return false;
+ }
+ }
+}
diff --git a/Pieces/Pawn.cs b/Pieces/Pawn.cs index 93be545..60ce309 100644 --- a/Pieces/Pawn.cs +++ b/Pieces/Pawn.cs @@ -1,42 +1,102 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Chess.Pieces -{ - class Pawn : ChessPiece - { - private bool firstMove = true; - - public Pawn(bool isWhite) : base(isWhite) - { - PieceImage = new Bitmap(!isWhite ? Chess.Properties.Resources.b_pawn_png_shadow_256px : Chess.Properties.Resources.w_pawn_png_shadow_256px); - } - - public override bool CanMoveTo(ChessBoard board, BoardTile currentTile, BoardTile destinationTile) - { - MoveCheckResult result; - - int space = 2; - if (!firstMove) space = 1; - - if (!IsWhite) - { - result = CanMoveDown(board, currentTile, destinationTile, space); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - } - else - { - result = CanMoveUp(board, currentTile, destinationTile, space); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - } - - return false; - } - } -} +using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Chess.Pieces
+{
+ class Pawn : ChessPiece
+ {
+ private bool firstMove = true;
+
+ public Pawn(bool isWhite) : base(isWhite)
+ {
+ PieceImage = new Bitmap(!isWhite ? Chess.Properties.Resources.b_pawn_png_shadow_256px : Chess.Properties.Resources.w_pawn_png_shadow_256px);
+ }
+
+ public override void PostMovementEvent(BoardTile tile)
+ {
+ firstMove = false;
+
+ // Pawn upgrade to queen
+ if (tile.OccupyingPiece == this)
+ {
+ if ((this.IsWhite && tile.Y == 0) || (!this.IsWhite && tile.Y == 7))
+ {
+ tile.OccupyingPiece = new Queen(this.IsWhite);
+ }
+ }
+
+ base.PostMovementEvent(tile);
+ }
+
+ internal override MoveCheckResult CanMoveDown(ChessBoard board, BoardTile currentTile, BoardTile destinationTile, int count = ChessBoard.BoardSize)
+ {
+ var result = base.CanMoveDown(board, currentTile, destinationTile, count);
+
+ if (result == MoveCheckResult.CanMove)
+ {
+ if (destinationTile.OccupyingPiece != null) result = MoveCheckResult.CantMove;
+ }
+
+ return result;
+ }
+
+ internal override MoveCheckResult CanMoveUp(ChessBoard board, BoardTile currentTile, BoardTile destinationTile, int count = ChessBoard.BoardSize)
+ {
+ var result = base.CanMoveUp(board, currentTile, destinationTile, count);
+
+ if (result == MoveCheckResult.CanMove)
+ {
+ if (destinationTile.OccupyingPiece != null) result = MoveCheckResult.CantMove;
+ }
+
+ return result;
+ }
+
+ public override bool CanMoveTo(ChessBoard board, BoardTile currentTile, BoardTile destinationTile)
+ {
+ MoveCheckResult result;
+
+ int space = 2;
+ if (!firstMove) space = 1;
+
+ if (!IsWhite)
+ {
+ result = CanMoveDown(board, currentTile, destinationTile, space);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ // take left
+ result = CanMoveDownLeft(board, currentTile, destinationTile, 1);
+ if (result == MoveCheckResult.CanMove && destinationTile.OccupyingPiece != null && destinationTile.OccupyingPiece.IsWhite != IsWhite) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ // take right
+ result = CanMoveDownRight(board, currentTile, destinationTile, 1);
+ if (result == MoveCheckResult.CanMove && destinationTile.OccupyingPiece != null && destinationTile.OccupyingPiece.IsWhite != IsWhite) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+ }
+ else
+ {
+ result = CanMoveUp(board, currentTile, destinationTile, space);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ // take left
+ result = CanMoveUpLeft(board, currentTile, destinationTile, 1);
+ if (result == MoveCheckResult.CanMove && destinationTile.OccupyingPiece != null && destinationTile.OccupyingPiece.IsWhite != IsWhite) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ // take right
+ result = CanMoveUpRight(board, currentTile, destinationTile, 1);
+ if (result == MoveCheckResult.CanMove && destinationTile.OccupyingPiece != null && destinationTile.OccupyingPiece.IsWhite != IsWhite) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+ }
+
+ return false;
+ }
+ }
+}
diff --git a/Pieces/Queen.cs b/Pieces/Queen.cs index 42998c4..6b1fb0b 100644 --- a/Pieces/Queen.cs +++ b/Pieces/Queen.cs @@ -1,59 +1,59 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using System.Runtime.InteropServices.WindowsRuntime; -using System.Text; -using System.Threading.Tasks; - -namespace Chess.Pieces -{ - class Queen : ChessPiece - { - public Queen(bool isWhite) : base(isWhite) - { - PieceImage = new Bitmap(!isWhite ? Chess.Properties.Resources.b_queen_png_shadow_256px : Chess.Properties.Resources.w_queen_png_shadow_256px); - } - - public override bool CanMoveTo(ChessBoard board, BoardTile currentTile, BoardTile destinationTile) - { - MoveCheckResult result; - - result = CanMoveDown(board, currentTile, destinationTile); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - - result = CanMoveUp(board, currentTile, destinationTile); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - - result = CanMoveLeft(board, currentTile, destinationTile); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - - result = CanMoveRight(board, currentTile, destinationTile); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - - // diagonal - - result = CanMoveDownLeft(board, currentTile, destinationTile); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - - result = CanMoveDownRight(board, currentTile, destinationTile); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - - result = CanMoveUpLeft(board, currentTile, destinationTile); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - - result = CanMoveUpRight(board, currentTile, destinationTile); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - - return false; - } - } -} +using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Runtime.InteropServices.WindowsRuntime;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Chess.Pieces
+{
+ class Queen : ChessPiece
+ {
+ public Queen(bool isWhite) : base(isWhite)
+ {
+ PieceImage = new Bitmap(!isWhite ? Chess.Properties.Resources.b_queen_png_shadow_256px : Chess.Properties.Resources.w_queen_png_shadow_256px);
+ }
+
+ public override bool CanMoveTo(ChessBoard board, BoardTile currentTile, BoardTile destinationTile)
+ {
+ MoveCheckResult result;
+
+ result = CanMoveDown(board, currentTile, destinationTile);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ result = CanMoveUp(board, currentTile, destinationTile);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ result = CanMoveLeft(board, currentTile, destinationTile);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ result = CanMoveRight(board, currentTile, destinationTile);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ // diagonal
+
+ result = CanMoveDownLeft(board, currentTile, destinationTile);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ result = CanMoveDownRight(board, currentTile, destinationTile);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ result = CanMoveUpLeft(board, currentTile, destinationTile);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ result = CanMoveUpRight(board, currentTile, destinationTile);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ return false;
+ }
+ }
+}
diff --git a/Pieces/Rook.cs b/Pieces/Rook.cs index 29c17c0..b6a0422 100644 --- a/Pieces/Rook.cs +++ b/Pieces/Rook.cs @@ -1,40 +1,64 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Chess.Pieces -{ - class Rook : ChessPiece - { - public Rook(bool isWhite) : base(isWhite) - { - PieceImage = new Bitmap(!isWhite ? Chess.Properties.Resources.b_rook_png_shadow_256px : Chess.Properties.Resources.w_rook_png_shadow_256px); - } - - public override bool CanMoveTo(ChessBoard board, BoardTile currentTile, BoardTile destinationTile) - { - MoveCheckResult result; - - result = CanMoveDown(board, currentTile, destinationTile); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - - result = CanMoveUp(board, currentTile, destinationTile); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - - result = CanMoveLeft(board, currentTile, destinationTile); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - - result = CanMoveRight(board, currentTile, destinationTile); - if (result == MoveCheckResult.CanMove) return true; - if (result == MoveCheckResult.CantMove) return false; - - return false; - } - } -} +using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Chess.Pieces
+{
+ class Rook : ChessPiece
+ {
+ public bool IsInInitialPosition { get; private set; }
+
+ public Rook(bool isWhite) : base(isWhite)
+ {
+ PieceImage = new Bitmap(!isWhite ? Chess.Properties.Resources.b_rook_png_shadow_256px : Chess.Properties.Resources.w_rook_png_shadow_256px);
+ IsInInitialPosition = true;
+ }
+
+ public override void PostMovementEvent(BoardTile tile)
+ {
+ this.IsInInitialPosition = false;
+
+ base.PostMovementEvent(tile);
+ }
+
+ public override bool CanMoveTo(ChessBoard board, BoardTile currentTile, BoardTile destinationTile)
+ {
+ MoveCheckResult result;
+
+ result = CanMoveDown(board, currentTile, destinationTile);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ result = CanMoveUp(board, currentTile, destinationTile);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ result = CanMoveLeft(board, currentTile, destinationTile);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ result = CanMoveRight(board, currentTile, destinationTile);
+ if (result == MoveCheckResult.CanMove) return true;
+ if (result == MoveCheckResult.CantMove) return false;
+
+ return false;
+ }
+
+ internal BoardTile GetCastleLocation(ChessBoard board, BoardTile tile)
+ {
+ if (tile.X == 0)
+ {
+ return board.Tiles[tile.Y, tile.X + 3];
+ }
+ else if (tile.X == 7)
+ {
+ return board.Tiles[tile.Y, tile.X - 2];
+ }
+
+ return tile;
+ }
+ }
+}
diff --git a/Player.cs b/Player.cs new file mode 100644 index 0000000..ca9fbcd --- /dev/null +++ b/Player.cs @@ -0,0 +1,20 @@ +using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Chess
+{
+ public class Player
+ {
+ public bool IsWhite;
+ public bool IsPlayersTurn;
+
+ public Player(bool isWhite, bool isPlayersTurn)
+ {
+ IsWhite = isWhite;
+ IsPlayersTurn = isPlayersTurn;
+ }
+ }
+}
diff --git a/PlayerMove.cs b/PlayerMove.cs new file mode 100644 index 0000000..7c8c67d --- /dev/null +++ b/PlayerMove.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Chess +{ + public class PlayerMove + { + public Player Player { get; } + public BoardTile From { get; } + public BoardTile To { get; } + + public PlayerMove(Player player, BoardTile from, BoardTile to) + { + Player = player; + From = from; + To = to; + } + + public override string ToString() + { + return From.ToString() + " -> " + To.ToString(); + } + } +} @@ -1,22 +1,22 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace Chess -{ - static class Program - { - /// <summary> - /// The main entry point for the application. - /// </summary> - [STAThread] - static void Main() - { - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new MainForm()); - } - } -} +using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace Chess
+{
+ static class Program
+ {
+ /// <summary>
+ /// The main entry point for the application.
+ /// </summary>
+ [STAThread]
+ static void Main()
+ {
+ Application.EnableVisualStyles();
+ Application.SetCompatibleTextRenderingDefault(false);
+ Application.Run(new MainForm());
+ }
+ }
+}
diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 642e315..7d06283 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -1,36 +1,36 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Chess")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Chess")] -[assembly: AssemblyCopyright("Copyright © 2020")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("cbf01088-874a-442b-867d-2456bed50dc0")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Chess")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Chess")]
+[assembly: AssemblyCopyright("Copyright © 2020")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("cbf01088-874a-442b-867d-2456bed50dc0")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index eb7ced0..22cdc8b 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -1,203 +1,203 @@ -//------------------------------------------------------------------------------ -// <auto-generated> -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// </auto-generated> -//------------------------------------------------------------------------------ - -namespace Chess.Properties { - using System; - - - /// <summary> - /// A strongly-typed resource class, for looking up localized strings, etc. - /// </summary> - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// <summary> - /// Returns the cached ResourceManager instance used by this class. - /// </summary> - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Chess.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// <summary> - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// </summary> - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// <summary> - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// </summary> - internal static System.Drawing.Bitmap b_bishop_png_shadow_256px { - get { - object obj = ResourceManager.GetObject("b_bishop_png_shadow_256px", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// <summary> - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// </summary> - internal static System.Drawing.Bitmap b_king_png_shadow_256px { - get { - object obj = ResourceManager.GetObject("b_king_png_shadow_256px", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// <summary> - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// </summary> - internal static System.Drawing.Bitmap b_knight_png_shadow_256px { - get { - object obj = ResourceManager.GetObject("b_knight_png_shadow_256px", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// <summary> - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// </summary> - internal static System.Drawing.Bitmap b_pawn_png_shadow_256px { - get { - object obj = ResourceManager.GetObject("b_pawn_png_shadow_256px", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// <summary> - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// </summary> - internal static System.Drawing.Bitmap b_queen_png_shadow_256px { - get { - object obj = ResourceManager.GetObject("b_queen_png_shadow_256px", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// <summary> - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// </summary> - internal static System.Drawing.Bitmap b_rook_png_shadow_256px { - get { - object obj = ResourceManager.GetObject("b_rook_png_shadow_256px", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// <summary> - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// </summary> - internal static System.Drawing.Bitmap square_brown_light_png_shadow_256px { - get { - object obj = ResourceManager.GetObject("square_brown_light_png_shadow_256px", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// <summary> - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// </summary> - internal static System.Drawing.Bitmap square_gray_light__png_shadow_256px { - get { - object obj = ResourceManager.GetObject("square_gray_light__png_shadow_256px", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// <summary> - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// </summary> - internal static System.Drawing.Bitmap w_bishop_png_shadow_256px { - get { - object obj = ResourceManager.GetObject("w_bishop_png_shadow_256px", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// <summary> - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// </summary> - internal static System.Drawing.Bitmap w_king_png_shadow_256px { - get { - object obj = ResourceManager.GetObject("w_king_png_shadow_256px", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// <summary> - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// </summary> - internal static System.Drawing.Bitmap w_knight_png_shadow_256px { - get { - object obj = ResourceManager.GetObject("w_knight_png_shadow_256px", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// <summary> - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// </summary> - internal static System.Drawing.Bitmap w_pawn_png_shadow_256px { - get { - object obj = ResourceManager.GetObject("w_pawn_png_shadow_256px", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// <summary> - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// </summary> - internal static System.Drawing.Bitmap w_queen_png_shadow_256px { - get { - object obj = ResourceManager.GetObject("w_queen_png_shadow_256px", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// <summary> - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// </summary> - internal static System.Drawing.Bitmap w_rook_png_shadow_256px { - get { - object obj = ResourceManager.GetObject("w_rook_png_shadow_256px", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - } -} +//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace Chess.Properties {
+ using System;
+
+
+ /// <summary>
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ /// </summary>
+ // This class was auto-generated by the StronglyTypedResourceBuilder
+ // class via a tool like ResGen or Visual Studio.
+ // To add or remove a member, edit your .ResX file then rerun ResGen
+ // with the /str option, or rebuild your VS project.
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Resources {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Resources() {
+ }
+
+ /// <summary>
+ /// Returns the cached ResourceManager instance used by this class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Chess.Properties.Resources", typeof(Resources).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ /// <summary>
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ /// </summary>
+ internal static System.Drawing.Bitmap b_bishop_png_shadow_256px {
+ get {
+ object obj = ResourceManager.GetObject("b_bishop_png_shadow_256px", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ /// </summary>
+ internal static System.Drawing.Bitmap b_king_png_shadow_256px {
+ get {
+ object obj = ResourceManager.GetObject("b_king_png_shadow_256px", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ /// </summary>
+ internal static System.Drawing.Bitmap b_knight_png_shadow_256px {
+ get {
+ object obj = ResourceManager.GetObject("b_knight_png_shadow_256px", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ /// </summary>
+ internal static System.Drawing.Bitmap b_pawn_png_shadow_256px {
+ get {
+ object obj = ResourceManager.GetObject("b_pawn_png_shadow_256px", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ /// </summary>
+ internal static System.Drawing.Bitmap b_queen_png_shadow_256px {
+ get {
+ object obj = ResourceManager.GetObject("b_queen_png_shadow_256px", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ /// </summary>
+ internal static System.Drawing.Bitmap b_rook_png_shadow_256px {
+ get {
+ object obj = ResourceManager.GetObject("b_rook_png_shadow_256px", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ /// </summary>
+ internal static System.Drawing.Bitmap square_brown_light_png_shadow_256px {
+ get {
+ object obj = ResourceManager.GetObject("square_brown_light_png_shadow_256px", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ /// </summary>
+ internal static System.Drawing.Bitmap square_gray_light__png_shadow_256px {
+ get {
+ object obj = ResourceManager.GetObject("square_gray_light__png_shadow_256px", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ /// </summary>
+ internal static System.Drawing.Bitmap w_bishop_png_shadow_256px {
+ get {
+ object obj = ResourceManager.GetObject("w_bishop_png_shadow_256px", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ /// </summary>
+ internal static System.Drawing.Bitmap w_king_png_shadow_256px {
+ get {
+ object obj = ResourceManager.GetObject("w_king_png_shadow_256px", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ /// </summary>
+ internal static System.Drawing.Bitmap w_knight_png_shadow_256px {
+ get {
+ object obj = ResourceManager.GetObject("w_knight_png_shadow_256px", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ /// </summary>
+ internal static System.Drawing.Bitmap w_pawn_png_shadow_256px {
+ get {
+ object obj = ResourceManager.GetObject("w_pawn_png_shadow_256px", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ /// </summary>
+ internal static System.Drawing.Bitmap w_queen_png_shadow_256px {
+ get {
+ object obj = ResourceManager.GetObject("w_queen_png_shadow_256px", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized resource of type System.Drawing.Bitmap.
+ /// </summary>
+ internal static System.Drawing.Bitmap w_rook_png_shadow_256px {
+ get {
+ object obj = ResourceManager.GetObject("w_rook_png_shadow_256px", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+ }
+}
diff --git a/Properties/Resources.resx b/Properties/Resources.resx index e4f3f00..de942ee 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -1,163 +1,163 @@ -<?xml version="1.0" encoding="utf-8"?> -<root> - <!-- - Microsoft ResX Schema - - Version 2.0 - - The primary goals of this format is to allow a simple XML format - that is mostly human readable. The generation and parsing of the - various data types are done through the TypeConverter classes - associated with the data types. - - Example: - - ... ado.net/XML headers & schema ... - <resheader name="resmimetype">text/microsoft-resx</resheader> - <resheader name="version">2.0</resheader> - <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> - <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> - <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> - <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> - <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> - <value>[base64 mime encoded serialized .NET Framework object]</value> - </data> - <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> - <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> - <comment>This is a comment</comment> - </data> - - There are any number of "resheader" rows that contain simple - name/value pairs. - - Each data row contains a name, and value. The row also contains a - type or mimetype. Type corresponds to a .NET class that support - text/value conversion through the TypeConverter architecture. - Classes that don't support this are serialized and stored with the - mimetype set. - - The mimetype is used for serialized objects, and tells the - ResXResourceReader how to depersist the object. This is currently not - extensible. For a given mimetype the value must be set accordingly: - - Note - application/x-microsoft.net.object.binary.base64 is the format - that the ResXResourceWriter will generate, however the reader can - read any of the formats listed below. - - mimetype: application/x-microsoft.net.object.binary.base64 - value : The object must be serialized with - : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter - : and then encoded with base64 encoding. - - mimetype: application/x-microsoft.net.object.soap.base64 - value : The object must be serialized with - : System.Runtime.Serialization.Formatters.Soap.SoapFormatter - : and then encoded with base64 encoding. - - mimetype: application/x-microsoft.net.object.bytearray.base64 - value : The object must be serialized into a byte array - : using a System.ComponentModel.TypeConverter - : and then encoded with base64 encoding. - --> - <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> - <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> - <xsd:element name="root" msdata:IsDataSet="true"> - <xsd:complexType> - <xsd:choice maxOccurs="unbounded"> - <xsd:element name="metadata"> - <xsd:complexType> - <xsd:sequence> - <xsd:element name="value" type="xsd:string" minOccurs="0" /> - </xsd:sequence> - <xsd:attribute name="name" use="required" type="xsd:string" /> - <xsd:attribute name="type" type="xsd:string" /> - <xsd:attribute name="mimetype" type="xsd:string" /> - <xsd:attribute ref="xml:space" /> - </xsd:complexType> - </xsd:element> - <xsd:element name="assembly"> - <xsd:complexType> - <xsd:attribute name="alias" type="xsd:string" /> - <xsd:attribute name="name" type="xsd:string" /> - </xsd:complexType> - </xsd:element> - <xsd:element name="data"> - <xsd:complexType> - <xsd:sequence> - <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> - <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> - </xsd:sequence> - <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> - <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> - <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> - <xsd:attribute ref="xml:space" /> - </xsd:complexType> - </xsd:element> - <xsd:element name="resheader"> - <xsd:complexType> - <xsd:sequence> - <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> - </xsd:sequence> - <xsd:attribute name="name" type="xsd:string" use="required" /> - </xsd:complexType> - </xsd:element> - </xsd:choice> - </xsd:complexType> - </xsd:element> - </xsd:schema> - <resheader name="resmimetype"> - <value>text/microsoft-resx</value> - </resheader> - <resheader name="version"> - <value>2.0</value> - </resheader> - <resheader name="reader"> - <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> - </resheader> - <resheader name="writer"> - <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> - </resheader> - <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> - <data name="b_bishop_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms"> - <value>..\Resources\b_bishop_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> - </data> - <data name="b_king_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms"> - <value>..\Resources\b_king_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> - </data> - <data name="b_knight_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms"> - <value>..\Resources\b_knight_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> - </data> - <data name="b_pawn_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms"> - <value>..\Resources\b_pawn_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> - </data> - <data name="b_queen_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms"> - <value>..\Resources\b_queen_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> - </data> - <data name="b_rook_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms"> - <value>..\Resources\b_rook_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> - </data> - <data name="square_brown_light_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms"> - <value>..\Resources\square brown light_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> - </data> - <data name="square_gray_light__png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms"> - <value>..\Resources\square gray light _png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> - </data> - <data name="w_bishop_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms"> - <value>..\Resources\w_bishop_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> - </data> - <data name="w_king_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms"> - <value>..\Resources\w_king_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> - </data> - <data name="w_knight_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms"> - <value>..\Resources\w_knight_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> - </data> - <data name="w_pawn_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms"> - <value>..\Resources\w_pawn_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> - </data> - <data name="w_queen_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms"> - <value>..\Resources\w_queen_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> - </data> - <data name="w_rook_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms"> - <value>..\Resources\w_rook_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value> - </data> +<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
+ <data name="b_bishop_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms">
+ <value>..\Resources\b_bishop_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+ </data>
+ <data name="b_king_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms">
+ <value>..\Resources\b_king_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+ </data>
+ <data name="b_knight_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms">
+ <value>..\Resources\b_knight_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+ </data>
+ <data name="b_pawn_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms">
+ <value>..\Resources\b_pawn_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+ </data>
+ <data name="b_queen_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms">
+ <value>..\Resources\b_queen_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+ </data>
+ <data name="b_rook_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms">
+ <value>..\Resources\b_rook_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+ </data>
+ <data name="square_brown_light_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms">
+ <value>..\Resources\square brown light_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+ </data>
+ <data name="square_gray_light__png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms">
+ <value>..\Resources\square gray light _png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+ </data>
+ <data name="w_bishop_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms">
+ <value>..\Resources\w_bishop_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+ </data>
+ <data name="w_king_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms">
+ <value>..\Resources\w_king_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+ </data>
+ <data name="w_knight_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms">
+ <value>..\Resources\w_knight_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+ </data>
+ <data name="w_pawn_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms">
+ <value>..\Resources\w_pawn_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+ </data>
+ <data name="w_queen_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms">
+ <value>..\Resources\w_queen_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+ </data>
+ <data name="w_rook_png_shadow_256px" type="System.Resources.ResXFileRef, System.Windows.Forms">
+ <value>..\Resources\w_rook_png_shadow_256px.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+ </data>
</root>
\ No newline at end of file diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs index 2655a4f..5a9023a 100644 --- a/Properties/Settings.Designer.cs +++ b/Properties/Settings.Designer.cs @@ -1,30 +1,30 @@ -//------------------------------------------------------------------------------ -// <auto-generated> -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// </auto-generated> -//------------------------------------------------------------------------------ - -namespace Chess.Properties -{ - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase - { - - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default - { - get - { - return defaultInstance; - } - } - } -} +//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace Chess.Properties
+{
+
+
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
+ internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
+ {
+
+ private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+
+ public static Settings Default
+ {
+ get
+ {
+ return defaultInstance;
+ }
+ }
+ }
+}
diff --git a/Properties/Settings.settings b/Properties/Settings.settings index 3964565..abf36c5 100644 --- a/Properties/Settings.settings +++ b/Properties/Settings.settings @@ -1,7 +1,7 @@ -<?xml version='1.0' encoding='utf-8'?> -<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)"> - <Profiles> - <Profile Name="(Default)" /> - </Profiles> - <Settings /> -</SettingsFile> +<?xml version='1.0' encoding='utf-8'?>
+<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
+ <Profiles>
+ <Profile Name="(Default)" />
+ </Profiles>
+ <Settings />
+</SettingsFile>
diff --git a/TODO.txt b/TODO.txt new file mode 100644 index 0000000..73819ef --- /dev/null +++ b/TODO.txt @@ -0,0 +1,5 @@ +List of unimplemented rules: +- 75 move rule +- en passant +- dont allow castling when in check +- dont allow castling when king passes an attacked tile
\ No newline at end of file diff --git a/bin/Debug/Chess.exe b/bin/Debug/Chess.exe Binary files differdeleted file mode 100644 index 73c3566..0000000 --- a/bin/Debug/Chess.exe +++ /dev/null diff --git a/bin/Debug/Chess.exe.config b/bin/Debug/Chess.exe.config deleted file mode 100644 index 56efbc7..0000000 --- a/bin/Debug/Chess.exe.config +++ /dev/null @@ -1,6 +0,0 @@ -<?xml version="1.0" encoding="utf-8" ?> -<configuration> - <startup> - <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> - </startup> -</configuration>
\ No newline at end of file diff --git a/bin/Debug/Chess.pdb b/bin/Debug/Chess.pdb Binary files differdeleted file mode 100644 index 4cd0333..0000000 --- a/bin/Debug/Chess.pdb +++ /dev/null diff --git a/bin/Release/Chess.exe b/bin/Release/Chess.exe Binary files differdeleted file mode 100644 index bb54dc3..0000000 --- a/bin/Release/Chess.exe +++ /dev/null diff --git a/bin/Release/Chess.exe.config b/bin/Release/Chess.exe.config deleted file mode 100644 index 56efbc7..0000000 --- a/bin/Release/Chess.exe.config +++ /dev/null @@ -1,6 +0,0 @@ -<?xml version="1.0" encoding="utf-8" ?> -<configuration> - <startup> - <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> - </startup> -</configuration>
\ No newline at end of file diff --git a/bin/Release/Chess.pdb b/bin/Release/Chess.pdb Binary files differdeleted file mode 100644 index e3b4478..0000000 --- a/bin/Release/Chess.pdb +++ /dev/null diff --git a/obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs b/obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs deleted file mode 100644 index 3871b18..0000000 --- a/obj/Debug/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs +++ /dev/null @@ -1,4 +0,0 @@ -// <autogenerated /> -using System; -using System.Reflection; -[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] diff --git a/obj/Debug/Chess.MainForm.resources b/obj/Debug/Chess.MainForm.resources Binary files differdeleted file mode 100644 index 6c05a97..0000000 --- a/obj/Debug/Chess.MainForm.resources +++ /dev/null diff --git a/obj/Debug/Chess.Properties.Resources.resources b/obj/Debug/Chess.Properties.Resources.resources Binary files differdeleted file mode 100644 index 35371b6..0000000 --- a/obj/Debug/Chess.Properties.Resources.resources +++ /dev/null diff --git a/obj/Debug/Chess.csproj.CoreCompileInputs.cache b/obj/Debug/Chess.csproj.CoreCompileInputs.cache deleted file mode 100644 index 8da1a1c..0000000 --- a/obj/Debug/Chess.csproj.CoreCompileInputs.cache +++ /dev/null @@ -1 +0,0 @@ -1b1ae2325e85edb2d670644e476ed984350486d2 diff --git a/obj/Debug/Chess.csproj.FileListAbsolute-LAPTOP-B78JCJFS.txt b/obj/Debug/Chess.csproj.FileListAbsolute-LAPTOP-B78JCJFS.txt deleted file mode 100644 index 9cb6ff2..0000000 --- a/obj/Debug/Chess.csproj.FileListAbsolute-LAPTOP-B78JCJFS.txt +++ /dev/null @@ -1,9 +0,0 @@ -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\bin\Debug\Chess.exe.config -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\bin\Debug\Chess.exe -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\bin\Debug\Chess.pdb -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\obj\Debug\Chess.MainForm.resources -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\obj\Debug\Chess.Properties.Resources.resources -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\obj\Debug\Chess.csproj.GenerateResource.cache -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\obj\Debug\Chess.csproj.CoreCompileInputs.cache -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\obj\Debug\Chess.exe -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\obj\Debug\Chess.pdb diff --git a/obj/Debug/Chess.csproj.FileListAbsolute.txt b/obj/Debug/Chess.csproj.FileListAbsolute.txt deleted file mode 100644 index 9f178e4..0000000 --- a/obj/Debug/Chess.csproj.FileListAbsolute.txt +++ /dev/null @@ -1,10 +0,0 @@ -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\bin\Debug\Chess.exe.config -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\bin\Debug\Chess.exe -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\bin\Debug\Chess.pdb -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\obj\Debug\Chess.MainForm.resources -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\obj\Debug\Chess.Properties.Resources.resources -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\obj\Debug\Chess.csproj.GenerateResource.cache -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\obj\Debug\Chess.csproj.CoreCompileInputs.cache -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\obj\Debug\Chess.exe -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\obj\Debug\Chess.pdb -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\obj\Debug\Chess.csprojAssemblyReference.cache diff --git a/obj/Debug/Chess.csproj.GenerateResource.cache b/obj/Debug/Chess.csproj.GenerateResource.cache Binary files differdeleted file mode 100644 index 62b3a45..0000000 --- a/obj/Debug/Chess.csproj.GenerateResource.cache +++ /dev/null diff --git a/obj/Debug/Chess.csprojAssemblyReference.cache b/obj/Debug/Chess.csprojAssemblyReference.cache Binary files differdeleted file mode 100644 index 594fb41..0000000 --- a/obj/Debug/Chess.csprojAssemblyReference.cache +++ /dev/null diff --git a/obj/Debug/Chess.exe b/obj/Debug/Chess.exe Binary files differdeleted file mode 100644 index 73c3566..0000000 --- a/obj/Debug/Chess.exe +++ /dev/null diff --git a/obj/Debug/Chess.pdb b/obj/Debug/Chess.pdb Binary files differdeleted file mode 100644 index 4cd0333..0000000 --- a/obj/Debug/Chess.pdb +++ /dev/null diff --git a/obj/Debug/DesignTimeResolveAssemblyReferences.cache b/obj/Debug/DesignTimeResolveAssemblyReferences.cache Binary files differdeleted file mode 100644 index e6fcb3b..0000000 --- a/obj/Debug/DesignTimeResolveAssemblyReferences.cache +++ /dev/null diff --git a/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache Binary files differdeleted file mode 100644 index 3a9edc4..0000000 --- a/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache +++ /dev/null diff --git a/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll b/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll Binary files differdeleted file mode 100644 index 22f2a2d..0000000 --- a/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll +++ /dev/null diff --git a/obj/Release/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs b/obj/Release/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs deleted file mode 100644 index 3871b18..0000000 --- a/obj/Release/.NETFramework,Version=v4.7.2.AssemblyAttributes.cs +++ /dev/null @@ -1,4 +0,0 @@ -// <autogenerated /> -using System; -using System.Reflection; -[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] diff --git a/obj/Release/Chess.MainForm.resources b/obj/Release/Chess.MainForm.resources Binary files differdeleted file mode 100644 index 6c05a97..0000000 --- a/obj/Release/Chess.MainForm.resources +++ /dev/null diff --git a/obj/Release/Chess.Properties.Resources.resources b/obj/Release/Chess.Properties.Resources.resources Binary files differdeleted file mode 100644 index 6c05a97..0000000 --- a/obj/Release/Chess.Properties.Resources.resources +++ /dev/null diff --git a/obj/Release/Chess.csproj.CoreCompileInputs.cache b/obj/Release/Chess.csproj.CoreCompileInputs.cache deleted file mode 100644 index ebf2dd0..0000000 --- a/obj/Release/Chess.csproj.CoreCompileInputs.cache +++ /dev/null @@ -1 +0,0 @@ -c5c1da89ec11211f5ccde59de778c88b1d2136fd diff --git a/obj/Release/Chess.csproj.FileListAbsolute.txt b/obj/Release/Chess.csproj.FileListAbsolute.txt deleted file mode 100644 index 25a0623..0000000 --- a/obj/Release/Chess.csproj.FileListAbsolute.txt +++ /dev/null @@ -1,10 +0,0 @@ -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\bin\Release\Chess.exe.config -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\bin\Release\Chess.exe -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\bin\Release\Chess.pdb -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\obj\Release\Chess.csprojAssemblyReference.cache -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\obj\Release\Chess.MainForm.resources -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\obj\Release\Chess.Properties.Resources.resources -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\obj\Release\Chess.csproj.GenerateResource.cache -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\obj\Release\Chess.csproj.CoreCompileInputs.cache -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\obj\Release\Chess.exe -C:\Users\Aldrik R\OneDrive - Office 365 Fontys\Homework\P-DB-SOFT-P-DB04\Deelproducten\Deelproduct wedstrijd\Chess\obj\Release\Chess.pdb diff --git a/obj/Release/Chess.csproj.GenerateResource.cache b/obj/Release/Chess.csproj.GenerateResource.cache Binary files differdeleted file mode 100644 index e76fea7..0000000 --- a/obj/Release/Chess.csproj.GenerateResource.cache +++ /dev/null diff --git a/obj/Release/Chess.csprojAssemblyReference.cache b/obj/Release/Chess.csprojAssemblyReference.cache Binary files differdeleted file mode 100644 index 4c4ceaf..0000000 --- a/obj/Release/Chess.csprojAssemblyReference.cache +++ /dev/null diff --git a/obj/Release/Chess.exe b/obj/Release/Chess.exe Binary files differdeleted file mode 100644 index bb54dc3..0000000 --- a/obj/Release/Chess.exe +++ /dev/null diff --git a/obj/Release/Chess.pdb b/obj/Release/Chess.pdb Binary files differdeleted file mode 100644 index e3b4478..0000000 --- a/obj/Release/Chess.pdb +++ /dev/null diff --git a/obj/Release/TempPE/Properties.Resources.Designer.cs.dll b/obj/Release/TempPE/Properties.Resources.Designer.cs.dll Binary files differdeleted file mode 100644 index 5e47250..0000000 --- a/obj/Release/TempPE/Properties.Resources.Designer.cs.dll +++ /dev/null diff --git a/packages.config b/packages.config new file mode 100644 index 0000000..a9de8b5 --- /dev/null +++ b/packages.config @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="Newtonsoft.Json" version="12.0.3" targetFramework="net472" /> +</packages>
\ No newline at end of file |
