Skip to content

Commit

Permalink
Added move sound.
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksanderNekr committed Jun 6, 2022
1 parent a1d0cba commit 66f3812
Show file tree
Hide file tree
Showing 30 changed files with 130 additions and 91 deletions.
1 change: 1 addition & 0 deletions ChessLearnProgram/Chess/Chess.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Content Include="Resources\move_sound.wav" />
<None Include="Resources\Фон для текста.png" />
<None Include="Resources\Фон для кнопки.jpg" />
<None Include="Resources\Фон для кнопки.png" />
Expand Down
11 changes: 8 additions & 3 deletions ChessLearnProgram/Chess/Pieces/ChessPiece.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System;
#nullable enable
using System;
using System.Collections.Generic;
using System.Media;
using System.Threading;
using System.Windows.Forms;

namespace Chess.Pieces
Expand All @@ -10,8 +13,9 @@ namespace Chess.Pieces
/// </summary>
public abstract class ChessPiece : Button
{
private string _color;
private Coordinate _currentCoordinate;
private string _color;
private Coordinate _currentCoordinate;
public static SoundPlayer? MoveSound;

public ChessPiece(Coordinate coordinate, string color)
{
Expand Down Expand Up @@ -90,6 +94,7 @@ public void MoveTo(Coordinate newCoordinate)
this.CurrentCoordinate = new Coordinate(newCoordinate.Row, newCoordinate.Column);
this.Clicks = 0;
this.BackColor = System.Drawing.Color.Transparent;
MoveSound?.Play();
}

public abstract List<Coordinate> GetValidMoves();
Expand Down
48 changes: 26 additions & 22 deletions ChessLearnProgram/Chess/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions ChessLearnProgram/Chess/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,9 @@
<data name="Фон_для_кнопки" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Фон для кнопки.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="move_sound" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\move_sound.wav;System.IO.MemoryStream, mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</data>
</root>
Binary file added ChessLearnProgram/Chess/Resources/move_sound.wav
Binary file not shown.
Binary file modified ChessLearnProgram/Chess/bin/Debug/Chess.dll
Binary file not shown.
Binary file modified ChessLearnProgram/Chess/bin/Debug/Chess.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified ChessLearnProgram/Chess/obj/Debug/Chess.dll
Binary file not shown.
Binary file modified ChessLearnProgram/Chess/obj/Debug/Chess.pdb
Binary file not shown.
45 changes: 30 additions & 15 deletions ChessLearnProgram/ChessLearnProgram/ChessBoardForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,20 @@ internal sealed partial class ChessBoardForm : Form

private SoundPlayer? _soundPlayer;
private Thread? _theoryThread;
public SoundPlayer? MoveSound;

public ChessBoardForm()
{
this.InitializeComponent();
ValidMove.ValidMoveColor = SettingsForm.IsShowMoves
? Color.Chartreuse
: Color.Transparent;
if (SettingsForm.IsHilightLastMove)
{
this.MoveSound = new SoundPlayer(Resource.move_sound);
}

ChessPiece.MoveSound = this.MoveSound;
}

private void UpdateChessBoard()
Expand All @@ -78,6 +85,14 @@ private void SizeTrackBar_Scroll(object sender, EventArgs e)
this.tableLayoutPanel1.Size = new Size(this.SizeTrackBar.Value, this.SizeTrackBar.Value + 2);
}

private void DiableAllControls()
{
foreach (Control control in this.tableLayoutPanel1.Controls)
{
control.Enabled = false;
}
}

private void PracticeButton_Click(object sender, EventArgs e)
{
this._theoryThread?.Abort();
Expand Down Expand Up @@ -508,15 +523,14 @@ private void Pawn_Click(object sender, EventArgs e)
coordinate.Row])
.OfType<ValidMove>();
foreach (ValidMove validMove in valids)
{
if (pawn.Clicks == 1)
{
validMove.Click -= this.ValidPawnMove_Click;
validMove.Click += this.ValidPawnMove_Click;
}
}
}

if ((ChessBoard.ChessBoardMatrix[2, 1] is Knight enemyKnight) && (enemyKnight.BackColor == ValidMove.ValidMoveColor))
if ((ChessBoard.ChessBoardMatrix[2, 1] is Knight enemyKnight)
&& (enemyKnight.BackColor == ValidMove.ValidMoveColor))
{
if (pawn.Clicks == 1 && pawn.CurrentCoordinate.Row == 2)
{
Expand Down Expand Up @@ -597,6 +611,7 @@ var queen
Поздравляем! Вы успешно смогли поставить мат королю соперника, тем самым выиграв партию!";
MessageBox.Show(@"Поздравляем! Вы успешно смогли поставить мат королю соперника, тем самым выиграв партию!",
@"Поздравляем!", MessageBoxButtons.OK, MessageBoxIcon.Information);
DiableAllControls();
return;
}
}
Expand Down Expand Up @@ -733,6 +748,7 @@ private void RunCorrectKingMove()
MessageBox.Show(@"Поздравляем! Вы смогли защитить короля, сделав рокировку! Этим ходом вы обеспечили не только безопасность своего короля,
но и открыли для ладьи сразу два пути для развития, что позволит вам провести свои пешки и сделать их ферзями!",
@"Поздравляем!", MessageBoxButtons.OK, MessageBoxIcon.Information);
DiableAllControls();
}

private void RunBadKingMoveMate()
Expand Down Expand Up @@ -924,7 +940,7 @@ private void ValidRookMove_Click(object sender, EventArgs e)
this.UpdateChessBoard();
MessageBox.Show(@"Замечательно! Вы поставили шах его королю, который удерживал ладью от удара и следующим ходом своего короля вы с лёгкостью заберёте его ладью и проведёте пешку, выиграв партию! Поздравляем!",
@"Победа!", MessageBoxButtons.OK, MessageBoxIcon.Information);
whiteRook.Enabled = false;
DiableAllControls();
}
else if (!moveCoord.Equals(new Coordinate(5, 3)) || (initialCoordinate.Column == 4))
{
Expand Down Expand Up @@ -1009,10 +1025,7 @@ private void ValidRookMoveInBishopLesson_Click(object sender, EventArgs e)
this.UpdateChessBoard();
MessageBox.Show(@"Отлично! Вы поставили мат королю соперника, поздравляю!", @"Победа!",
MessageBoxButtons.OK, MessageBoxIcon.Information);
foreach (Control control in this.tableLayoutPanel1.Controls)
{
control.Enabled = false;
}
DiableAllControls();
}
else if ((initialCoord.Row == 7) && (moveCoord.Row == 0))
{
Expand Down Expand Up @@ -1129,7 +1142,7 @@ private void ValidBishopMove_Click(object sender, EventArgs e)
private void LoadQueenPracticeScene()
{
var whiteKing = new King(new Coordinate(3, 7), "White");
whiteKing.Click += this.King_Click;
whiteKing.Click += this.King_Click;
var whiteQueen = new Queen(new Coordinate(0, 0), "White");
whiteQueen.Click += this.Queen_Click;
_ = new Pawn(new Coordinate(6, 0), "White");
Expand Down Expand Up @@ -1257,6 +1270,7 @@ private void ValidQueenMove_Click(object sender, EventArgs e)
Вы справились с матом в 4 хода, поздравляю!";
MessageBox.Show(@"Вы справились с матом в 4 хода, поздравляю!",
@"Победа!", MessageBoxButtons.OK, MessageBoxIcon.Information);
DiableAllControls();
return;
}

Expand Down Expand Up @@ -1355,13 +1369,13 @@ private void LoadKnightPracticeScene()
whiteKnightRight.Click += this.Knight_Click;
var whiteKnightLeft = new Knight(new Coordinate(5, 2), "White");
whiteKnightLeft.Click += this.Knight_Click;
_ = new Rook(new Coordinate(7, 7), "White");
_ = new Rook(new Coordinate(7, 0), "White");
_ = new Rook(new Coordinate(7, 7), "White");
_ = new Rook(new Coordinate(7, 0), "White");
var bishop = new Bishop(new Coordinate(4, 2), "White");
bishop.Click += this.BishopInknightLesson_Click;
_ = new Bishop(new Coordinate(7, 2), "White");
_ = new Queen(new Coordinate(7, 3), "White");
_ = new King(new Coordinate(7, 4), "White");
_ = new Bishop(new Coordinate(7, 2), "White");
_ = new Queen(new Coordinate(7, 3), "White");
_ = new King(new Coordinate(7, 4), "White");
for (var i = 0; i < 8; i++)
{
_ = new Pawn(new Coordinate(6, i), "White");
Expand Down Expand Up @@ -1501,6 +1515,7 @@ private void ValidKnightMove_Click(object sender, EventArgs e)
Учитесь играть в шахматы играя!";
MessageBox.Show("Поздравляем! Вы смогли поставить \"мат Легаля\"! Надеемся, что навыки, полученные в ходе прохождения курса не пропадут зря! Учитесь играть в шахматы играя!",
"Поздравляем!", MessageBoxButtons.OK, MessageBoxIcon.Information);
DiableAllControls();
}
else
{
Expand Down
3 changes: 1 addition & 2 deletions ChessLearnProgram/ChessLearnProgram/ChessBoardForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -16552,6 +16552,5 @@
AADAAAAAAAAQAMAAAAAAADAAwAAAAAAA8ADAAAAAAADwAMAAAAAAA/AAwAAAAAAP8ADgAAAAAA/wAOAA
AAAAP/AA4AAAAAD/8ADwAAAAAf/wAPAAAAAD//AA8AAAAA//8AD4AAAAH//wAPwAAAA///AA/gAAAH//
8AD/AAAAf//wAP+AAAH///AA/+AAA///8AD/8AAP///wAP/8ADf///AA////////8AA=
</value>
</data>
</value></data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<Content Include="Resources\bishop_train.wav" />
<Content Include="Resources\king_train.wav" />
<Content Include="Resources\knight_train.wav" />
<Content Include="Resources\move_sound.wav" />
<Content Include="Resources\pawn_train.wav" />
<Content Include="Resources\queen_train.wav" />
<Content Include="Resources\rook_train.wav" />
Expand Down
Loading

0 comments on commit 66f3812

Please sign in to comment.