Traffic Lights - Complete the code.

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

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

#1 anonymous26  Icon User is offline

  • D.I.C Lover

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

Traffic Lights - Complete the code.

Posted 19 February 2012 - 03:44 PM

*
POPULAR

Introduction

Game programming is a lot more than graphics, IO and collision detection - it's also about getting subsystems to communicate and work in harmony. This small challenge, which appears deceptively simple, employs a traffic light system that is found in games like Grand Theft Auto and LA Noire for example.

The goal os this exercise is to debug and complete the code, implementing the various methods to get is working as per the exectable contained in TrafficLights.zip in the Traffic-Lights Github repository here.

What you will need

The code was written using Vusual Studio 2008 Pro, and it is advised at the very least that you use either Visual C++ 2008/2010 Express Editions. You are free to use whichever IDE you wish, but if it breaks I won't be any help - I'll just say 'use Visual C++ Express'.

This is a console application not needing any special APIs or SDKs. My reason for this is that I would prefer people to focus on the logic over making it look pretty.

What is provided

I have written the code and deleted nearly all method implemetations and introduced errors. It is up to you, either as a group to share ideas on this thread (recommended) or indivdually (not recommended), on the appropriate implementation. The class declarations should not be altered.

All methods and variables declarations have been left in place in order to complete the code, but if you feel you cannot work out the logic to use what is provided then I will allow you to modify as appropriate. Before you do, it might be an idea to post your thoughts on this thread to see what others might think to avoid coming up with a lesser solution.

Rules that must not be broken!

- DO NOT PM me asking for help or hints - this is a challenge and I shall be remaining silent unless things really start going off the rails.

- DO NOT use any other language apart from C++, as this serves as a little lesson in smarter ways to code in the language.

Deadline

In order to make this as accessible as possible I have allowed two weeks from today to complete the challenge which will close on March 5th, 2012. After this dealine I will submit my solution and offer comments and/or suggestions for those who have attempted it.

Good luck, and most of all have fun! :unsure:

Is This A Good Question/Topic? 5
  • +

Replies To: Traffic Lights - Complete the code.

#2 Ricky65  Icon User is offline

  • D.I.C Head

Reputation: 38
  • View blog
  • Posts: 115
  • Joined: 03-June 10

Re: Traffic Lights - Complete the code.

Posted 26 February 2012 - 11:40 AM

Interesting challenge.

Traffic lights are something that professional video game developers struggle with. Take a look at EA Black Box and Need For Speed: World. Working traffic lights are not implemented, they just flash red!
Was This Post Helpful? 0
  • +
  • -

#3 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 26 February 2012 - 11:55 AM

Good observation! Will check that out.

I remember when I was selecting my university as a student, the college presented something similar to this (but only one set instead of two) as some code to complete for new students.

This challenge will make you think a fair bit, but is rewarding once solved.
Was This Post Helpful? 1
  • +
  • -

#4 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 28 February 2012 - 03:15 PM

Anybody got going after one week?
Was This Post Helpful? 0
  • +
  • -

#5 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 29 February 2012 - 06:54 PM

Dammit, 4 days to go and I just seen this challenge :( Maybe the next one :)
Was This Post Helpful? 0
  • +
  • -

#6 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 29 February 2012 - 07:03 PM

You can still have a go. The average person should get it done in under a day. :)
Was This Post Helpful? 0
  • +
  • -

#7 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 01 March 2012 - 12:57 AM

Hmm, I have looked over the code and analyzed the exe file. I couldn't solve this if my life depended on it :(

Here is how I see it:

We need to draw the traficLightFrame to the console twice.

More to come
Was This Post Helpful? 0
  • +
  • -

#8 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 - 03:11 AM

At least you're having a go. Better than nothing! :)
Was This Post Helpful? 0
  • +
  • -

#9 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 01 March 2012 - 01:14 PM

This is why I am having a go. If I cannot perform such a task, I better think about getting better at C++ :) I'll still try work on it though.
Was This Post Helpful? 0
  • +
  • -

#10 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 - 01:21 PM

Good stuff. Just do the best you can. :)
Was This Post Helpful? 0
  • +
  • -

#11 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 01 March 2012 - 02:07 PM

I found this snippet which has help a lot ;) Console Drawing

Except for the black rectangle which encompasses the * light signal.

Once I've gotten the light to properly render, I will then move on to changing it's signal and then its signal color.

Once I have a working traffic light, then I will move onto synchronizing 2 sets of traffic lights.

Great challenge so far Butch

This post has been edited by aaron1178: 01 March 2012 - 02:31 PM

Was This Post Helpful? 0
  • +
  • -

#12 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 - 04:33 PM

Thanks! :)

Be careful! You might not need all the code shown in the link. Nice investigative work though, I didn't know that was there.

Have you attempted to build the project in its current state yet?
Was This Post Helpful? 0
  • +
  • -

#13 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 01 March 2012 - 04:59 PM

Sure have :) that was the first thing I did when I downloaded the challenge. By doing so, I found those errors you where talking about and provided me with a visual representation of where i'm at, and that was just a console with nothing being written to the console.

Then I printed the TrafficLightSignal* variable after I added another 2 spaces for red and amber or vice versa. Then I googled console coloring and found that link, which has really helped me a lot because now I have the blue background . The only current problem I am trying to solve is that in your exe file, where the signal * lies, there is a box with a black background, I am trying to solve that. As I write this, I may have just figure out how :)
Was This Post Helpful? 1
  • +
  • -

#14 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 - 05:04 PM

Awesome! I am eager now to see what you come up with! :)
Was This Post Helpful? 0
  • +
  • -

#15 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 01 March 2012 - 06:49 PM

Hmmm, It's not coming so good. I cant get the backcolor of a certain char to work :\

Scratch that :) I wasn't using GetStdHandle(STD_OUTPUT_HANDLE). Now I have the street light rendered. Now to start on coloring a selected char (*).

Update: Got that working too. Now I am just thinking of a way to synchronize a traffic light with all 3 signals.

This post has been edited by aaron1178: 01 March 2012 - 07:10 PM

Was This Post Helpful? 0
  • +
  • -

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