Jump to content

  • Log In with Google      Sign In   
  • Create Account

Simple projects? (C#)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
17 replies to this topic

#1 melloorr   Members   -  Reputation: 100

Like
0Likes
Like

Posted 30 December 2011 - 08:52 AM

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.

Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9598

Like
1Likes
Like

Posted 30 December 2011 - 09:01 AM

One fun relatively simple project I enjoyed was the maze generator project from the C# Workshop.

#3 melloorr   Members   -  Reputation: 100

Like
0Likes
Like

Posted 30 December 2011 - 09:06 AM

One fun relatively simple project I enjoyed was the maze generator project from the C# Workshop.

Wow, looks pretty complicated to be honest, should take me a few months to do Posted Image

Would basic C# be enough for me to do it?

#4 SiCrane   Moderators   -  Reputation: 9598

Like
0Likes
Like

Posted 30 December 2011 - 09:14 AM

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.

#5 melloorr   Members   -  Reputation: 100

Like
0Likes
Like

Posted 30 December 2011 - 09:19 AM

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.

#6 melloorr   Members   -  Reputation: 100

Like
0Likes
Like

Posted 30 December 2011 - 10:24 AM

@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

#7 SiCrane   Moderators   -  Reputation: 9598

Like
0Likes
Like

Posted 30 December 2011 - 10:38 AM

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.

#8 melloorr   Members   -  Reputation: 100

Like
0Likes
Like

Posted 31 December 2011 - 11:13 AM

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?

#9 SiCrane   Moderators   -  Reputation: 9598

Like
0Likes
Like

Posted 31 December 2011 - 11:19 AM

Could you show an example of what you're having trouble with? I'm not entirely sure what you're asking.

#10 melloorr   Members   -  Reputation: 100

Like
0Likes
Like

Posted 31 December 2011 - 11:25 AM

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

#11 SiCrane   Moderators   -  Reputation: 9598

Like
0Likes
Like

Posted 31 December 2011 - 11:29 AM

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.

#12 melloorr   Members   -  Reputation: 100

Like
0Likes
Like

Posted 31 December 2011 - 11:37 AM

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

#13 SiCrane   Moderators   -  Reputation: 9598

Like
1Likes
Like

Posted 31 December 2011 - 11:51 AM

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

#14 melloorr   Members   -  Reputation: 100

Like
0Likes
Like

Posted 31 December 2011 - 12:02 PM

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.

#15 boogyman19946   Members   -  Reputation: 1063

Like
0Likes
Like

Posted 31 December 2011 - 12:09 PM

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.
"If highly skilled generalists are rare, though, then highly skilled innovators are priceless." - ApochPiQ

My personal links :)
- Khan Academy - For all your math needs
- Java API Documentation - For all your Java info needs :D
- C++ Standard Library Reference - For some of your C++ needs ^.^

#16 SiCrane   Moderators   -  Reputation: 9598

Like
0Likes
Like

Posted 31 December 2011 - 12:11 PM

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);


#17 melloorr   Members   -  Reputation: 100

Like
0Likes
Like

Posted 31 December 2011 - 09:41 PM

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;
}


#18 boogyman19946   Members   -  Reputation: 1063

Like
0Likes
Like

Posted 01 January 2012 - 04:39 AM

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.
"If highly skilled generalists are rare, though, then highly skilled innovators are priceless." - ApochPiQ

My personal links :)
- Khan Academy - For all your math needs
- Java API Documentation - For all your Java info needs :D
- C++ Standard Library Reference - For some of your C++ needs ^.^




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS