Advertisement
SuperLemrick

Chess Program Part 1

Dec 27th, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace Chess
  11. {
  12.     // the following enum allows us to identify a chess piece as black or white
  13.     public enum PlayerType
  14.     {
  15.         BLACK,
  16.         WHITE
  17.     }
  18.  
  19.     public abstract class AbstractChessPiece
  20.     {
  21.         // the following variables define the AbstractChessPiece
  22.  
  23.         public String Name;             // "Pawn", "Rook", etc.
  24.         public String Abbreviation;     // "P", "R", etc.
  25.  
  26.         public PlayerType Player;       // BLACK or WHITE
  27.         public int Col;                 // 0 - 7
  28.         public int Row;                 // 0 - 7
  29.         public bool HasMoved;           // true or false
  30.  
  31.         // This function should be completed by the student.
  32.         // The AbstractChessPiece initializes the member variables with the
  33.         // provided information.
  34.         public AbstractChessPiece(String newName, String newAbbreviation, PlayerType newPlayer)
  35.         {
  36.             Name = newName;
  37.             Abbreviation = newAbbreviation;
  38.             Player = newPlayer;
  39.  
  40.             HasMoved = false;
  41.         }
  42.  
  43.         // This abstract method is defined but not implemented by AbstractChessPiece.
  44.         // Each derived class will have to implement their own version.
  45.         abstract public bool CanMoveToLocation(int targetCol, int targetRow, ChessBoard gameBoard);
  46.  
  47.         // This method will be implemented by the student.
  48.         // Given a listed of ChessSquares in the path, determine if the indicated
  49.         // targetRow and column can be reached within the number of steps allowed.
  50.         protected bool CanFollowPath(int targetCol, int targetRow,
  51.                                      LinkedList<ChessSquare> path, int stepsAllowed)
  52.         {
  53.             return true;    // not yet implemented (final project)!
  54.         }
  55.  
  56.         // This function will be implemented by the student.
  57.         // Override the ToString() method to return some nicer description of the piece.
  58.         override public String ToString()
  59.         {
  60.             if (Player == PlayerType.BLACK)
  61.                 return "Black " + Name + " at (" + Col + "," + Row + ")";
  62.             else
  63.                 return "White " + Name + " at (" + Col + "," + Row + ")";
  64.         }
  65.     }
  66.  
  67.     // This class will be implemented by the student.
  68.     public class Pawn : AbstractChessPiece
  69.     {
  70.         public Pawn(PlayerType player)
  71.             : base("Pawn", "P", player)
  72.         {
  73.         }
  74.         override public bool CanMoveToLocation(int targetCol, int targetRow, ChessBoard gameBoard)
  75.         {
  76.             return true;
  77.         }
  78.     }
  79.  
  80.     // This class will be implemented by the student.
  81.     public class Rook : AbstractChessPiece
  82.     {
  83.         public Rook(PlayerType player)
  84.             : base("Rook", "R", player)
  85.         {
  86.         }
  87.         override public bool CanMoveToLocation(int targetCol, int targetRow, ChessBoard gameBoard)
  88.         {
  89.             return true;
  90.         }
  91.     }
  92.  
  93.     // This class will be implemented by the student.
  94.     public class Knight : AbstractChessPiece
  95.     {
  96.         public Knight(PlayerType player)
  97.             : base("Knight", "K", player)
  98.         {
  99.         }
  100.         override public bool CanMoveToLocation(int targetCol, int targetRow, ChessBoard gameBoard)
  101.         {
  102.             return true;
  103.         }
  104.     }
  105.  
  106.     // This class will be implemented by the student.
  107.     public class Bishop : AbstractChessPiece
  108.     {
  109.         public Bishop(PlayerType player)
  110.             : base("Bishop", "B", player)
  111.         {
  112.         }
  113.         override public bool CanMoveToLocation(int targetCol, int targetRow, ChessBoard gameBoard)
  114.         {
  115.             return true;
  116.         }
  117.     }
  118.  
  119.     // This class will be implemented by the student.
  120.     public class Queen : AbstractChessPiece
  121.     {
  122.         public Queen(PlayerType player)
  123.             : base("Queen", "Q", player)
  124.         {
  125.         }
  126.         override public bool CanMoveToLocation(int targetCol, int targetRow, ChessBoard gameBoard)
  127.         {
  128.             return true;
  129.         }
  130.     }
  131.  
  132.     // This class will be implemented by the student.
  133.     public class King : AbstractChessPiece
  134.     {
  135.         public King(PlayerType player)
  136.             : base("King", "K", player)
  137.         {
  138.         }
  139.         override public bool CanMoveToLocation(int targetCol, int targetRow, ChessBoard gameBoard)
  140.         {
  141.             return true;
  142.         }
  143.     }
  144.  
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement