Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6224731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:43:17+00:00 2026-05-24T08:43:17+00:00

I have a while loop that loops until bool done = true; In the

  • 0

I have a while loop that loops until bool done = true;
In the method TestMoves(), depending on user input, the method returns the bool done as either true or false. However, I do not know how to “send” this value back to the while loop in my Start() method to stop the loop. Here is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {


        public static void Main(string[] args)
        {
            Start("r");
        }

        public static string Start(string move)
        {

            Console.Write("Welcome to the Shotgun App\nEnter s for single player and m for multiplayer: ");
            string gameType = Console.ReadLine();

            if (gameType == "s")
            {

                Console.Write("Single Player Controls:\n r = reload\n s = shield\n f = fire\n ***you start with ammo\n Ready to play?");
                Console.ReadLine();

                int ammo = 1;

                bool done = false;
                while (!done)
                {
                    Console.Write("\nEnter your move: ");
                    move = Console.ReadLine();


                    switch (move)
                    {
                        case "r":
                            Console.Write("\nYou have reloaded, press enter for Genius\n");

                            ammo++;
                            Console.Write("Your ammo is " + ammo);

                            Console.ReadLine();

                            string geniusMove = "";
                            Genius(geniusMove, move, done);
                            Console.ReadLine();




                            break;
                        case "s":
                            Console.Write("\nYou have shielded, press enter for Genius\n");

                            Console.Write("Your ammo is " + ammo);

                            Console.ReadLine();

                            geniusMove = "";
                            Genius(geniusMove, move, done);
                            Console.ReadLine();




                            break;
                        case "f":
                            if (ammo != 0)
                            {
                                Console.Write("\nYou have fired, press enter for Genius\n");

                                ammo--;
                                Console.Write("Your ammo is " + ammo);

                                Console.ReadLine();

                                geniusMove = "";
                                Genius(geniusMove, move, done);
                                Console.ReadLine();
                            }
                            else
                            {
                                Console.Write("You don't have enough ammo, try again");
                                done = false;
                            }
                            break;
                        default:
                            Console.Write("\nInvalid move, try again\n");
                            done = false;
                            break;
                    }


                }
                return move;
            }
            else
            {
                return move;
            }
        }

        static string Genius(string geniusMove, string move, bool done)
        {
            int geniusAmmo = 1;

            geniusMove = "r";
            if (geniusMove == "f")
            {

                geniusAmmo--;
                Console.Write("Genius had decided to fire.\nGenius ammo is " + geniusAmmo + "\n");
            }
            else if (geniusMove == "r")
            {

                geniusAmmo++;
                Console.Write("Genius had decided to reload.\nGenius ammo is " + geniusAmmo + "\n");
            }
            else if (geniusMove == "s")
            {
                Console.Write("Genius had decided to shield.\nGenius ammo is " + geniusAmmo + "\n");
            }
            TestMoves(move, geniusMove, done);
            return geniusMove;
        }


        static bool TestMoves(string move, string geniusMove, bool done)
        {

            if (move == "s" && geniusMove == "f")
            {
                Console.Write("No one has died yet");
                done = false;
                return done;
            }
            else if (move == "f" && geniusMove == "f")
            {
                Console.Write("You both died!  Good game!");
                done = true;
                return done;
            }
            else if (move != "s" && geniusMove == "f")
            {
                Console.Write("You died!  Good game!");
                done = true;
                return done;
            }
            else if (move == "f" && geniusMove == "s")
            {
                Console.Write("No one has died yet");
                done = false;
                return done;
            }
            else if (move == "f" && geniusMove != "s")
            {
                Console.Write("Genius died!  Good game!");
                done = true;
                return done;
            }
            else if (move != "f" && geniusMove != "f")
            {
                Console.Write("No one has died yet");
                done = false;
                return done;
            }
            else
            {
                return done;
            }

        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:43:18+00:00Added an answer on May 24, 2026 at 8:43 am

    Is there a reason you need to call TestMoves from inside of Genius instead of from your loop? It seems to me that your code could be rewritten like this:

    //Every instance of:
    
    string geniusMove = "";
    Genius(geniusMove, move, done);
    Console.ReadLine();
    
    //seems like it could be rewritten as:
    
    string geniusMove = "";
    Genius(geniusMove, move, done);
    done = TestMoves(geniusMove, move, done);
    Console.ReadLine();
    //and then you can remove the call to TestMoves from Genius
    

    The overall flow of all the code is a bit confusing to me. You have each function returning a value, but don’t appear to be doing anything with the return value. I have a feeling that with a bit of refactoring, you could make this code much shorter and more logical.

    After looking at your code a bit more it looks like you could place the call to TestMoves at the very end of your loop:

                        default:
                            Console.Write("\nInvalid move, try again\n");
                            done = false;
                            break;
                    }
    
                    //add it here:
                    done = TestMoves(geniusMove, move, done);
    
                }
                return move;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a Linux program that runs in a while(true) loop, which waits
I have a script that uses a simple while loop to display a progress
I have a tabled view in a while loop, where a user can view
I have a function that loops while doing something that could throw an exception.
The while loop I have while reading in from a file doesn't break. I'm
I'm trying to understand how a while loop looks in IL. I have written
I have a Label, whose content is displayed by a while loop. when i
What I want to do is have a while statement which loops whilst the
I have written a code that solves MST using Prim method. I read that
I am playing with Java and want to do a simple while loop that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.