@kainui @nincompoop
http://pastebin.com/5xvsFbvk When a tile is clicked, the image of the tile changes to a transparent green, to show the user that the tile has been clicked. Changing the other tiles with the transparent green on them back to normal erases the string drawn on them, so it must be re-drawn. Attached here is what it should look like when the user clicks on another tile. The first tile clicked is the one under the green one.
aaaaaaaaaaand attached here is what actually happens.
The piece disappears from the tile it's supposed to be drawn on, and is drawn on the tile that is clicked, even though the clicked tile doesn't have a piece on it to draw.
I'm confused, your code looks like it is doing the same exact thing twice?
yeah I know I'm really bad at being efficient with coding. However, it's /almost/ the exact same thing. The "greentile" variable stores the last tile that was made green. Its only purpose is to make it easier to take the green off of the last tile, rather than looping through all of the tiles to check for the only one that's green and then reset it. What the code is supposed to do is reset the image property so that the last tile is no longer green, and then assign the newly-clicked tile to greentile, and then make the newly-clicked tile green. However, resetting the last tile clears the string that's drawn from it (if there's a piece on it), so I'm re-drawing if before I re-assign greentile. Then, when the new tile is made green, that also clears the string drawn on it (again, if there is a piece on it), so I'm re-drawing the string onto it. I have no idea what's causing the error though.
also @wio
Which part of the code are we dealing with?
the whole thing, really.
the DrawString (and probably the re-assigning of the greentile variable) are causing problems.
Sidenote: Why can't the Piece class store the text for the unicode character?
not a terrible idea I reckon
^+1
I'm not sure how 'getpiece' works
wio i was thinking he's modifying the same underlying object so when he redraws his other piece, the greentile also ends up getting that piece drawn on it, but cant test the theory without an ide set up over here
In my opinion, pieces should not know about tiles, but tiles should know about pieces. Tile's should have a piece member, and it should be null when empty.
FIXED IT ``` private void newtile_click(object sender, EventArgs e) { Tile t = (Tile)sender; MessageBox.Show(t.x.ToString() + ", " + t.y.ToString()); t.Image = Chess.Properties.Resources.green; if (greentile != null) { greentile.Image = null; Piece p1 = getpiece(greentile); if (p1 != null) { drawpiece(t, p1.GetString()); } } Piece p = getpiece(t); Tile lasttile = greentile; greentile = t; t.Refresh(); if (lasttile != null) { lasttile.Refresh(); drawpiece(lasttile, getpiece(lasttile).GetString()); } p = getpiece(t); if (p != null) { drawpiece(t, p.GetString()); } } ```
Not sure why it was drawing the piece on the tile in the first place, but when I was debugging and set breakpoints and whatnot, no piece was returned for the new tile, so refreshing the new tile got rid of the incorrectly drawn piece. It looks like I just needed to add another variable to refresh and re-draw on the old tile after greentile was re-assigned.
I see.
But I don't think you should be calling draw piece so many times.
Yeah probably not. Gonna take the first one out and see what happens.
And it shouldn't be a problem to just redraw the entire board after an update.
That's how I did it when I did it in vb, and it made the whole thing lag a few seconds while everything was being re-drawn, and there was a good bit of flickering there too.
How can it have trouble redrawing a checkerboard? It should take fractions of a second
it was going through every tile, refreshing, drawing a circle, filling a circle, drawing a string on it, and possibly changing its image.
no idea how it was having problems doing that, but it was.
Keeping track of when a piece needs to be redrawn or not sounds like hell.
There is no excuse. It should be easy to redraw the board in fractions of a second.
it only needs to be re-drawn when it is moved, or when its tile's image is changed
btw, I'm planning on putting the pathing method in the piece class, which is why I'm storing tile inside of piece rather than piece inside of tile.
Hmmm, I think it only makes sense for Tile to have a piece, and not vise versa
I tile draws itself, and if you want the piece to take care of drawing itself, then you can have the title pass its offsets to the piece.
Well, the piece isn't a control or anything, it's more of just data. The only physical representation of Piece on the form is when DrawPiece is called.
This is just my coder's intuition telling me that pieces needing to know about their tile will lead to future problems.
yo are you still alive because I have another question
What is it?
actually wait nvm I think I got it. Apparently I can't use a number in a variable name with var blah = list.where()~
Join our real-time social learning platform and learn together with your friends!