0% found this document useful (0 votes)
11 views28 pages

THIS Is Documentation For Hangman

The document provides a comprehensive guide for setting up and running a console-based Hangman game written in C#. It includes instructions on installing Visual Studio 2022, configuring the project, handling user inputs, managing errors, and source code for the game. Additionally, it features screenshots of game operations and a bibliography for further reference.

Uploaded by

tamkeenebrahim76
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views28 pages

THIS Is Documentation For Hangman

The document provides a comprehensive guide for setting up and running a console-based Hangman game written in C#. It includes instructions on installing Visual Studio 2022, configuring the project, handling user inputs, managing errors, and source code for the game. Additionally, it features screenshots of game operations and a bibliography for further reference.

Uploaded by

tamkeenebrahim76
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 28

TAMKEEN EBRAHIM

EDUV4935339
Table of Contents
1-A description of the program.............................................................................................................2
2 -Instructions on which operating system to use................................................................................3
3-The type and version of programs used............................................................................................5
4 -How to install and set up the program.............................................................................................6
5-A method to run the program...........................................................................................................9
6-The values to enter when asked for user input...............................................................................10
7-Ways to handle any error messages................................................................................................11
8-Screenshots of all operations..........................................................................................................13
9-Source Codes....................................................................................................................................14
10-Bibliography...................................................................................................................................26
1-A description of the
program
-The program is a console-based Hangman game written in
C#. The game chooses a random word from a prepared list,
and the player attempts to guess it by typing one letter at a
time. The player has a limited number of chances to guess
the word properly. This code implements the Hangman game
in a simple yet useful manner, with features for starting a new
game, making guesses, and handling win/lose scenarios.
2 -Instructions on which
operating system to use.
Instructions for Visual Studio 2022 on Windows
Open Visual Studio 2022:

-Launch Visual Studio 2022 from your Start menu or desktop


shortcut.
Create a New Project:
-Click on Create a new project.
-Choose the Console App template. Make sure it's a C#
template.
-Click Next.
Configure Your New Project:
-Enter the project name (e.g., Hangman Project).
-Choose the location where you want to save the project.
-Click Create.
Replace the Default Code:
-In the Solution Explorer pane on the right, find the
Program.cs file.
-Double-click it to open.
-Delete any code already in Program.cs.
-Copy the provided Hangman game code and paste it into the
Program.cs file.
Build and Run the Project:
-Press Ctrl+F5 to build and run the program without
debugging.
-Alternatively, press F5 to run with debugging
3-The type and version of
programs used
Visual Studio 2022:

Type: Integrated Development Environment (IDE)


Version: Visual Studio 2022 (any updated version within this
release should work fine)
4 -How to install and set up
the program.
STEP 1 ; INSTAL VISUAL STUDIO
Download Visual Studio 2022:
-Go to the Visual Studio 2022 download page.
-Choose the edition that suits your needs (Community,
Professional, or Enterprise).
-The Community edition is free and suitable for most users.
-Click Download.
Run the Installer:
-Open the downloaded installer file.
-When the Visual Studio Installer opens, choose the
workloads you want to install.
For this project, select:
-.NET desktop development
-ASP.NET and web development (optional, but recommended
for comprehensive .NET development tools)
Install:
-Click Install to begin the installation process.
-Wait for the installation to complete.
- This might take some time depending on your internet
speed and system performance.
STEP2 : SET UP UR HANGMAN PROJECT
Open Visual Studio 2022:

-Launch Visual Studio 2022 from the Start menu or desktop


shortcut.
Create a New Project:
-On the start window, click Create a new project.
-In the Create a new project window, filter by Console,
choose Console App, and click Next.
Configure Your Project:
-Enter a project name (e.g., Hangman Project).
-Choose a location to save your project.
-Click Create.
Replace the Default Code:
-In the Solution Explorer pane on the right, find Program.cs
and double-click it to open.
-Delete the default code in Program.cs.
-Copy the provided Hangman game code and paste it into
Program.cs.
Step 3: BUILD AND RUN THE PROJECT
Build the Project:
-Click on Build in the top menu and select Build Solution or
press Ctrl+Shift+B.
Run the Project;
-Press Ctrl+F5 to run the program without debugging, or F5
to run with debugging
5-A method to run the
program.
- Open Visual Studio 2022.
-Create a new Console App project.
-Replace the default code in Program.cs with your Hangman
game code.
-Build the project using Ctrl+Shift+B.
-Run the project using Ctrl+F5.
-By following these steps, you can successfully run your
Hangman game program in Visual Studio 2022.
6-The values to enter when
asked for user input
Initial Prompt:
-When you start the game, you will see the game state and a
prompt asking for your guess.
Prompt:
-Enter your guess (or 'quit' to exit, 'new' for new game):
Valid Inputs:
-Single Letter: Enter a single letter to guess a letter in the
word (e.g., A, B, C).
- 'quit': Type quit to exit the game.
- 'new': Type new to start a new game.
Invalid Input:
-If you enter something other than a single letter, quit, or
new, the program will prompt:
7-Ways to handle any error
messages
User Input Invalid
Problem;
-The user might enter something that isn't a valid letter, quit,
or new.
Solution:
-Implement input validation to check if the user input is a
single letter or one of the special commands (quit, new).
-Inform the user of invalid input and prompt them to try
again.

Incorrect Word or State Initialization


Problem:

-Errors in initializing or updating the game state might cause


incorrect gameplay behaviour.

Solution:

-Ensure proper initialization of variables.

-Verify that the game state is updated correctly.


Uncaught Expectations

Problem:

-Runtime errors or exceptions could occur during execution


(e.g., accessing an out-of-bounds index).

Solution:

-Use try-catch blocks to catch exceptions and handle them


gracefully.

-Provide user-friendly error messages.

File or Resource Access Issues

Problem:

-If you plan to add features that involve file operations (e.g.,
saving scores), file access errors may occur.

Solution:

-Use try-catch blocks for file operations.

-Ensure that necessary files or resources are available and


accessible
8-Screenshots of all
operations.

- When u start the game

- INCORECT guess

- won the game with correct guess

- Invalid in puts

- when u run out of attempts


- type ‘new ‘ to start an new game

- type ‘quit’ to quit game

9-Source Codes
Code in writing:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hangman_project_1
{
internal class Program
{
static string[] words = { "HELP", "TOUGH",
"PROGRAMMING", "MYLMS", "LEMONADE" }; //Words: An
array of possible words for the game
static Random random = new Random(); //Random: An
instance of the Random class to select a random word
static string wordToGuess; //Word to guess: The
word that the player needs to guess
static char[] currentWordState; //Current word state: An
array representing the current state of the guessed word
static HashSet<char> correctGuesses; //Correct guesses:
A set of correctly guessed letters
static HashSet<char> incorrectGuesses; //Incorrect
guesses: A set of incorrectly guessed letters
static int remainingAttempts; //Ramaining attempts:
The number of attempts left for the player

static void Main(string[] args)


{
StartNewGame();

while (true) //While (true): An infinite loop to keep


the game running until the player decides to qui
{
Console.Clear();
DisplayGameState();

// Make a guess
Console.Write("Enter your guess (or 'quit' to exit,
'new' for new game): ");
string input = Console.ReadLine().Trim().ToUpper();

// SEE if player wants to end the game and quit


if (input == "QUIT")
{
Console.WriteLine("Thanks for playing!
Goodbye.");
break;
}
// See if the player is intrested to start a new game
else if (input == "NEW")
{
StartNewGame();
continue;
}

// Make sure the input is correct


if (input.Length != 1 || !char.IsLetter(input[0]))
{
Console.WriteLine("Invalid input. Please enter a
single letter, 'quit', or 'new'.");
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
continue;
}

char guess = input[0];

// See the word the player used to guess is in the


right word
if (wordToGuess.Contains(guess))
{
// Refresh the word state
for (int i = 0; i < wordToGuess.Length; i++)
{
if (wordToGuess[i] == guess)
{
currentWordState[i] = guess;
}
}
correctGuesses.Add(guess);
}
else
{
//When the word guess is incorrect add to
incorrect guesses
if (!incorrectGuesses.Contains(guess))
{
incorrectGuesses.Add(guess);
remainingAttempts--;
}
}

// See for the win critera


if (string.Join("", currentWordState) ==
wordToGuess)
{
Console.Clear();
Console.WriteLine("Congratulations! You guessed
the word!");
Console.WriteLine($"The word was:
{wordToGuess}");

// Put the score on scoreboard


EnterScore(wordToGuess, 10 -
remainingAttempts);

// Ask for a new game or to quit


Console.Write("Press 'enter' to start a new game
or 'q' to quit: ");
string choice =
Console.ReadLine().Trim().ToUpper();
if (choice == "Q")
{
break;
}
else
{
StartNewGame();
}
}

// See for any lose condition


if (remainingAttempts <= 0)
{
Console.Clear();
Console.WriteLine("Game Over! You ran out of
attempts.");
Console.WriteLine($"The word was:
{wordToGuess}");

// Ask for a new game or to quit


Console.Write("Press 'enter' to start a new game
or 'q' to quit: ");
string choice =
Console.ReadLine().Trim().ToUpper();
if (choice == "Q")
{
break;
}
else
{
StartNewGame();
}
}
}

Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}

static void StartNewGame()


{
wordToGuess = words[random.Next(words.Length)];
currentWordState = new char[wordToGuess.Length];
correctGuesses = new HashSet<char>();
incorrectGuesses = new HashSet<char>();
remainingAttempts = 10;

//Start currentWordState with underscores


for (int i = 0; i < currentWordState.Length; i++)
{
currentWordState[i] = '_';
}
}

static void DisplayGameState()


{
Console.WriteLine("Hangman Game");
Console.WriteLine("-------------");
Console.WriteLine();

// Show the current word state


Console.Write("Word: ");
foreach (char c in currentWordState)
{
Console.Write(c + " ");
}
Console.WriteLine();

// Show the incorrect guesses


Console.Write("Incorrect Guesses: ");
foreach (char c in incorrectGuesses)
{
Console.Write(c + " ");
}
Console.WriteLine();

// Show the remaining attempts


Console.WriteLine($"Attempts Remaining:
{remainingAttempts}");
Console.WriteLine();
}

static void EnterScore(string word, int score)


{
Console.WriteLine($"Score for '{word}' entered:
{score}");

}
}
}
10-Bibliography
- https://www.geeksforgeeks.org/c-sharp-
programming-language/

- https://docs.microsoft.com/en-us/visualstudio/get-
started/

-
https://docs.microsoft.com/en-us/dotnet/csharp/progr
amming-guide/
-https://eduvosonline.sharepoint.com/:f:/r/sites/
ITECA0-M00BasicCProgramming/Shared
%20Documents/General/Demo%202?
csf=1&web=1&e=88Xn4c

-ITECA0-M00 Lesson 8 - Lesson 10-20240702_100909-


Meeting Recording.mp4

-ITECA0-M00 Lesson 5 - Lesson 7-20240626_101842-


Meeting Recording.mp4
-ITECA0-M00 Lesson 16 & Lesson 18-
20240709_102435-Meeting Recording.mp4

-ITECA0-M00 Lesson 11 - Lesson 14-20240703_101303-


Meeting Recording.mp4

-ITECA0-M00 Lesson 1 - Lesson 4-20240625_102018-


Meeting Recording.mp4

-ITECA0-M00 Lesson 11 - Lesson 14-20240703_101303-


Meeting Recording.mp4
Demo 2

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy