Untitled

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




int pullTotal,
    negativepullTotal,
    attempts = 0,
    ropeInput,
    totalPullStrength = 0,
    roundCounter = 0,
    rightLeprechaunWins = 0,
    leftLeprechaunWins = 0,
    neitherLeprechaunWins = 0;
char replay = 'Y';
string leprechaun1name;
string leprechaun2name;
string namedRope;
const string rope = "~~~~~~~~~~",
             pit = "1234||7890";



// 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')
{
    //clearing attempt token to prevent auto finish of game and so total pull strength doesnt carry over 
    attempts = 0;
    totalPullStrength= 0;

    //refresh the screen to move to the game.
    Console.Clear();

    //title screen of the game
    Console.WriteLine($"PLayer 1: {leprechaun1name}" + $"\nPLayer 2: {leprechaun2name}" + "\n\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();

    //user begins the game
    

        while (attempts <= 10 && totalPullStrength <= 5 && totalPullStrength >= -5)
        {
            /// 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)
            {
                negativepullTotal = pullTotal * -1;
                Console.WriteLine($"Leprechaun 1 has pulled {negativepullTotal} to the left! What Majesty! ");
            }
            else if (pullTotal > 0)
            {
                Console.WriteLine($"the leprechaun has pulled {pullTotal} to the right! Splendid!! ");
            }
            else if (pullTotal == 0)
            {
                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));

            //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++;
            }
            //left boy wins
            else if  (totalPullStrength <= -5)
            {
                Console.WriteLine("The Left Leprechaun pulls his brother to his death. what a grim scene. Collect the gold! ");
                leftLeprechaunWins++;
            }

            // nobody wins
            else if (attempts == 10 && totalPullStrength > -5 && totalPullStrength < 5)
            {
                Console.WriteLine("Neither Leprechaun prevails!");
                neitherLeprechaunWins++;
            }
            // re
            else
            {
                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

    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");