Last active
December 18, 2016 01:26
-
-
Save CuriousTommy/ff14de96428e8e503697f55c7020a366 to your computer and use it in GitHub Desktop.
I am trying to use the sleep_for function from the example here (http://stackoverflow.com/a/9747668), but when I try to use it, I always keep getting errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <3ds.h> | |
#include <stdio.h> | |
#include <chrono> | |
#include <thread> | |
#include <iostream> | |
using namespace std; | |
using namespace std::this_thread; // sleep_for, sleep_until | |
using namespace std::chrono_literals; // ns, us, ms, s, h, etc. | |
using std::chrono::system_clock; | |
// Prototypes | |
void AddDonationAmount(float total, float &donate, float amount); | |
void GreetingMessage(float total, float donate, float amount); | |
void Nintendo3DSScreenStuff(); | |
void StateResults(float total, float donate); | |
void SubtractDonationAmount(float total, float &donate, float amount); | |
bool ValdiateAmount(float total, float donate); | |
int main(int argc, char **argv) | |
{ | |
float totalBalance = 10000, donateAmount = 0, modifyAmount = 1000; | |
//Initialize gfx (note: not needed if you're using SF2Dlib) | |
gfxInitDefault(); | |
consoleInit(GFX_TOP, NULL); | |
GreetingMessage(totalBalance, donateAmount, modifyAmount); | |
// Main loop | |
while (aptMainLoop()) | |
{ | |
//Scan all the inputs. This should be done once for each frame | |
hidScanInput(); | |
u32 kDown = hidKeysDown(); | |
if (kDown & KEY_A) | |
{ | |
AddDonationAmount(totalBalance, donateAmount, modifyAmount); | |
consoleClear(); | |
GreetingMessage(totalBalance, donateAmount, modifyAmount); | |
} | |
else if (kDown & KEY_B) | |
{ | |
SubtractDonationAmount(totalBalance, donateAmount, modifyAmount); | |
consoleClear(); | |
GreetingMessage(totalBalance, donateAmount, modifyAmount); | |
} | |
else if (kDown & KEY_START) | |
{ | |
StateResults(totalBalance, donateAmount); | |
sleep_for(2s); | |
break; | |
} | |
Nintendo3DSScreenStuff(); | |
} | |
gfxExit(); | |
return 0; | |
} | |
void AddDonationAmount(float total, float &donate, float amount) | |
{ | |
float donateTemp = donate; | |
donateTemp += amount; | |
if (ValdiateAmount(total, donateTemp)) | |
{ | |
donate = donateTemp; | |
} | |
else | |
{ | |
cout << "You don't have enough money in your wallet." << endl; | |
//sleep_for(2s); | |
} | |
} | |
void GreetingMessage(float total, float donate, float amount) | |
{ | |
cout << "Welcome to the Children With No Life Foundation. We dedicate ourselves " | |
<< "with helping children who have no social life what so ever, so that they " | |
<< "can be more like the other cool kids who do have a life." << endl | |
<< endl << endl; | |
cout << "How much would you like to donate?" << endl | |
<< "\tYou currently have " << total << " dollars in you wallet" << endl | |
<< "\tYour donation amount is currently " << donate << endl | |
<< endl; | |
cout << "Press A to add " << amount <<" dollars" << endl | |
<< "Press B to remove " << amount << " dollars" << endl | |
<< "Press Start to send the money and exit the program" << endl; | |
} | |
void Nintendo3DSScreenStuff() | |
{ | |
// Flush and swap framebuffers, this is needed for rendering these will not be needed when using SF2D lib | |
gfxFlushBuffers(); | |
gfxSwapBuffers(); | |
//Wait for VBlank, this is needed for rendering these will not be needed when using SF2D lib | |
gspWaitForVBlank(); | |
} | |
void StateResults(float total, float donate) | |
{ | |
double percentage; | |
percentage = donate/total; | |
if (percentage > .50) | |
{ | |
cout << "Wow! Thank you so much for your donation! " | |
<< "We will have a picture of you hanged on our wall!" | |
<< endl; | |
} | |
else if (percentage < .0075) | |
{ | |
cout << "Every little bit counts!" << endl; | |
} | |
else if (percentage < .15) | |
{ | |
cout << "Thank you for your contribution" << endl; | |
} | |
else if (percentage < .25) | |
{ | |
cout << "That's pretty nice of you"; | |
} | |
else if (percentage <= .50) | |
{ | |
cout << "That is a good amount money you have donated. " | |
<< "Thank you for your contribution." | |
<< endl; | |
} | |
else if (percentage == 0) | |
{ | |
cout << "I see..." << endl; | |
} | |
cout << "Sending you back to the homebrew menu" << endl; | |
} | |
void SubtractDonationAmount(float total, float &donate, float amount) | |
{ | |
float donateTemp = donate; | |
donateTemp -= amount; | |
if (ValdiateAmount(total, donateTemp)) | |
{ | |
donate = donateTemp; | |
} | |
else | |
{ | |
cout << "Donation amount is set to zero" << endl; | |
//sleep_for(2s); | |
} | |
} | |
bool ValdiateAmount(float total, float donate) | |
{ | |
if (donate > total) | |
{ | |
return false; | |
} | |
else if (donate < 0) | |
{ | |
return false; | |
} | |
else | |
{ | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment