3 Replies - 204 Views - Last Post: 09 February 2013 - 08:15 AM Rate Topic: -----

#1 abbish1337  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 09-February 13

Need direction for solving a problem c#

Posted 09 February 2013 - 04:54 AM

Hello! I have a program, that should print out a string at any given coordinates with foreground and background colors on the screen. My problem I have is, Im not quite sure on how I should make the coordinates and print out the string. Should I be using a constructor that takes in the arguments for the coordinate position and the string and then create an instance of my class that takes these parameters? ive come so far:

class ColoredText
    {
        public int x, y; // koordinaterna
        public string hello;
        ConsoleColor Color;

        public ColoredText(int x, int y, string Position)
        {
            
        }
    }



What im looking for now is somebody to GUIDE me to the right direction, Im not looking for help in any other ways then that. Thanks.

This post has been edited by Skydiver: 09 February 2013 - 04:59 AM
Reason for edit:: Put code within code tags. In the future, learn to do this yourself.


Is This A Good Question/Topic? 0
  • +

Replies To: Need direction for solving a problem c#

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3177
  • View blog
  • Posts: 9,632
  • Joined: 05-May 12

Re: Need direction for solving a problem c#

Posted 09 February 2013 - 05:10 AM

Unless you are planning on doing something else with the text once it has been rendered on the console, it's probably not worth instantiating a class. It would be better to simply have a static method that takes the position, color, and text.
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 2890
  • View blog
  • Posts: 9,597
  • Joined: 12-December 12

Re: Need direction for solving a problem c#

Posted 09 February 2013 - 05:19 AM

I assume you are doing this in order to learn something about Classes and OOP? In which case, yes, you could set the x, y, and text values in the constructor:

    class ColoredText 
    {
        public int X, Y; // koordinaterna
        public string Text;
        ConsoleColor Color;

        public ColoredText(int X, int Y, string InitialText)
        {
            this.X = X;
            this.Y = Y;
            this.Text = InitialText;
        }
        public void Write() 
        {
            // write Text to the Console at X, Y
        }
    }

This post has been edited by andrewsw: 09 February 2013 - 05:20 AM

Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5315
  • View blog
  • Posts: 11,371
  • Joined: 02-June 10

Re: Need direction for solving a problem c#

Posted 09 February 2013 - 08:15 AM

I hope you're not offended when I say "Sounds like a perfect question for learning by trial and error."

So much more is learned by trial and error than by someone just handing you the answer. Play with it a little. Unless you are an elephant you're not going to hurt anything by typing.

Throw in a couple different methods to experiment with this. Play with it. Have fun with it. Use the breakpoints and debugger to actually watch the code executeand the objects/variables change values. Learn to visualize the code as its being executed.

It's the only real way to LEARN how new components/features/code really work and have any true comprehension of the tools available to you.

I don't want you to write my code, just give me ideas on how to solve my problem. - Read this article
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1