|
-
September 28th, 2012, 08:53 AM
#3
Re: Creating a random number game as a client/server game
I decided to try to make it just as a standalone console application to make sure that I am doing it properly, and then move into the server/client relationship.
Here is what I have so far.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string userChoice = ("");
while (userChoice == "")
{
Thread.Sleep(1000);
Console.WriteLine("Hello. Welcome to the World of Random Numbers. Please select an option.");
Console.WriteLine("");
Console.WriteLine("1. Start random number game.");
Console.WriteLine("2. Instructions.");
Console.WriteLine("3. Exit.");
userChoice = Console.ReadLine();
{
if (userChoice == "2")
{
Console.WriteLine("The server will ask you for a higher and lower number. Please select the range");
Console.WriteLine("of the game you would like to play.");
userChoice = ("");
}
else if (userChoice == "3")
{
Console.WriteLine("Thanks for coming. Have a great day.");
Thread.Sleep(2000);
Environment.Exit(1);
userChoice = ("");
}
else if (userChoice == "1")
{
PlayGame myGame = new PlayGame();
string playAgain = "y";
while (playAgain == "y")
{
Console.WriteLine("Please enter the lowest number in the guessing game...");
myGame.userLow = Console.Read();
Console.WriteLine("Please enter the highest number in the guessing game...");
myGame.userHigh = Console.Read();
Console.WriteLine("Ok, I have picked a random number between " + myGame.userLow + "and" + myGame.userHigh + ". Please make a guess at which number I have chosen");
myGame.userGuess = Console.Read();
if (myGame.userGuess == myGame.serverNumber)
{
Console.WriteLine("Congratulations! You guess the correct number!");
Console.WriteLine("Would you like to play again?");
playAgain = Console.ReadLine();
}
else if (myGame.userGuess != myGame.serverNumber)
{
Console.WriteLine("Sorry, please try again...");
myGame.userGuess = Console.Read();
}
}
}
else
{
Console.WriteLine("Sorry, that is not a valid option. Please try again");
userChoice = ("");
}
}
}
}
}
}
After these lines:
Code:
Console.WriteLine("Please enter the lowest number in the guessing game...");
myGame.userLow = Console.Read();
Console.WriteLine("Please enter the highest number in the guessing game...");
myGame.userHigh = Console.Read();
I need to have int serverNumber generated as a rnadom number between userLow and userHigh, but I keep getting an error stating that I cannot implicitly convert string to int, and vice versa if I try any other ways.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|