Jump to content

Need help in putting timer on simple quiz program

So hey guys I'm currently making a simple quiz game for my OOP class, I'm almost done with the game the only thing I need to add is a countdown timer for each level of the game. The problem is that I don't know how will I add a timer because all of the tutorials that I find needs a trigger button wherein it will start the timer and pause the timer. The timer I need is when you actually play the game the timer will start initially. 

 

You can see the code here:

Code for the questions,timer,check if correct & wrong - https://pastebin.com/PByPeCq2

XML - https://pastebin.com/GC1EuSdx

Code for the main menu - https://pastebin.com/hgxQYuc3

XML - https://pastebin.com/PQradAh6

 

Spoiler

PC: CPU: Ryzen 5 5600X @ Curve optimzer -25,  Cooler: Noctua NH-D15 Chromax.Black, Motherboard: Asus Rog Strix B500-F Gaming WiFi II, GPU: Sapphire Nitro+ RX 7800XT @ Stock , RAM: G.Skill Trident Z RGB 2x16GB DDR4 3600Mhz CL18, HDD: Western Digital Caviar Black 2TB, SSD: Samsung 850 Evo 250GB | Team Group MP33 1TB NVME, Case: NZXT H7 Flow Black, PSU: NZXT C1200  I Peripherals: Keyboard: Ducky Shine 6 RGB Special Edition, Mouse: Razer Orochi V2, Headset: Philips SHP9500, Mousepad: Glorious Stealth Extended I Laptop: MSI GS63VR Stealth Pro CPU: i7-6700HQ@ 2.6ghz, GPU: GTX 1060, Memory: 16GB DDR4 2400Mhz, HDD: 1TB+128GB SSD

 

 

Link to post
Share on other sites

I guess in the tutorials you where watching, theyve used the button to call a function...

Instead of that, you can simply call the timer from a method that runs when the object is created. (put whathever tutorials call from button inside the onCreate maybe xD or a constructor so it starts automatically)

 

Few recommendations you did not asked for xD 

-Since you are learning OOP, make a class called Timer or so.

-Define inside the class, public methods to control the timer

 So when you have

Timer counter = new Timer();

 You can do things like this

counter.start();

counter.stop();

counter.countBackwardsFrom("2:23:00");

 

Right now you have all your data hardcoded inside HUUGE arrays of strings

If you continue to work like that, you will find that, over time is harder and harder to maintain the application so please 

consider to move all your data to a database. Is not that complicated, and it makes your life easier as a programmer.

 

 

Link to post
Share on other sites

17 minutes ago, Edwin Dimas said:

I guess in the tutorials you where watching, theyve used the button to call a function...

Instead of that, you can simply call the timer from a method that runs when the object is created. (put whathever tutorials call from button inside the onCreate maybe xD or a constructor so it starts automatically)

 

Few recommendations you did not asked for xD 

-Since you are learning OOP, make a class called Timer or so.

-Define inside the class, public methods to control the timer

 So when you have

Timer counter = new Timer();

 You can do things like this

counter.start();

counter.stop();

counter.countBackwardsFrom("2:23:00");

 

Right now you have all your data hardcoded inside HUUGE arrays of strings

If you continue to work like that, you will find that, over time is harder and harder to maintain the application so please 

consider to move all your data to a database. Is not that complicated, and it makes your life easier as a programmer.

 

 

Thanks for replying! To be honest in our OOP class our professor hasn't even really thought us anything useful that can be used in this project so I just looked on tutorials and most of the codes was copied from the tutorial.

Spoiler

PC: CPU: Ryzen 5 5600X @ Curve optimzer -25,  Cooler: Noctua NH-D15 Chromax.Black, Motherboard: Asus Rog Strix B500-F Gaming WiFi II, GPU: Sapphire Nitro+ RX 7800XT @ Stock , RAM: G.Skill Trident Z RGB 2x16GB DDR4 3600Mhz CL18, HDD: Western Digital Caviar Black 2TB, SSD: Samsung 850 Evo 250GB | Team Group MP33 1TB NVME, Case: NZXT H7 Flow Black, PSU: NZXT C1200  I Peripherals: Keyboard: Ducky Shine 6 RGB Special Edition, Mouse: Razer Orochi V2, Headset: Philips SHP9500, Mousepad: Glorious Stealth Extended I Laptop: MSI GS63VR Stealth Pro CPU: i7-6700HQ@ 2.6ghz, GPU: GTX 1060, Memory: 16GB DDR4 2400Mhz, HDD: 1TB+128GB SSD

 

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×