• Advertisement
Sign in to follow this  

Simple projects? (C#)

This topic is 2213 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone, been a while since I was here but I want to get back into C# so I need some tasks/small projects that will allow me learn the basics again, and let me learn new things too.

Does anyone have any ideas please?

Thanks, melloorr.

Share this post


Link to post
Share on other sites
Advertisement
That was the first project for the C# workshop. For about four or five weeks worth of lessons and a lot of people new to C# before the workshop managed to complete working programs. So yes, basic C# should be enough.

I will admit it probably looks a lot more intimidating because during one or other of the forum upgrades line breaks got stripped out of the post so you've got huge walls of text where it was broken up before.

Share this post


Link to post
Share on other sites
Yeah it is pretty hard to read to be honest, but I will at least attempt it, and if I cannot do it, I will go through some of the lessons then attempt it again.

Share this post


Link to post
Share on other sites
@SiCrane, I don't suppose you or any other mods can edit the post please?
If I take my eyes away for a second, I have to spend 5 mins trying to find where I was up to.

Thanks

Share this post


Link to post
Share on other sites
Actually, clicking on the edit button not only strips out line breaks but also manages to strip out spaces. I'm almost positive that I'd do more damage than help if I tried editing the actual post. As an alternative, you could try cutting and pasting the post contents into a Word document (or whatever your favorite rich text editor is) and adding line breaks manually to that.

Share this post


Link to post
Share on other sites
Hidden
I've edited it. Do you want me to PM it to you? So you can update the post (or not). I can post if here first if you like

Share this post


Link to post
Okay I'm not getting this. I cannot do it.

I just can't work out how to get one variable to another, method, class. I have the book Pro C# 2010, but it hardly has any information on it (despite the size of the it).

Are there any tutorials that can get me used to working with multiple classes, and methods?

Share this post


Link to post
Share on other sites
Could you show an example of what you're having trouble with? I'm not entirely sure what you're asking.

Share this post


Link to post
Share on other sites
Well, looking at some of their answers to the project, they have classes withint width in them, but I do not know how to get int width, into a different class to use it with that class also.

Share this post


Link to post
Share on other sites
To access a member of a class instance you just use the . operator on that instance. So if you have a class Maze with a int member variable named width and you had a Maze instance named maze you could just use maze.width to get the width value for that particular maze.

Share this post


Link to post
Share on other sites
Hmm, still not quite getting it. I think I will do some more reading up on it, then maybe try a text based game first, then attempt that again.

Thanks for the help

Share this post


Link to post
Share on other sites
I would still like to help you get this point. Can you show a more complete example of what you're trying to do?

Share this post


Link to post
Share on other sites

I would still like to help you get this point. Can you show a more complete example of what you're trying to do?


This is the code that I currently have (not much):

using System;
class MazeGenerator
{
static void Main()
{

Console.Title = "Welcome to the Random Maze Generator for C#";
Console.WriteLine("Welcome to the Random Maze Generator for C#");
Console.WriteLine("Please press Enter to continue to the Generator");
MazeQuery();

Console.ReadLine();
}
static void MazeQuery()
{
int mazeWidth, mazeHeight, wall, numberOfRooms;
do
{
Console.Write("Please enter the number of columns: ");
mazeWidth = int.Parse(Console.ReadLine());
} while (mazeWidth < 2 || mazeWidth > 50);
do
{
Console.Write("Please enter the number of rows: ");
mazeHeight = int.Parse(Console.ReadLine());
} while (mazeHeight < 2 || mazeHeight > 50);
numberOfRooms = mazeWidth * mazeHeight;

wall = numberOfRooms * 2 - (mazeWidth + mazeHeight);
Console.ReadLine();
}
}


I don't know how to get numberOfRooms or wall to a new method or class to calculate what walls I have to knock down.

Share this post


Link to post
Share on other sites
Perhaps if you see a code example you'll be able to put things together a little better.

Suppose you have the following:



public class Maze
{
public int width;
}


Then the following code does the following: creates an instance of Maze and calls it myMaze, creates a variable called newWidth with value 32, and writes newWidth into the width variable of the Maze class instance (myMaze)


public class Maze
{
public int width;
}

public class Main
{
public static void Main(string[] arguments)
{
Maze myMaze = new Maze();
int newWidth = 32;
myMaze.width = newWidth;
}
}


If you want to save the width variable into something else, say, the newWidth variable, you can do it like so:



public class Maze
{
public int width;
}

public class Main
{
public static void Main(string[] arguments)
{
Maze myMaze = new Maze();
int newWidth = myMaze.width;
}
}


EDIT: you can create a Maze instance in Main() and pass it as an argument to the mazeQuery() function where you can save the data into its members.

Share this post


Link to post
Share on other sites
In this case you'd use a function parameter. So if you had

static void SomeFunction(int rooms) {
// stuff
}

You could call it in MazeQuery() like:

SomeFunction(numberOfRooms);

Share this post


Link to post
Share on other sites
I get it now, and if I wanted to get something from a class, I could also use something like this:

using System;
class SimpleClass
{
public static void Main()
{
Console.WriteLine(ThatClass.yes);
Console.ReadLine();
}
}
class ThatClass
{
public static int yes = 10;
}

Share this post


Link to post
Share on other sites
That's correct. Since variable yes is static, you have no need to instantiate the class ThatClass before using it, you can just call it directly like you have above.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement