//resets everything to starting state void SetupGame() { //turn number = 0 turnnum = 0; //checker counter reset _checkCount = new PieceCount(); //clear highlighted pieces gBoard.Highlighted.Clear(); //unselect any selected piece gBoard.Selected = null; //reset board state //places pieces in start positions gBoard.Cboard = new Piece[6,6]; for (int i = 1; i < 12; i += 2) { if (i == 7) i--; gBoard.Cboard[i % 6, i / 6] = new Piece("black"); } for (int i = 25; i < 36; i += 2) { if (i == 31) i--; gBoard.Cboard[i % 6, i / 6] = new Piece("red"); } //set color of pieces to ensure black goes first gBoard.SetColors(Turn); //if its the player's turn, highlight their pieces if(Turn)gBoard.HighlightAll(Turn); //launch windows form prompt to ask for game details p = new prompt(); p.Show(); }
//function to handle clicking on a specific square by the player //returns whether the game is over or not public bool Click(int x, int y, ref bool turn, PieceCount pcount) { //if the list of highlighted pieces does not contain the clicked square //end the function if (!Highlighted.Contains(new Vector2(x, y))) return false; //if the player has yet to select a piece, select the piece that was clicked if (Selected == null) { if (Cboard[x, y] != null && Cboard[x, y] == turn) { Selected = Tuple.Create(x, y); Highlighted.Clear(); Highlighted.Add(new Vector2(x, y)); HighlightSingle(x, y, turn); //highlight places to move piece } } //else the player is either moving or jumping else { //if the clicked position is the selected piece //unselect it if (Cboard[x, y] != null) { if (Selected.Item1 == x && Selected.Item2 == y) { Selected = null; Highlighted.Clear(); if(!_jumping)HighlightAll(turn); else Highlighted.Add(new Vector2(x,y)); //highlight all possible pieces to move } } //handle moving the piece else { //if the position selected is a jumping distance, handle jumping if (Math.Abs(x - Selected.Item1) == 2) { _jumping = false; int dx = x - Selected.Item1; int dy = y - Selected.Item2; //erase the piece that is being jumped over Cboard[x - dx / 2, y - dy / 2] = null; //subtract one piece from the count pcount.Subtract(!turn); //if the count is 0 the game is over if (pcount.GetCount(!turn) == 0) { turn = !turn; Selected = null; return true; } //move the piece Cboard[x, y] = Cboard[Selected.Item1, Selected.Item2]; Cboard[Selected.Item1, Selected.Item2] = null; //clear selected and highlighted Selected = null; Highlighted.Clear(); //check if there are more jumps from that same piece var moves = Move.GenerateSingleJumps(Cboard, x, y, turn); if (moves.Count == 0) { turn = !turn; HighlightAll(turn); } else { //force the player to keep jumping Highlighted.Add(new Vector2(x,y)); _jumping = true; } if (Highlighted.Count == 0) return true; } //otherwise handle moving the piece else { _jumping = false; Cboard[x, y] = Cboard[Selected.Item1, Selected.Item2]; Cboard[Selected.Item1, Selected.Item2] = null; Selected = null; Highlighted.Clear(); turn = !turn; HighlightAll(turn); if (Highlighted.Count == 0) return true; } } } return false; }