console Hangman game

hangman game ideas assistance

Page 1 of 1

3 Replies - 1830 Views - Last Post: 05 December 2009 - 10:32 PM Rate Topic: -----

#1 skulachi  Icon User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 7
  • Joined: 04-December 09

console Hangman game

Posted 04 December 2009 - 09:59 AM

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication2
{
	class Program
	{
		static void Main(string[] args)
		{
			using (StreamReader sr = new StreamReader("word.txt"))

			Console.WriteLine(sr.ReadLine());
		   


			string sName;
			char cGuess;


			//draw the hang structure
			//displaying the game display output on screen


			Console.WriteLine("							  *************************	");
			Console.WriteLine("							  *		Hangman		*	");
			Console.WriteLine("							  *		Survival	   *	");
			Console.WriteLine("							  *		 Quest		 *	");
			Console.WriteLine("							  *************************	");
			Console.WriteLine("								   ________________		");
			Console.WriteLine("								   |		 |			 ");
			Console.WriteLine("								   |		( )			");
			Console.WriteLine("								   |		/|\\		   ");
			Console.WriteLine("								   |		 |			 ");
			Console.WriteLine("								   |		/|\\		   ");
			Console.WriteLine("								   |					   ");
			Console.WriteLine("								   |					   ");
			Console.WriteLine("								  _|_______				");


			Console.WriteLine();
			Console.WriteLine();

			//Ask user to Enter Name
			Console.Write("Enter your Name: ");
			sName = Convert.ToString(Console.ReadLine());


			Console.Clear();

			//displaying user greeting message
			Console.WriteLine(sName + ", Lets See you go");






			Console.WriteLine("				________________		  ");
			Console.WriteLine("				|		   |			 ");
			Console.WriteLine("				|						 ");
			Console.WriteLine("				|						 ");
			Console.WriteLine("				|						 ");
			Console.WriteLine("				|						 ");
			Console.WriteLine("				|						 ");
			Console.WriteLine("				|						 ");
			Console.WriteLine("			   _|_______				  ");


			Console.WriteLine();


			Console.WriteLine();
			Console.WriteLine("						   ***Enter a new letter***");
			Console.WriteLine();
			Console.Write("What Is Your Guess? : ");
			cGuess = Convert.ToChar(Console.ReadLine());
			cGuess = char.ToUpper((char)cGuess);//converting all character input to uppercase

		   

			Console.WriteLine(" your guess so far is " + cGuess);
			Console.ReadKey();
		}
	}
}


I am new to the world of programming and as a matter of fact this is my 6th week in it and i am trying to implement this game. i am trying to do this i am having difficulty, i have run out of ideas, i need guidance please,

I tried to read the guesses from streamReader but all effort has failed me,

if have also been trying to implement functions which i am just hearing about 3days ago, but all effort in reading is not yielding... it like the more i read the less i undrstand.... hmmn i know i would be considered dummy there but its ok especially as this effort as cost me sleepless nights in my quest to get it riight ....


please how do i read in the words in the files to the guess and match the word , how also can i display a path of each hanging man state each time a character is missed?
these are my problems and i have tried, your suggestions are highly needed.
Thank you all.

Is This A Good Question/Topic? 0
  • +

Replies To: console Hangman game

#2 MentalFloss  Icon User is offline

  • "ADDICTED"[2:5]
  • member icon

Reputation: 526
  • View blog
  • Posts: 1,397
  • Joined: 02-September 09

Re: console Hangman game

Posted 04 December 2009 - 11:53 AM

Start by telling us your exact specification.
Type it all up as detailed as you can.

Try to avoid programming concepts entirely.

For example, I'll do tic tac toe.

Game Rules:
- Two players
- One player uses "X" tokens and the other player uses "O" tokens.
- Each player alternates turns placing their tokens on a 3x3 board.
- When one player has scored 3 of the same token in a row (Either diagonally, horizontally, or vertically) that player wins.
- If all spaces on the board are occupied by player tokens, the game is a tie (cats game)



Then, once you know the rules that you need to adhere to, you can start fleshing out the programming concepts.

Game Logic:
- Game begins by presenting an ASCII drawing of a tic-tac-toe board on screen.
	- tic-tac-toe board's squares each have a number in them which will allow players to specify their move.
- Player One inputs a number (1-9) of their choice.
- Game checks to make sure that their choice is not already filled in with a token.
	- If it is, Game prompts player to enter choice.
	- If it is not, Game replaces number with player's token.
- Game checks if newly placed token wins the game or causes a tie.
	- If it is either a win or a tie:
		- If it is a win, Game prompts player that they won.
		- If it is a tie, Game prompts player that the game is a tie.
		- Game asks if they would like to play a new game.
			- If yes, start over.
			- If no, exit.
- Player Two inputs a number (1-9) of their choice.
- Game checks to make sure that their choice is not already filled in with a token.
	- If it is, Game prompts player to enter choice.
	- If it is not, Game replaces number with player's token.
- Game checks if newly placed token wins the game or causes a tie.
	- If it is either a win or a tie:
		- If it is a win, Game prompts player that they won.
		- If it is a tie, Game prompts player that the game is a tie.
		- Game asks if they would like to play a new game.
			- If yes, start over.
			- If no, exit.



Then, you're like OH WOW! Player One behavior and Player Two behavior are the same! They can be a method!

Game Logic Revised:

- Game begins by presenting an ASCII drawing of a tic-tac-toe board on screen.
	- tic-tac-toe board's squares each have a number in them which will allow players to specify their move.
- Game Repeat:
	- Call [Player Input] and give current player.


[Player Input] Receive current player.
- Ask player to input number (1-9) for their choice.
- Player One inputs a number (1-9) of their choice.
- Game checks to make sure that their choice is not already filled in with a token.
	- If it is, Game prompts player to enter choice.
	- If it is not, Game replaces number with player's token.



You know, and so on and on.... just keep tweaking and revising until it is in logical chunks and concepts.
THEN
You start coding :)

So, yeah... write that up and post it. And we'll help you out with what needs to be done.

This post has been edited by MentalFloss: 04 December 2009 - 11:54 AM

Was This Post Helpful? 0
  • +
  • -

#3 Teres  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 22
  • Joined: 02-December 09

Re: console Hangman game

Posted 05 December 2009 - 10:49 AM

Here's how I would read user guess
Console.WriteLine();
			Console.WriteLine("						   ***Enter a new letter***");
			Console.WriteLine();
			bool repeat = false;
			do
			{
				Console.Write("What Is Your Guess? : ");
				string sGuess = Console.ReadLine();
				if (sGuess.Length > 1)
				{
					Console.WriteLine("Ekem... no cheating, just one letter is allowed");
					repeat = true;
				}
				else
				{
					cGuess = Convert.ToChar(sGuess);
					if (char.IsLetter(cGuess) == true)
					{
						cGuess = char.ToUpper((char)cGuess);//converting all character input to uppercase
						repeat = false;
					}
					else
					{
						Console.WriteLine("You can enter only letters");
						repeat = true;
					}
				}
			} while (repeat);


I would also create a method with an int parameter to distinguish what kind of a gallow should be drawn.
It could return a bool type saying wheter the player is dead.
Was This Post Helpful? 0
  • +
  • -

#4 carltech  Icon User is offline

  • What did you call me?
  • member icon

Reputation: 28
  • View blog
  • Posts: 997
  • Joined: 19-October 07

Re: console Hangman game

Posted 05 December 2009 - 10:32 PM

I would make a few drawing methods...one for the tree, rope and title, one to add body parts...The main screen could bee drawn once then you could use Console.CursorTop/Left to add the body parts and write over the question with spaces to blank them out and ask again and add the letters to the specific places->this could reduce any flickering that would occur when clearing the console and redrawing everything.

All in all it sounds pretty simple. My friend did hangman in assembly and said it was a nightmare.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1