1. 增加棋盘与棋子渲染功能及相关素材
@@ -25,6 +25,44 @@ namespace ChineseChess.Core
|
|||||||
|
|
||||||
public IEnumerable<ChessMove> GetMoves() => Moves;
|
public IEnumerable<ChessMove> GetMoves() => Moves;
|
||||||
|
|
||||||
|
public void ResetChessboard()
|
||||||
|
{
|
||||||
|
AlivingChessman.Clear();
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.King , ChessCamp.Red, new ChessboardPosition(4, 0)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Mandarins, ChessCamp.Red, new ChessboardPosition(3, 0)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Mandarins, ChessCamp.Red, new ChessboardPosition(5, 0)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Knights , ChessCamp.Red, new ChessboardPosition(2, 0)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Knights , ChessCamp.Red, new ChessboardPosition(6, 0)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Elephants, ChessCamp.Red, new ChessboardPosition(1, 0)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Elephants, ChessCamp.Red, new ChessboardPosition(7, 0)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Rooks , ChessCamp.Red, new ChessboardPosition(0, 0)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Rooks , ChessCamp.Red, new ChessboardPosition(8, 0)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Cannons , ChessCamp.Red, new ChessboardPosition(1, 2)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Cannons , ChessCamp.Red, new ChessboardPosition(7, 2)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Pawns , ChessCamp.Red, new ChessboardPosition(0, 3)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Pawns , ChessCamp.Red, new ChessboardPosition(2, 3)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Pawns , ChessCamp.Red, new ChessboardPosition(4, 3)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Pawns , ChessCamp.Red, new ChessboardPosition(6, 3)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Pawns , ChessCamp.Red, new ChessboardPosition(8, 3)));
|
||||||
|
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.King , ChessCamp.Black, new ChessboardPosition(4, 9)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Mandarins, ChessCamp.Black, new ChessboardPosition(3, 9)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Mandarins, ChessCamp.Black, new ChessboardPosition(5, 9)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Knights , ChessCamp.Black, new ChessboardPosition(2, 9)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Knights , ChessCamp.Black, new ChessboardPosition(6, 9)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Elephants, ChessCamp.Black, new ChessboardPosition(1, 9)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Elephants, ChessCamp.Black, new ChessboardPosition(7, 9)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Rooks , ChessCamp.Black, new ChessboardPosition(0, 9)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Rooks , ChessCamp.Black, new ChessboardPosition(8, 9)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Cannons , ChessCamp.Black, new ChessboardPosition(1, 7)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Cannons , ChessCamp.Black, new ChessboardPosition(7, 7)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Pawns , ChessCamp.Black, new ChessboardPosition(0, 6)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Pawns , ChessCamp.Black, new ChessboardPosition(2, 6)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Pawns , ChessCamp.Black, new ChessboardPosition(4, 6)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Pawns , ChessCamp.Black, new ChessboardPosition(6, 6)));
|
||||||
|
AlivingChessman.Add(new Chessman(ChessType.Pawns , ChessCamp.Black, new ChessboardPosition(8, 6)));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 移动棋子到目标位置,若目标位置存在棋子,则移除
|
/// 移动棋子到目标位置,若目标位置存在棋子,则移除
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@@ -48,6 +48,6 @@
|
|||||||
return new ChessboardPosition(left.Col - right.Col, left.Row - right.Row);
|
return new ChessboardPosition(left.Col - right.Col, left.Row - right.Row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ChessboardPosition Zero => new ChessboardPosition();
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -4,6 +4,12 @@ namespace ChineseChess.Core
|
|||||||
{
|
{
|
||||||
public class Game
|
public class Game
|
||||||
{
|
{
|
||||||
// TODO
|
public Chessboard Chessboard { get; } = new Chessboard();
|
||||||
|
|
||||||
|
public Game()
|
||||||
|
{
|
||||||
|
Chessboard.ResetChessboard();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
104
ChineseChess/CGame.cs
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
using ChineseChess.Core;
|
||||||
|
|
||||||
|
namespace ChineseChess
|
||||||
|
{
|
||||||
|
internal class CGame : Control
|
||||||
|
{
|
||||||
|
private Bitmap _ChessboardBitmap;
|
||||||
|
private ResourceHelper _ResHelper;
|
||||||
|
|
||||||
|
private Game _Game;
|
||||||
|
private ChessboardPosition? _CurrMouseOverPos;
|
||||||
|
private Chessman _CurrSelectedChessman;
|
||||||
|
|
||||||
|
public CGame()
|
||||||
|
{
|
||||||
|
DoubleBuffered = true;
|
||||||
|
_ResHelper = ResourceHelper.Instance;
|
||||||
|
_ChessboardBitmap = _ResHelper.GetChessboardBitmap(0);
|
||||||
|
MinimumSize = MaximumSize = Size = _ChessboardBitmap.Size;
|
||||||
|
_Game = new Game();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnPaint(PaintEventArgs pevent)
|
||||||
|
{
|
||||||
|
foreach (var chessman in _Game.Chessboard.GetChessmen())
|
||||||
|
DrawChessman(pevent.Graphics, chessman);
|
||||||
|
|
||||||
|
if (_CurrSelectedChessman != null && _CurrMouseOverPos.HasValue && _CurrSelectedChessman.Position != _CurrMouseOverPos.Value)
|
||||||
|
DrawChessman(pevent.Graphics, _CurrSelectedChessman, _CurrMouseOverPos.Value);
|
||||||
|
|
||||||
|
|
||||||
|
base.OnPaint(pevent);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnMouseMove(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
var pos = GetChessboardPosition(e.Location);
|
||||||
|
if (_CurrMouseOverPos != pos)
|
||||||
|
{
|
||||||
|
_CurrMouseOverPos = pos;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
base.OnMouseMove(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnClick(EventArgs e)
|
||||||
|
{
|
||||||
|
Chessman selected = null;
|
||||||
|
if (_CurrMouseOverPos.HasValue)
|
||||||
|
selected = _Game.Chessboard.GetChessmanByPos(_CurrMouseOverPos.Value);
|
||||||
|
if (_CurrSelectedChessman != selected)
|
||||||
|
{
|
||||||
|
_CurrSelectedChessman = selected;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
base.OnClick(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawChessman(Graphics g, Chessman chessman)
|
||||||
|
{
|
||||||
|
DrawImageByCentre(g, _ResHelper.GetChessmanBitmap(chessman.Type, chessman.Camp), GetChessboardGridPoint(chessman.Position));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawChessman(Graphics g, Chessman chessman, ChessboardPosition pos)
|
||||||
|
{
|
||||||
|
DrawImageByCentre(g, _ResHelper.GetChessmanBitmap(chessman.Type, chessman.Camp), GetChessboardGridPoint(pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Point GetChessboardGridPoint(ChessboardPosition position)
|
||||||
|
{
|
||||||
|
return new Point(position.Col * _ResHelper.ChessboardCellSize.Width + _ResHelper.ChessboardOffset.Width,
|
||||||
|
_ResHelper.ChessboardGridSize.Height - position.Row * _ResHelper.ChessboardCellSize.Height + _ResHelper.ChessboardOffset.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ChessboardPosition? GetChessboardPosition(Point point)
|
||||||
|
{
|
||||||
|
int x = point.X - _ResHelper.ChessboardOffset.Width + _ResHelper.ChessboardCellSize.Width / 2;
|
||||||
|
int y = point.Y - _ResHelper.ChessboardOffset.Height + _ResHelper.ChessboardCellSize.Height / 2;
|
||||||
|
if (x < 0 || y < 0
|
||||||
|
|| x >= _ResHelper.ChessboardSize.Width * _ResHelper.ChessboardCellSize.Width
|
||||||
|
|| y >= _ResHelper.ChessboardSize.Height * _ResHelper.ChessboardCellSize.Height)
|
||||||
|
return null;
|
||||||
|
x /= _ResHelper.ChessboardCellSize.Width;
|
||||||
|
y /= _ResHelper.ChessboardCellSize.Height;
|
||||||
|
return new ChessboardPosition(x, _ResHelper.ChessboardSize.Height - y - 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawImageByCentre(Graphics g, Image image, Point point)
|
||||||
|
{
|
||||||
|
g.DrawImage(image, point.X - image.Width/2, point.Y - image.Height/2, image.Width, image.Height);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnPaintBackground(PaintEventArgs pevent)
|
||||||
|
{
|
||||||
|
pevent.Graphics.DrawImage(_ChessboardBitmap, 0, 0, _ChessboardBitmap.Width, _ChessboardBitmap.Height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -4,6 +4,26 @@
|
|||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<TargetFramework>net5.0-windows</TargetFramework>
|
<TargetFramework>net5.0-windows</TargetFramework>
|
||||||
<UseWindowsForms>true</UseWindowsForms>
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
|
<ApplicationIcon>Resources\ChineseChess.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\ChineseChess.Core\ChineseChess.Core.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Update="Properties\Resources.Designer.cs">
|
||||||
|
<DesignTime>True</DesignTime>
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Update="Properties\Resources.resx">
|
||||||
|
<Generator>ResXFileCodeGenerator</Generator>
|
||||||
|
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||||
|
</EmbeddedResource>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
18
ChineseChess/MainForm.Designer.cs
generated
@@ -29,13 +29,27 @@ namespace ChineseChess
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
|
||||||
|
this.Game = new ChineseChess.CGame();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
|
// Game
|
||||||
|
//
|
||||||
|
this.Game.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.Game.MaximumSize = new System.Drawing.Size(458, 530);
|
||||||
|
this.Game.MinimumSize = new System.Drawing.Size(458, 530);
|
||||||
|
this.Game.Name = "Game";
|
||||||
|
this.Game.Size = new System.Drawing.Size(458, 530);
|
||||||
|
this.Game.TabIndex = 0;
|
||||||
|
this.Game.Text = "chineseChessGame1";
|
||||||
|
//
|
||||||
// MainForm
|
// MainForm
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(784, 561);
|
this.ClientSize = new System.Drawing.Size(458, 529);
|
||||||
|
this.Controls.Add(this.Game);
|
||||||
|
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||||
this.Name = "MainForm";
|
this.Name = "MainForm";
|
||||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||||
this.Text = "象棋";
|
this.Text = "象棋";
|
||||||
@@ -45,6 +59,8 @@ namespace ChineseChess
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
private CGame Game;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
133
ChineseChess/Properties/Resources.Designer.cs
generated
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// 此代码由工具生成。
|
||||||
|
// 运行时版本:4.0.30319.42000
|
||||||
|
//
|
||||||
|
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||||
|
// 重新生成代码,这些更改将会丢失。
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace ChineseChess.Properties {
|
||||||
|
using System;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 一个强类型的资源类,用于查找本地化的字符串等。
|
||||||
|
/// </summary>
|
||||||
|
// 此类是由 StronglyTypedResourceBuilder
|
||||||
|
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
|
||||||
|
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
|
||||||
|
// (以 /str 作为命令选项),或重新生成 VS 项目。
|
||||||
|
[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>
|
||||||
|
/// 返回此类使用的缓存的 ResourceManager 实例。
|
||||||
|
/// </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("ChineseChess.Properties.Resources", typeof(Resources).Assembly);
|
||||||
|
resourceMan = temp;
|
||||||
|
}
|
||||||
|
return resourceMan;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 重写当前线程的 CurrentUICulture 属性,对
|
||||||
|
/// 使用此强类型资源类的所有资源查找执行重写。
|
||||||
|
/// </summary>
|
||||||
|
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||||
|
internal static global::System.Globalization.CultureInfo Culture {
|
||||||
|
get {
|
||||||
|
return resourceCulture;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
resourceCulture = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap Chessboard1 {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("Chessboard1", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap Chessboard2 {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("Chessboard2", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap ChessmanSprites {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("ChessmanSprites", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap ChineseChess {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("ChineseChess", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Icon ChineseChessIcon {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("ChineseChessIcon", resourceCulture);
|
||||||
|
return ((System.Drawing.Icon)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap SelectBorderGreen {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("SelectBorderGreen", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找 System.Drawing.Bitmap 类型的本地化资源。
|
||||||
|
/// </summary>
|
||||||
|
internal static System.Drawing.Bitmap SelectBorderRed {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("SelectBorderRed", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
142
ChineseChess/Properties/Resources.resx
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
<?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=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||||
|
<data name="Chessboard1" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\Chessboard1.bmp;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
<data name="Chessboard2" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\Chessboard2.bmp;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
<data name="ChessmanSprites" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\ChessmanSprites.bmp;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
<data name="ChineseChess" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\ChineseChess.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
<data name="ChineseChessIcon" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\ChineseChess.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
<data name="SelectBorderGreen" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\SelectBorderGreen.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
<data name="SelectBorderRed" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\SelectBorderRed.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
</root>
|
85
ChineseChess/ResourceHelper.cs
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using ChineseChess.Core;
|
||||||
|
using ChineseChess.Properties;
|
||||||
|
|
||||||
|
namespace ChineseChess
|
||||||
|
{
|
||||||
|
class ResourceHelper
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 获取资源助手实例(单例对象)
|
||||||
|
/// </summary>
|
||||||
|
public static ResourceHelper Instance { get; } = new ResourceHelper();
|
||||||
|
|
||||||
|
private Dictionary<ChessType, Bitmap> _RedChessmans = new Dictionary<ChessType, Bitmap>(7);
|
||||||
|
private Dictionary<ChessType, Bitmap> _BlackChessmans = new Dictionary<ChessType, Bitmap>(7);
|
||||||
|
private Bitmap[] Chessboards = new Bitmap[] { Resources.Chessboard1, Resources.Chessboard2 };
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public Size ChessmanBitmapSize { get; } = new Size(47, 46);
|
||||||
|
public Size ChessboardCellSize { get; } = new Size(50, 50);
|
||||||
|
public Size ChessboardSize { get; } = new Size(9, 10);
|
||||||
|
public Size ChessboardGridSize { get; } = new Size(50 * 8, 50 * 9);
|
||||||
|
public Size ChessboardOffset { get; } = new Size(27, 36);
|
||||||
|
|
||||||
|
|
||||||
|
private ChessType[] _ChessmanOrder = new ChessType[] { ChessType.King, ChessType.Mandarins, ChessType.Elephants, ChessType.Knights, ChessType.Rooks, ChessType.Cannons, ChessType.Pawns };
|
||||||
|
private ChessCamp[] _ChessCampOrder = new ChessCamp[] { ChessCamp.Red, ChessCamp.Black };
|
||||||
|
|
||||||
|
private ResourceHelper()
|
||||||
|
{
|
||||||
|
var sprites = Resources.ChessmanSprites;
|
||||||
|
Point offset = Point.Empty;
|
||||||
|
foreach (var camp in _ChessCampOrder)
|
||||||
|
{
|
||||||
|
var chessmans = camp == ChessCamp.Red ? _RedChessmans : _BlackChessmans;
|
||||||
|
foreach (var type in _ChessmanOrder)
|
||||||
|
{
|
||||||
|
Bitmap bitmap = new Bitmap(ChessmanBitmapSize.Width, ChessmanBitmapSize.Height);
|
||||||
|
using (var g = Graphics.FromImage(bitmap))
|
||||||
|
{
|
||||||
|
g.DrawImage(sprites, new Rectangle(Point.Empty, ChessmanBitmapSize), new Rectangle(offset, ChessmanBitmapSize), GraphicsUnit.Pixel);
|
||||||
|
}
|
||||||
|
bitmap.MakeTransparent(Color.FromArgb(0xFF, 0x00, 0xFF));
|
||||||
|
chessmans.Add(type, bitmap);
|
||||||
|
offset.X += ChessmanBitmapSize.Width;
|
||||||
|
}
|
||||||
|
offset.X = 0;
|
||||||
|
offset.Y = ChessmanBitmapSize.Height + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取象棋图片
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="type">棋子类型</param>
|
||||||
|
/// <param name="camp">棋子阵营</param>
|
||||||
|
/// <returns>返回缓存中的图片</returns>
|
||||||
|
public Bitmap GetChessmanBitmap(ChessType type, ChessCamp camp)
|
||||||
|
{
|
||||||
|
if (camp == ChessCamp.Red)
|
||||||
|
return _RedChessmans[type];
|
||||||
|
else if (camp == ChessCamp.Black)
|
||||||
|
return _BlackChessmans[type];
|
||||||
|
else
|
||||||
|
throw new ArgumentException("无效阵营参数", nameof(camp));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取棋盘图片
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="index">棋盘索引 0~1</param>
|
||||||
|
/// <returns>返回缓存中的图片</returns>
|
||||||
|
public Bitmap GetChessboardBitmap(int index)
|
||||||
|
{
|
||||||
|
return Chessboards[index];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
BIN
ChineseChess/Resources/Chessboard1.bmp
Normal file
After Width: | Height: | Size: 239 KiB |
BIN
ChineseChess/Resources/Chessboard2.bmp
Normal file
After Width: | Height: | Size: 239 KiB |
BIN
ChineseChess/Resources/ChessmanSprites.bmp
Normal file
After Width: | Height: | Size: 32 KiB |
BIN
ChineseChess/Resources/ChineseChess.ico
Normal file
After Width: | Height: | Size: 68 KiB |
BIN
ChineseChess/Resources/ChineseChess.png
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
ChineseChess/Resources/SelectBorderGreen.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
ChineseChess/Resources/SelectBorderRed.png
Normal file
After Width: | Height: | Size: 2.9 KiB |