Tsjech
Tsjech
CC#
Created by Tsjech on 2/4/2024 in #help
Bitmap PixelFormat causing OutOfMemoryException
When I add a size to Bitmap bmp setting the label.Image throws an OutOfMemoryException, but not when I remove the size to Bitmap bmp Does anyone know what I have to do to fix this?
private void PromotePiece(Move move)
{
Bitmap bmp = new Bitmap(PiecesImage, boxSize, boxSize);

if (move.PromotedPiece is Knight) {
Label promotionKnigt = new Label();
promotionKnigt.Location = new Point(move.Location.X * boxSize + boxSize / 2, move.Location.Y * boxSize);
promotionKnigt.Size = new Size(boxSize, boxSize);
promotionKnigt.Image = bmp.Clone(move.PromotedPiece.PieceOfImage, bmp.PixelFormat);
promotionKnigt.Click += PromoteToKnight;
this.Controls.Add(promotionKnigt);
} else {
Label promotionQueen = new Label();
promotionQueen.Location = new Point(move.Location.X * boxSize + boxSize / 2, (move.Location.Y + 1) * boxSize);
promotionQueen.Size = new Size(boxSize, boxSize);
promotionQueen.Image = bmp.Clone(move.PromotedPiece.PieceOfImage, bmp.PixelFormat);
promotionQueen.Click += PromoteToQueen;
this.Controls.Add(promotionQueen);
}
}
private void PromotePiece(Move move)
{
Bitmap bmp = new Bitmap(PiecesImage, boxSize, boxSize);

if (move.PromotedPiece is Knight) {
Label promotionKnigt = new Label();
promotionKnigt.Location = new Point(move.Location.X * boxSize + boxSize / 2, move.Location.Y * boxSize);
promotionKnigt.Size = new Size(boxSize, boxSize);
promotionKnigt.Image = bmp.Clone(move.PromotedPiece.PieceOfImage, bmp.PixelFormat);
promotionKnigt.Click += PromoteToKnight;
this.Controls.Add(promotionKnigt);
} else {
Label promotionQueen = new Label();
promotionQueen.Location = new Point(move.Location.X * boxSize + boxSize / 2, (move.Location.Y + 1) * boxSize);
promotionQueen.Size = new Size(boxSize, boxSize);
promotionQueen.Image = bmp.Clone(move.PromotedPiece.PieceOfImage, bmp.PixelFormat);
promotionQueen.Click += PromoteToQueen;
this.Controls.Add(promotionQueen);
}
}
6 replies
CC#
Created by Tsjech on 1/17/2024 in #help
Recursive method and memory problems
I am implementing the DFS algorithm and I am keeping track of what routes have been passed and their value, the core of the algorithm looks like this:
private void DFSVisitting(Planet current, Planet old, bool[] visited, int len)
{
int length;
length = len;
visited[current.id] = true;
if (!(current == old)) {
foreach (Route route in gameScreen.board.routes) {
if (!(route.color == color && route.built)) continue;
if ((route.planet1 == current && route.planet2 == old) || (route.planet2 == current && route.planet1 == old)) length += route.costs;
}
}

List<Planet> neighbours = adjacent[current.id];
foreach (Planet p in neighbours) {
if (!visited[p.id]) {
DFSVisitting(p, current, visited, length);
// returns here
lengths.Add(length);
length = 0;
}
}
lengths.Add(length);
}
private void DFSVisitting(Planet current, Planet old, bool[] visited, int len)
{
int length;
length = len;
visited[current.id] = true;
if (!(current == old)) {
foreach (Route route in gameScreen.board.routes) {
if (!(route.color == color && route.built)) continue;
if ((route.planet1 == current && route.planet2 == old) || (route.planet2 == current && route.planet1 == old)) length += route.costs;
}
}

List<Planet> neighbours = adjacent[current.id];
foreach (Planet p in neighbours) {
if (!visited[p.id]) {
DFSVisitting(p, current, visited, length);
// returns here
lengths.Add(length);
length = 0;
}
}
lengths.Add(length);
}
the problem is, if the network is searching down a path and ends in a dead at the function returns at the place of my comment, but the length variable has been forgotten by the program (atleast what i think) because this method has been called multiple times already and is now returning to an older instance of itself. So is there any way to surpass this issue? Nodes are planets and Edges are Routes.
24 replies
CC#
Created by Tsjech on 10/16/2023 in #help
❔ Need help adding a label from a child class to the screen that exists in the parent class
So im coding a board game and the board is its own class, now when the game ends I would like to show that by adding a label with some text to the screen, yet this label exists in the parent class because it takes up more of the screen than just the gameboard (which isnt the entire screen). Is there any way I can show this label only when the game ends (which is checked in the board class)? (please ask me more questions if needed this explaination is far from good :) )
242 replies
CC#
Created by Tsjech on 9/29/2023 in #help
✅ PaintEventArgs and Graphics
No description
46 replies