C
C#16mo ago
luness

❔ The method startgame() is buggy, replace it with a constructor that takes size as parameter

Hi, i got this message from my teacher: "The StartGame() method in Board is buggy. I suggest to replace it with a constructor for the class Board which takes the parameter Size as input. The in the Main function you can just create an instance of a given size without asking to the player." However I dont know what he means by that, down below i've listed my two classes that he wants me to make the changes in. And i have also made some changes and marked it with //changed... I appreciate any help! https://pastebin.com/spGSB32Z - My board class https://pastebin.com/xBZARHM9 - my main class
Pastebin
using System;using System.Collections.Generic;using System.Drawing;...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin
using System;using System.Linq;using N_Puzzle;class Program{ - Past...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
7 Replies
Doombox
Doombox16mo ago
public class Board
{
private readonly int _size;
public Board(int size)
{
_size = size;
}
}
public class Board
{
private readonly int _size;
public Board(int size)
{
_size = size;
}
}
is what was being suggested the public Board() bit being the constructor then when you do new Board() you actually pass in the size via new Board(10); or whatever size you want he doesn't want you asking the player to decide the size of the board it seems like you have a LOT of empty lines, which makes it much harder to read though that just might be pastebin
luness
luness16mo ago
So where it says public tile[,] Tiles etc.. above that i place the one you commented ? Like this: {} public class board{private readonly int size; public Board(int size) {size = size;} } ? my bad for the lines, its just pastebin
Doombox
Doombox16mo ago
you can put the constructor/size field anywhere really, shouldn't matter
danilwhale
danilwhale16mo ago
rename your StartGame() to public Board
Doombox
Doombox16mo ago
I just recommend replacing the private property Size with a private field, and making it readonly just prevents you from accidentally changing it in your code later though really if you're in school your teacher should be teaching the things he's asking of you at least in terms of the constructor bit
luness
luness16mo ago
the code is done, I just got it back to make those small changes, but ill try to make the changes you recommended me. yeah my teacher has been talking about constructor but I've just forgot how it works thanks for help 🙂
Accord
Accord16mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.