Traffic Lights - Complete the code.

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4

47 Replies - 29386 Views - Last Post: 10 April 2013 - 07:47 PM

#16 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Traffic Lights - Complete the code.

Posted 01 March 2012 - 11:57 PM

Are you adding new variables of any kind?

I hope not... :)
Was This Post Helpful? 0
  • +
  • -

#17 aaron1178  Icon User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 169
  • View blog
  • Posts: 1,298
  • Joined: 22-October 08

Re: Traffic Lights - Complete the code.

Posted 02 March 2012 - 03:35 PM

No, not at all :) It's just I was using your hConsole variable and it had not been allocated :\ So what do I do! I start using it when its not set to a value :\ Now that is fixed :) And I have the traffic lights fully rendered as you do.

The only problem is, I am having a little trouble with setting them up so I can change an individual light color on a set of lights. So at the moment I am brain storming some ideas :)
Was This Post Helpful? 1
  • +
  • -

#18 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Traffic Lights - Complete the code.

Posted 02 March 2012 - 04:21 PM

Awesome! I don't know why you're allocating hConsole when it's statically declared though.
Was This Post Helpful? 0
  • +
  • -

#19 aaron1178  Icon User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 169
  • View blog
  • Posts: 1,298
  • Joined: 22-October 08

Re: Traffic Lights - Complete the code.

Posted 02 March 2012 - 04:55 PM

This is a stupid question, what do you mean? I know its declared as a static variable. But I have no idea what you mean :/
Was This Post Helpful? 0
  • +
  • -

#20 Shane Hudson  Icon User is offline

  • D.I.C Technophile
  • member icon

Reputation: 343
  • View blog
  • Posts: 1,286
  • Joined: 06-December 09

Re: Traffic Lights - Complete the code.

Posted 02 March 2012 - 04:59 PM

This is very tempting.. but I am such a beginner at C++ that I am not sure I could implement it well enough yet. Might give it a go!
Was This Post Helpful? 0
  • +
  • -

#21 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Traffic Lights - Complete the code.

Posted 02 March 2012 - 05:02 PM

View Postaaron1178, on 02 March 2012 - 11:55 PM, said:

This is a stupid question, what do you mean? I know its declared as a static variable. But I have no idea what you mean :/

In this instance it means that it only has file scope.

View PostShane Hudson, on 02 March 2012 - 11:59 PM, said:

This is very tempting.. but I am such a beginner at C++ that I am not sure I could implement it well enough yet. Might give it a go!

Why not! At least do as much as you can before the deadline. :)

This post has been edited by ButchDean: 02 March 2012 - 05:01 PM

Was This Post Helpful? 0
  • +
  • -

#22 aaron1178  Icon User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 169
  • View blog
  • Posts: 1,298
  • Joined: 22-October 08

Re: Traffic Lights - Complete the code.

Posted 03 March 2012 - 12:29 AM

Yep, I am screwed :( in the static void ConfigureLightsAndDisplay(char* lights, int lightSet) method. I am no good with dereference pointers. I just don't understand their concepts at this time. And I am having trouble trying to visualize why it would require such a pointer as a parameter.

Hey, at least I got the traffic light signal to render like yours. I could even set the color of the signal (*), but unfortunately all three of them to the same color.
Was This Post Helpful? 0
  • +
  • -

#23 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Traffic Lights - Complete the code.

Posted 03 March 2012 - 03:22 PM

At least you tried. Will be releasing the code in a couple of days now.
Was This Post Helpful? 0
  • +
  • -

#24 aaron1178  Icon User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 169
  • View blog
  • Posts: 1,298
  • Joined: 22-October 08

Re: Traffic Lights - Complete the code.

Posted 04 March 2012 - 12:40 AM

I've been reading this article on pointers. And I feel as if it has really made me understand the concepts of pointers.

http://augustcouncil...torial/ptr.html

I might have another crack at it, even though there is little time left.

EDIT:

Okay, I've got to work tomorrow so I will post what I have done so far.

I've modified Core.cpp to the following because the while loop was an infinite loop and I couldn't get the timer working so here is Core.cpp
int main()
{
	int lightsSet = 0;

	LIGHTSDISPLAY->UpdateDisplay(lightsSet);

	cin.get();

	return 0;
}



and here is ConsoleOutput.cpp. I've got it working so you can set the default signal. But the only thing is that the traffic light was a bit to many characters.
static void ConfigureLightsAndDisplay(char* lights, int lightSet)
{
	ClearScreen();

	int BackC = 1;//Blue
	int ForgC = 0;//Black

	WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);//
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor); //

	for( int e = 0; e < 3; e++ )
	{
		for( int i = 0; i < sizeof(trafficLightFrame); i++ )
		{
			if(lights[i] == '*')
			{
				if(e == lightSet)
				{
					if( lightSet == 0 ){ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), RED); }
					else if( lightSet == 1 ){ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), AMBER); }
					else{ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), GREEN); }					
				}
				else
				{
					SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0);				
				}
					cout << lights[i];
			}
			else
			{
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
				cout << lights[i];
			}

		}
	}
	ClearScreen();
}



And that produces a result of Attached File  Aaron1178-TrafficLightsChallengeResult.zip (10.77K)
Number of downloads: 76

This post has been edited by aaron1178: 04 March 2012 - 02:03 AM

Was This Post Helpful? 1
  • +
  • -

#25 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Traffic Lights - Complete the code.

Posted 04 March 2012 - 03:57 PM

Ah, well... here are some observations that I'm sure you've noticed:

1. You need the timer function to get the lights to work anyway, in order to time the game loop.
2. I really don't like cin.get(); being in there, but I realize you put it in there to stop the program quitting. If the original while were left in you would only have to hit Escape to quit the app.
3. This code:

WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);



just isn't necessary.
4. ConfigureLightsAndDisplay() won't work as you have it because you are not querying the state of the system with the methods contained in LightStatus.cpp.
5. The traffic light you have drawn are not the same as in the example exe.

You certainly did have an idea of what was going on under the hood. Good attempt, and Kudos for being the only one who appears to have attempted it! :)
Was This Post Helpful? 0
  • +
  • -

#26 aaron1178  Icon User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 169
  • View blog
  • Posts: 1,298
  • Joined: 22-October 08

Re: Traffic Lights - Complete the code.

Posted 04 March 2012 - 04:48 PM

Thank you :) i'm looking forward to seeing you code and analysing it to see how it all works :)
Was This Post Helpful? 0
  • +
  • -

#27 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Traffic Lights - Complete the code.

Posted 04 March 2012 - 05:06 PM

Not long now! I've just finished writing the code for the next challenge which will be based on this one (but quite a bit easier). :)
Was This Post Helpful? 0
  • +
  • -

#28 aaron1178  Icon User is offline

  • Dovakiin, Dragonborn
  • member icon

Reputation: 169
  • View blog
  • Posts: 1,298
  • Joined: 22-October 08

Re: Traffic Lights - Complete the code.

Posted 04 March 2012 - 05:11 PM

Cool :) Looking forward to it... Just will take some time out on the 8th and 9th... Mass Effect 3 ohh yeah :)
Was This Post Helpful? 0
  • +
  • -

#29 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Traffic Lights - Complete the code.

Posted 04 March 2012 - 05:22 PM

I hear yuh! :)
Was This Post Helpful? 0
  • +
  • -

#30 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Traffic Lights - Complete the code.

Posted 05 March 2012 - 02:50 PM

CHALLENGE CLOSED

The complete solution to the challenge can be found here.

I'd like to give special kudos to aaron1178 for having a good go at this.

Please fire any questions you have. The next challenge that I will be putting up soon is based on this, so for those interested it is advised you study this carefully. :)
Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4