I am pleased to note that I got full functionality to my program!!
Besides my exhaustion doesn't update for some reason and my starves doesn't increment. Thanks for the help BearNutts for pointing my obvious mistakes.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace IslandDrunk
{
class Program
{
static void Main(string[] args)
{
int lives = 0, drowns = 0, starves = 0;
Console.WriteLine("All you need to know... \n1 moves drunk up, 2 moves drunk right, 3 moves drunk down, 4 moves drunk left");
Play(lives, drowns, starves);
}
public static int NumRows()
{
int inNumRows;
String inStringValue;
inStringValue = Console.ReadLine();
while (int.TryParse(inStringValue, out inNumRows) == false)
{
Console.WriteLine("Invalid input");
Console.Write("Please re-enter an integer value between 3 and 25. \n");
inStringValue = Console.ReadLine();
}
if ((inNumRows <= 3) || (inNumRows >= 25))
{
Console.WriteLine("Invalid input");
Console.Write("Please re-enter an integer value between 3 and 25. \n");
inStringValue = Console.ReadLine();
}
return inNumRows;
}
public static int NumColumns()
{
int inNumColumns;
String inStringValue;
inStringValue = Console.ReadLine();
while (int.TryParse(inStringValue, out inNumColumns) == false)
{
Console.WriteLine("Invalid input");
Console.Write("Please re-enter an integer value between 3 and 25. \n");
inStringValue = Console.ReadLine();
}
if((inNumColumns <= 3) || (inNumColumns >= 25))
{
Console.WriteLine("Invalid input");
Console.Write("Please re-enter an integer value between 3 and 25. \n");
inStringValue = Console.ReadLine();
}
return inNumColumns;
}
public static int NumBridges()
{
int inNumBridges;
String inStringValue;
inStringValue = Console.ReadLine();
while (int.TryParse(inStringValue, out inNumBridges) == false)
{
Console.WriteLine("Invalid input");
Console.Write("Please re-enter an integer value between 1 and 25. \n");
inStringValue = Console.ReadLine();
}
if ((inNumBridges <= 0) || (inNumBridges >= 25))
{
Console.WriteLine("Invalid input");
Console.Write("Please re-enter an integer value between 1 and 25. \n");
inStringValue = Console.ReadLine();
}
return inNumBridges;
}
public static int NumExhaustion()
{
int inNumExhaustion;
String inStringValue;
inStringValue = Console.ReadLine();
while (int.TryParse(inStringValue, out inNumExhaustion) == false)
{
Console.WriteLine("Invalid input");
Console.Write("Please re-enter an integer value between 1 and 25. \n");
inStringValue = Console.ReadLine();
}
if ((inNumExhaustion <= 0) || (inNumExhaustion >= 25))
{
Console.WriteLine("Invalid input");
Console.Write("Please re-enter an integer value between 1 and 25. \n");
inStringValue = Console.ReadLine();
}
return inNumExhaustion;
}
public static void Play(int lives, int drowns, int starves)
{
Console.WriteLine("\nPlease enter the amount of rows you want for your island, \nmust be greater than 3, less than 25.");
int rows = NumRows();
Console.WriteLine("\nPlease enter the amount of columns you want for your island, \nmust be greater than 3, less than 25.");
int columns = NumColumns();
Console.WriteLine("\nPlease enter the number of bridges you prefer.");
int bridgeCount = NumBridges();
Console.WriteLine("\nPlease enter how long your drunk can go without food.");
int exhaustion = NumExhaustion();
int drunkGuyX, drunkGuyY;
drunkGuyX = columns / 2;
drunkGuyY = rows / 2;
char[,] island = Dimensions(columns, rows);
Water(island, columns, rows); //Generate water.
Bridge(island, columns, rows, bridgeCount); //Generate bridges.
Land(island, columns, rows); //Generate land.
island[drunkGuyX, drunkGuyY] = 'D'; //Generates drunks location.
MoveDrunk(island, columns, rows, exhaustion, drunkGuyX, drunkGuyY, lives, drowns, starves); //Move D.
Island(island, columns, rows); //Create the island's dimensions.
Console.Read();
}
// Generate the dimensions from user input.
public static char[,] Dimensions(int columns, int rows)
{
char[,] island = new char[columns, rows];
return island;
}
// Create array.
public static void Island(char[,] island, int x, int y)
{
for (int i = 0; i < x; i++)
{
for (int z = 0; z < y; z++)
{
Console.Write(island[i, z]);
}
Console.WriteLine();
}
}
// Fill land in array.
public static char[,] Land(char[,] landArea, int x, int y)
{
for (int i = 1; i < x - 1; i++)
{
for (int z = 1; z < y - 1; z++)
{
landArea[i, z] = '+';
}
}
return landArea;
}
// Fill water in array.
public static char[,] Water(char[,] landArea, int x, int y)
{
for (int i = 0; i < x; i++)
{
for (int z = 0; z < y; z++)
{
landArea[i, z] = 'W';
}
}
return landArea;
}
// Generate random placement of bridges from user input.
public static char[,] Bridge(char[,] bridge, int x, int y, int bridgeCount)
{
int numBridges = 0;
while (numBridges < bridgeCount)
{
Random random = new Random();
int randy = random.Next(0, 4);
if (randy == 0)
{
int left = random.Next(1, x - 1);
if (bridge[left, 0] != 'B')
{
bridge[left, 0] = 'B';
numBridges++;
}
}
if (randy == 1)
{
int bottom = random.Next(1, y - 1);
if (bridge[x - 1, bottom] != 'B')
{
bridge[x - 1, bottom] = 'B';
numBridges++;
}
}
if (randy == 2)
{
int right = random.Next(1, x - 1);
if (bridge[right, y - 1] != 'B')
{
bridge[right, y - 1] = 'B';
numBridges++;
}
}
if (randy == 3)
{
int top = random.Next(1, y - 1);
if (bridge[0, top] != 'B')
{
bridge[0, top] = 'B';
numBridges++;
}
}
}
return bridge;
}
// Move the D and update lives, drowns, and starves.
public static char[,] MoveDrunk(char[,] drunk, int x, int y, int exhaustion, int drunkGuyX, int drunkGuyY, int lives, int drowns, int starves)
{
Random random = new Random();
int s = random.Next(1, 4);
int gameCount = 0;
int exh = 0;
while (gameCount < 50)
{
if (exh < exhaustion)
{
if (s == 1)// Random 1, move up.
{
drunk[drunkGuyX, drunkGuyY] = '+';
exh++;
Console.WriteLine("Your drunk moved, " + s + " and your exhaustion level is, " + exh + ".");
drunkGuyY++;
if (drunk[drunkGuyX, drunkGuyY] == 'W')
{
drowns++;
gameCount++;
Console.WriteLine("Game Over... \n\n" + "Results: " + "\n\nSurvived: " + lives + "\nDrowned: " + drowns + "\nStarved: " + starves + "\n");
Play(lives, drowns, starves);
}
if (drunk[drunkGuyX, drunkGuyY] == 'B')
{
lives++;
gameCount++;
Console.WriteLine("Game Over... \n\n" + "Results: " + "\n\nSurvived: " + lives + "\nDrowned: " + drowns + "\nStarved: " + starves + "\n");
Play(lives, drowns, starves);
}
drunk[drunkGuyX, drunkGuyY] = 'D';
random = new Random();
Island(drunk, x, y);
//Console.ReadKey();
return MoveDrunk(drunk, x, y, exhaustion, drunkGuyX, drunkGuyY, lives, drowns, starves);
}
else if (s == 2)// Random 2, move right.
{
drunk[drunkGuyX, drunkGuyY] = '+';
exh++;
Console.WriteLine("Your drunk moved, " + s + " and your exhaustion level is, " + exh + ".");
drunkGuyX++;
if (drunk[drunkGuyX, drunkGuyY] == 'B')
{
lives++;
gameCount++;
Console.WriteLine("Game Over... \n\n" + "Results: " + "\n\nSurvived: " + lives + "\nDrowned: " + drowns + "\nStarved: " + starves + "\n");
Play(lives, drowns, starves);
}
if (drunk[drunkGuyX, drunkGuyY] == 'W')
{
drowns++;
gameCount++;
Console.WriteLine("Game Over... \n\n" + "Results: " + "\n\nSurvived: " + lives + "\nDrowned: " + drowns + "\nStarved: " + starves + "\n");
Play(lives, drowns, starves);
}
drunk[drunkGuyX, drunkGuyY] = 'D';
random = new Random();
Island(drunk, x, y);
//Console.ReadKey();
return MoveDrunk(drunk, x, y, exhaustion, drunkGuyX, drunkGuyY, lives, drowns, starves);
}
else if (s == 3)// Random 3, move down.
{
drunk[drunkGuyX, drunkGuyY] = '+';
exh++;
Console.WriteLine("Your drunk moved, " + s + " and your exhaustion level is, " + exh + ".");
drunkGuyY--;
if (drunk[drunkGuyX, drunkGuyY] == 'B')
{
lives++;
gameCount++;
Console.WriteLine("Game Over... \n\n" + "Results: " + "\n\nSurvived: " + lives + "\nDrowned: " + drowns + "\nStarved: " + starves + "\n");
Play(lives, drowns, starves);
}
if (drunk[drunkGuyX, drunkGuyY] == 'W')
{
drowns++;
gameCount++;
Console.WriteLine("Game Over... \n\n" + "Results: " + "\n\nSurvived: " + lives + "\nDrowned: " + drowns + "\nStarved: " + starves + "\n");
Play(lives, drowns, starves);
}
drunk[drunkGuyX, drunkGuyY] = 'D';
random = new Random();
Island(drunk, x, y);
//Console.ReadKey();
return MoveDrunk(drunk, x, y, exhaustion, drunkGuyX, drunkGuyY, lives, drowns, starves);
}
else// Random 4, move left.
{
drunk[drunkGuyX, drunkGuyY] = '+';
exh++;
Console.WriteLine("Your drunk moved, " + s + " and your exhaustion level is, " + exh + ".");
drunkGuyX--;
if (drunk[drunkGuyX, drunkGuyY] == 'B')
{
lives++;
gameCount++;
Console.WriteLine("Game Over... \n\n" + "Results: " + "\n\nSurvived: " + lives + "\nDrowned: " + drowns + "\nStarved: " + starves + "\n");
Play(lives, drowns, starves);
}
if (drunk[drunkGuyX, drunkGuyY] == 'W')
{
drowns++;
gameCount++;
Console.WriteLine("Game Over... \n\n" + "Results: " + "\n\nSurvived: " + lives + "\nDrowned: " + drowns + "\nStarved: " + starves + "\n");
Play(lives, drowns, starves);
}
drunk[drunkGuyX, drunkGuyY] = 'D';
random = new Random();
Island(drunk, x, y);
//Console.ReadKey();
return MoveDrunk(drunk, x, y, exhaustion, drunkGuyX, drunkGuyY, lives, drowns, starves);
}
}
// End the game with input.
if (exh == exhaustion)
{
starves++;
gameCount++;
Console.WriteLine("Game Over... \n\n" + "Results: " + "\n\nSurvived: " + lives + "\nDrowned: " + drowns + "\nStarved: " + starves + "\n");
Console.WriteLine("Do you want to keep playing? Enter n to end the game and any other key to play again.");
String inStringValue;
inStringValue = Console.ReadLine();
string endGame = inStringValue;
if (endGame == "n")
{
Console.WriteLine("This Game is about to close in 4 seconds...");
System.Threading.Thread.Sleep(4000);
System.Environment.Exit(0);
}
else
{
Play(lives, drowns, starves);
}
}
}
return drunk;
}
}
}