Refactored code. Replaced IF and ELSE statements with Switches. Cleaner and more readable.

This commit is contained in:
Starstreak 2025-11-09 02:49:13 +00:00
parent 8b25a1f5e0
commit 1aa6704da4

304
main.go
View file

@ -49,7 +49,7 @@ var stats string // variable for stats generation output
var statsCombat string // variable used for combat stats generation during fights
var PlayerName string // player's name...
var condoms = 0 // its better to have them and not need them
var diseases = 0 // what happens if you have connies
var diseases = 0 // what happens if you don't have connies
var money = 1800 // not specific currency
var days = 30 // total number of days (default 30)
var experience = 0 // your experience from combat battle fights (starts at 0)
@ -66,6 +66,7 @@ var childsupport = 0 // default 0 but changes if you get a hoe preggers
var playerHP = 200 // default hit points for the player
// Lipgloss - Props to
// Styles for the game dialog
var border = lipgloss.NewStyle().
BorderStyle(lipgloss.NormalBorder()).
BorderForeground(lipgloss.Color("63"))
@ -84,6 +85,14 @@ var storyStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("#ffffffff ")).
Background(lipgloss.Color("#0000FF"))
var propertyStyle = lipgloss.NewStyle().
BorderStyle(lipgloss.NormalBorder()).
Width(75).
BorderForeground(lipgloss.Color("228")).
BorderBackground(lipgloss.Color("#5023aaff")).
Foreground(lipgloss.Color("#ffffffff ")).
Background(lipgloss.Color("#5023aaff"))
var slutStyle = lipgloss.NewStyle().
BorderStyle(lipgloss.NormalBorder()).
Width(75).
@ -124,7 +133,7 @@ func HitTheStreets() {
choice := ""
bumHP := 100
i := 1
for playerHP > 0 {
for playerHP >= 0 {
for i > 0 {
ClearScreen()
CombatStats()
@ -133,14 +142,20 @@ func HitTheStreets() {
fmt.Println("Your choice,")
fmt.Print(green.Render(PlayerName), ">")
fmt.Scan(&choice)
if strings.ToUpper(choice) == "B" {
switch {
case strings.ToUpper(choice) == "B":
bumHP = 100 * level
enemyList := []string{"homeless piece of shit", "drug addled homeless bum", "shit smeared homeless bum", "crazy homeless person"}
enemyNameGen := enemyList[rand.IntN(len(enemyList))]
enemyName := strings.Clone(enemyNameGen)
attackList := []string{"a broken whiskey bottle!", "a tinfoil hat!", "a rusty heroine needle!", "his crusty dick!", "a soiled newspaper!",
"a crack pipe!", "moldy bread!"}
outerLoop:
for bumHP > 0 {
ClearScreen()
fmt.Println(storyStyle.Render("Bum Fight!"))
fmt.Println()
fmt.Println("You are staring at a ", red.Render("homeless piece of shit!"), "with", bumHP, " HP")
fmt.Println("You are staring at a ", red.Render(enemyName), "with", bumHP, " HP")
fmt.Println("")
fmt.Println("What do you do?")
fmt.Println("")
@ -152,20 +167,23 @@ func HitTheStreets() {
fmt.Print(green.Render(PlayerName), ">")
homelessFight := ""
fmt.Scan(&homelessFight)
if strings.ToUpper(homelessFight) == "F" {
switch {
case strings.ToUpper(homelessFight) == "F":
chance := rand.IntN(100)
if chance > 40 {
attack := 20 // default attack power
switch {
case chance > 40:
attack := 40 // default attack power
switch {
case fentanyl <= 0:
attack = 20
attack = 40 * level
default:
modifier := attack * fentanyl // default attack power multiplied by amount of fentanyl
attack = attack + modifier
buffs := attack * fentanyl // default attack power multiplied by amount of fentanyl
modifier := level * 2 // double the damage based on level
attack = attack + buffs + modifier //
}
bumHP = bumHP - attack
bumHP = bumHP - attack // attack homeless person
ClearScreen()
fmt.Println(red.Render("You smash the bum for "), attack, "hit points!")
fmt.Println("The bum has ", bumHP, " HP left")
@ -173,29 +191,31 @@ func HitTheStreets() {
switch {
case bumHP <= 0:
money = money + 200
case bumHP <= 0: // what happens if homeless person HP goes to or below 0
money = money*level + 300
bumfights = bumfights - 1
experienceGain := cocaines * 100
levelGain := level * 100
experience = experience + levelGain + experienceGain + 100
experience = experience + levelGain + experienceGain + levelGain
break outerLoop
}
} else {
default:
ClearScreen()
fmt.Println(red.Render("You missed, he dodged your attack!"))
fmt.Println()
homelessAttack := 20
playerHP = playerHP - homelessAttack
fmt.Println(red.Render("The homeless thug attacks you with a broken whiskey bottle for"), homelessAttack, " HP")
randomAttack := attackList[rand.IntN(len(attackList))]
fmt.Println(red.Render("The "), enemyName, red.Render("attacks you with "), randomAttack, red.Render(" for"), homelessAttack, red.Render(" HP"))
fmt.Println("Perhaps you should lay off the donuts...")
if playerHP < 0 {
switch {
case playerHP <= 0:
bumHP = 100
break outerLoop
}
MashEnterKey()
}
} else {
default:
fmt.Println("You go back to HQ.")
bumfights = bumfights - 1
bumHP = 0
@ -204,13 +224,12 @@ func HitTheStreets() {
}
}
bumfights = bumfights - 1
} else if strings.ToUpper(choice) == "R" {
case strings.ToUpper(choice) == "R":
MainMachine()
}
}
}
MainMachine()
}
}
func RedRoom() {
@ -222,8 +241,8 @@ func RedRoom() {
fmt.Println("Your choice,")
fmt.Print(green.Render(PlayerName), ">")
fmt.Scan(&choice)
// buy whore
if strings.ToUpper(choice) == "B" {
switch {
case strings.ToUpper(choice) == "B": // buy whore
ClearScreen()
fmt.Println(slutStyle.Render("Sex Slave Menu"))
fmt.Println("Price: ", red.Render("$2000 per whore."))
@ -233,54 +252,60 @@ func RedRoom() {
fmt.Print(green.Render(PlayerName), ">")
slavePurchase := ""
fmt.Scan(&slavePurchase)
if strings.ToUpper(slavePurchase) == "Y" {
if money > 2000 {
switch {
case strings.ToUpper(slavePurchase) == "Y":
switch {
case money >= 2000:
whores = whores + 1
money = money - 5000
money = money - 2000 // *** BUG FIX: Changed 5000 to 2000 ***
ClearScreen()
fmt.Println(slutStyle.Render("You just purchased 1 whore to be a sex slave!"))
MashEnterKey()
i = 0
} else {
default:
ClearScreen()
fmt.Println(slutStyle.Render("Get some money, broke-ass!"))
MashEnterKey()
i = 0
}
} else {
default:
i = 0
}
} else if strings.ToUpper(choice) == "P" {
case strings.ToUpper(choice) == "P": // Buy Connies (Condoms)
ClearScreen()
fmt.Println(slutStyle.Render("$10 to buy a five pack of connies?"))
fmt.Println("Price: ", red.Render("$10 for a five pack."))
fmt.Println("Your cash: $", strconv.Itoa(money))
fmt.Println("")
fmt.Println("Buy connies (Y/N)?")
fmt.Println("Buy five connies (Y/N)?")
fmt.Print(green.Render(PlayerName), ">")
lapPurchase := ""
fmt.Scan(&lapPurchase)
if strings.ToUpper(lapPurchase) == "Y" {
if money > 10 {
switch {
case strings.ToUpper(lapPurchase) == "Y":
switch {
case money >= 10:
money = money - 10
condoms = condoms + 5
ClearScreen()
fmt.Println(slutStyle.Render("You just purchased a five pack of connies."))
fmt.Println()
MashEnterKey()
ClearScreen()
i = 0
} else {
default:
ClearScreen()
fmt.Println(slutStyle.Render("Get some money, broke-ass!"))
MashEnterKey()
ClearScreen()
i = 0
}
} else {
default:
i = 0
}
} else if strings.ToUpper(choice) == "L" {
case strings.ToUpper(choice) == "L": // Get Lap Dance
ClearScreen()
fmt.Println(slutStyle.Render("Get a fucking lap dance!"))
fmt.Println("Price: ", red.Render("$20 for a 3 minute song."))
@ -289,8 +314,8 @@ func RedRoom() {
fmt.Println("Buy a lap dance (Y/N)?")
lapPurchase := ""
fmt.Scan(&lapPurchase)
if strings.ToUpper(lapPurchase) == "Y" {
if money >= 20 {
switch {
case strings.ToUpper(lapPurchase) == "Y":
money = money - 20
ClearScreen()
fmt.Println(slutStyle.Render("That slut grinds on your dick to the song 'I like it that way' by Backstreet Boys."))
@ -299,18 +324,14 @@ func RedRoom() {
playerHP = playerHP + 100
MashEnterKey()
i = 0
} else {
default:
ClearScreen()
fmt.Println(slutStyle.Render("Get some money, broke-ass!"))
MashEnterKey()
i = 0
}
} else {
i = 0
}
// Fuck Whore
} else if strings.ToUpper(choice) == "F" {
case strings.ToUpper(choice) == "F": // Fuck Whore
ClearScreen()
fmt.Println(border.Render("Get your dick wet at OPP McDick's"))
fmt.Println("Price: ", red.Render("$100 to fuck a dirty whore for an hour."))
@ -320,10 +341,13 @@ func RedRoom() {
fmt.Print(green.Render(PlayerName), ">")
fuckPurchase := ""
fmt.Scan(&fuckPurchase)
if strings.ToUpper(fuckPurchase) == "Y" {
if money >= 100 {
switch {
case strings.ToUpper(fuckPurchase) == "Y":
switch {
case money >= 100:
money = money - 100
if condoms == 0 {
switch {
case condoms == 0:
stdChance := rand.IntN(100)
preggoChance := rand.IntN(100)
@ -332,7 +356,7 @@ func RedRoom() {
fmt.Println("You just fucked a dirty whore! Oh... shit, it's your cousin!")
MashEnterKey()
switch {
switch { // This is a switch without an expression, useful for condition checking
case stdChance <= 50:
diseases = diseases + 1
ClearScreen()
@ -341,7 +365,7 @@ func RedRoom() {
MashEnterKey()
}
switch {
switch { // This is a switch without an expression, useful for condition checking
case preggoChance <= 25:
ClearScreen()
fmt.Println(red.Render("Uh oh!"))
@ -349,11 +373,12 @@ func RedRoom() {
fmt.Print(green.Render(PlayerName), "(Y/N) >")
soccerBalls := ""
fmt.Scan(&soccerBalls)
if strings.ToUpper(soccerBalls) == "Y" {
switch {
case strings.ToUpper(soccerBalls) == "Y":
money = money + 500
fmt.Println(red.Render("Bonus! You just made $500... The kid is great at sewing soccer balls!"))
MashEnterKey()
} else {
default:
fmt.Println(red.Render("You have too much of a heart to sell your kid. Now you have to pay child support!"))
offspring = offspring + 1
fmt.Println("")
@ -361,28 +386,28 @@ func RedRoom() {
MashEnterKey()
}
}
} else {
default:
condoms = condoms - 1
playerHP = playerHP + 200
}
ClearScreen()
i = 0
} else {
default:
ClearScreen()
fmt.Println(red.Render("Get some money, broke-ass!"))
MashEnterKey()
i = 0
}
} else {
default:
i = 0
}
// Return to HQ
} else if strings.ToUpper(choice) == "R" {
case strings.ToUpper(choice) == "R": // Return to HQ
i = 1
MainMachine()
} else {
i = 0
default:
i = 0 // If any other input is given, loop again
}
}
}
@ -397,7 +422,8 @@ func DoctorsOffice() {
fmt.Println("Your choice,")
fmt.Print(green.Render(PlayerName), ">")
fmt.Scan(&choice)
if strings.ToUpper(choice) == "C" {
switch {
case strings.ToUpper(choice) == "C":
ClearScreen()
fmt.Println(storyStyle.Render("Doctor's Miracle STD/STI Cures"))
fmt.Println()
@ -409,37 +435,42 @@ func DoctorsOffice() {
fmt.Println("(N)o")
stdCure := ""
fmt.Scan(&stdCure)
if strings.ToUpper(stdCure) == "Y" {
if money > 100 {
switch {
case strings.ToUpper(stdCure) == "Y":
switch {
case money >= 100:
fmt.Println("You pay the doctor $100 and you and/or your 'friends' are cured.")
money = money - 100
diseases = 0
i = 1
MashEnterKey()
} else {
default:
fmt.Println("You're too poor to cure your diseases.")
i = 1
if diseases >= 1 {
switch {
case diseases >= 1:
fmt.Println("But you still have a diseases.")
MashEnterKey()
} else {
default:
fmt.Println()
MashEnterKey()
}
}
} else {
default:
ClearScreen()
fmt.Println("No cure for you. I guess.")
if diseases >= 0 {
switch {
case diseases > 0:
fmt.Println("But you still have a disease.")
MashEnterKey()
} else {
fmt.Println()
MashEnterKey()
i = 1
default:
i = 1
}
i = 0
}
} else {
default:
ClearScreen()
fmt.Println("You head back to HQ.")
MashEnterKey()
@ -455,92 +486,103 @@ func PropertyRoom() {
i := 0
choice := ""
for i < 1 {
fmt.Println(storyStyle.Render(propertyRoom))
fmt.Println(propertyStyle.Render(propertyRoom))
fmt.Println("Your choice,")
fmt.Print(green.Render(PlayerName), ">")
fmt.Scan(&choice)
if strings.ToUpper(choice) == "C" {
switch {
case strings.ToUpper(choice) == "C": // Cocaine Menu
ClearScreen()
fmt.Println(border.Render("Cocaine Menu"))
fmt.Println(propertyStyle.Render("Cocaine Menu"))
fmt.Println("Price: ", red.Render("$1000 per gram."))
fmt.Println("Your cash: $", strconv.Itoa(money))
fmt.Println("")
fmt.Println("Buy one gram (Y/N)?")
cokePurchase := ""
fmt.Scan(&cokePurchase)
if strings.ToUpper(cokePurchase) == "Y" {
if money > 1000 {
switch { // Check purchase confirmation (Y/N)
case strings.ToUpper(cokePurchase) == "Y":
switch { // Check money
case money >= 1000:
cocaines = cocaines + 1
money = money - 1000
ClearScreen()
fmt.Println("You just purchased 1 gram of coke!")
MashEnterKey()
i = 0
} else {
default:
ClearScreen()
fmt.Println(red.Render("Get some money, broke-ass!"))
MashEnterKey()
i = 0
}
} else {
default:
i = 0
}
} else if strings.ToUpper(choice) == "L" {
case strings.ToUpper(choice) == "L": // LSD Menu
ClearScreen()
fmt.Println(border.Render("LSD Menu"))
fmt.Println(propertyStyle.Render("LSD Menu"))
fmt.Println("Price: ", red.Render("$100 for five tabs."))
fmt.Println("Your cash: $", strconv.Itoa(money))
fmt.Println("")
fmt.Println("Buy six tabs (Y/N)?")
fmt.Println("Buy five tabs (Y/N)?")
LSDPurchase := ""
fmt.Scan(&LSDPurchase)
if strings.ToUpper(LSDPurchase) == "Y" {
if money > 100 {
switch { // Check purchase confirmation (Y/N)
case strings.ToUpper(LSDPurchase) == "Y":
switch {
case money >= 100: // When money is at least 100 do the following
LSD = LSD + 5
money = money - 100
ClearScreen()
fmt.Println("You just purchased 5 tabs of LSD! Fuck yeah!")
MashEnterKey()
i = 0
} else {
default: // otherwise do this when the user doesn't have 100 dollars
ClearScreen()
fmt.Println(red.Render("You don't have the greenbacks, loser! Get some money, broke-ass!"))
MashEnterKey()
i = 0
}
} else {
default:
i = 0
}
} else if strings.ToUpper(choice) == "F" {
case strings.ToUpper(choice) == "F": // Fentanyl Menu
ClearScreen()
fmt.Println(border.Render("Fentanyl Menu"))
fmt.Println(propertyStyle.Render("Fentanyl Menu"))
fmt.Println("Price: ", red.Render("$500 per hundred milligrams."))
fmt.Println("Your cash: $", strconv.Itoa(money))
fmt.Println("")
fmt.Println("Buy 100 milligrams (Y/N)?")
fentyPurchase := ""
fmt.Scan(&fentyPurchase)
if strings.ToUpper(fentyPurchase) == "Y" {
if money > 500 {
switch { // Check purchase confirmation (Y/N)
case strings.ToUpper(fentyPurchase) == "Y":
switch { // Check money
case money >= 500:
fentanyl = fentanyl + 1
money = money - 500
ClearScreen()
fmt.Println("You just purchased 1 bag of fenty!")
MashEnterKey()
i = 0
} else {
default:
ClearScreen()
fmt.Println(red.Render("Get some money, broke-ass!"))
MashEnterKey()
i = 0
}
} else {
default:
i = 0
}
} else if strings.ToUpper(choice) == "R" {
case strings.ToUpper(choice) == "R": // Return to Main Machine
i = 1
MainMachine()
} else {
default: // Invalid input
i = 0
}
}
@ -557,20 +599,21 @@ func ClockOut() {
switch choice {
case 1:
chance := rand.IntN(100)
if chance < 50 {
ClearScreen()
if cocaines > 1 {
switch {
case chance <= 50:
switch cocaines {
case 0:
fmt.Println(red.Render("You bust your wife right in the fucking face!"))
MashEnterKey()
default:
fmt.Println(red.Render("You pull out 1kg of cocaine and smash it open all over your face"))
fmt.Println(red.Render("You shout 'COKE SLAM!'"))
fmt.Println(red.Render("You bust your wife right in the fucking face!"))
fmt.Println(red.Render("YARRRRR! (You don't know why you're a pirate now)"))
MashEnterKey()
ClearScreen()
} else {
fmt.Println(red.Render("You bust your wife right in the fucking face!"))
MashEnterKey()
}
} else {
default:
ClearScreen()
fmt.Println(red.Render("You try to bust your wife in the face but she dodges you and runs out the"))
fmt.Println(red.Render("front door!"))
@ -593,20 +636,24 @@ func ClockOut() {
}
ClearScreen()
fmt.Println(border.Render("It is a new day!"))
if days == 0 {
switch {
case days <= 0:
fmt.Println("You have run out of days...")
MashEnterKey()
GameOver()
} else {
default:
days = days - 1
if diseases >= 1 {
switch {
case diseases >= 1:
bumfights = bumfightsTotal - 15 - diseases
} else {
default:
bumfights = bumfightsTotal
}
childsupport = offspring * 100
prostituteIncome := whores*500 - childsupport
money = money + taxes + prostituteIncome
diseaseUpkeep := diseases * 25
whoresProfit := whores * 500
income := whoresProfit - childsupport - diseaseUpkeep
money = money + taxes + income
fmt.Println("Cha ching! You now have ", money)
MainMachine()
}
@ -630,27 +677,27 @@ func CheckStats() {
}
func CombatStats() {
if experience == 1000 {
switch {
case experience >= 1000:
level = 2
} else if experience == 4000 {
case experience >= 4000:
level = 3
} else if experience == 8000 {
case experience >= 9000:
level = 4
} else if experience == 25000 {
case experience >= 18000:
level = 5
} else if experience == 75000 {
case experience >= 30000:
level = 6
} else if experience == 120000 {
case experience >= 60000:
level = 7
} else if experience == 175000 {
case experience >= 120000:
level = 8
} else if experience == 250000 {
case experience >= 240000:
level = 9
} else if experience == 1000000 {
case experience >= 480000:
level = 10
} else {
fmt.Println()
}
statsCombat = "Name: " + PlayerName + "\n" + "Hit Points: " + strconv.Itoa(playerHP) + "\n" + "Level :" + strconv.Itoa(level) + "\n" + "Money: $" + strconv.Itoa(money) + "\n" + "Experience :" + strconv.Itoa(experience) + "\n" + "Bum Fights Left: " + strconv.Itoa(bumfights) // builds Combat Stats
}
@ -663,26 +710,21 @@ func MainMachine() {
fmt.Println("Your choice,")
fmt.Print(green.Render(PlayerName), ">")
fmt.Scan(&choice)
if strings.ToUpper(choice) == "H" {
switch {
case strings.ToUpper(choice) == "H":
HitTheStreets()
i = 1
} else if strings.ToUpper(choice) == "P" {
case strings.ToUpper(choice) == "P":
PropertyRoom()
i = 1
} else if strings.ToUpper(choice) == "B" {
case strings.ToUpper(choice) == "B":
breakRoom()
i = 1
} else if strings.ToUpper(choice) == "R" {
case strings.ToUpper(choice) == "R":
RedRoom()
i = 1
} else if strings.ToUpper(choice) == "D" {
case strings.ToUpper(choice) == "D":
DoctorsOffice()
i = 1
} else if strings.ToUpper(choice) == "G" {
case strings.ToUpper(choice) == "G":
ClockOut()
i = 1
} else {
i = 0
case strings.ToUpper(choice) == "Q":
GameOver()
}
}
}