Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is the code but I want to add the stream reader so the input is taken from a text file. HELP! using System; using

This is the code but I want to add the stream reader so the input is taken from a text file. HELP!

using System; using System.IO;

namespace Group1_Drill_Assignment { class Program { static void Main(string[] args) {

bool[,] wellpoints = new bool[400, 200]; points(wellpoints); Console.WriteLine("Enter the first letter of the direction you want to drill in (u,d,l,r) and a positive legnth by which you want to drill (Enter q to quit) "); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("NOTE: Make sure to put a space between the direction and the length "); Console.ForegroundColor = ConsoleColor.White;

int[] currentIndex = { 199, 4 }; int[] nextIndex = { currentIndex[0], currentIndex[1] }; string[] p = Console.ReadLine().Split(); char direction = char.Parse(p[0]);

while (direction != 'q') { int value = Int32.Parse(p[1]); getIndex(direction, value, currentIndex); bool safe = approveValues(currentIndex, nextIndex, wellpoints); string message = (safe) ? "safe" : "DANGER";

Console.WriteLine("{0} {1} {2}", currentIndex[0] - 200, (currentIndex[1] + 1) * -1, message); nextIndex[0] = currentIndex[0]; nextIndex[1] = currentIndex[1]; if (!safe) break; p = Console.ReadLine().Split(); direction = char.Parse(p[0]);

} }

public static void points(bool[,] wellpoints) { wellpoints[200, 0] = true; wellpoints[200, 2] = true; wellpoints[200, 1] = true; wellpoints[201, 2] = true; wellpoints[202, 2] = true; wellpoints[203, 2] = true; wellpoints[205, 2] = true; wellpoints[206, 2] = true; wellpoints[207, 2] = true; wellpoints[203, 3] = true; wellpoints[205, 3] = true; wellpoints[203, 4] = true; wellpoints[204, 4] = true; wellpoints[205, 4] = true; wellpoints[207, 3] = true; wellpoints[207, 4] = true; wellpoints[207, 5] = true; wellpoints[207, 6] = true; wellpoints[206, 6] = true; wellpoints[205, 6] = true; wellpoints[204, 6] = true; wellpoints[203, 6] = true; wellpoints[202, 6] = true; wellpoints[201, 6] = true; wellpoints[200, 6] = true; wellpoints[199, 6] = true; wellpoints[199, 5] = true; wellpoints[199, 4] = true; }

public static void getIndex(char d, int value, int[] currentIndex) { if (d=='u') { currentIndex[1] = currentIndex[1] - value; } else if (d == 'l') { currentIndex[0] = currentIndex[0] - value; } else if (d == 'd') { currentIndex[1] = currentIndex[1] + value; } else if (d == 'r') { currentIndex[0] = currentIndex[0] + value; } }

public static bool approveValues(int[] currentIndex, int[] nextIndex, bool[,] wellpoints) { bool value = true; int count = 0; for(int i = nextIndex[0]; i<=currentIndex[0]; i++) { for(int j = nextIndex[1]; j 1) { value = false; } count += 1; } } return value;

} } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions

Question

=+1. What is the schedule for this project?

Answered: 1 week ago

Question

What is operatiing system?

Answered: 1 week ago

Question

Be familiar with the five basic ways to manage demand.

Answered: 1 week ago