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
Now i want to initialize the game and start it
but i just can't get it to work
Is the problem the arguments for
Startgame
??public void StartGame()
take zero argumentsok and i want it to take 3?
that is up to you really how you want it to work
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)
i tried changing it
but it doens't WOREK
you didn't specify the types
aah
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?like
it says
startgame must be static
so i change it to static
but then i get 20 errors
you already made a constructor that take two players, why not create an instance and use that?
and create two players however you do that
**
is this what you mean?
yes
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 =
like so?
I don't understandwell, you wrote the GameManager class, so must have had an idea how you wanted to interact with it
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
?
the GameManager expect two Player instances to be provided
yes
and i'm providing it
player1
and
player2
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 communicateWe 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
sounds like you should talk to the teacher about it
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
what does the Player class look like?
var player1 = new Player();
var player2 = new Player();
So i need to fix the arguments ?well, Player is abstract so it needs to be subclassed, with an implementation of RequestMove
ok i think i slightly remember abstarct
i'm guessing that you need to provide that implementation, with something that answer back with the selected move
I have no idea what the requested move is
that is something he "made"
it's called with a list of the current valid moves, and you need to answer which one to make
`
we have two classes that should derive from Player i guess?
ComputerPlayer already derive from Player, so if you check that player 2 is a computer, instantiate that instead of HumanPlayer
so we check it like this?
with an if statement
what
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
you can yes, just have a
Player player2;
above the if, assign it to either HumanPlayer or ComputerPlayer based on the test?
I don't understand that part
`
is this not what you mean?
yes, but player2 need to be declared outside the if, or it's not in scope for creating the game manager
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
Would this be what you mean?
Ok i think that is right
with arguments as needed
Hmm
So i should replace the first 2 lines of code with the last 3 lines of code?
yes, and back to
new GameManager(player1, player2)
`
So you mean something like this?
you don't need the second if
Ok! I see what you mean
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
Ahh
the implementation isn't done
no, that part you have to write. wait for a selection on the board and return it there
I took his implementation and added it there
ok so it creates an instance of a game
with player1 and player 2
and then i start the game with startgame()
I haven't written this part so gonna have to go through it
This looks like AI?
hard to say if it is ai. the last if checks if it's a draw
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
uhm, if it works i don't see why
It currently doesn't
Sorry wrong
When the game starts with Startgame()
there should be a game board that comes up
if that makes sense?
makes sense, not sure how you communicate the board state with the user interface
They have explained it as such
This is my setup game dialog
Which seems to be accurate to the description
However i guess the problem comes at GameWindow
so you need to write GameGrid which is placed in GameWindow
Yeah i think so!
GameGrid is quite complex
and i'm not entirely sure it's correct
Do you make any sense of it? π
It seems to react to button clicks
and updating the grid accordingly
somewhat, you have an event called TileClicked that can notify any subscribers when a row,col is clicked
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?
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)
Where should i check if it calls UpodateBoard
There is no call to UpdateBoard within my GameWindow at least
you can right click it and select 'find all references'
"no references found"
So we aren't actually using it yet
I might imagine that the grid isn't instanciated either
would be easier if you put all the code on github
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
it's only a main branch, you need to push your branch
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?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
Yeah sorry it might have something to do with privacy
that is the wrong repo also
It's called Assignment2repository
If i change this to public
are you able to change it?
Or just view it
only view
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
Hmm okay. What do you mean by make "Board in GameManager accessible"?
make it a property or mark it public
When you say board, do you mean grid?
make GameGrid accessible in GameManager?
field GameManager.Board
ooooh
you mean this field?
yes
oki so if i assign that as public
it's generally better to make it a property
public GameBoard Board { get; private set; }
but that will workI 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 displayedyou copied the computer player logic to the human player, so it will not wait for input, only sleep two seconds
oooooooooooh
so it will player computer vs computer (with just random moves)
yeah i totally get what you mean
so i have to implement the HumanPlayer.cs
yes, but to get the display working first so you can see them play
yeah
hmm
so GameGrid.UpdateBoard can be changed to take Disk[,] instead
what type is Disc?
enum?
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
Hmm that seems very complicated
yeah i shouldn't have tried
i completely fucked it
that's what git it for, you can commit and go back
how do i go back?
i went back to all my changes
but still have 5 errors now
you did something with GameGrid.xaml, there should be a GameBoard there
I can't undo anything there
'
it does have GameBoard?
the
<Grid Name="GameBoard"...
should declare GameBoard that is used in xaml.csso 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?yeah, it's commented in the xaml
i'm totally lost
i have 5 errors
I haven't even changed anythiung
try a rebuild
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
have you updated visual studio? seems to be a bug fixed in november
It doesn't update automatically ?
no (unless you tell it to)
oh
Will update it, one moment
ok it fixed now!
ok no
when i try to run i get the 5 errors back
maybe the generated files are in a weird state. exit vs, delete the bin and obj folders and try again
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
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
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?
did you add GameGrid to GameWindow?
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
you add it as any other control, it the xaml it says
<!-- You can add a GameGrid control or just a placeholder grid here -->
oh ok i found that line of code in gamewinddow.xaml
like so?
like im losing it
every line of code i change i get 100 errors
that's just software development, you get better with experience
ok i think i did it after some suffering
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
i think you can figure that one out
yeah i just did hehe
x:name
i think i managed to apply the gamegrid onto gamewindow
however when i run the program it's still blank
yes, you need to make it update now
did you change GameGrid.UpdateBoard to take Disk[,] instead?
i don't thnk so
and change the comparison with "B"/"W" to Disk.Black/Disk.White. makes it easier
Ok i think i managed to do that
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 endsMainWindow?
GameWindow
Ok i thnk i managed to do it
i tried running but got runtime error
public void StartGame(GameGrid grid)
game.StartGame(gameGrid);
where does gameGrid come from? it should be the grid control you added
Added it before the loop and at the end of it
in GameWindow.xaml.cs
at the start i think
public partial class GameWindow : Window
{
private GameManager gameManager;
private GameGrid gameGrid;
delete that gameGrid and use GameGridControl, the name you gave it in xaml
Oh ok so i remove that entire line
private GameGrid gameGrid;
will make a property named GameGridControl, which is the actual control in the window so you can interact with it
oooh
so we pass "GameGridControl" from the .xaml
yes, and you later send in the current board state and ask it to update with that information
i see
that's smart
there is probably better ways to do it, but observable collections and data binding might not be in this level of class
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
same? no exception now
ah yeah sorry
exception is solved <3
does it play computer vs computer?
Noo
neither the score or board shows
guessing that wpf will not update the ui until the click handler is complete
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 onthe click handler is the whole
private void NewGameButton_Click(object sender, RoutedEventArgs e)
i'm likely on tomorrowThanks Sehra, you are literally my saviour
don't forget to commit and push to github
:aaaa:
@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?Or anyone really
https://github.com/aljomatrix/Assignment2Repository
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 π