-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
117 lines (112 loc) · 4.12 KB
/
Program.cs
File metadata and controls
117 lines (112 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/**
* ######################################################
* ## Programming Assignment #3 ##
* ## Developer: Matthew Obert ##
* ## Date Submitted: September 06 2019 ##
* ## Purpose: Generate ASCII and Algorithmic X. ##
* ######################################################
*/
using System;
using static System.Console;
namespace AsciiX
{
class Program
{
static void WriteMenu(string output)
{
Clear();
WriteLine("Choose an option:\n1 = ASCII Art X\n2 = Algorithmic X\n");
WriteLine("To exit, press 0 (zero) key.\n\n");
WriteLine(output);
}
static void RepeatChar(string character, int reps)
{
for (int i = 0; i < reps; i++)
{
Write(character);
}
}
static void GenerateX(int height)
{
WriteLine("The desired height is {0}.", height);
//generate algorithmic X
for (int i = 0; i < height/2; i++)
{
RepeatChar(" ", i+1);
RepeatChar("#", 1);
RepeatChar(" ", height - (2 * (i + 1)));
WriteLine("#");
}
if (height % 2 != 0)
{
RepeatChar(" ", (height / 2) + 1);
WriteLine("#");
}
for (int i = (height / 2) - 1; i > -1; i--)
{
RepeatChar(" ", i + 1);
RepeatChar("#", 1);
RepeatChar(" ", height - (2 * (i + 1)));
WriteLine("#");
}
}
static void Main(string[] args)
{
string input;
string message = "";
int choice = 0;
while (0 == 0)
{
WriteMenu(message);
input = ReadLine();
while (!int.TryParse(input, out choice))
{
message = "Invalid input.\nPlease choose a number: 0, 1, or 2.";
WriteMenu(message);
input = ReadLine();
}
switch (choice)
{
case 0:
Console.WriteLine("Exiting...");
Environment.Exit(0);
break;
case 1:
WriteLine("Generating ASCII Art X ...");
WriteLine();
WriteLine(" __ __");
WriteLine(" \\ \\ / /");
WriteLine(" \\ V /");
WriteLine(" > <");
WriteLine(" / . \\");
WriteLine(" /_/ \\_\\");
WriteLine();
WriteLine("Press any key to return to menu.");
ReadKey();
break;
case 2:
message = "Generating Algorithmic X ...\nEnter desired height of X:";
WriteMenu(message);
input = ReadLine();
while (!int.TryParse(input, out choice))
{
message = "Generating Algorithmic X ...\nEnter desired height of X:\n";
message += "\nInvalid input.\nPlease choose a number greater than two.";
message += "\nLarge values require a large console to display correctly.";
WriteMenu(message);
input = ReadLine();
}
GenerateX(choice);
message = ""; // set message to empty string to prevent unwanted repetition
WriteLine("Press any key to return to menu.");
ReadKey();
break;
default:
message = "Please choose 0, 1, or 2 next time.";
WriteMenu(message);
break;
}
}
}
}
}