-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cs
149 lines (131 loc) · 4.43 KB
/
Player.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
* Authors: Wesley Kwiecinski - Z1896564, Ojas DhiYogi - Z1849680
* CSCI 473 Assignment 5
* Due 4/14/2022
*
* Player class. Handles creating the pieces of the board and removing them when necessary
*
* Wesley was responsible for this class.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assign5
{
internal class Player : IDisposable
{
private int killCount = 0; //how many pieces the player has taken out
public int deadPieces = 0;
private List<Piece> pieces = null;
private Piece king;
/// <summary>
/// Gets the list of pieces in the game
/// </summary>
public List<Piece> Pieces
{
get => pieces;
}
/// <summary>
/// Stores a constant reference to the king for ease of access.
/// </summary>
public Piece King
{
get => king;
}
public int KillCount
{
get => killCount;
set => killCount += value;
}
/// <summary>
/// Player constructor
/// </summary>
/// <param name="turn">Refers to if it's the player's turn when the game starts.
/// True => White, False => black</param>
public Player(bool turn = false)
{
pieces = new List<Piece>(16);
if(turn) //white piece
{
//Add 8 pawns to bottom
for (int i = 0; i < 8; i++)
{
Pawn p = new Pawn(i, 6, turn, Chess.pawnImgW);
pieces.Add(p);
}
//Add 2 rooks on the side
Rook r = new Rook(0, 7, turn, Chess.rookImgW);
Rook r1 = new Rook(7, 7, turn, Chess.rookImgW);
pieces.Add(r);
pieces.Add(r1);
//Add the knights
Knight k = new Knight(1, 7, turn, Chess.knightImgW);
Knight k1 = new Knight(6, 7, turn, Chess.knightImgW);
pieces.Add(k);
pieces.Add(k1);
//Add the bishops
Bishop b = new Bishop(2, 7, turn, Chess.bishopImgW);
Bishop b1 = new Bishop(5, 7, turn, Chess.bishopImgW);
pieces.Add(b);
pieces.Add(b1);
//Add the king & queen
King king = new King(4, 7, turn, Chess.kingImgW);
Queen queen = new Queen(3, 7, turn, Chess.queenImgW);
pieces.Add(king);
this.king = king;
pieces.Add(queen);
} else //black piece
{
//Add 8 pawns to top
for(int i = 0; i < 8; i++)
{
Pawn p = new Pawn(i, 1, turn, Chess.pawnImgB);
pieces.Add(p);
}
//Add 2 rooks on the side
Rook r = new Rook(0, 0, turn, Chess.rookImgB);
Rook r1 = new Rook(7, 0, turn, Chess.rookImgB);
pieces.Add(r);
pieces.Add(r1);
//Add the knights
Knight k = new Knight(1, 0, turn, Chess.knightImgB);
Knight k1 = new Knight(6, 0, turn, Chess.knightImgB);
pieces.Add(k);
pieces.Add(k1);
//Add the bishops
Bishop b = new Bishop(2, 0, turn, Chess.bishopImgB);
Bishop b1 = new Bishop(5, 0, turn, Chess.bishopImgB);
pieces.Add(b);
pieces.Add(b1);
//Add the king & queen
King king = new King(4, 0, turn, Chess.kingImgB);
Queen queen = new Queen(3, 0, turn, Chess.queenImgB);
pieces.Add(king);
this.king = king;
pieces.Add(queen);
}
}
/// <summary>
/// Removes a piece in the event that piece collide
/// </summary>
/// <param name="piece"></param>
public void RemovePiece(Piece piece)
{
if(pieces.Contains(piece))
{
pieces.Remove(piece);
}
}
/// <summary>
/// Dispose every piece and clear the
/// </summary>
public void Dispose()
{
foreach(Piece p in pieces)
p.Dispose();
pieces.Clear();
}
}
}