0.0.1_2
This commit is contained in:
parent
124206e34a
commit
613ed97bdb
@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
|
||||
|
||||
## [0.0.1_2] 2024-08-07
|
||||
|
||||
### fixed
|
||||
|
||||
- number display
|
||||
|
||||
## [0.0.1_1] 2024-08-06
|
||||
|
||||
|
101
👨💻/lib/GRP.hpp
Normal file
101
👨💻/lib/GRP.hpp
Normal file
@ -0,0 +1,101 @@
|
||||
#include <gmpxx.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <math.h>
|
||||
#include <sstream>
|
||||
|
||||
namespace GRP {
|
||||
using integer = mpz_class;
|
||||
using flat = mpf_class;
|
||||
using number = mpq_class;
|
||||
|
||||
using str = std::string;
|
||||
|
||||
number pow(number base, integer exp) {
|
||||
number result = 1;
|
||||
for (integer i = 0; i < exp; i++)
|
||||
result *= base;
|
||||
return result;
|
||||
}
|
||||
|
||||
integer precision;
|
||||
integer kilo = 1'000;
|
||||
|
||||
std::vector<str> formatLong = {" thousand"," million"," billion"," trillion"," quadrillion"," quintillion"," sextillion"," septillion"," octillion"," nonillion"};
|
||||
std::vector<str> prefixes = {"","un","duo","tre","quattuor","quin","sex","septen","octo","novem"};
|
||||
std::vector<str> suffixes = {"decillion","vigintillion","trigintillion","quadragintillion","quinquagintillion","sexagintillion","septuagintillion","octogintillion","nonagintillion"};
|
||||
|
||||
integer round(number x) {
|
||||
return x.get_num() / x.get_den();
|
||||
}
|
||||
|
||||
str toString(number x) {
|
||||
std::stringstream result;
|
||||
if (x >= 1'000'000) {
|
||||
size_t suffix = 1;
|
||||
|
||||
x /= kilo;
|
||||
x = round(x);
|
||||
|
||||
while(x > 999'999) {
|
||||
x /= kilo;
|
||||
x = round(x);
|
||||
suffix++;
|
||||
}
|
||||
|
||||
integer big = round(x / kilo);
|
||||
integer small = round(x - big * kilo);
|
||||
|
||||
if(small == 0) {
|
||||
result << big << formatLong[suffix];
|
||||
} else {
|
||||
str sml = small.get_str();
|
||||
char smallf[] = "000";
|
||||
for(int i = 0; i < sml.length(); i++) {
|
||||
smallf[2 - i] = sml[sml.length() - i - 1];
|
||||
}
|
||||
|
||||
if(smallf[1] == '0' && smallf[2] == '0') smallf[1] = 0x00;
|
||||
if(smallf[2] == '0') smallf[2] = 0x00;
|
||||
|
||||
result << big << '.' << smallf << formatLong[suffix];
|
||||
}
|
||||
|
||||
return result.str();
|
||||
} else {
|
||||
x *= 10;
|
||||
integer big = round(x/10);
|
||||
|
||||
integer small = round(x - big * 10);
|
||||
|
||||
integer kilos = big / kilo;
|
||||
integer ones = big - kilos * kilo;
|
||||
if(kilos > 0) {
|
||||
str oness = ones.get_str();
|
||||
char onesf[] = "000";
|
||||
for(size_t i = 0; i < oness.length(); i++) {
|
||||
onesf[2 - i] = oness[oness.length() - i - 1];
|
||||
}
|
||||
|
||||
result << kilos << ',' << onesf;
|
||||
} else {
|
||||
if(small != 0) result << ones << '.' << small;
|
||||
else result << ones;
|
||||
}
|
||||
|
||||
return result.str();
|
||||
}
|
||||
|
||||
return "error: HOW!";
|
||||
}
|
||||
|
||||
void init(integer precision = 1) {
|
||||
precision = pow(precision, 10);
|
||||
|
||||
for(int i = 0; i < suffixes.size(); i++) {
|
||||
for(int j = 0; j < prefixes.size(); j++) {
|
||||
formatLong.push_back(' ' + prefixes[j] + suffixes[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
17
👨💻/main.cpp
17
👨💻/main.cpp
@ -3,6 +3,7 @@
|
||||
#include <sstream>
|
||||
|
||||
#include "./lib/CMD.hpp"
|
||||
#include "./lib/GRP.hpp"
|
||||
|
||||
#define RESET "\033[0m"
|
||||
#define BLACK "\033[30m" /* Black */
|
||||
@ -58,7 +59,7 @@ struct TclickerSave {
|
||||
TclickerSave save = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
const str name = "Transistor Clicker";
|
||||
const str version = "0.0.1_1";
|
||||
const str version = "0.0.1_2";
|
||||
|
||||
const number cursorPrice = 15, mossPrice = 100, smallFABPrice = 1'000, mediumFABprice = 11'000, largeFABPrice = 120'000, intelI860Price = 1'305'078, startupPrice = 17'000'000, oakTreePrice = 200'000'000;
|
||||
const number cursorYeild = 0.1, mossYeild = 1, smallFABYeild = 10, mediumFABYeild = 60, largeFABYeild = 260, intelI860Yeild = 1'700, startupYeild = 10'000, oakTreeYeild = 120'000;
|
||||
@ -97,13 +98,11 @@ void clear(std::vector<str>&) {
|
||||
printTitileCard();
|
||||
}
|
||||
|
||||
str TransitorsString(number transistors, str colA = BOLDGREEN, str colB = BOLDBLUE, integer precision = 1) {
|
||||
str TransitorsString(number transistors, bool round = true, str colA = BOLDGREEN, str colB = BOLDBLUE) {
|
||||
std::stringstream ss;
|
||||
integer transistorsInt = toInt(transistors*precision);
|
||||
|
||||
number finalTransistors = number(transistorsInt, precision);
|
||||
str plural = finalTransistors == 1 ? "transistor" : "transistors";
|
||||
ss << colA << finalTransistors << ' ' << colB << plural;
|
||||
if(round) transistors = GRP::round(transistors);
|
||||
str plural = GRP::round(transistors * 10) / 10 == 1 ? "transistor" : "transistors";
|
||||
ss << colA << GRP::toString(transistors) << ' ' << colB << plural;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
@ -234,7 +233,7 @@ void balance(std::vector<str>& args) {
|
||||
}
|
||||
std::cout << BOLDBLUE << "You have " << TransitorsString(save.transistorBalance) << ".\n";
|
||||
std::cout << BOLDBLUE << "You have made " << TransitorsString(save.totalTransistors) << " in total.\n";
|
||||
std::cout << BOLDBLUE << "You make " << TransitorsString(calcTPS(), BOLDGREEN, BOLDBLUE, 10) << " per second.\n";
|
||||
std::cout << BOLDBLUE << "You make " << TransitorsString(calcTPS(), false) << " per second.\n";
|
||||
|
||||
CMD::log("They have" + TransitorsString(save.transistorBalance, "", "") + "!");
|
||||
}
|
||||
@ -398,6 +397,8 @@ void help(std::vector<str>& args) {
|
||||
}
|
||||
|
||||
int main() {
|
||||
GRP::init();
|
||||
|
||||
std::jthread gameThread = CMD::init(name, BOLDGREEN + str("@HCC") + BOLDBLUE + " ~/You" + RESET + "$ ", onTick);
|
||||
|
||||
CMD::exit = onExit;
|
||||
|
Loading…
x
Reference in New Issue
Block a user