Last active
February 26, 2019 17:27
-
-
Save NeonixRIT/ebb0152f047f9cdc35e4d0ed87c5501d to your computer and use it in GitHub Desktop.
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
//My First C# project. A simple multiplication game that I keep adding to overtime as I get ideas. | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace MultiplicationGame | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.Title = "Multiplication Game"; | |
//Point to return to if player decides to replay after they lose | |
Restart: | |
//Strings used later to prevent an error if the incorrect format is input | |
string[] alpha = new string[26] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; | |
string[] alpha2 = new string[24] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "z" }; | |
string[] func = new string[31] { "+", "-", "*", "/", "!", "@", "#", "$", "%", "^", "&", "(", ")", "_", "=", "{", "}", "[", "]", "\n", "|", ";", ":", "\"", "'", "<", ">", ",", ".", "?", " " }; | |
string[] num = new string[9] { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; | |
//Starting Variable Values | |
float armour = 0; | |
bool divineShield = false; | |
int divineShield2 = 0; | |
double experience = 0.0d; | |
double health = 100.0d; | |
int maxHealth = 100; | |
double points = 0; | |
double skips = 0.0d; | |
int turn = 0; | |
int turnsCorrect = 0; | |
int min01 = 1; | |
int max01 = 11; | |
int min02 = 1; | |
int max02 = 101; | |
Start: | |
Random numberGenerator = new Random(); | |
//Every 20 turns increase difficutly | |
turn++; | |
if (turn % 20 == 0) | |
{ | |
++min01; | |
++min02; | |
max01 += 3; | |
max02 += 3; | |
} | |
int num01 = numberGenerator.Next(min01, max01); | |
int num02 = numberGenerator.Next(min02, max02); | |
string answer; | |
string correctAnswer = Convert.ToString(num01 * num02); | |
Console.WriteLine("Turn: " + turn); | |
if (armour > 0) | |
{ | |
Console.WriteLine("Armour: " + armour); | |
} | |
Console.WriteLine("Health: " + health); | |
Console.WriteLine("Points: " + Math.Round(points)); | |
Console.WriteLine("Experience: " + experience); | |
//Label to return to if an invalid character is entered. | |
Retry: | |
//Asks the question to be answered. Checks if the number is squared | |
Console.WriteLine(); | |
if (num01 == num02) | |
{ | |
Console.WriteLine("what is " + num02 + " squared?"); | |
} | |
else | |
{ | |
Console.WriteLine("What is " + num01 + " multiplied by " + num02 + "?"); | |
} | |
Console.WriteLine(); | |
answer = Console.ReadLine(); | |
//Checks if answer is correct | |
if (answer == correctAnswer) | |
{ | |
//Keeps track of how many turns the Player got correct | |
++turnsCorrect; | |
Console.WriteLine(); | |
//Adds Health | |
if (health > maxHealth) | |
{ | |
health = maxHealth; | |
} | |
if (health < maxHealth) | |
{ | |
health += 1.0f; | |
} else if (health == maxHealth) | |
{ | |
armour += 1f; | |
} | |
//Makes sure player can't receive less than 1 point | |
double pointGain = Math.Round(Convert.ToDouble(answer) / 25 + turnsCorrect); | |
if (pointGain < 1f) | |
{ | |
pointGain = 1f; | |
} | |
//Adds the points | |
points += pointGain; | |
//Calculates and adds experience (Answer of the question / (Points Gained that round - current health) + 8 + (turns correct times 2) | |
double experienceGain = Math.Round(Convert.ToDouble(answer) / (Math.Abs(pointGain - health)) + 8 + (turnsCorrect * 2)); | |
experience += experienceGain; | |
//Power up every 10 turns | |
if (experience >= 100 && turn % 10 == 0) | |
{ | |
Console.WriteLine(); | |
Console.WriteLine("Experience: " + experience); | |
Console.WriteLine(); | |
Console.WriteLine("Choose:"); | |
Console.WriteLine("(1) +1 Skip (skips the question and counts as a correct answer. To use: type \"skip\"). Cost: 100"); | |
Console.WriteLine("(2) +4 Health. Cost: 100"); | |
Console.WriteLine("(3) Divine Shield (allows you to get a question wrong with no negative effects. Does not stack). Cost 100"); | |
Console.WriteLine("(4) +25 Max Health. Cost: 200"); | |
Console.WriteLine("(5) +5 Skips. Cost: 300"); | |
Console.WriteLine("(6) +50 Health. Cost: 300"); | |
Console.WriteLine("(7) Divine Shield 2.0 (can stack multiple divine shield 2.0s with a normal divine shield) and +90 experience. Cost: 300"); | |
Console.WriteLine("(8) Skip this upgrade."); | |
Console.Write("Choice: "); | |
//Changes variables based on the Player's input | |
Choices: | |
string choice = Console.ReadLine(); | |
if (choice == "1") | |
{ | |
experience -= 100; | |
skips += 1; | |
} | |
else if (choice == "2") | |
{ | |
experience -= 100; | |
if (health < maxHealth) | |
{ | |
health += 4.0f; | |
if (health > maxHealth) | |
{ | |
armour = Convert.ToInt16(health) - maxHealth; | |
health = maxHealth; | |
} | |
} | |
else if (health == maxHealth) | |
{ | |
armour += 4; | |
} | |
} | |
else if (choice == "3") | |
{ | |
if (divineShield == false) | |
{ | |
experience -= 100; | |
divineShield = true; | |
} | |
else if (divineShield == true) | |
{ | |
Console.WriteLine(); | |
Console.WriteLine("Divine Shield does not stack. Please choose something else."); | |
goto Choices; | |
} | |
} | |
else if (choice == "4" && experience >= 200) | |
{ | |
experience -= 200; | |
maxHealth += 25; | |
} | |
else if (choice == "5" && experience >= 300) | |
{ | |
experience -= 300; | |
skips += 5; | |
} | |
else if (choice == "6" && experience >= 300) | |
{ | |
experience -= 300; | |
if (health < maxHealth) | |
{ | |
health += 50; | |
if (health > maxHealth) | |
{ | |
armour = Convert.ToInt16(health) - maxHealth; | |
health = maxHealth; | |
} | |
} | |
else if (health == maxHealth) | |
{ | |
armour += 25; | |
} | |
} | |
else if (choice == "7" && experience >= 300) | |
{ | |
experience -= 300; | |
divineShield2 += 1; | |
experience += 90; | |
} | |
else if (choice == "8") | |
{ | |
} | |
else if (choice == "4" || choice == "5" || choice == "6" && experience < 300) | |
{ | |
Console.WriteLine(); | |
Console.WriteLine("You do not have enough experience"); | |
Console.WriteLine(); | |
Console.Write("Choice: "); | |
goto Choices; | |
} | |
else if (choice != "1" || choice != "2" || choice != "3" || choice != "4" || choice != "5" || choice != "6" || choice != "7") | |
{ | |
Console.WriteLine(); | |
Console.WriteLine("Please input a number (1,2,3,4,5,6, or 7)"); | |
Console.WriteLine(); | |
Console.Write("Choice: "); | |
goto Choices; | |
} | |
} | |
//Switch response if answer is correct | |
int responsindex = numberGenerator.Next(1, 4); | |
switch (responsindex) | |
{ | |
case 1: | |
{ | |
if (points == 1f) | |
{ | |
Console.WriteLine("Congrats, your answer was correct. Plus " + pointGain + " point and you gain 1 health."); | |
Console.WriteLine("You gain " + experienceGain + " experience."); | |
Console.WriteLine(); | |
} | |
else | |
{ | |
Console.WriteLine("Congrats, your answer was correct. Plus " + pointGain + " points and you gain 1 health."); | |
Console.WriteLine("You gain " + experienceGain + " experience."); | |
Console.WriteLine(); | |
} | |
break; | |
} | |
case 2: | |
{ | |
if (points == 1f) | |
{ | |
Console.WriteLine("Correct! Plus " + pointGain + " Point and 1 health."); | |
Console.WriteLine("You gain " + experienceGain + " experience."); | |
Console.WriteLine(); | |
} | |
else | |
{ | |
Console.WriteLine("Correct! Plus " + pointGain + " Points and 1 health."); | |
Console.WriteLine("You gain " + experienceGain + " experience."); | |
Console.WriteLine(); | |
} | |
break; | |
} | |
case 3: | |
{ | |
if (points == 1f) | |
{ | |
Console.WriteLine("Spot on! Plus " + pointGain + " Point and 1 health."); | |
Console.WriteLine("You gain " + experienceGain + " experience."); | |
Console.WriteLine(); | |
} | |
else | |
{ | |
Console.WriteLine("Spot on! Plus " + pointGain + " Points and 1 health."); | |
Console.WriteLine("You gain " + experienceGain + " experience."); | |
Console.WriteLine(); | |
} | |
break; | |
} | |
default: | |
{ | |
throw new Exception("Unexspected Case"); | |
} | |
} | |
//Goes to next question while keeping variable values | |
goto Start; | |
//Checks if Player is using a skip and if they have one | |
} else if (answer.ToUpper() == "SKIP") | |
{ | |
if (skips >= 1) | |
{ | |
if (health < maxHealth) | |
{ | |
health += 1.0f; | |
} | |
else if (health == maxHealth) | |
{ | |
armour += 1; | |
} | |
points *= 1.1f; | |
experience += 20; | |
skips -= 1; | |
Console.WriteLine(); | |
} | |
else | |
{ | |
Console.WriteLine(); | |
Console.WriteLine("You have no skips availible"); | |
goto Retry; | |
} | |
goto Start; | |
//Created a section to help with troubleshooting | |
} else if (answer.ToUpper() == "DEVCHEATS") | |
{ | |
Dev: | |
Console.WriteLine(); | |
Console.WriteLine("Welcome"); | |
Console.WriteLine(); | |
Console.WriteLine("Choose:"); | |
Console.WriteLine("(1) Reveal Answer"); | |
Console.WriteLine("(2) Infinite Health"); | |
Console.WriteLine("(3) + Experience"); | |
Console.WriteLine("(4) Instant Kill"); | |
Console.WriteLine("(5) Many Skips"); | |
Console.WriteLine("(6) Increase Difficulty"); | |
Console.WriteLine("(7) Exit Developer Console"); | |
Console.WriteLine(); | |
string devAnswer = Console.ReadLine(); | |
if (devAnswer == "1") | |
{ | |
Console.WriteLine(); | |
Console.WriteLine("The answer is: " + correctAnswer); | |
Console.WriteLine(); | |
goto Retry; | |
} | |
else if (devAnswer == "2") | |
{ | |
health /= 0; | |
Console.WriteLine("Health: " + health); | |
Console.WriteLine(); | |
goto Retry; | |
} | |
else if (devAnswer == "3") | |
{ | |
experience += 300; | |
Console.WriteLine("Experience: " + experience); | |
Console.WriteLine(); | |
goto Retry; | |
} | |
else if (devAnswer == "4") | |
{ | |
health = -100; | |
goto Retry; | |
} | |
else if (devAnswer == "5") | |
{ | |
skips = int.MaxValue; | |
Console.WriteLine("Skips: " + skips); | |
Console.WriteLine(); | |
goto Retry; | |
} | |
else if (devAnswer == "6") | |
{ | |
max01 += 100; | |
max02 += 100; | |
goto Retry; | |
} | |
else if (devAnswer == "7") | |
{ | |
goto Retry; | |
} else if (num.Any(devAnswer.ToLower().Contains) == false) | |
{ | |
Console.WriteLine("That's not a number."); | |
Console.ReadKey(); | |
goto Dev; | |
} else | |
{ | |
Console.WriteLine("... only 7 choices. Choose 1-7."); | |
Console.ReadKey(); | |
goto Dev; | |
} | |
//If answer is wrong | |
} else if (answer != correctAnswer && alpha.Any((answer.ToLower()).Contains) == false && func.Any((answer.ToLower()).Contains) == false) //Makes sure that the input provided is a number to prevent an error | |
{ | |
Console.WriteLine(); | |
//How far the Player's answer was off | |
double diff = Convert.ToInt64(Math.Round(Math.Abs(Convert.ToDouble(answer) - num01 * num02))); | |
//How many points will be lost | |
double lostPoints = Convert.ToInt64(Math.Round(points * 0.25f)); | |
//Variable holding how much armour will be lost | |
float lostArmour = 0; | |
//Checks if Player has the Divine Shield power up to save them | |
if (divineShield == true || divineShield2 >= 1) | |
{ | |
if (divineShield2 >= 1 && divineShield == true) | |
{ | |
divineShield = false; | |
Console.WriteLine("Oh, your answer was " + diff + " off. But you had Divine Shield so you lost no health and no points."); | |
Console.WriteLine(); | |
goto Start; | |
} | |
else if (divineShield2 >= 1 && divineShield == false) | |
{ | |
divineShield2 -= 1; | |
Console.WriteLine("Oh, your answer was " + diff + " off. But you had Divine Shield 2.0 to save you. You lost no health and no points."); | |
Console.WriteLine(); | |
goto Start; | |
} | |
else if (divineShield2 == 0 && divineShield == true) | |
{ | |
divineShield = false; | |
Console.WriteLine("Oh, your answer was " + diff + " off. But you had Divine Shield so you lost no health and no points."); | |
Console.WriteLine(); | |
goto Start; | |
} | |
} | |
//Subtract point | |
points -= lostPoints; | |
//Can't lose more points that you have | |
if (lostPoints > points) | |
{ | |
lostPoints = points; | |
} | |
//Calculate how much health the player loses | |
double lostHealth = Convert.ToInt64(Math.Round(diff / 5)); | |
if (lostHealth > maxHealth) | |
{ | |
lostHealth = Math.Round(lostHealth / 5); | |
} | |
if (lostHealth > maxHealth) | |
{ | |
lostHealth = Math.Round(lostHealth / 5); | |
} | |
if (lostHealth > maxHealth) | |
{ | |
lostHealth = Math.Round(lostHealth / 5); | |
} | |
if (lostHealth > (maxHealth / 2)) | |
{ | |
lostHealth = Math.Round(lostHealth / 5); | |
} | |
if (lostHealth > maxHealth) | |
{ | |
lostHealth = maxHealth; | |
} | |
if (lostHealth < 1) | |
{ | |
lostHealth = 1; | |
} | |
//Subtracts health (honestly the armour was the hardest thing to code and work my mind around in this entire game) | |
//if they have no armour | |
if (armour == 0) | |
{ | |
//Subtract health as normal | |
health -= Math.Round(lostHealth); | |
//If they have armour | |
} else if (armour > 0) | |
{ | |
//But if damage is less than 5 (the ammout of dmg 1 armour reduces) | |
if (lostHealth < 5) | |
{ | |
//Half damage taken instead of subracting 5 | |
lostHealth = Math.Round(lostHealth / 2); | |
lostArmour = 1; | |
armour -= lostArmour; | |
} else | |
{ | |
//if damage is greater than armour damage reduction | |
if (lostHealth > (armour * 5)) | |
{ | |
//armour reduces damage by 5 per armour | |
lostHealth -= (armour * 5); | |
//Out put to tell the Player how much armour was lost | |
lostArmour = armour; | |
//Sets armour to 0 as if damage is greater than armour damage reduction than all armour should be used up | |
armour = 0; | |
//This was the harder one to wrap my head around as I want to subract armour but only the amount of armour that was used | |
} else if (lostHealth < (armour * 5)) | |
{ | |
//Round lost health to nearest 5 | |
lostHealth = Math.Round(lostHealth / 5) * 5; | |
//Divide by 5 as armour is worth 5 health (if damage is 20 and I have 5 armour 20/5 is 4 so subract 4 armour) | |
lostArmour = Convert.ToInt16(lostHealth) / 5; | |
armour -= lostArmour; | |
lostHealth = 0; | |
} | |
} | |
//Subracts lostHealth after it is calculated | |
health -= Math.Round(lostHealth); | |
} | |
//Switch response if answer is wrong | |
int responseIndex2 = numberGenerator.Next(1, 4); | |
switch (responseIndex2) | |
{ | |
case 1: | |
{ | |
if (lostPoints == 1) | |
{ | |
Console.WriteLine("Nope! You were " + diff + " off. Minus 1 point! Minus " + lostHealth + " health and " + lostArmour + " armour!"); | |
Console.WriteLine(); | |
} | |
else | |
{ | |
Console.WriteLine("Nope! You were " + diff + " off. Minus " + lostPoints + " points! Minus " + lostHealth + " health and " + lostArmour + "armour!"); | |
Console.WriteLine(); | |
} | |
break; | |
} | |
case 2: | |
{ | |
if (lostPoints == 1) | |
{ | |
Console.WriteLine("Wrong! You were " + diff + " off. Minus 1 point, and you lost " + lostHealth + " health and " + lostArmour + " armour!"); | |
Console.WriteLine(); | |
} | |
else | |
{ | |
Console.WriteLine("Wrong! You were " + diff + " off. Minus " + lostPoints + " points, and you lost " + lostHealth + " health and " + lostArmour + " armour"); | |
Console.WriteLine(); | |
} | |
break; | |
} | |
case 3: | |
{ | |
if (lostPoints == 1) | |
{ | |
Console.WriteLine("You were " + diff + " off. You lose 1 point, " + lostHealth + " health, and " + lostArmour + " armour :("); | |
Console.WriteLine(); | |
} else | |
{ | |
Console.WriteLine("You were " + diff + " off. You lose " + lostPoints + " points, " + lostHealth + " health, and " + lostArmour + " armour :("); | |
Console.WriteLine(); | |
} | |
break; | |
} | |
default: | |
{ | |
throw new Exception("Unexpected Case"); | |
} | |
} | |
//Checks for 0 health and ends games | |
if (health <= 0.0f) | |
{ | |
health = 0.0f; | |
Console.WriteLine(); | |
Console.WriteLine("Game Over :("); | |
Console.WriteLine("You finished with " + points + " points."); | |
Console.WriteLine(); | |
Console.WriteLine("Would you like to replay? Y/N"); | |
Console.Write("Choice: "); | |
//Checks if player wants to replay or not | |
End: | |
string reply = Console.ReadLine(); | |
if (reply.ToLower() == "y" && alpha2.Any(reply.ToLower().Contains) == false && func.Any(reply.ToLower().Contains) == false && num.Any(reply.ToLower().Contains) == false) | |
{ | |
Console.Clear(); | |
goto Restart; | |
} else if (reply.ToLower() == "n" && alpha2.Any(reply.ToLower().Contains) == false && func.Any(reply.ToLower().Contains) == false && num.Any(reply.ToLower().Contains) == false) | |
{ | |
Environment.Exit(0); | |
} else | |
{ | |
Console.WriteLine(); | |
Console.WriteLine("Please enter a valid answer (\"y\" or \"n\")"); | |
Console.WriteLine(); | |
goto End; | |
} | |
} | |
goto Start; | |
} else | |
{ | |
Console.WriteLine(); | |
Console.WriteLine("Please enter a valid answer."); | |
goto Retry; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment