Othello WPF game

I'm absolutely desperate for some help. I'm triyng to make a othello game for like 6 months now but i just don't know what to do and i just want to finish this godforsaken assignment. The video shows how far i've come.
182 Replies
Merineth πŸ‡ΈπŸ‡ͺ
Now i want to initialize the game and start it but i just can't get it to work
Merineth πŸ‡ΈπŸ‡ͺ
namespace Assignment2.Model
{
internal class GameManager
{
GameBoard Board;
Player Player1;
Player Player2;
Player CurrentPlayer;

public GameManager(Player player1, Player player2)
{
this.Board = new GameBoard();

this.Player1 = player1;
this.Player2 = player2;

//Black starts the game
if (player1.Disk == Disk.Black)
{
this.CurrentPlayer = Player1;
}
else
{
this.CurrentPlayer = Player2;
}
}
public void StartGame()
{
while(Board.GameOver() == false)
{
if(Board.hasValidMoves(CurrentPlayer.Disk))
{
//Creating a list of valid moves for the curent player
List<(int x, int y)> ValidMoves = Board.GetValidMoves(CurrentPlayer.Disk);

(int x, int y) tempMove = CurrentPlayer.RequestMove(Board, ValidMoves);

//Making sure that a valid move is chose, if not a new move is requested until it is valid
while (Board.IsValidMove(tempMove.x, tempMove.y, CurrentPlayer.Disk) == false)
{
tempMove = CurrentPlayer.RequestMove(Board, ValidMoves);
}

(int x, int y) chosenMove = tempMove;

Board.ExecuteMove(chosenMove.x, chosenMove.y, CurrentPlayer.Disk);

switchPlayer();
}
else
{
//If the curent player has no valid moves, it becomes the next players turn
switchPlayer();
}
}
if (Board.DiskCount(Player1.Disk) == Board.DiskCount(Player2.Disk))
{
//what to do here
namespace Assignment2.Model
{
internal class GameManager
{
GameBoard Board;
Player Player1;
Player Player2;
Player CurrentPlayer;

public GameManager(Player player1, Player player2)
{
this.Board = new GameBoard();

this.Player1 = player1;
this.Player2 = player2;

//Black starts the game
if (player1.Disk == Disk.Black)
{
this.CurrentPlayer = Player1;
}
else
{
this.CurrentPlayer = Player2;
}
}
public void StartGame()
{
while(Board.GameOver() == false)
{
if(Board.hasValidMoves(CurrentPlayer.Disk))
{
//Creating a list of valid moves for the curent player
List<(int x, int y)> ValidMoves = Board.GetValidMoves(CurrentPlayer.Disk);

(int x, int y) tempMove = CurrentPlayer.RequestMove(Board, ValidMoves);

//Making sure that a valid move is chose, if not a new move is requested until it is valid
while (Board.IsValidMove(tempMove.x, tempMove.y, CurrentPlayer.Disk) == false)
{
tempMove = CurrentPlayer.RequestMove(Board, ValidMoves);
}

(int x, int y) chosenMove = tempMove;

Board.ExecuteMove(chosenMove.x, chosenMove.y, CurrentPlayer.Disk);

switchPlayer();
}
else
{
//If the curent player has no valid moves, it becomes the next players turn
switchPlayer();
}
}
if (Board.DiskCount(Player1.Disk) == Board.DiskCount(Player2.Disk))
{
//what to do here
Β΄cs

}
}
private void switchPlayer()
{
CurrentPlayer = (CurrentPlayer == Player1) ? Player2 : Player1;
}


}
}
Β΄cs

}
}
private void switchPlayer()
{
CurrentPlayer = (CurrentPlayer == Player1) ? Player2 : Player1;
}


}
}
Is the problem the arguments for Startgame??
Sehra
Sehraβ€’2w ago
public void StartGame() take zero arguments
Merineth πŸ‡ΈπŸ‡ͺ
ok and i want it to take 3?
Sehra
Sehraβ€’2w ago
that is up to you really how you want it to work
Merineth πŸ‡ΈπŸ‡ͺ
I just mainly want it to work but yeah i guess i want it to take 3 arguemtns GameManager Game = GameManager.StartGame(player1Name, player2Name, isPlayer2Computer); StartGame(player1Name, player2Name, isPlayer2Computer)
Merineth πŸ‡ΈπŸ‡ͺ
i tried changing it but it doens't WOREK
Sehra
Sehraβ€’2w ago
you didn't specify the types
Merineth πŸ‡ΈπŸ‡ͺ
aah
string player1Name = setUpDialog.Player1Name;
string player2Name = setUpDialog.Player2Name;
bool isPlayer2Computer = setUpDialog.IsPlayer2Computer;
string player1Name = setUpDialog.Player1Name;
string player2Name = setUpDialog.Player2Name;
bool isPlayer2Computer = setUpDialog.IsPlayer2Computer;
since they are string string bool public void StartGame(string player1Name, string player2Name, bool isPlayer2Computer) That gives no errors thank god I assume it can't return void?
Merineth πŸ‡ΈπŸ‡ͺ
like it says startgame must be static so i change it to static but then i get 20 errors
Sehra
Sehraβ€’2w ago
you already made a constructor that take two players, why not create an instance and use that?
var player1 = ...;
var player2 = ...;
var gameManager = new GameManager(player1, player2);
gameManager.StartGame();
var player1 = ...;
var player2 = ...;
var gameManager = new GameManager(player1, player2);
gameManager.StartGame();
and create two players however you do that
Merineth πŸ‡ΈπŸ‡ͺ
public GameManager(Player player1, Player player2)
{
this.Board = new GameBoard();
this.Player1 = player1;
this.Player2 = player2;

//Black starts the game
if (player1.Disk == Disk.Black)
{
this.CurrentPlayer = Player1;
}
else
{
this.CurrentPlayer = Player2;
}
}**
public GameManager(Player player1, Player player2)
{
this.Board = new GameBoard();
this.Player1 = player1;
this.Player2 = player2;

//Black starts the game
if (player1.Disk == Disk.Black)
{
this.CurrentPlayer = Player1;
}
else
{
this.CurrentPlayer = Player2;
}
}**
** is this what you mean?
Sehra
Sehraβ€’2w ago
yes
Merineth πŸ‡ΈπŸ‡ͺ
ok so i remove // Initialize the game with the provided player data GameManager Game = GameManager.StartGame(player1Name, player2Name, isPlayer2Computer); and us ethe constructor instead and have the startgame() method take that argument? i don't understand GameManager Game =
if (result == true) // If OK was clicked (DialogResult = true)
{
// Retrieve player names and player types
string player1Name = setUpDialog.Player1Name;
string player2Name = setUpDialog.Player2Name;
bool isPlayer2Computer = setUpDialog.IsPlayer2Computer;

// Update the status section with the player names
Player1Label.Text = "Player 1: " + player1Name;
Player2Label.Text = "Player 2: " + player2Name;

// Set the score to 0
Player1Score.Text = "Black Disks: 0";
Player2Score.Text = "White Disks: 0";


GameManager Game =

}
if (result == true) // If OK was clicked (DialogResult = true)
{
// Retrieve player names and player types
string player1Name = setUpDialog.Player1Name;
string player2Name = setUpDialog.Player2Name;
bool isPlayer2Computer = setUpDialog.IsPlayer2Computer;

// Update the status section with the player names
Player1Label.Text = "Player 1: " + player1Name;
Player2Label.Text = "Player 2: " + player2Name;

// Set the score to 0
Player1Score.Text = "Black Disks: 0";
Player2Score.Text = "White Disks: 0";


GameManager Game =

}
like so? I don't understand
Sehra
Sehraβ€’2w ago
well, you wrote the GameManager class, so must have had an idea how you wanted to interact with it
Merineth πŸ‡ΈπŸ‡ͺ
private void NewGameButton_Click(object sender, RoutedEventArgs e)
{
// Show the SetUpGameDialog to collect player names and types
SetUpGameDialog setUpDialog = new SetUpGameDialog();
bool? result = setUpDialog.ShowDialog(); // Show dialog and wait for result

if (result == true) // If OK was clicked (DialogResult = true)
{
// Retrieve player names and player types
string player1Name = setUpDialog.Player1Name;
string player2Name = setUpDialog.Player2Name;
bool isPlayer2Computer = setUpDialog.IsPlayer2Computer;

// Update the status section with the player names
Player1Label.Text = "Player 1: " + player1Name;
Player2Label.Text = "Player 2: " + player2Name;

// Set the score to 0
Player1Score.Text = "Black Disks: 0";
Player2Score.Text = "White Disks: 0";


// Create the GameManager instance
GameManager gameManager = new GameManager(player1, player2);

// Start the game
gameManager.StartGame();

}
private void NewGameButton_Click(object sender, RoutedEventArgs e)
{
// Show the SetUpGameDialog to collect player names and types
SetUpGameDialog setUpDialog = new SetUpGameDialog();
bool? result = setUpDialog.ShowDialog(); // Show dialog and wait for result

if (result == true) // If OK was clicked (DialogResult = true)
{
// Retrieve player names and player types
string player1Name = setUpDialog.Player1Name;
string player2Name = setUpDialog.Player2Name;
bool isPlayer2Computer = setUpDialog.IsPlayer2Computer;

// Update the status section with the player names
Player1Label.Text = "Player 1: " + player1Name;
Player2Label.Text = "Player 2: " + player2Name;

// Set the score to 0
Player1Score.Text = "Black Disks: 0";
Player2Score.Text = "White Disks: 0";


// Create the GameManager instance
GameManager gameManager = new GameManager(player1, player2);

// Start the game
gameManager.StartGame();

}
I haven't written game manager this is a gorup project with 2 peopl kewhich we hiave been working on for like over 6 months overdue by like 5 is this what yuou mena ?
Sehra
Sehraβ€’2w ago
the GameManager expect two Player instances to be provided
Merineth πŸ‡ΈπŸ‡ͺ
yes and i'm providing it player1 and player2
Sehra
Sehraβ€’2w ago
var player1 = new Player(...) but i don't see how that class is defined so you have to figured that part out since it's a group project you may want to do this together with the others instead to hash out how the different parts you write should communicate
Merineth πŸ‡ΈπŸ‡ͺ
We were supposed to doi it as 3 we are group oif 2 he isn't doing anythjing so i have to somehow figure this out by myself but i'm not good enough to do it myself So i'm completely stuck I'm gonna completely fail all other courses becausse this takes up 100% of my time
Sehra
Sehraβ€’2w ago
sounds like you should talk to the teacher about it
Merineth πŸ‡ΈπŸ‡ͺ
What is she going to do? I wont pass until this project is finished i already passed the exams etc she wont do shit I'm just desperate to have someone help me finish this as i'm just simply not advanced enough to create something as complex as this
Sehra
Sehraβ€’2w ago
what does the Player class look like?
Merineth πŸ‡ΈπŸ‡ͺ
abstract class Player
{
public Disk Disk { get; set; }
string Name { get; set; }

public Player(string name, Disk disk)
{
this.Name = name;
this.Disk = disk;
}

public abstract (int x, int y) RequestMove(GameBoard board, List<(int x, int y)> validMoves);

}
abstract class Player
{
public Disk Disk { get; set; }
string Name { get; set; }

public Player(string name, Disk disk)
{
this.Name = name;
this.Disk = disk;
}

public abstract (int x, int y) RequestMove(GameBoard board, List<(int x, int y)> validMoves);

}
var player1 = new Player(); var player2 = new Player(); So i need to fix the arguments ?
Sehra
Sehraβ€’2w ago
well, Player is abstract so it needs to be subclassed, with an implementation of RequestMove
Merineth πŸ‡ΈπŸ‡ͺ
ok i think i slightly remember abstarct
Sehra
Sehraβ€’2w ago
i'm guessing that you need to provide that implementation, with something that answer back with the selected move
Merineth πŸ‡ΈπŸ‡ͺ
I have no idea what the requested move is that is something he "made"
Sehra
Sehraβ€’2w ago
it's called with a list of the current valid moves, and you need to answer which one to make
Merineth πŸ‡ΈπŸ‡ͺ
internal class ComputerPlayer : Player
{
// Constructor
public ComputerPlayer(string name, Disk disk) : base(name, disk)
{
}

// Override RequestMove
public override (int x, int y) RequestMove(GameBoard board, List<(int x, int y)> validMoves)
{
//placeholder move
(int x, int y) selectedMove = (-1,-1);

// Create a thread for the move calculation
Thread moveThread = new Thread(() =>
{
Random random = new Random();
int index = random.Next(validMoves.Count);

selectedMove = validMoves[index];

//Sleep for 2 seconds
Thread.Sleep(2000);
});

// Start the thread and wait for it to finish
moveThread.Start();
moveThread.Join(); // Wait for the thread to finish before proceeding

// Return the selected move
return selectedMove;

}

}
internal class ComputerPlayer : Player
{
// Constructor
public ComputerPlayer(string name, Disk disk) : base(name, disk)
{
}

// Override RequestMove
public override (int x, int y) RequestMove(GameBoard board, List<(int x, int y)> validMoves)
{
//placeholder move
(int x, int y) selectedMove = (-1,-1);

// Create a thread for the move calculation
Thread moveThread = new Thread(() =>
{
Random random = new Random();
int index = random.Next(validMoves.Count);

selectedMove = validMoves[index];

//Sleep for 2 seconds
Thread.Sleep(2000);
});

// Start the thread and wait for it to finish
moveThread.Start();
moveThread.Join(); // Wait for the thread to finish before proceeding

// Return the selected move
return selectedMove;

}

}
`
{
internal class HumanPlayer
{
}
}
{
internal class HumanPlayer
{
}
}
we have two classes that should derive from Player i guess?
Sehra
Sehraβ€’2w ago
ComputerPlayer already derive from Player, so if you check that player 2 is a computer, instantiate that instead of HumanPlayer
Merineth πŸ‡ΈπŸ‡ͺ
private void NewGameButton_Click(object sender, RoutedEventArgs e)
{
// Show the SetUpGameDialog to collect player names and types
SetUpGameDialog setUpDialog = new SetUpGameDialog();
bool? result = setUpDialog.ShowDialog(); // Show dialog and wait for result

if (result == true) // If OK was clicked (DialogResult = true)
{
// Retrieve player names and player types
string player1Name = setUpDialog.Player1Name;
string player2Name = setUpDialog.Player2Name;
bool isPlayer2Computer = setUpDialog.IsPlayer2Computer;

// Update the status section with the player names
Player1Label.Text = "Player 1: " + player1Name;
Player2Label.Text = "Player 2: " + player2Name;

// Set the score to 0
Player1Score.Text = "Black Disks: 0";
Player2Score.Text = "White Disks: 0";

if (isPlayer2Computer)
{

}
// Create the GameManager instance
GameManager gameManager = new GameManager(player1, player2);

// Start the game
gameManager.StartGame();

}
private void NewGameButton_Click(object sender, RoutedEventArgs e)
{
// Show the SetUpGameDialog to collect player names and types
SetUpGameDialog setUpDialog = new SetUpGameDialog();
bool? result = setUpDialog.ShowDialog(); // Show dialog and wait for result

if (result == true) // If OK was clicked (DialogResult = true)
{
// Retrieve player names and player types
string player1Name = setUpDialog.Player1Name;
string player2Name = setUpDialog.Player2Name;
bool isPlayer2Computer = setUpDialog.IsPlayer2Computer;

// Update the status section with the player names
Player1Label.Text = "Player 1: " + player1Name;
Player2Label.Text = "Player 2: " + player2Name;

// Set the score to 0
Player1Score.Text = "Black Disks: 0";
Player2Score.Text = "White Disks: 0";

if (isPlayer2Computer)
{

}
// Create the GameManager instance
GameManager gameManager = new GameManager(player1, player2);

// Start the game
gameManager.StartGame();

}
so we check it like this? with an if statement
Sehra
Sehraβ€’2w ago
class HumanPlayer : Player
{
public HumanPlayer(string name, Disk disk) : base(name, disk)
{
}

public override (int x, int y) RequestMove(GameBoard board, List<(int x, int y)> validMoves)
{
// your code here
}
}
class HumanPlayer : Player
{
public HumanPlayer(string name, Disk disk) : base(name, disk)
{
}

public override (int x, int y) RequestMove(GameBoard board, List<(int x, int y)> validMoves)
{
// your code here
}
}
Merineth πŸ‡ΈπŸ‡ͺ
what
Merineth πŸ‡ΈπŸ‡ͺ
like this doesn't work because it's expecting 2 arguments of some sort so we need to create player 1 and player 2 ? if player 2 is a computer then we just want to instantiate it immediately
Sehra
Sehraβ€’2w ago
you can yes, just have a Player player2; above the if, assign it to either HumanPlayer or ComputerPlayer based on the test
Merineth πŸ‡ΈπŸ‡ͺ
? I don't understand that part
if (isPlayer2Computer)
{
Player player2 = new ComputerPlayer(...);
}
if (isPlayer2Computer)
{
Player player2 = new ComputerPlayer(...);
}
` is this not what you mean?
Sehra
Sehraβ€’2w ago
yes, but player2 need to be declared outside the if, or it's not in scope for creating the game manager
Merineth πŸ‡ΈπŸ‡ͺ
Ok, but how do i check with the if, if i can't create it inside th eif ooh i see what you mean i create the gamemanager based on it
Player player1 = new HumanPlayer(player1Name, Disk.White);
Player player2computer = new ComputerPlayer(player2Name, Disk.Black);
Player player2 = new HumanPlayer(player2Name, Disk.Black);

// Create the GameManager instance. If the
if (isPlayer2Computer)
{
GameManager gameManager = new GameManager(player1, player2computer);
}
else
{
GameManager gameManager = new GameManager(player1, player2);
}
Player player1 = new HumanPlayer(player1Name, Disk.White);
Player player2computer = new ComputerPlayer(player2Name, Disk.Black);
Player player2 = new HumanPlayer(player2Name, Disk.Black);

// Create the GameManager instance. If the
if (isPlayer2Computer)
{
GameManager gameManager = new GameManager(player1, player2computer);
}
else
{
GameManager gameManager = new GameManager(player1, player2);
}
Would this be what you mean? Ok i think that is right
Sehra
Sehraβ€’2w ago
Player player2;
if (isComputer) player2 = new ComputerPlayer
else player2 = new HumanPlayer
Player player2;
if (isComputer) player2 = new ComputerPlayer
else player2 = new HumanPlayer
with arguments as needed
Merineth πŸ‡ΈπŸ‡ͺ
Hmm
Player player2computer = new ComputerPlayer(player2Name, Disk.Black);
Player player2 = new HumanPlayer(player2Name, Disk.Black);


Player player2;
if (isComputer) player2 = new ComputerPlayer
else player2 = new HumanPlayer
Player player2computer = new ComputerPlayer(player2Name, Disk.Black);
Player player2 = new HumanPlayer(player2Name, Disk.Black);


Player player2;
if (isComputer) player2 = new ComputerPlayer
else player2 = new HumanPlayer
So i should replace the first 2 lines of code with the last 3 lines of code?
Sehra
Sehraβ€’2w ago
yes, and back to new GameManager(player1, player2)
Merineth πŸ‡ΈπŸ‡ͺ
// Creates 3 instances for the if statement
Player player1 = new HumanPlayer(player1Name, Disk.White);
Player player2;
if (isComputer)
{
player2 = new ComputerPlayer;
}
else
{
player2 = new HumanPlayer;
}


// Create the GameManager instance. If the
if (isPlayer2Computer)
{
new GameManager(player1, player2);
}
else
{
new GameManager(player1, player2);
}
// Creates 3 instances for the if statement
Player player1 = new HumanPlayer(player1Name, Disk.White);
Player player2;
if (isComputer)
{
player2 = new ComputerPlayer;
}
else
{
player2 = new HumanPlayer;
}


// Create the GameManager instance. If the
if (isPlayer2Computer)
{
new GameManager(player1, player2);
}
else
{
new GameManager(player1, player2);
}
` So you mean something like this?
Sehra
Sehraβ€’2w ago
you don't need the second if
Merineth πŸ‡ΈπŸ‡ͺ
Ok! I see what you mean
public partial class GameWindow : Window
{
public GameWindow()
{
InitializeComponent();
}

// Event handler for the "New Game" button click
private void NewGameButton_Click(object sender, RoutedEventArgs e)
{
// Show the SetUpGameDialog to collect player names and types
SetUpGameDialog setUpDialog = new SetUpGameDialog();
bool? result = setUpDialog.ShowDialog(); // Show dialog and wait for result

if (result == true) // If OK was clicked (DialogResult = true)
{
// Retrieve player names and player types
string player1Name = setUpDialog.Player1Name;
string player2Name = setUpDialog.Player2Name;
bool isPlayer2Computer = setUpDialog.IsPlayer2Computer;

// Update the status section with the player names
Player1Label.Text = "Player 1: " + player1Name;
Player2Label.Text = "Player 2: " + player2Name;

// Set the score to 0
Player1Score.Text = "Black Disks: 0";
Player2Score.Text = "White Disks: 0";


// Creates 3 instances for the if statement
Player player1 = new HumanPlayer(player1Name, Disk.White);
Player player2;
if (isPlayer2Computer)
{
player2 = new ComputerPlayer(player2Name, Disk.Black);
}
else
{
player2 = new HumanPlayer(player2Name, Disk.Black);
}


// Create the GameManager instance.
GameManager game = new GameManager(player1, player2);


}
else
{
// If the user cancels the setup
MessageBox.Show("Game setup was canceled.", "Canceled");
}
}
public partial class GameWindow : Window
{
public GameWindow()
{
InitializeComponent();
}

// Event handler for the "New Game" button click
private void NewGameButton_Click(object sender, RoutedEventArgs e)
{
// Show the SetUpGameDialog to collect player names and types
SetUpGameDialog setUpDialog = new SetUpGameDialog();
bool? result = setUpDialog.ShowDialog(); // Show dialog and wait for result

if (result == true) // If OK was clicked (DialogResult = true)
{
// Retrieve player names and player types
string player1Name = setUpDialog.Player1Name;
string player2Name = setUpDialog.Player2Name;
bool isPlayer2Computer = setUpDialog.IsPlayer2Computer;

// Update the status section with the player names
Player1Label.Text = "Player 1: " + player1Name;
Player2Label.Text = "Player 2: " + player2Name;

// Set the score to 0
Player1Score.Text = "Black Disks: 0";
Player2Score.Text = "White Disks: 0";


// Creates 3 instances for the if statement
Player player1 = new HumanPlayer(player1Name, Disk.White);
Player player2;
if (isPlayer2Computer)
{
player2 = new ComputerPlayer(player2Name, Disk.Black);
}
else
{
player2 = new HumanPlayer(player2Name, Disk.Black);
}


// Create the GameManager instance.
GameManager game = new GameManager(player1, player2);


}
else
{
// If the user cancels the setup
MessageBox.Show("Game setup was canceled.", "Canceled");
}
}
// Event handler for the "Exit Game" button click
private void ExitGameButton_Click(object sender, RoutedEventArgs e)
{
// Close the application
Application.Current.Shutdown();
}
}
}
// Event handler for the "Exit Game" button click
private void ExitGameButton_Click(object sender, RoutedEventArgs e)
{
// Close the application
Application.Current.Shutdown();
}
}
}
So it lookos something like this now I'm getting no errors from the code now so it seems okay However a tiny other problem started
Merineth πŸ‡ΈπŸ‡ͺ
Ahh the implementation isn't done
Sehra
Sehraβ€’2w ago
no, that part you have to write. wait for a selection on the board and return it there
Merineth πŸ‡ΈπŸ‡ͺ
I took his implementation and added it there
// Retrieve player names and player types
string player1Name = setUpDialog.Player1Name;
string player2Name = setUpDialog.Player2Name;
bool isPlayer2Computer = setUpDialog.IsPlayer2Computer;

// Update the status section with the player names
Player1Label.Text = "Player 1: " + player1Name;
Player2Label.Text = "Player 2: " + player2Name;

// Set the score to 0
Player1Score.Text = "Black Disks: 0";
Player2Score.Text = "White Disks: 0";


// Creates 3 instances for the if statement
Player player1 = new HumanPlayer(player1Name, Disk.White);
Player player2;
if (isPlayer2Computer)
{
player2 = new ComputerPlayer(player2Name, Disk.Black);
}
else
{
player2 = new HumanPlayer(player2Name, Disk.Black);
}


// Create the GameManager instance.
GameManager game = new GameManager(player1, player2);
game.StartGame();
// Retrieve player names and player types
string player1Name = setUpDialog.Player1Name;
string player2Name = setUpDialog.Player2Name;
bool isPlayer2Computer = setUpDialog.IsPlayer2Computer;

// Update the status section with the player names
Player1Label.Text = "Player 1: " + player1Name;
Player2Label.Text = "Player 2: " + player2Name;

// Set the score to 0
Player1Score.Text = "Black Disks: 0";
Player2Score.Text = "White Disks: 0";


// Creates 3 instances for the if statement
Player player1 = new HumanPlayer(player1Name, Disk.White);
Player player2;
if (isPlayer2Computer)
{
player2 = new ComputerPlayer(player2Name, Disk.Black);
}
else
{
player2 = new HumanPlayer(player2Name, Disk.Black);
}


// Create the GameManager instance.
GameManager game = new GameManager(player1, player2);
game.StartGame();
ok so it creates an instance of a game with player1 and player 2 and then i start the game with startgame()
public void StartGame()
{
while(Board.GameOver() == false)
{
if(Board.hasValidMoves(CurrentPlayer.Disk))
{
//Creating a list of valid moves for the curent player
List<(int x, int y)> ValidMoves = Board.GetValidMoves(CurrentPlayer.Disk);

(int x, int y) tempMove = CurrentPlayer.RequestMove(Board, ValidMoves);

//Making sure that a valid move is chose, if not a new move is requested until it is valid
while (Board.IsValidMove(tempMove.x, tempMove.y, CurrentPlayer.Disk) == false)
{
tempMove = CurrentPlayer.RequestMove(Board, ValidMoves);
}

(int x, int y) chosenMove = tempMove;

Board.ExecuteMove(chosenMove.x, chosenMove.y, CurrentPlayer.Disk);

switchPlayer();
}
else
{
//If the curent player has no valid moves, it becomes the next players turn
switchPlayer();
}
}
if (Board.DiskCount(Player1.Disk) == Board.DiskCount(Player2.Disk))
{
//what to do here

}
}
public void StartGame()
{
while(Board.GameOver() == false)
{
if(Board.hasValidMoves(CurrentPlayer.Disk))
{
//Creating a list of valid moves for the curent player
List<(int x, int y)> ValidMoves = Board.GetValidMoves(CurrentPlayer.Disk);

(int x, int y) tempMove = CurrentPlayer.RequestMove(Board, ValidMoves);

//Making sure that a valid move is chose, if not a new move is requested until it is valid
while (Board.IsValidMove(tempMove.x, tempMove.y, CurrentPlayer.Disk) == false)
{
tempMove = CurrentPlayer.RequestMove(Board, ValidMoves);
}

(int x, int y) chosenMove = tempMove;

Board.ExecuteMove(chosenMove.x, chosenMove.y, CurrentPlayer.Disk);

switchPlayer();
}
else
{
//If the curent player has no valid moves, it becomes the next players turn
switchPlayer();
}
}
if (Board.DiskCount(Player1.Disk) == Board.DiskCount(Player2.Disk))
{
//what to do here

}
}
I haven't written this part so gonna have to go through it This looks like AI?
Sehra
Sehraβ€’2w ago
hard to say if it is ai. the last if checks if it's a draw
Merineth πŸ‡ΈπŸ‡ͺ
Yeah that makes sense if that happens then i have an already made window that pops up and it says it's a draw Do you think it's easier to remake it from scratch? Probably not
Sehra
Sehraβ€’2w ago
uhm, if it works i don't see why
Merineth πŸ‡ΈπŸ‡ͺ
It currently doesn't Sorry wrong
Merineth πŸ‡ΈπŸ‡ͺ
When the game starts with Startgame() there should be a game board that comes up if that makes sense?
Sehra
Sehraβ€’2w ago
makes sense, not sure how you communicate the board state with the user interface
Merineth πŸ‡ΈπŸ‡ͺ
They have explained it as such
Merineth πŸ‡ΈπŸ‡ͺ
This is my setup game dialog
No description
Merineth πŸ‡ΈπŸ‡ͺ
Which seems to be accurate to the description However i guess the problem comes at GameWindow
Sehra
Sehraβ€’2w ago
so you need to write GameGrid which is placed in GameWindow
Merineth πŸ‡ΈπŸ‡ͺ
Yeah i think so! GameGrid is quite complex and i'm not entirely sure it's correct
namespace Assignment2.View
{
public partial class GameGrid : UserControl
{
// Event to notify the GameManager about the clicked position
public event Action<int, int> TileClicked;

public GameGrid()
{
InitializeComponent();
}

// MouseDown handler to determine which tile was clicked
private void GameBoard_MouseDown(object sender, MouseButtonEventArgs e)
{
// Get the position of the mouse click relative to the grid
var position = e.GetPosition(GameBoard);

// Determine which row and column were clicked
int row = (int)(position.Y / (GameBoard.ActualHeight / 8)); // Assuming an 8x8 grid
int column = (int)(position.X / (GameBoard.ActualWidth / 8));

// Notify subscribers (e.g., GameManager)
TileClicked?.Invoke(row, column);
}
namespace Assignment2.View
{
public partial class GameGrid : UserControl
{
// Event to notify the GameManager about the clicked position
public event Action<int, int> TileClicked;

public GameGrid()
{
InitializeComponent();
}

// MouseDown handler to determine which tile was clicked
private void GameBoard_MouseDown(object sender, MouseButtonEventArgs e)
{
// Get the position of the mouse click relative to the grid
var position = e.GetPosition(GameBoard);

// Determine which row and column were clicked
int row = (int)(position.Y / (GameBoard.ActualHeight / 8)); // Assuming an 8x8 grid
int column = (int)(position.X / (GameBoard.ActualWidth / 8));

// Notify subscribers (e.g., GameManager)
TileClicked?.Invoke(row, column);
}
// Update the visual state of the board (e.g., draw pieces)
public void UpdateBoard(string[,] boardState)
{
GameBoard.Children.Clear(); // Clear previous state

for (int row = 0; row < 8; row++)
{
for (int column = 0; column < 8; column++)
{
var tile = new Border
{
Background = (row + column) % 2 == 0 ? Brushes.White : Brushes.Black, // Checkerboard pattern
BorderBrush = Brushes.Gray,
BorderThickness = new Thickness(1)
};

if (boardState[row, column] == "W")
{
tile.Child = new Ellipse
{
Fill = Brushes.White,
Width = 40,
Height = 40,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
}
else if (boardState[row, column] == "B")
{
tile.Child = new Ellipse
{
Fill = Brushes.Black,
Width = 40,
Height = 40,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
}

Grid.SetRow(tile, row);
Grid.SetColumn(tile, column);
GameBoard.Children.Add(tile);
}
}
}
}
}
// Update the visual state of the board (e.g., draw pieces)
public void UpdateBoard(string[,] boardState)
{
GameBoard.Children.Clear(); // Clear previous state

for (int row = 0; row < 8; row++)
{
for (int column = 0; column < 8; column++)
{
var tile = new Border
{
Background = (row + column) % 2 == 0 ? Brushes.White : Brushes.Black, // Checkerboard pattern
BorderBrush = Brushes.Gray,
BorderThickness = new Thickness(1)
};

if (boardState[row, column] == "W")
{
tile.Child = new Ellipse
{
Fill = Brushes.White,
Width = 40,
Height = 40,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
}
else if (boardState[row, column] == "B")
{
tile.Child = new Ellipse
{
Fill = Brushes.Black,
Width = 40,
Height = 40,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
}

Grid.SetRow(tile, row);
Grid.SetColumn(tile, column);
GameBoard.Children.Add(tile);
}
}
}
}
}
Do you make any sense of it? 😭 It seems to react to button clicks and updating the grid accordingly
Sehra
Sehraβ€’2w ago
somewhat, you have an event called TileClicked that can notify any subscribers when a row,col is clicked
Merineth πŸ‡ΈπŸ‡ͺ
Yeah seems like it the problem however is that when the Startgame() function is called the tiles don't come up? or the window rather?
Sehra
Sehraβ€’2w ago
see if something calls UpdateBoard, or if you have to do it. it expect a string[8,8] with B/W specified (or nothing if no tile is there)
Merineth πŸ‡ΈπŸ‡ͺ
Where should i check if it calls UpodateBoard There is no call to UpdateBoard within my GameWindow at least
Sehra
Sehraβ€’2w ago
you can right click it and select 'find all references'
Merineth πŸ‡ΈπŸ‡ͺ
"no references found" So we aren't actually using it yet I might imagine that the grid isn't instanciated either
Sehra
Sehraβ€’2w ago
would be easier if you put all the code on github
Merineth πŸ‡ΈπŸ‡ͺ
Okii one moment I'm not too familiar with github yet I have my own branch i'm working it right now How would i share it? https://github.com/aljomatrix/Assignment2Repository.git like so maybe? I'm not sure what's safe or not to share online
Sehra
Sehraβ€’2w ago
it's only a main branch, you need to push your branch
Merineth πŸ‡ΈπŸ‡ͺ
Ok i think i did it It's weird because when i start the game and it goes to the StartGame() method i loops through the while(Board.GameOver() == false) over and over but the actual game doesn't show in the background if that makes sense?
Sehra
Sehraβ€’2w ago
you need to hook up the GameGrid to show the board state. try and get github working https://github.com/aljomatrix/Assignment2 only one branch here, no code
Merineth πŸ‡ΈπŸ‡ͺ
Yeah sorry it might have something to do with privacy that is the wrong repo also It's called Assignment2repository
Merineth πŸ‡ΈπŸ‡ͺ
If i change this to public are you able to change it? Or just view it
Sehra
Sehraβ€’2w ago
only view
Merineth πŸ‡ΈπŸ‡ͺ
Ok it's visible now https://github.com/aljomatrix/Assignment2Repository I'm working on mainbranch
Sehra
Sehraβ€’2w ago
ok, so you probably want to make Board in GameManager accessible, then you can read BoardState from it it returns Disc[,] so change GameGrid.UpdateBoard to that instead and compare with Disk.White/Black instead of the string W/B
Merineth πŸ‡ΈπŸ‡ͺ
Hmm okay. What do you mean by make "Board in GameManager accessible"?
Sehra
Sehraβ€’2w ago
make it a property or mark it public
Merineth πŸ‡ΈπŸ‡ͺ
When you say board, do you mean grid? make GameGrid accessible in GameManager?
Sehra
Sehraβ€’2w ago
field GameManager.Board
Merineth πŸ‡ΈπŸ‡ͺ
ooooh you mean this field?
Sehra
Sehraβ€’2w ago
yes
Merineth πŸ‡ΈπŸ‡ͺ
oki so if i assign that as public
internal class GameManager
{
public GameBoard Board;
Player Player1;
Player Player2;
Player CurrentPlayer;
internal class GameManager
{
public GameBoard Board;
Player Player1;
Player Player2;
Player CurrentPlayer;
Sehra
Sehraβ€’2w ago
it's generally better to make it a property public GameBoard Board { get; private set; } but that will work
Merineth πŸ‡ΈπŸ‡ͺ
I see it seems like the startgame while loop is looping endlessly or actually (int x, int y) tempMove = CurrentPlayer.RequestMove(Board, ValidMoves); it gets to this line here and waits for input from user but there is no board or grid displayed
Sehra
Sehraβ€’2w ago
you copied the computer player logic to the human player, so it will not wait for input, only sleep two seconds
Merineth πŸ‡ΈπŸ‡ͺ
oooooooooooh
Sehra
Sehraβ€’2w ago
so it will player computer vs computer (with just random moves)
Merineth πŸ‡ΈπŸ‡ͺ
yeah i totally get what you mean so i have to implement the HumanPlayer.cs
Sehra
Sehraβ€’2w ago
yes, but to get the display working first so you can see them play
Merineth πŸ‡ΈπŸ‡ͺ
yeah hmm
Sehra
Sehraβ€’2w ago
so GameGrid.UpdateBoard can be changed to take Disk[,] instead
Merineth πŸ‡ΈπŸ‡ͺ
what type is Disc? enum?
Sehra
Sehraβ€’2w ago
Disk, under models you need to change GameWindow.xaml to include a GameGrid not sure what's easiest, but maybe change GameManager.StartGame to take the GameGrid as argument, and last in the game loop call UpdateBoard(Board.BoardState), then you don't need to make GameManager.Board public anymore
Merineth πŸ‡ΈπŸ‡ͺ
Hmm that seems very complicated yeah i shouldn't have tried i completely fucked it
Sehra
Sehraβ€’2w ago
that's what git it for, you can commit and go back
Merineth πŸ‡ΈπŸ‡ͺ
how do i go back?
Merineth πŸ‡ΈπŸ‡ͺ
i went back to all my changes
Merineth πŸ‡ΈπŸ‡ͺ
but still have 5 errors now
Sehra
Sehraβ€’2w ago
you did something with GameGrid.xaml, there should be a GameBoard there
Merineth πŸ‡ΈπŸ‡ͺ
I can't undo anything there

<UserControl x:Class="Assignment2.View.GameGrid"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="400" d:DesignWidth="400">
<Grid>
<!-- Dynamically generate game tiles -->
<Grid Name="GameBoard" Background="LightGray" MouseDown="GameBoard_MouseDown">
<!-- Define rows and columns for the grid -->
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
</Grid>
</Grid>
</UserControl>

<UserControl x:Class="Assignment2.View.GameGrid"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="400" d:DesignWidth="400">
<Grid>
<!-- Dynamically generate game tiles -->
<Grid Name="GameBoard" Background="LightGray" MouseDown="GameBoard_MouseDown">
<!-- Define rows and columns for the grid -->
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
</Grid>
</Grid>
</UserControl>
' it does have GameBoard?
Sehra
Sehraβ€’2w ago
the <Grid Name="GameBoard"... should declare GameBoard that is used in xaml.cs
Merineth πŸ‡ΈπŸ‡ͺ
so i add private GameManager gameManager; private GameGrid gameGrid; into my GameWindow.xaml.cs ? ok adding those two seems to have solved it So now to the original problem I want to grid to be displayed on the GameWindow?
Sehra
Sehraβ€’2w ago
yeah, it's commented in the xaml
Merineth πŸ‡ΈπŸ‡ͺ
i'm totally lost i have 5 errors I haven't even changed anythiung
Sehra
Sehraβ€’2w ago
try a rebuild
Merineth πŸ‡ΈπŸ‡ͺ
Yeah i did :( and it's still the same i'm able to run the program up until i enter the player 1 and player 2 as computer
Sehra
Sehraβ€’2w ago
have you updated visual studio? seems to be a bug fixed in november
Merineth πŸ‡ΈπŸ‡ͺ
It doesn't update automatically ?
Sehra
Sehraβ€’2w ago
no (unless you tell it to)
Merineth πŸ‡ΈπŸ‡ͺ
oh Will update it, one moment ok it fixed now! ok no when i try to run i get the 5 errors back
Sehra
Sehraβ€’2w ago
maybe the generated files are in a weird state. exit vs, delete the bin and obj folders and try again
Merineth πŸ‡ΈπŸ‡ͺ
I'm trying to go back but i have no idea what's wrong my entire gamegrid is completely ruined Severity Code Description Project File Line Suppression State Error (active) CS0103 The name 'GameBoard' does not exist in the current context Assignment2 C:\Users\aljom\Documents\Plugg Programmering filer\OOP\Assignment2\Assignment2Repository\Assignment2\Assignment2\View\GameGrid.xaml.cs 27
Sehra
Sehraβ€’2w ago
yes i see it, but that field/property should be generated automatically from the xaml. i don't do ui programming so not really sure what could be wrong
Merineth πŸ‡ΈπŸ‡ͺ
ok i fixed it So the main problem now is that the board isn't showing for the two computers playing I have unironically zero clue how that is fixed grid should be applied onto gamewindow?
Sehra
Sehraβ€’2w ago
did you add GameGrid to GameWindow?
Merineth πŸ‡ΈπŸ‡ͺ
Most likely not Completely honestly i have no idea how to apply the game grid onto the gamewindow That is way to advanced for me :I
Sehra
Sehraβ€’2w ago
you add it as any other control, it the xaml it says <!-- You can add a GameGrid control or just a placeholder grid here -->
Merineth πŸ‡ΈπŸ‡ͺ
oh ok i found that line of code in gamewinddow.xaml
<local:GameGrid Name="GameGridControl" />
<local:GameGrid Name="GameGridControl" />
like so? like im losing it every line of code i change i get 100 errors
Sehra
Sehraβ€’2w ago
that's just software development, you get better with experience
Merineth πŸ‡ΈπŸ‡ͺ
ok i think i did it after some suffering
Merineth πŸ‡ΈπŸ‡ͺ
Severity Code Description Project File Line Suppression State Error XLS0513 Because 'GameGrid' is implemented in the same assembly, you must set the x:Name attribute rather than the Name attribute. Assignment2 C:\Users\aljom\Documents\Plugg Programmering filer\OOP\Assignment2\Assignment2Repository\Assignment2\Assignment2\View\GameWindow.xaml 24
Sehra
Sehraβ€’2w ago
i think you can figure that one out
Merineth πŸ‡ΈπŸ‡ͺ
yeah i just did hehe x:name
Merineth πŸ‡ΈπŸ‡ͺ
i think i managed to apply the gamegrid onto gamewindow however when i run the program it's still blank
Sehra
Sehraβ€’2w ago
yes, you need to make it update now did you change GameGrid.UpdateBoard to take Disk[,] instead?
Merineth πŸ‡ΈπŸ‡ͺ
public void UpdateBoard(string[,] boardState)
public void UpdateBoard(string[,] boardState)
i don't thnk so
Sehra
Sehraβ€’2w ago
and change the comparison with "B"/"W" to Disk.Black/Disk.White. makes it easier
Merineth πŸ‡ΈπŸ‡ͺ
Ok i think i managed to do that
public void UpdateBoard(Disk[,] boardState)
{
GameBoard.Children.Clear(); // Clear previous state

for (int row = 0; row < 8; row++)
{
for (int column = 0; column < 8; column++)
{
var tile = new Border
{
Background = (row + column) % 2 == 0 ? Brushes.White : Brushes.Black, // Checkerboard pattern
BorderBrush = Brushes.Gray,
BorderThickness = new Thickness(1)
};

if (boardState[row, column] == Disk.White)
{
tile.Child = new Ellipse
{
Fill = Brushes.White,
Width = 40,
Height = 40,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
}
else if (boardState[row, column] == Disk.Black)
{
tile.Child = new Ellipse
{
Fill = Brushes.Black,
Width = 40,
Height = 40,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
}

Grid.SetRow(tile, row);
Grid.SetColumn(tile, column);
GameBoard.Children.Add(tile);
}
}
}
}
}
public void UpdateBoard(Disk[,] boardState)
{
GameBoard.Children.Clear(); // Clear previous state

for (int row = 0; row < 8; row++)
{
for (int column = 0; column < 8; column++)
{
var tile = new Border
{
Background = (row + column) % 2 == 0 ? Brushes.White : Brushes.Black, // Checkerboard pattern
BorderBrush = Brushes.Gray,
BorderThickness = new Thickness(1)
};

if (boardState[row, column] == Disk.White)
{
tile.Child = new Ellipse
{
Fill = Brushes.White,
Width = 40,
Height = 40,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
}
else if (boardState[row, column] == Disk.Black)
{
tile.Child = new Ellipse
{
Fill = Brushes.Black,
Width = 40,
Height = 40,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
}

Grid.SetRow(tile, row);
Grid.SetColumn(tile, column);
GameBoard.Children.Add(tile);
}
}
}
}
}
Sehra
Sehraβ€’2w ago
change GameManager.StartGame to take a GameGrid as argument, in MainGameWindow.xaml.cs send in the GameGridControl you added then in StartGame, add gameGrid.UpdateBoard(Board.BoardState) when you want to update. i suggest at the start of StartGame and before the while loop ends
Merineth πŸ‡ΈπŸ‡ͺ
MainWindow?
Sehra
Sehraβ€’2w ago
GameWindow
Merineth πŸ‡ΈπŸ‡ͺ
Ok i thnk i managed to do it i tried running but got runtime error
Merineth πŸ‡ΈπŸ‡ͺ
public void StartGame(GameGrid grid) game.StartGame(gameGrid);
public void StartGame(GameGrid grid)
{
grid.UpdateBoard(Board.BoardState);
while (Board.GameOver() == false)
{
if(Board.hasValidMoves(CurrentPlayer.Disk))
{
//Creating a list of valid moves for the curent player
List<(int x, int y)> ValidMoves = Board.GetValidMoves(CurrentPlayer.Disk);

(int x, int y) tempMove = CurrentPlayer.RequestMove(Board, ValidMoves);

//Making sure that a valid move is chose, if not a new move is requested until it is valid
while (Board.IsValidMove(tempMove.x, tempMove.y, CurrentPlayer.Disk) == false)
{
tempMove = CurrentPlayer.RequestMove(Board, ValidMoves);
}

(int x, int y) chosenMove = tempMove;

Board.ExecuteMove(chosenMove.x, chosenMove.y, CurrentPlayer.Disk);

switchPlayer();
}
else
{
//If the curent player has no valid moves, it becomes the next players turn
switchPlayer();
}
grid.UpdateBoard(Board.BoardState);
}
if (Board.DiskCount(Player1.Disk) == Board.DiskCount(Player2.Disk))
{
//what to do here

}
}
private void switchPlayer()
{
CurrentPlayer = (CurrentPlayer == Player1) ? Player2 : Player1;
}


}
}
public void StartGame(GameGrid grid)
{
grid.UpdateBoard(Board.BoardState);
while (Board.GameOver() == false)
{
if(Board.hasValidMoves(CurrentPlayer.Disk))
{
//Creating a list of valid moves for the curent player
List<(int x, int y)> ValidMoves = Board.GetValidMoves(CurrentPlayer.Disk);

(int x, int y) tempMove = CurrentPlayer.RequestMove(Board, ValidMoves);

//Making sure that a valid move is chose, if not a new move is requested until it is valid
while (Board.IsValidMove(tempMove.x, tempMove.y, CurrentPlayer.Disk) == false)
{
tempMove = CurrentPlayer.RequestMove(Board, ValidMoves);
}

(int x, int y) chosenMove = tempMove;

Board.ExecuteMove(chosenMove.x, chosenMove.y, CurrentPlayer.Disk);

switchPlayer();
}
else
{
//If the curent player has no valid moves, it becomes the next players turn
switchPlayer();
}
grid.UpdateBoard(Board.BoardState);
}
if (Board.DiskCount(Player1.Disk) == Board.DiskCount(Player2.Disk))
{
//what to do here

}
}
private void switchPlayer()
{
CurrentPlayer = (CurrentPlayer == Player1) ? Player2 : Player1;
}


}
}
Sehra
Sehraβ€’2w ago
where does gameGrid come from? it should be the grid control you added
Merineth πŸ‡ΈπŸ‡ͺ
Added it before the loop and at the end of it
Sehra
Sehraβ€’2w ago
in GameWindow.xaml.cs
Merineth πŸ‡ΈπŸ‡ͺ
at the start i think public partial class GameWindow : Window { private GameManager gameManager; private GameGrid gameGrid;
Sehra
Sehraβ€’2w ago
delete that gameGrid and use GameGridControl, the name you gave it in xaml
Merineth πŸ‡ΈπŸ‡ͺ
Oh ok so i remove that entire line private GameGrid gameGrid;
Sehra
Sehraβ€’2w ago
will make a property named GameGridControl, which is the actual control in the window so you can interact with it
No description
Merineth πŸ‡ΈπŸ‡ͺ
oooh so we pass "GameGridControl" from the .xaml
game.StartGame(GameGridControl);
game.StartGame(GameGridControl);
Sehra
Sehraβ€’2w ago
yes, and you later send in the current board state and ask it to update with that information
Merineth πŸ‡ΈπŸ‡ͺ
i see that's smart
Sehra
Sehraβ€’2w ago
there is probably better ways to do it, but observable collections and data binding might not be in this level of class
Merineth πŸ‡ΈπŸ‡ͺ
that's odd, is exactly the same? even after it updates i even put a breakpoint to make sure that it reaches the update of the board
Sehra
Sehraβ€’2w ago
same? no exception now
Merineth πŸ‡ΈπŸ‡ͺ
ah yeah sorry exception is solved <3
Sehra
Sehraβ€’2w ago
does it play computer vs computer?
Merineth πŸ‡ΈπŸ‡ͺ
Noo
Merineth πŸ‡ΈπŸ‡ͺ
neither the score or board shows
Sehra
Sehraβ€’2w ago
guessing that wpf will not update the ui until the click handler is complete
Merineth πŸ‡ΈπŸ‡ͺ
yeah that makes sense (int x, int y) tempMove = CurrentPlayer.RequestMove(Board, ValidMoves); you mean this line right? So the next step is to fix human player so it can be triggered? or am i mistaken it's a little late I'm super grateful for the help so far tho I'll be continuing tomorrow, i hope you'll be on
Sehra
Sehraβ€’2w ago
the click handler is the whole private void NewGameButton_Click(object sender, RoutedEventArgs e) i'm likely on tomorrow
Merineth πŸ‡ΈπŸ‡ͺ
Thanks Sehra, you are literally my saviour
Sehra
Sehraβ€’2w ago
don't forget to commit and push to github
Merineth πŸ‡ΈπŸ‡ͺ
:aaaa:
Merineth πŸ‡ΈπŸ‡ͺ
@Sehra Going through it now and it is in fact updating moves that it's doing based on tempMove. However nothing is visually showing on the GameWindow or GameGrid. By any chance do you know why?
No description
Merineth πŸ‡ΈπŸ‡ͺ
It is in fact going through the game jbut it's not showing it in my gamewindow.. Truthfully i have no idea what i'm supposed to do πŸ˜” anyone? I'm on my hands and knees begging 😭

Did you find this page helpful?