Overwrite
Complete Overwrite of the Folder with the free shard. ServUO 57.3 has been added.
This commit is contained in:
211
Scripts/Scripts-master/Games/Battle Chess/Pieces/Bishop.cs
Normal file
211
Scripts/Scripts-master/Games/Battle Chess/Pieces/Bishop.cs
Normal file
@@ -0,0 +1,211 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
using Server;
|
||||
using Server.Items;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
public class Bishop : BaseChessPiece
|
||||
{
|
||||
public static int GetGumpID( ChessColor color )
|
||||
{
|
||||
return color == ChessColor.Black ? 2339 : 2332;
|
||||
}
|
||||
|
||||
public override int Power
|
||||
{
|
||||
get
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Bishop( BChessboard board, ChessColor color, Point2D position ) : base( board, color, position )
|
||||
{
|
||||
}
|
||||
|
||||
public override void InitializePiece()
|
||||
{
|
||||
m_Piece = new ChessMobile( this );
|
||||
m_Piece.Name = string.Format( "Bishop [{0}]", m_Color.ToString() );
|
||||
|
||||
switch ( m_BChessboard.ChessSet )
|
||||
{
|
||||
case ChessSet.Classic : CreateClassic();
|
||||
break;
|
||||
|
||||
case ChessSet.Fantasy : CreateFantasy();
|
||||
break;
|
||||
|
||||
case ChessSet.FantasyGiant : CreateFantasyGiant();
|
||||
break;
|
||||
|
||||
case ChessSet.Animal : CreateAnimal();
|
||||
break;
|
||||
|
||||
case ChessSet.Undead : CreateUndead();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateUndead()
|
||||
{
|
||||
m_MoveSound = 415;
|
||||
m_CaptureSound = 1004;
|
||||
m_DeathSound = 1005;
|
||||
|
||||
m_Piece.BodyValue = 78; // Liche
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateAnimal()
|
||||
{
|
||||
m_MoveSound = 858;
|
||||
m_CaptureSound = 616;
|
||||
m_DeathSound = 623;
|
||||
|
||||
m_Piece.BodyValue = 80; // Giant toad
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateFantasyGiant()
|
||||
{
|
||||
m_MoveSound = 373;
|
||||
m_CaptureSound = 372;
|
||||
m_DeathSound = 376;
|
||||
|
||||
m_Piece.BodyValue = 316; // Wanderer of the void
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateFantasy()
|
||||
{
|
||||
m_MoveSound = 579;
|
||||
m_CaptureSound = 283;
|
||||
m_DeathSound = 250;
|
||||
|
||||
m_Piece.BodyValue = 124; // Evil mage
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateClassic()
|
||||
{
|
||||
m_MoveSound = 251;
|
||||
m_CaptureSound = 773;
|
||||
m_DeathSound = 1063;
|
||||
|
||||
m_Piece.Female = false;
|
||||
m_Piece.BodyValue = 0x190;
|
||||
|
||||
if ( m_BChessboard.OverrideMinorHue )
|
||||
m_Piece.Hue = Hue;
|
||||
else
|
||||
m_Piece.Hue = m_BChessboard.SkinHue;
|
||||
|
||||
Item item = null;
|
||||
|
||||
item = new HoodedShroudOfShadows( Hue );
|
||||
item.Name = "Bishop's Robe";
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new Boots( MinorHue );
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new QuarterStaff();
|
||||
item.Hue = MinorHue;
|
||||
m_Piece.AddItem( item );
|
||||
}
|
||||
|
||||
public override bool CanMoveTo(Point2D newLocation, ref string err)
|
||||
{
|
||||
if ( ! base.CanMoveTo (newLocation, ref err) )
|
||||
return false;
|
||||
|
||||
int dx = newLocation.X - m_Position.X;
|
||||
int dy = newLocation.Y - m_Position.Y;
|
||||
|
||||
if ( Math.Abs( dx ) != Math.Abs( dy ) )
|
||||
{
|
||||
err = "Bishops can move only on diagonals";
|
||||
return false; // Not a diagonal movement
|
||||
}
|
||||
|
||||
int xDirection = dx > 0 ? 1 : -1;
|
||||
int yDirection = dy > 0 ? 1 : -1;
|
||||
|
||||
if ( Math.Abs( dx ) > 1 )
|
||||
{
|
||||
// Verify that the path to target is empty
|
||||
for ( int i = 1; i < Math.Abs( dx ); i++ ) // Skip the bishop square and stop before target
|
||||
{
|
||||
int xOffset = xDirection * i;
|
||||
int yOffset = yDirection * i;
|
||||
|
||||
if ( m_BChessboard[ m_Position.X + xOffset, m_Position.Y + yOffset ] != null )
|
||||
{
|
||||
err = "Bishops can't move over other pieces";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Verify target piece
|
||||
BaseChessPiece piece = m_BChessboard[ newLocation ];
|
||||
|
||||
if ( piece == null || piece.Color != m_Color )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = "You can't capture pieces of your own color";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override ArrayList GetMoves(bool capture)
|
||||
{
|
||||
ArrayList moves = new ArrayList();
|
||||
|
||||
int[] xDirection = new int[] { -1, 1, -1, 1 };
|
||||
int[] yDirection = new int[] { -1, 1, 1, -1 };
|
||||
|
||||
for ( int i = 0; i < 4; i++ )
|
||||
{
|
||||
int xDir = xDirection[ i ];
|
||||
int yDir = yDirection[ i ];
|
||||
|
||||
int offset = 1;
|
||||
|
||||
while ( true )
|
||||
{
|
||||
Point2D p = new Point2D( m_Position.X + offset * xDir, m_Position.Y + offset * yDir );
|
||||
|
||||
if ( ! m_BChessboard.IsValid( p ) )
|
||||
break;
|
||||
|
||||
BaseChessPiece piece = m_BChessboard[ p ];
|
||||
|
||||
if ( piece == null )
|
||||
{
|
||||
moves.Add( p );
|
||||
offset++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( capture && piece.Color != m_Color )
|
||||
{
|
||||
moves.Add( p );
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return moves;
|
||||
}
|
||||
}
|
||||
}
|
||||
240
Scripts/Scripts-master/Games/Battle Chess/Pieces/King.cs
Normal file
240
Scripts/Scripts-master/Games/Battle Chess/Pieces/King.cs
Normal file
@@ -0,0 +1,240 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
using Server;
|
||||
using Server.Items;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
public class King : BaseChessPiece
|
||||
{
|
||||
private int m_CheckSound;
|
||||
private int m_CheckMateSound;
|
||||
|
||||
public override int Power
|
||||
{
|
||||
get
|
||||
{
|
||||
return 100; // Useless
|
||||
}
|
||||
}
|
||||
|
||||
public King( BChessboard board, ChessColor color, Point2D position ) : base( board, color, position )
|
||||
{
|
||||
}
|
||||
|
||||
public override void InitializePiece()
|
||||
{
|
||||
m_Piece = new ChessMobile( this );
|
||||
m_Piece.Name = string.Format( "King [{0}]", m_Color.ToString() );
|
||||
|
||||
switch ( m_BChessboard.ChessSet )
|
||||
{
|
||||
case ChessSet.Classic : CreateClassic();
|
||||
break;
|
||||
|
||||
case ChessSet.Fantasy : CreateFantasy();
|
||||
break;
|
||||
|
||||
case ChessSet.FantasyGiant : CreateFantasyGiant();
|
||||
break;
|
||||
|
||||
case ChessSet.Animal : CreateAnimal();
|
||||
break;
|
||||
|
||||
case ChessSet.Undead : CreateUndead();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateUndead()
|
||||
{
|
||||
m_MoveSound = 1163;
|
||||
m_CaptureSound = 1162;
|
||||
m_DeathSound = 361;
|
||||
m_CheckSound = 772;
|
||||
m_CheckMateSound = 716;
|
||||
|
||||
m_Piece.BodyValue = 148; // Skeletal mage
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateAnimal()
|
||||
{
|
||||
m_MoveSound = 95;
|
||||
m_CaptureSound = 1223;
|
||||
m_DeathSound = 98;
|
||||
m_CheckSound = 98;
|
||||
m_CheckMateSound = 99;
|
||||
|
||||
m_Piece.BodyValue = 213; // Polar bear
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateFantasyGiant()
|
||||
{
|
||||
m_MoveSound = 1152;
|
||||
m_CaptureSound = 1150;
|
||||
m_DeathSound = 0;
|
||||
m_CheckSound = 1152;
|
||||
m_CheckMateSound = 1149;
|
||||
|
||||
m_Piece.BodyValue = 311; // Shadow knight
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateFantasy()
|
||||
{
|
||||
m_MoveSound = 610;
|
||||
m_CaptureSound = 606;
|
||||
m_DeathSound = 0;
|
||||
m_CheckSound = 604;
|
||||
m_CheckMateSound = 613;
|
||||
|
||||
m_Piece.BodyValue = 767; // Betrayer
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateClassic()
|
||||
{
|
||||
m_MoveSound = 1055;
|
||||
m_CaptureSound = 1068;
|
||||
m_DeathSound = 0;
|
||||
m_CheckSound = 1086;
|
||||
m_CheckMateSound = 1088;
|
||||
|
||||
m_Piece.Female = false;
|
||||
m_Piece.BodyValue = 0x190;
|
||||
|
||||
if ( m_BChessboard.OverrideMinorHue )
|
||||
m_Piece.Hue = Hue;
|
||||
else
|
||||
m_Piece.Hue = m_BChessboard.SkinHue;
|
||||
m_Piece.AddItem( new ShortHair( m_BChessboard.OverrideMinorHue ? Hue : m_BChessboard.HairHue ) );
|
||||
|
||||
Item item = null;
|
||||
|
||||
item = new Boots( MinorHue );
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new LongPants( Hue );
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new FancyShirt( Hue );
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new Doublet( MinorHue );
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new Cloak( MinorHue );
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new Scepter();
|
||||
item.Hue = MinorHue;
|
||||
m_Piece.AddItem( item );
|
||||
}
|
||||
|
||||
public override bool CanMoveTo(Point2D newLocation, ref string err)
|
||||
{
|
||||
if ( ! base.CanMoveTo (newLocation, ref err) )
|
||||
return false;
|
||||
|
||||
// Verify if this is a castle
|
||||
BaseChessPiece rook = m_BChessboard[ newLocation ];
|
||||
|
||||
if ( rook is Rook && rook.Color == m_Color )
|
||||
{
|
||||
// Trying to castle
|
||||
return m_BChessboard.AllowCastle( this, rook, ref err );
|
||||
}
|
||||
|
||||
int dx = newLocation.X - m_Position.X;
|
||||
int dy = newLocation.Y - m_Position.Y;
|
||||
|
||||
if ( Math.Abs( dx ) > 1 || Math.Abs( dy ) > 1 )
|
||||
{
|
||||
err = "The can king can move only 1 tile at a time";
|
||||
return false; // King can move only 1 tile away from its position
|
||||
}
|
||||
|
||||
// Verify target piece
|
||||
BaseChessPiece piece = m_BChessboard[ newLocation ];
|
||||
|
||||
if ( piece == null || piece.Color != m_Color )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = "You can't capture pieces of your same color";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override ArrayList GetMoves(bool capture)
|
||||
{
|
||||
ArrayList moves = new ArrayList();
|
||||
|
||||
for ( int dx = -1; dx <= 1; dx++ )
|
||||
{
|
||||
for ( int dy = -1; dy <= 1; dy++ )
|
||||
{
|
||||
if ( dx == 0 && dy == 0 )
|
||||
continue; // Can't move to same spot
|
||||
|
||||
Point2D p = new Point2D( m_Position.X + dx, m_Position.Y + dy );
|
||||
|
||||
if ( ! m_BChessboard.IsValid( p ) )
|
||||
continue;
|
||||
|
||||
BaseChessPiece piece = m_BChessboard[ p ];
|
||||
|
||||
if ( piece == null )
|
||||
moves.Add( p );
|
||||
else if ( capture && piece.Color != m_Color )
|
||||
moves.Add( p );
|
||||
}
|
||||
}
|
||||
|
||||
return moves;
|
||||
}
|
||||
|
||||
public override bool IsCastle(Point2D loc)
|
||||
{
|
||||
Rook rook = m_BChessboard[ loc ] as Rook;
|
||||
|
||||
string err = null;
|
||||
|
||||
return rook != null && rook.Color == m_Color && m_BChessboard.AllowCastle( this, rook, ref err );
|
||||
}
|
||||
|
||||
public void EndCastle( Point2D location )
|
||||
{
|
||||
m_HasMoved = true;
|
||||
|
||||
m_Move = new Move( this, location );
|
||||
|
||||
Point2D worldLocation = m_BChessboard.BoardToWorld( location );
|
||||
|
||||
m_Piece.GoTo( worldLocation );
|
||||
}
|
||||
|
||||
public void PlayCheck()
|
||||
{
|
||||
m_BChessboard.PlaySound( m_Piece, m_CheckSound );
|
||||
m_Piece.Say( "*CHECK*" );
|
||||
}
|
||||
|
||||
public void PlayCheckMate()
|
||||
{
|
||||
m_BChessboard.PlaySound( m_Piece, m_CheckMateSound );
|
||||
m_Piece.Say( "CHECKMATE" );
|
||||
}
|
||||
|
||||
public void PlayStaleMate()
|
||||
{
|
||||
m_BChessboard.PlaySound( m_Piece, m_CheckSound );
|
||||
m_Piece.Say( "STALEMATE" );
|
||||
}
|
||||
}
|
||||
}
|
||||
209
Scripts/Scripts-master/Games/Battle Chess/Pieces/Knight.cs
Normal file
209
Scripts/Scripts-master/Games/Battle Chess/Pieces/Knight.cs
Normal file
@@ -0,0 +1,209 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
using Server;
|
||||
using Server.Items;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
public class Knight : BaseChessPiece
|
||||
{
|
||||
public static int GetGumpID( ChessColor color )
|
||||
{
|
||||
return color == ChessColor.Black ? 2342 : 2335;
|
||||
}
|
||||
|
||||
public override int Power
|
||||
{
|
||||
get
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Knight( BChessboard board, ChessColor color, Point2D position ) : base( board, color, position )
|
||||
{
|
||||
}
|
||||
|
||||
public override void InitializePiece()
|
||||
{
|
||||
m_Piece = new ChessMobile( this );
|
||||
m_Piece.Name = string.Format( "Knight [{0}]", m_Color.ToString() );
|
||||
|
||||
switch ( m_BChessboard.ChessSet )
|
||||
{
|
||||
case ChessSet.Classic : CreateClassic();
|
||||
break;
|
||||
|
||||
case ChessSet.Fantasy : CreateFantasy();
|
||||
break;
|
||||
|
||||
case ChessSet.FantasyGiant : CreateFantasyGiant();
|
||||
break;
|
||||
|
||||
case ChessSet.Animal : CreateAnimal();
|
||||
break;
|
||||
|
||||
case ChessSet.Undead : CreateUndead();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateUndead()
|
||||
{
|
||||
m_MoveSound = 588;
|
||||
m_CaptureSound = 1164;
|
||||
m_DeathSound = 416;
|
||||
|
||||
m_Piece.Female = false;
|
||||
m_Piece.BodyValue = 0x190;
|
||||
m_Piece.AddItem( new HoodedShroudOfShadows( Hue ) );
|
||||
|
||||
Server.Mobiles.SkeletalMount mount = new Server.Mobiles.SkeletalMount();
|
||||
mount.Hue = MinorHue;
|
||||
mount.Rider = m_Piece;
|
||||
|
||||
m_Piece.Direction = Facing;
|
||||
}
|
||||
|
||||
private void CreateAnimal()
|
||||
{
|
||||
m_MoveSound = 183;
|
||||
m_CaptureSound = 1011;
|
||||
m_DeathSound = 185;
|
||||
|
||||
m_Piece.BodyValue = 292; // Pack llama
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateFantasyGiant()
|
||||
{
|
||||
m_MoveSound = 875;
|
||||
m_CaptureSound = 378;
|
||||
m_DeathSound = 879;
|
||||
|
||||
m_Piece.BodyValue = 315; // Flesh renderer
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateFantasy()
|
||||
{
|
||||
m_MoveSound = 762;
|
||||
m_CaptureSound = 758;
|
||||
m_DeathSound = 759;
|
||||
|
||||
m_Piece.BodyValue = 101; // Centaur
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateClassic()
|
||||
{
|
||||
m_MoveSound = 588;
|
||||
m_CaptureSound = 168;
|
||||
m_DeathSound = 170;
|
||||
|
||||
m_Piece.Female = false;
|
||||
m_Piece.BodyValue = 0x190;
|
||||
|
||||
if ( m_BChessboard.OverrideMinorHue )
|
||||
m_Piece.Hue = Hue;
|
||||
else
|
||||
m_Piece.Hue = m_BChessboard.SkinHue;
|
||||
m_Piece.AddItem( new PonyTail( m_BChessboard.OverrideMinorHue ? Hue : m_BChessboard.HairHue ) );
|
||||
|
||||
Item item = null;
|
||||
|
||||
item = new PlateLegs();
|
||||
item.Hue = Hue;
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new PlateChest();
|
||||
item.Hue = Hue;
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new PlateArms();
|
||||
item.Hue = Hue;
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new PlateGorget();
|
||||
item.Hue = Hue;
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new PlateGloves();
|
||||
item.Hue = Hue;
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new Doublet( MinorHue );
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new Lance();
|
||||
item.Hue = MinorHue;
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
Server.Mobiles.Horse horse = new Server.Mobiles.Horse();
|
||||
horse.BodyValue = 200;
|
||||
horse.Hue = MinorHue;
|
||||
|
||||
horse.Rider = m_Piece;
|
||||
|
||||
m_Piece.Direction = Facing;
|
||||
}
|
||||
|
||||
public override bool CanMoveTo(Point2D newLocation, ref string err)
|
||||
{
|
||||
if ( ! base.CanMoveTo (newLocation, ref err) )
|
||||
return false;
|
||||
|
||||
// Care only about absolutes for knights
|
||||
int dx = Math.Abs( newLocation.X - m_Position.X );
|
||||
int dy = Math.Abs( newLocation.Y - m_Position.Y );
|
||||
|
||||
if ( ! ( ( dx == 1 && dy == 2 ) || ( dx == 2 && dy == 1 ) ) )
|
||||
{
|
||||
err = "Knights can only make L shaped moves (2-3 tiles length)";
|
||||
return false; // Wrong move
|
||||
}
|
||||
|
||||
// Verify target piece
|
||||
BaseChessPiece piece = m_BChessboard[ newLocation ];
|
||||
|
||||
if ( piece == null || piece.Color != m_Color )
|
||||
return true;
|
||||
else
|
||||
{
|
||||
err = "You can't capture pieces of your same color";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override ArrayList GetMoves(bool capture)
|
||||
{
|
||||
ArrayList moves = new ArrayList();
|
||||
|
||||
for ( int dx = -2; dx <= 2; dx++ )
|
||||
{
|
||||
for ( int dy = -2; dy <= 2; dy++ )
|
||||
{
|
||||
if ( ! ( ( Math.Abs( dx ) == 1 && Math.Abs( dy ) == 2 ) || ( Math.Abs( dx ) == 2 && Math.Abs( dy ) == 1 ) ) )
|
||||
continue;
|
||||
|
||||
Point2D p = new Point2D( m_Position.X + dx, m_Position.Y + dy );
|
||||
|
||||
if ( ! m_BChessboard.IsValid( p ) )
|
||||
continue;
|
||||
|
||||
BaseChessPiece piece = m_BChessboard[ p ];
|
||||
|
||||
if ( piece == null )
|
||||
moves.Add( p );
|
||||
else if ( capture && piece.Color != m_Color )
|
||||
moves.Add( p );
|
||||
}
|
||||
}
|
||||
|
||||
return moves;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
348
Scripts/Scripts-master/Games/Battle Chess/Pieces/Pawn.cs
Normal file
348
Scripts/Scripts-master/Games/Battle Chess/Pieces/Pawn.cs
Normal file
@@ -0,0 +1,348 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
using Server;
|
||||
using Server.Items;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
public class Pawn : BaseChessPiece
|
||||
{
|
||||
public static int GetGumpID( ChessColor color )
|
||||
{
|
||||
return color == ChessColor.Black ? 2343 : 2336;
|
||||
}
|
||||
|
||||
public override int Power
|
||||
{
|
||||
get
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool AllowEnPassantCapture
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_EnPassantRisk;
|
||||
}
|
||||
set { m_EnPassantRisk = value; }
|
||||
}
|
||||
|
||||
private bool m_EnPassantRisk = false;
|
||||
|
||||
public Pawn( BChessboard board, ChessColor color, Point2D position ) : base( board, color, position )
|
||||
{
|
||||
}
|
||||
|
||||
public override void InitializePiece()
|
||||
{
|
||||
m_Piece = new ChessMobile( this );
|
||||
m_Piece.Name = string.Format( "Pawn [{0}]", m_Color.ToString() );
|
||||
|
||||
switch ( m_BChessboard.ChessSet )
|
||||
{
|
||||
case ChessSet.Classic : CreateClassic();
|
||||
break;
|
||||
|
||||
case ChessSet.Fantasy : CreateFantasy();
|
||||
break;
|
||||
|
||||
case ChessSet.FantasyGiant : CreateFantasyGiant();
|
||||
break;
|
||||
|
||||
case ChessSet.Animal : CreateAnimal();
|
||||
break;
|
||||
|
||||
case ChessSet.Undead : CreateUndead();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateUndead()
|
||||
{
|
||||
m_MoveSound = 451;
|
||||
m_CaptureSound = 1169;
|
||||
m_DeathSound = 455;
|
||||
|
||||
m_Piece.BodyValue = 56; // Skeleton
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateAnimal()
|
||||
{
|
||||
m_MoveSound = 1217;
|
||||
m_CaptureSound = 226;
|
||||
m_DeathSound = 228;
|
||||
|
||||
m_Piece.BodyValue = 221; // Walrus
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateFantasyGiant()
|
||||
{
|
||||
m_MoveSound = 709;
|
||||
m_CaptureSound = 712;
|
||||
m_DeathSound = 705;
|
||||
|
||||
m_Piece.BodyValue = 303; // Devourer
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateFantasy()
|
||||
{
|
||||
m_MoveSound = 408;
|
||||
m_CaptureSound = 927;
|
||||
m_DeathSound = 411;
|
||||
|
||||
m_Piece.BodyValue = 776; // Horde Minion
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateClassic()
|
||||
{
|
||||
m_MoveSound = 821;
|
||||
m_CaptureSound = 1094;
|
||||
m_DeathSound = 1059;
|
||||
|
||||
m_Piece.Female = false;
|
||||
m_Piece.BodyValue = 0x190;
|
||||
|
||||
if ( m_BChessboard.OverrideMinorHue )
|
||||
m_Piece.Hue = Hue;
|
||||
else
|
||||
m_Piece.Hue = m_BChessboard.SkinHue;
|
||||
m_Piece.AddItem( new ShortHair( m_BChessboard.OverrideMinorHue ? Hue : m_BChessboard.HairHue ) );
|
||||
|
||||
Item item = null;
|
||||
|
||||
item = new ChainChest();
|
||||
item.Hue = Hue;
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new ChainLegs();
|
||||
item.Hue = MinorHue;
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new Boots();
|
||||
item.Hue = Hue;
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new Buckler();
|
||||
item.Hue = MinorHue;
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new Scimitar();
|
||||
item.Hue = MinorHue;
|
||||
m_Piece.AddItem( item );
|
||||
}
|
||||
|
||||
public override bool CanMoveTo(Point2D newLocation, ref string err)
|
||||
{
|
||||
if ( ! base.CanMoveTo (newLocation, ref err) )
|
||||
return false;
|
||||
|
||||
if ( newLocation.X == m_Position.X )
|
||||
{
|
||||
// Regular move
|
||||
int dy = newLocation.Y - m_Position.Y;
|
||||
|
||||
// Trying to move more than two pieces, or more than one piece after the first move
|
||||
if ( Math.Abs( dy ) > 2 || ( Math.Abs( dy ) ) > 1 && m_HasMoved )
|
||||
{
|
||||
err = "You can move only 1 tile at a time, or 2 if it's the pawn's first move";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verify direction
|
||||
if ( m_Color == ChessColor.Black && dy < 0 )
|
||||
{
|
||||
err = "You can't move pawns backwards";
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( m_Color == ChessColor.White && dy > 0 )
|
||||
{
|
||||
err = "You can't move pawns backwards";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verify if there are pieces (any) on the target squares
|
||||
for ( int i = 1; i <= Math.Abs( dy ); i++ )
|
||||
{
|
||||
int offset = m_Color == ChessColor.Black ? i : -i;
|
||||
|
||||
if ( m_BChessboard[ m_Position.X, m_Position.Y + offset ] != null )
|
||||
{
|
||||
err = "Pawns can't move over other pieces, and capture in diagonal";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Trying to capture?
|
||||
int dx = newLocation.X - m_Position.X;
|
||||
int dy = newLocation.Y - m_Position.Y;
|
||||
|
||||
if ( Math.Abs( dx ) != 1 || Math.Abs( dy ) != 1 )
|
||||
{
|
||||
err = "Pawns move straight ahead, or capture in diagonal only";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verify direction
|
||||
if ( m_Color == ChessColor.Black && dy < 0 )
|
||||
{
|
||||
err = "You can't move pawns backwards";
|
||||
return false;
|
||||
}
|
||||
if ( m_Color == ChessColor.White && dy > 0 )
|
||||
{
|
||||
err = "You can't move pawns backwards";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verify if there's a piece to capture
|
||||
BaseChessPiece piece = m_BChessboard[ newLocation ];
|
||||
|
||||
if ( piece != null && piece.Color != m_Color )
|
||||
return true;
|
||||
else
|
||||
{
|
||||
// Verify for an en passant capture
|
||||
Point2D passant = new Point2D( m_Position.X + dx, m_Position.Y );
|
||||
|
||||
BaseChessPiece target = m_BChessboard[ passant ];
|
||||
|
||||
if ( target != null && target.AllowEnPassantCapture && target.Color != m_Color )
|
||||
return true;
|
||||
else
|
||||
{
|
||||
err = "You must capture a piece when moving in diagonal";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override ArrayList GetMoves(bool capture)
|
||||
{
|
||||
ArrayList moves = new ArrayList();
|
||||
|
||||
int direction = m_Color == ChessColor.Black ? 1 : -1;
|
||||
|
||||
Point2D step = new Point2D( m_Position.X, m_Position.Y + direction );
|
||||
|
||||
if ( m_BChessboard.IsValid( step ) && m_BChessboard[ step ] == null )
|
||||
{
|
||||
moves.Add( step );
|
||||
|
||||
// Verify if this pawn can make a second step
|
||||
step.Y += direction;
|
||||
|
||||
if ( ! m_HasMoved && m_BChessboard[ step ] == null )
|
||||
moves.Add( step ); // Point2D is a value type
|
||||
}
|
||||
|
||||
if ( capture )
|
||||
{
|
||||
// Verify captures too
|
||||
Point2D p1 = new Point2D( m_Position.X + 1, m_Position.Y + direction );
|
||||
Point2D p2 = new Point2D( m_Position.X - 1, m_Position.Y + direction );
|
||||
|
||||
if ( m_BChessboard.IsValid( p1 ) )
|
||||
{
|
||||
BaseChessPiece piece1 = m_BChessboard[ p1 ];
|
||||
if ( piece1 != null && piece1.Color != m_Color )
|
||||
moves.Add( p1 );
|
||||
else
|
||||
{
|
||||
Point2D pass1 = new Point2D( m_Position.X - 1, m_Position.Y );
|
||||
|
||||
if ( m_BChessboard.IsValid( pass1 ) )
|
||||
{
|
||||
BaseChessPiece passpiece1 = m_BChessboard[ pass1 ];
|
||||
if ( passpiece1 != null && passpiece1.Color != m_Color && passpiece1.AllowEnPassantCapture )
|
||||
moves.Add( p1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( m_BChessboard.IsValid( p2 ) )
|
||||
{
|
||||
BaseChessPiece piece2 = m_BChessboard[ p2 ];
|
||||
if ( piece2 != null && piece2.Color != m_Color )
|
||||
moves.Add( p2 );
|
||||
else
|
||||
{
|
||||
Point2D pass2 = new Point2D( m_Position.X + 1, m_Position.Y );
|
||||
|
||||
if ( m_BChessboard.IsValid( p2 ) )
|
||||
{
|
||||
BaseChessPiece passpiece2 = m_BChessboard[ pass2 ];
|
||||
if ( passpiece2 != null && passpiece2.AllowEnPassantCapture && passpiece2.Color != m_Color )
|
||||
moves.Add( pass2 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return moves;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// States whether this pawn has reached the other side of the board and should be promoted
|
||||
/// </summary>
|
||||
public bool ShouldBePromoted
|
||||
{
|
||||
get
|
||||
{
|
||||
if ( m_Color == ChessColor.White && m_Position.Y == 0 )
|
||||
return true;
|
||||
else if ( m_Color == ChessColor.Black && m_Position.Y == 7 )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override void MoveTo(Move move)
|
||||
{
|
||||
// Set En Passant flags
|
||||
int dy = Math.Abs( move.To.Y - m_Position.Y );
|
||||
|
||||
if ( ! m_HasMoved && dy == 2 )
|
||||
{
|
||||
m_EnPassantRisk = true;
|
||||
}
|
||||
|
||||
base.MoveTo (move);
|
||||
}
|
||||
|
||||
public override BaseChessPiece GetCaptured(Point2D at, ref bool enpassant)
|
||||
{
|
||||
BaseChessPiece basePiece = base.GetCaptured (at, ref enpassant);
|
||||
|
||||
if ( basePiece != null && basePiece.Color != m_Color )
|
||||
return basePiece; // Normal capture
|
||||
|
||||
if ( at.X == m_Position.X )
|
||||
return null; // Straight movement
|
||||
|
||||
Point2D p = new Point2D( at.X, m_Position.Y );
|
||||
basePiece = m_BChessboard[ p ];
|
||||
|
||||
if ( basePiece != null && basePiece.Color != m_Color )
|
||||
{
|
||||
enpassant = true;
|
||||
return basePiece;
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
251
Scripts/Scripts-master/Games/Battle Chess/Pieces/Queen.cs
Normal file
251
Scripts/Scripts-master/Games/Battle Chess/Pieces/Queen.cs
Normal file
@@ -0,0 +1,251 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
using Server;
|
||||
using Server.Items;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for Queen.
|
||||
/// </summary>
|
||||
public class Queen : BaseChessPiece
|
||||
{
|
||||
public static int GetGumpID( ChessColor color )
|
||||
{
|
||||
return color == ChessColor.Black ? 2344 : 2377;
|
||||
}
|
||||
|
||||
public override int Power
|
||||
{
|
||||
get
|
||||
{
|
||||
return 9;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Queen( BChessboard board, ChessColor color, Point2D position ) : base( board, color, position )
|
||||
{
|
||||
}
|
||||
|
||||
public override void InitializePiece()
|
||||
{
|
||||
m_Piece = new ChessMobile( this );
|
||||
m_Piece.Name = string.Format( "Queen [{0}]", m_Color.ToString() );
|
||||
|
||||
switch ( m_BChessboard.ChessSet )
|
||||
{
|
||||
case ChessSet.Classic : CreateClassic();
|
||||
break;
|
||||
|
||||
case ChessSet.Fantasy : CreateFantasy();
|
||||
break;
|
||||
|
||||
case ChessSet.FantasyGiant : CreateFantasyGiant();
|
||||
break;
|
||||
|
||||
case ChessSet.Animal : CreateAnimal();
|
||||
break;
|
||||
|
||||
case ChessSet.Undead: CreateUndead();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateUndead()
|
||||
{
|
||||
m_MoveSound = 896;
|
||||
m_CaptureSound = 382;
|
||||
m_DeathSound = 1202;
|
||||
|
||||
m_Piece.BodyValue = 310; // Wailing banshee
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateAnimal()
|
||||
{
|
||||
m_MoveSound = 123;
|
||||
m_CaptureSound = 120;
|
||||
m_DeathSound = 124;
|
||||
|
||||
m_Piece.BodyValue = 216; // Cow
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateFantasyGiant()
|
||||
{
|
||||
m_MoveSound = 883;
|
||||
m_CaptureSound = 880;
|
||||
m_DeathSound = 888;
|
||||
|
||||
m_Piece.BodyValue = 174; // Semidar
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateFantasy()
|
||||
{
|
||||
m_MoveSound = 1200;
|
||||
m_CaptureSound = 1201;
|
||||
m_DeathSound = 1202;
|
||||
|
||||
m_Piece.BodyValue = 149; // Succubus
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateClassic()
|
||||
{
|
||||
m_MoveSound = 823;
|
||||
m_CaptureSound = 824;
|
||||
m_DeathSound = 814;
|
||||
|
||||
m_Piece.Female = true;
|
||||
m_Piece.BodyValue = 0x191;
|
||||
|
||||
if ( m_BChessboard.OverrideMinorHue )
|
||||
m_Piece.Hue = Hue;
|
||||
else
|
||||
m_Piece.Hue = m_BChessboard.SkinHue;
|
||||
m_Piece.AddItem( new LongHair( m_BChessboard.OverrideMinorHue ? Hue : m_BChessboard.HairHue ) );
|
||||
|
||||
Item item = null;
|
||||
|
||||
item = new FancyDress( Hue );
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new Sandals( MinorHue );
|
||||
m_Piece.AddItem( item );
|
||||
|
||||
item = new Scepter();
|
||||
item.Hue = MinorHue;
|
||||
m_Piece.AddItem( item );
|
||||
}
|
||||
|
||||
public override bool CanMoveTo(Point2D newLocation, ref string err)
|
||||
{
|
||||
if ( ! base.CanMoveTo (newLocation, ref err) )
|
||||
return false;
|
||||
|
||||
int dx = newLocation.X - m_Position.X;
|
||||
int dy = newLocation.Y - m_Position.Y;
|
||||
|
||||
if ( dx == 0 || dy == 0 )
|
||||
{
|
||||
// Straight movement
|
||||
if ( Math.Abs( dx ) > 1 ) // If it's just 1 step no need to check for intermediate pieces
|
||||
{
|
||||
int direction = dx > 0 ? 1 : -1;
|
||||
|
||||
// Moving along X axis
|
||||
for ( int i = 1; i < Math.Abs( dx ); i++ )
|
||||
{
|
||||
int offset = direction * i;
|
||||
|
||||
if ( m_BChessboard[ m_Position.X + offset, m_Position.Y ] != null )
|
||||
{
|
||||
err = "The queen can't move over other pieces";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( Math.Abs( dy ) > 1 )
|
||||
{
|
||||
// Moving along Y axis
|
||||
int direction = dy > 0 ? 1 : -1;
|
||||
|
||||
for ( int i = 1; i < Math.Abs( dy ); i++ )
|
||||
{
|
||||
int offset = direction * i;
|
||||
|
||||
if ( m_BChessboard[ m_Position.X, m_Position.Y + offset ] != null )
|
||||
{
|
||||
err = "The queen can't move over other pieces";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Diagonal movement
|
||||
if ( Math.Abs( dx ) != Math.Abs( dy ) )
|
||||
{
|
||||
err = "The queen moves only on straight lines or diagonals";
|
||||
return false; // Uneven
|
||||
}
|
||||
|
||||
if ( Math.Abs( dx ) > 1 )
|
||||
{
|
||||
int xDirection = dx > 0 ? 1 : -1;
|
||||
int yDirection = dy > 0 ? 1 : -1;
|
||||
|
||||
for ( int i = 1; i < Math.Abs( dx ); i++ )
|
||||
{
|
||||
int xOffset = xDirection * i;
|
||||
int yOffset = yDirection * i;
|
||||
|
||||
if ( m_BChessboard[ m_Position.X + xOffset, m_Position.Y + yOffset ] != null )
|
||||
{
|
||||
err = "The queen can't move over other pieces";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Verify target piece
|
||||
BaseChessPiece piece = m_BChessboard[ newLocation ];
|
||||
|
||||
if ( piece == null || piece.Color != m_Color )
|
||||
return true;
|
||||
else
|
||||
{
|
||||
err = "You can't capture pieces of your same color";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override ArrayList GetMoves(bool capture)
|
||||
{
|
||||
ArrayList moves = new ArrayList();
|
||||
|
||||
int[] xDirection = new int[] { -1, 1, -1, 1, 1, -1, 0, 0 };
|
||||
int[] yDirection = new int[] { -1, 1, 1, -1, 0, 0, 1, -1 };
|
||||
|
||||
for ( int i = 0; i < 8; i++ )
|
||||
{
|
||||
int xDir = xDirection[ i ];
|
||||
int yDir = yDirection[ i ];
|
||||
|
||||
int offset = 1;
|
||||
|
||||
while ( true )
|
||||
{
|
||||
Point2D p = new Point2D( m_Position.X + offset * xDir, m_Position.Y + offset * yDir );
|
||||
|
||||
if ( ! m_BChessboard.IsValid( p ) )
|
||||
break;
|
||||
|
||||
BaseChessPiece piece = m_BChessboard[ p ];
|
||||
|
||||
if ( piece == null )
|
||||
{
|
||||
moves.Add( p );
|
||||
offset++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( capture && piece.Color != m_Color )
|
||||
{
|
||||
moves.Add( p );
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return moves;
|
||||
}
|
||||
}
|
||||
}
|
||||
286
Scripts/Scripts-master/Games/Battle Chess/Pieces/Rook.cs
Normal file
286
Scripts/Scripts-master/Games/Battle Chess/Pieces/Rook.cs
Normal file
@@ -0,0 +1,286 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
using Server;
|
||||
using Server.Items;
|
||||
|
||||
namespace Arya.Chess
|
||||
{
|
||||
public class Rook : BaseChessPiece
|
||||
{
|
||||
private bool m_Castle;
|
||||
|
||||
public static int GetGumpID( ChessColor color )
|
||||
{
|
||||
return color == ChessColor.Black ? 2340 : 2333;
|
||||
}
|
||||
|
||||
public override int Power
|
||||
{
|
||||
get
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
public Rook( BChessboard board, ChessColor color, Point2D position ) : base( board, color, position )
|
||||
{
|
||||
}
|
||||
|
||||
public override void InitializePiece()
|
||||
{
|
||||
m_Piece = new ChessMobile( this );
|
||||
m_Piece.Name = string.Format( "Rook [{0}]", m_Color.ToString() );
|
||||
|
||||
switch ( m_BChessboard.ChessSet )
|
||||
{
|
||||
case ChessSet.Classic : CreateClassic();
|
||||
break;
|
||||
|
||||
case ChessSet.Fantasy : CreateFantasy();
|
||||
break;
|
||||
|
||||
case ChessSet.FantasyGiant : CreateFantasyGiant();
|
||||
break;
|
||||
|
||||
case ChessSet.Animal : CreateAnimal();
|
||||
break;
|
||||
|
||||
case ChessSet.Undead : CreateUndead();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateUndead()
|
||||
{
|
||||
m_MoveSound = 880;
|
||||
m_CaptureSound = 357;
|
||||
m_DeathSound = 1156;
|
||||
|
||||
m_Piece.BodyValue = 154; // Mummy
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateAnimal()
|
||||
{
|
||||
m_MoveSound = 159;
|
||||
m_CaptureSound = 158;
|
||||
m_DeathSound = 162;
|
||||
|
||||
m_Piece.BodyValue = 29; // Gorilla
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateFantasyGiant()
|
||||
{
|
||||
m_MoveSound = 767;
|
||||
m_CaptureSound = 367;
|
||||
m_DeathSound = 371;
|
||||
|
||||
m_Piece.BodyValue = 312; // Abysmal Horror
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateFantasy()
|
||||
{
|
||||
m_MoveSound = 461;
|
||||
m_CaptureSound = 463;
|
||||
m_DeathSound = 465;
|
||||
|
||||
m_Piece.Female = false;
|
||||
m_Piece.BodyValue = 55; // Troll
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
private void CreateClassic()
|
||||
{
|
||||
m_MoveSound = 287;
|
||||
m_CaptureSound = 268;
|
||||
m_DeathSound = 269;
|
||||
|
||||
m_Piece.Female = false;
|
||||
m_Piece.BodyValue = 14;
|
||||
|
||||
m_Piece.Hue = Hue;
|
||||
}
|
||||
|
||||
public override bool CanMoveTo(Point2D newLocation, ref string err)
|
||||
{
|
||||
if ( ! base.CanMoveTo (newLocation, ref err) )
|
||||
return false;
|
||||
|
||||
// Verify if this is a castle
|
||||
BaseChessPiece king = m_BChessboard[ newLocation ];
|
||||
|
||||
if ( king is King && king.Color == m_Color )
|
||||
{
|
||||
// Trying to castle
|
||||
return m_BChessboard.AllowCastle( king, this, ref err );
|
||||
}
|
||||
|
||||
int dx = newLocation.X - m_Position.X;
|
||||
int dy = newLocation.Y - m_Position.Y;
|
||||
|
||||
// Rooks can only move in one direction
|
||||
if ( dx != 0 && dy != 0 )
|
||||
{
|
||||
err = "Rooks can only move on straight lines";
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( dx != 0 )
|
||||
{
|
||||
// Moving on the X axis
|
||||
int direction = dx > 0 ? 1 : -1;
|
||||
|
||||
if ( Math.Abs( dx ) > 1 )
|
||||
{
|
||||
// Verify that the cells in between are empty
|
||||
for ( int i = 1; i < Math.Abs( dx ); i++ ) // Start 1 tile after the rook, and stop one tile before destination
|
||||
{
|
||||
int offset = direction * i;
|
||||
|
||||
if ( m_BChessboard[ m_Position.X + offset, m_Position.Y ] != null )
|
||||
{
|
||||
err = "Rooks can't move over pieces";
|
||||
return false; // There's a piece on the
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Verify if there's a piece to each at the end
|
||||
BaseChessPiece piece = m_BChessboard[ newLocation ];
|
||||
|
||||
if ( piece == null || piece.Color != m_Color )
|
||||
return true;
|
||||
else
|
||||
{
|
||||
err = "You can't capture pieces of your same color";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Moving on the Y axis
|
||||
int direction = dy > 0 ? 1 : -1;
|
||||
|
||||
if ( Math.Abs( dy ) > 1 )
|
||||
{
|
||||
// Verify that the cells in between are empty
|
||||
for ( int i = 1; i < Math.Abs( dy ); i++ )
|
||||
{
|
||||
int offset = direction * i;
|
||||
|
||||
if ( m_BChessboard[ m_Position.X, m_Position.Y + offset ] != null )
|
||||
{
|
||||
err = "The rook can't move over other pieces";
|
||||
return false; // Piece on the way
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Verify for piece at end
|
||||
BaseChessPiece piece = m_BChessboard[ newLocation ];
|
||||
|
||||
if ( piece == null || piece.Color != m_Color )
|
||||
return true;
|
||||
else
|
||||
{
|
||||
err = "You can't capture pieces of your same color";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override ArrayList GetMoves(bool capture)
|
||||
{
|
||||
ArrayList moves = new ArrayList();
|
||||
|
||||
int[] xDirection = new int[] { -1, 1, 0, 0 };
|
||||
int[] yDirection = new int[] { 0, 0, 1, -1 };
|
||||
|
||||
for ( int i = 0; i < 4; i++ )
|
||||
{
|
||||
int xDir = xDirection[ i ];
|
||||
int yDir = yDirection[ i ];
|
||||
|
||||
int offset = 1;
|
||||
|
||||
while ( true )
|
||||
{
|
||||
Point2D p = new Point2D( m_Position.X + offset * xDir, m_Position.Y + offset * yDir );
|
||||
|
||||
if ( ! m_BChessboard.IsValid( p ) )
|
||||
break;
|
||||
|
||||
BaseChessPiece piece = m_BChessboard[ p ];
|
||||
|
||||
if ( piece == null )
|
||||
{
|
||||
moves.Add( p );
|
||||
offset++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( capture && piece.Color != m_Color )
|
||||
{
|
||||
moves.Add( p );
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return moves;
|
||||
}
|
||||
|
||||
public override bool IsCastle(Point2D loc)
|
||||
{
|
||||
King king = m_BChessboard[ loc ] as King;
|
||||
|
||||
string err = null;
|
||||
|
||||
return king != null && king.Color == m_Color && m_BChessboard.AllowCastle( king, this, ref err );
|
||||
}
|
||||
|
||||
public void Castle()
|
||||
{
|
||||
m_Castle = true;
|
||||
|
||||
int dx = 0;
|
||||
|
||||
if ( m_Position.X == 0 )
|
||||
dx = 3;
|
||||
else if ( m_Position.X == 7 )
|
||||
dx = -2;
|
||||
|
||||
Move move = new Move( this, new Point2D( m_Position.X + dx, m_Position.Y ) );
|
||||
|
||||
MoveTo( move );
|
||||
}
|
||||
|
||||
public override void OnMoveOver()
|
||||
{
|
||||
if ( ! m_Castle )
|
||||
base.OnMoveOver ();
|
||||
else
|
||||
{
|
||||
m_Castle = false;
|
||||
|
||||
m_BChessboard.ApplyMove( m_Move );
|
||||
|
||||
King king = m_BChessboard.GetKing( m_Color ) as King;
|
||||
|
||||
int dx = 0;
|
||||
|
||||
if ( m_Position.X == 3 )
|
||||
dx = -2;
|
||||
else
|
||||
dx = 2;
|
||||
|
||||
king.EndCastle( new Point2D( king.Position.X + dx, king.Position.Y ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user