Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
5.8 kB
2
Indexable
Never
// Written by Derek Wiberg
//Section A01
// 

int pullTotal,
    negativepullTotal,
    attempts = 0,
    ropeInput,
    totalPullStrength = 0,
    roundCounter = 0,
    rightLeprechaunWins = 0,
    leftLeprechaunWins = 0,
    neitherLeprechaunWins = 0;

string leprechaun1name;
string leprechaun2name;
const string rope = "~~~~~~~~~~",
             pit = "1234||7890";

char replay = 'Y';

// logic for first leprechaun string 


Console.Write("Please enter the string for Leprechaun 1! It must be 3 characters or else! ");
leprechaun1name = Console.ReadLine();

while (leprechaun1name.Length != 3)
{
    Console.WriteLine("INVALID ENTRY!!!!!!");
    Console.Write("PLease enter a valid length for the poor Leprechaun: ");
    leprechaun1name = Console.ReadLine();
}

//logic for 2nd leprechaun string
Console.Write("Thank you! Now for the 2nd Leprechaun, It must be 3 characters or else!: ");
leprechaun2name = Console.ReadLine();

while (leprechaun2name.Length != 3)
{
    Console.WriteLine("INVALID ENTRY!!!!!!");
    Console.Write("Do you think this is a game!?!?!? Please enter a valid length for the poor second Leprechaun: ");
    leprechaun2name = Console.ReadLine();
}

//logic for string length determination 

Console.Write("Give me a starting location of leprechaun 2 over 20 or else there shall be no tug of war! ");
ropeInput = int.Parse(Console.ReadLine());

while (ropeInput < 20)
{
    Console.WriteLine("Please enter a valid string length ");
    ropeInput = int.Parse(Console.ReadLine());
}


while (replay == 'Y')
{

    // resets the board if the player wants to play again
    Console.Clear();

    // reset values
    attempts = 0;
    totalPullStrength = 0;
    negativepullTotal = 0;
    pullTotal = 0;

    //title screen of the game

    Console.WriteLine($"PLayer 1: {leprechaun1name}" + $"\nPLayer 2: {leprechaun2name}" + "\n\n");
    Console.WriteLine(pit.PadLeft(ropeInput));
    Console.WriteLine(leprechaun1name.PadLeft(ropeInput-10) + rope + leprechaun2name);
    Console.WriteLine(pit.PadLeft(ropeInput));
    Console.WriteLine("Please Press Enter to Begin");
    Console.ReadLine();

    // refresh screen for start of real game
    Console.Clear();

    while (attempts <= 10 && totalPullStrength <= 5 && totalPullStrength >= -5) 
    {

        // set up the board
        Console.Clear();

        /// random gen for lep 1 and 2 
        /// lep1 is left, lep2 is right 
        /// so minus 2 from 1 should give us the differnce
        /// from here we use negative integer to mean go to the left, or pull left
        /// and then positive integer means pull to the right 
        /// tie will mean no movement 

        Console.WriteLine($"PLayer 1: {leprechaun1name}" + $"\nPLayer 2: {leprechaun2name}" + "\n\n\n");


        //random number generator logic for the pull strengths 
        Random rnd = new Random();
        int lepreachaunAlpha = rnd.Next(1, 5);
        int lepreachaunOmega = rnd.Next(1, 5);
        pullTotal = lepreachaunAlpha - lepreachaunOmega;


        // running counter of the pull strength, if reaches -4 left-chaun wins, if +4 right-chaun wins
        // also works as the counter for rope animation, totalPullStrength relates to the pit location
        totalPullStrength = totalPullStrength + pullTotal;
        Console.WriteLine(totalPullStrength);

        if (pullTotal < 0)         // case if pull left
        {
            negativepullTotal = pullTotal * -1;
            Console.WriteLine($"Leprechaun 1 has pulled {negativepullTotal} to the left! What Majesty! ");

        }
        else if (pullTotal > 0)    // case if pull right
        {
            Console.WriteLine($"the leprechaun has pulled {pullTotal} to the right! Splendid!! ");

        }
        else // case if equal
        {
            Console.WriteLine($"It is a tie! They're an even match dont ya see!!!");

        }
        ////some stuff about the rope 
        Console.WriteLine(pit.PadLeft(ropeInput));
        Console.WriteLine(leprechaun1name.PadLeft(ropeInput - 10 + totalPullStrength) + rope + leprechaun2name);
        Console.WriteLine(pit.PadLeft(ropeInput));

        ///kill screen controls

        // case if right wins
        if (totalPullStrength >= 5)
        {
            Console.WriteLine("The Right Leprechaun pulls his brother to his death. what a grim scene. Collect the gold! ");
            rightLeprechaunWins++;
        }
        // case if left wins
        else if (totalPullStrength <= -5)
        {
            Console.WriteLine("The Left Leprechaun pulls his brother to his death. what a grim scene. Collect the gold! ");
            leftLeprechaunWins++;
        }
        // case if max attempts with no winner
        else if (attempts == 10 && totalPullStrength > -5 && totalPullStrength < 5)
        {
            Console.WriteLine("Neither Leprechaun prevails!");
            neitherLeprechaunWins++;
        } 
        // catch all
        else 
        {
            /// added button to activate logic 
            Console.WriteLine("Press Enter To pull");
            Console.ReadLine();

            attempts++;
        }

    }
    roundCounter++;


    Console.WriteLine("Would you like to play again? Y/N");
    replay = char.ToUpper(char.Parse(Console.ReadLine()));
}
// prints all the results if they don't want to play again
Console.WriteLine("thanks for playing!" + $" You played {roundCounter} rounds of tug of war");
Console.WriteLine($"Leprechaun 1 won {leftLeprechaunWins} number of times");
Console.WriteLine($"Leprechaun 2 won {rightLeprechaunWins} number of times");
Console.WriteLine($"It was a draw {neitherLeprechaunWins} number of times");