Click here to Skip to main content
15,902,112 members
Home / Discussions / C#
   

C#

 
GeneralRe: how to insert wifi scan data into sql table Pin
Olu_0112-Feb-15 23:17
Olu_0112-Feb-15 23:17 
GeneralRe: how to insert wifi scan data into sql table Pin
Wendelius13-Feb-15 3:01
mentorWendelius13-Feb-15 3:01 
GeneralRe: how to insert wifi scan data into sql table Pin
Olu_0116-Feb-15 12:16
Olu_0116-Feb-15 12:16 
AnswerRe: how to insert wifi scan data into sql table Pin
Chris Quinn13-Feb-15 0:29
Chris Quinn13-Feb-15 0:29 
GeneralRe: how to insert wifi scan data into sql table Pin
Olu_0116-Feb-15 12:15
Olu_0116-Feb-15 12:15 
AnswerRe: how to insert wifi scan data into sql table Pin
Richard Deeming13-Feb-15 2:39
mveRichard Deeming13-Feb-15 2:39 
GeneralRe: how to insert wifi scan data into sql table Pin
Olu_0116-Feb-15 12:12
Olu_0116-Feb-15 12:12 
Questionhow can i call a whole word function in update when lives =0... whole word fun displays whole word... but i am facing different errors when i call it in update.. Pin
Member 1144879612-Feb-15 17:35
Member 1144879612-Feb-15 17:35 
C#
using UnityEngine;
using System.Collections;

namespace InaneGames {
/// <summary>
/// Hang man game script
/// </summary>
public class HangMan : MonoBehaviour
{ // high score
		public char str;
		public GUISkin guiskin;
		// high score
	public enum State	
	{
		IDLE,
		NEXT_WORD
	};
		public static bool check;


		// my full word


		public static  bool FW=true;


		// my  full wors ends
		public bool rc;
	private State m_state;
	/// <summary>
	/// The time before displaying the next word
	/// </summary>
	public float nextWordTime = 1;
	private float m_nextWordTime;
	
	/// <summary>
	/// An array of text files
	/// </summary>
	public TextAsset[] fileTexts;
	
	/// <summary>
	/// The score bonus per letter.
	/// </summary>
	public int scoreBonusPerLetter = 15;
	
	/// <summary>
	/// The score punish per wrong letter.
	/// </summary>
	public int scorePunishPerWrongLetter = 20;
	
	/// <summary>
	/// The mystery letter for displaying when a letter has not been pressed
	/// </summary>
	public char mysteryLetter = '!';	
	
	private bool resetLivesOnCorrectWord = true;	
	
	/// <summary>
	/// The number of lives for the hangman
	/// </summary>
	public int lives;
	
	/// <summary>
	/// The max number of questions.
	/// </summary>
	public int maxQuestions = 8;
	
	/// <summary>
	/// the number of lives the player starts off with
	/// </summary>
	public string freeLetters = " ";
	
	/// <summary>
	/// The audio clip to play when you get the right letter
	/// </summary>
	public AudioClip onCorrectAC;
	
	/// <summary>
	/// The audio clip to play when you get the incorrect letter
	/// </summary>
	public AudioClip onIncorrectAC;
	
	/// <summary>
	/// The audio clip to play when you get the right word
	/// </summary>	
	public AudioClip onRightWordAC;
	
	/// <summary>
	/// The audio clip to play when you lose
	/// </summary>	
	public AudioClip onLoseAC;
	
	private string[] m_words;
	private bool[] m_gotLetter;
	
	private string m_currentWord;
	private int m_wordIndex=0;
	private string m_word = "";

	
	private int m_lives;
	private int m_score = 0;

		// HIGH SCORE
		public int highScore;
		// hogh score ends


	private HangManGUI m_hangManGUI;
	public bool chooseRandomCategory = true;
	
		// high score
		public void OnGUI () {
			GUI.skin = guiskin;
			
			
			
			

			
			

			
			GUI.Label ( new Rect (0, 0, 300, 40),   " High Scores:" + highScore); 
		}


		// high score ends



		public void Awake()
	{



			// HIGH SCORE
			highScore = PlayerPrefs.GetInt ("High Score", 0);
			// HIGH SCORE ENDS


		m_lives = lives;
		int r = Misc.getIntValue("CATEGORY_INDEX");

		if(chooseRandomCategory)
		{
			r = Random.Range(0,fileTexts.Length-1);
		}
		
		TextAsset ta = fileTexts[r];
		//make all words uppercase
		string str = ta.text.ToUpper();
		
		//split our words
		m_words = str.Split('\n');
		m_words = randomizeArray(m_words);
		m_hangManGUI = gameObject.GetComponent<HangManGUI>();
		
		setNextWord();

		if(m_hangManGUI)
		{
			m_hangManGUI.init( ta.name, m_word,m_lives);
		}
	}
		
	public bool checkIfWordContainsLetter(string str)
	{
		 rc = false;
		for(int i=0; i<m_currentWord.Length; i++)
		{
			string tmp = m_currentWord[i].ToString();
			if(tmp.Equals(str))			
			{
				m_gotLetter[i]=true;
				rc=true;
			}

		}
		return rc;
	}
	public void fillWord()
	{



		m_word = "";
		for(int i=0; i<m_currentWord.Length; i++)
		{
			if(m_gotLetter[i])
			{
				m_word += m_currentWord[i];
			}else{
				m_word += mysteryLetter.ToString(); 
					//m_word+=m_currentWord[i];
			} 

		}

	}

	void Update()
		{ 

		

			// high score
			if(m_score > highScore){
				highScore = m_score;
				PlayerPrefs.SetInt("High Score", highScore);
				PlayerPrefs.Save();
				// high score ends

				
			}

		if(m_state == State.NEXT_WORD)
		{
			handleNextWord();
		}


	}
	void handleNextWord()
	{

		m_nextWordTime-=Time.deltaTime;
		if(m_nextWordTime<0)
		{
			m_state = State.IDLE;
			setNextWord();
			if(resetLivesOnCorrectWord)
			{
				m_lives = lives;
			}
			m_hangManGUI.setLives(m_lives);			
		}
	}  
	void onCorrectLetter()
	{ 



			fillWord ();
		m_hangManGUI.setWord( m_word );
			
		if(m_word.Equals(m_currentWord))
		{	
			if(audio)
			{
				audio.PlayOneShot(onRightWordAC);
			}
			m_score += m_currentWord.Length * scoreBonusPerLetter;
			m_hangManGUI.setScore (m_score);		
			m_nextWordTime = nextWordTime;
			m_state = State.NEXT_WORD;
			

		
		}else{
			if(audio)
			{
				audio.PlayOneShot(onCorrectAC);
			}
		}
	}
	void onIncorretLetter()
	{

		m_lives--;
		m_hangManGUI.setLives ( m_lives );
		m_score -= scorePunishPerWrongLetter;
		m_hangManGUI.setScore(m_score);



		if (m_lives > 0) {	
								if (audio) {
										audio.PlayOneShot (onIncorrectAC);
								}
						} else {
		 
								if (audio) {


										audio.PlayOneShot (onLoseAC);
								}
				             

			
								m_hangManGUI.setGameOver (false);
	
						
					
				}

	}
	public void selectLetter(string str)
	{
		if(checkIfWordContainsLetter(str))
		{
			onCorrectLetter();			
		}else{
			onIncorretLetter();
		}

					
	}
	
	void setNextWord()
	{
		if(m_wordIndex+1 <= m_words.Length)
		{
			m_currentWord = m_words[m_wordIndex++];
			m_word = "";
			m_gotLetter = new bool[m_currentWord.Length];
			for(int i=0; i<m_currentWord.Length; i++)
			{
				m_gotLetter[i]=false;
				if(isFreeLetter(m_currentWord[i]))
				{
					m_word += m_currentWord[i].ToString();
					m_gotLetter[i]=true;
				}else{
					m_word += mysteryLetter.ToString();
					
				}
			}
			m_hangManGUI.clearButtons();
			m_hangManGUI.setWord(m_word);
		}else{
			m_hangManGUI.setGameOver(true);
		}
	}
	
	public bool isFreeLetter(char str)
	{
	
							 rc = false;


								for (int i=0; i<freeLetters.Length; i++) {
										if (str == freeLetters [i]) {
												rc = true;
										}

								}
						
		 

								return rc;
						 


	}

		//my function start
		public bool wholeword(){
				
			rc = true;
			for (int j=0; j<freeLetters.Length; j++) {
				if (str == freeLetters[j]){
					rc=true;
				}}
			return rc;}
		// my function ends.

	
	string[] randomizeArray(string[] arr)
	{
	    for (int i = arr.Length - 1; i > 0; i--) 
		{
	        int r = Random.Range(0,i);
	        var tmp = arr[i];
	        arr[i] = arr[r];
	        arr[r] = tmp;
	    }
		return arr;
	}
}
}

SuggestionRe: how can i call a whole word function in update when lives =0... whole word fun displays whole word... but i am facing different errors when i call it in update.. Pin
Richard MacCutchan12-Feb-15 22:33
mveRichard MacCutchan12-Feb-15 22:33 
Questionhow can i show a pop up of high scores for few seconds when high scores are achieved in c# Pin
Member 1144879612-Feb-15 17:31
Member 1144879612-Feb-15 17:31 
AnswerRe: how can i show a pop up of high scores for few seconds when high scores are achieved in c# Pin
Pete O'Hanlon12-Feb-15 19:21
mvePete O'Hanlon12-Feb-15 19:21 
QuestionC# and AccDB: Products with category in combo box. Pin
sdfsdfsdfewrew3feff12-Feb-15 16:04
sdfsdfsdfewrew3feff12-Feb-15 16:04 
AnswerRe: C# and AccDB: Products with category in combo box. Pin
Dave Kreskowiak12-Feb-15 16:54
mveDave Kreskowiak12-Feb-15 16:54 
GeneralRe: C# and AccDB: Products with category in combo box. Pin
sdfsdfsdfewrew3feff15-Feb-15 14:35
sdfsdfsdfewrew3feff15-Feb-15 14:35 
GeneralRe: C# and AccDB: Products with category in combo box. Pin
Dave Kreskowiak15-Feb-15 16:20
mveDave Kreskowiak15-Feb-15 16:20 
GeneralRe: C# and AccDB: Products with category in combo box. Pin
sdfsdfsdfewrew3feff16-Feb-15 2:51
sdfsdfsdfewrew3feff16-Feb-15 2:51 
GeneralRe: C# and AccDB: Products with category in combo box. Pin
Dave Kreskowiak16-Feb-15 3:03
mveDave Kreskowiak16-Feb-15 3:03 
GeneralRe: C# and AccDB: Products with category in combo box. Pin
sdfsdfsdfewrew3feff16-Feb-15 13:37
sdfsdfsdfewrew3feff16-Feb-15 13:37 
GeneralRe: C# and AccDB: Products with category in combo box. Pin
Dave Kreskowiak16-Feb-15 14:27
mveDave Kreskowiak16-Feb-15 14:27 
GeneralRe: C# and AccDB: Products with category in combo box. Pin
sdfsdfsdfewrew3feff16-Feb-15 15:56
sdfsdfsdfewrew3feff16-Feb-15 15:56 
GeneralRe: C# and AccDB: Products with category in combo box. Pin
Dave Kreskowiak16-Feb-15 16:11
mveDave Kreskowiak16-Feb-15 16:11 
Questionerror is coming while application is running and ask to continue the application Pin
Member 1142314612-Feb-15 4:41
Member 1142314612-Feb-15 4:41 
AnswerRe: error is coming while application is running and ask to continue the application Pin
Dave Kreskowiak12-Feb-15 5:10
mveDave Kreskowiak12-Feb-15 5:10 
AnswerRe: error is coming while application is running and ask to continue the application Pin
OriginalGriff12-Feb-15 5:26
mveOriginalGriff12-Feb-15 5:26 
AnswerRe: error is coming while application is running and ask to continue the application Pin
jschell12-Feb-15 11:15
jschell12-Feb-15 11:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.