Автор работы: Пользователь скрыл имя, 16 Мая 2013 в 09:07, курсовая работа
Аргументы против игр просты: они отнимают у человека время, развивают в нем агрессивные инстинкты, притупляют воображение, служат причиной сотен болезней, начиная от близорукости и кончая воспалением мозга... И вообще — плохо это и все! А немногочисленные либералы относятся к играм как к возрастной болезни — мол, со временем пройдет... И действительно, у некоторых проходит.
Введение………………………………………………………………………...4
Актуальность и значение темы………………………………………………..4
Формулировка целей курсового проекта…..…………………………………6
Аналитический обзор игровых приложений…….…………………………...7
Описание процесса разработки………………………………………………..9
Руководство пользователя……………………………………………………15
Заключение……………………………………………………………………20
Список использованных источников………………………………………..21
Приложения…………………………………………………………………...22
Приложение 1…………………………………………………………………22
/// <summary>
/// Indicates the original or solved word is displayed
/// </summary>
public const int ViewingWord = 6;
/// <summary>
/// The game is diplaying the initial screen
/// </summary>
public const int InitialDisplay = -1;
}
#endregion
#region Game difficulty related
/// <summary>
/// The difficulty levels of the game
/// </summary>
enum DifficultyLevel
{
Easy,
Medium,
Hard
}
/// <summary>
/// The current game difficulty level
/// </summary>
private DifficultyLevel gameDifficulty = DifficultyLevel.Easy;
private const string EasyWordPrefix = "e:";
private const string MediumWordPrefix = "m:";
private const string HardWordPrefix = "h:";
/// <summary>
/// The help timer waits to and checks if you
/// are having difficulty with a word. It provides
/// an extra letter for your convenience
/// </summary>
System.Timers.Timer helpLetterTimer = new System.Timers.Timer();
/// <summary>
/// The time interval for the help timer
/// </summary>
const int HelpTimerInterval = 60000;
/// <summary>
/// Determines if a help letter was given
/// </summary>
bool helpGiven = false;
#endregion
#region Current puzzle word related
private int randomPos1;
private int randomPos2;
/// <summary>
/// The current puzzle word to be solved
/// </summary>
private string CurrentPuzzleWord
{
get
{
return _currentPuzzleWord;
}
}
private string _currentPuzzleWord;
#endregion
#endregion
#region Default constructor
/// <summary>
/// Default constructor
/// Starts off the game engine and window
/// </summary>
public WordGuess()
{
InitializeComponent();
InitiailizeForm();
InitializeWords();
DisplayGuess();
}
#endregion
#region Main game routines
/// <summary>
/// Displays the starting Lingo screen
/// </summary>
private void DisplayGuess()
{
currentAttempt = GameState.InitialDisplay;
string Guess = "GUESS";
for (int i = 0; i < WordLength; i++)
{
MyFadeLabel fl = initLayout.Controls[i] as MyFadeLabel;
fl.Text = Guess[i] + "";
fl.Font = bold;
fl.FadeFromBackColor = Label.DefaultBackColor;
fl.FadeFromForeColor = Label.DefaultBackColor;
if (i == 4)
fl.FadeToBackColor = Color.Orange;
else
fl.FadeToBackColor = Color.CornflowerBlue;
fl.FadeToForeColor = Color.WhiteSmoke;
fl.FadeDuration = 1000;
fl.Fade();
}
guess.Text = "Press ENTER";
guess.SelectionStart = guess.Text.Length;
guess.SelectionLength = 0;
}
/// <summary>
/// Starts a new game
/// </summary>
private void StartGame()
{
Random r = new Random(DateTime.Now.
// Determine two random positions in the word to guess
// NOTE: I had earlier used a naive approach to get the random
// positions. However, that method meant randomPos2 = randomPos1 + 1
// 20% of the time. The following snippet improves it to 16%.
randomPos1 = r.Next(0, WordLength);
randomPos2 = r.Next(0, WordLength - 1);
if (randomPos2 == randomPos1)
{
randomPos2++;
}
// Get the random word to guess making sure its of
// the right difficulty
wordIndex = r.Next(0, words.Count);
while (!
{
wordIndex = r.Next(0, words.Count);
}
_currentPuzzleWord = words[wordIndex].Substring(2);
// Reset the grid and display the inital random letters
ResetGrid();
initLayout.Controls[
initLayout.Controls[
// Set the tooltips for these letters
SetLetterToolTip(initLayout.
SetLetterToolTip(initLayout.
// Highlight the first two letters
MyFadeLabel fl = initLayout.Controls[
fl.FadeToForeColor = Color.White;
fl.FadeToBackColor = Color.CornflowerBlue;
fl.Font = bold;
fl.FadeDuration = fl.MaxTransitions;
fl.Fade();
fl = initLayout.Controls[
fl.FadeToForeColor = Color.White;
fl.FadeToBackColor = Color.CornflowerBlue;
fl.Font = bold;
fl.FadeDuration = fl.MaxTransitions;
fl.Fade();
currentAttempt = GameState.FirstAttempt;
guess.Text = "";
// Reset the history to an empty text entry
history.Clear();
history.Add(guess.Text);
historyIndex = 1;
// Mark the inital two letters as solved
solved[randomPos1] = solved[randomPos2] = true;
definitionLink.Visible = false;
// Set up the bonus score and start the timer
bonusScore = MaximumBonusScore;
bonusTimer.Start();
// Reset help given status
helpGiven = false;
// Reset the font color for the text box
guess.ForeColor = TextBox.DefaultForeColor;
}
/// <summary>
/// Loads the word list from the resource file
/// </summary>
private void InitializeWords()
{
Assembly assembly = Assembly.GetExecutingAssembly(
StreamReader r = new StreamReader(assembly.
while (!r.EndOfStream)
{
words.Add(r.ReadLine());
}
r.Close();
}
#endregion
#region Key press event handlers
/// <summary>
/// The core game processing logic
/// in a monolithic block of code
/// Handles the key press event on the textbox
/// where a guess is entered. The game logic is driven by
/// the key that is pressed
/// </summary>
private void ProcessNormalKeys(object sender, KeyPressEventArgs e)
{
// We handle most of the key presses
e.Handled = true;
// Reset history index to the last position
historyIndex = history.Count;
// If we are displaying the initial Lingo screen
// wait until we get an enter key press
if (currentAttempt == GameState.InitialDisplay)
{
if (e.KeyChar != (char)Keys.Enter)
return;
else
{
StartGame();
return;
}
}
// If escape was pressed once, display the actual word
// If presesed twice, close the form
if (e.KeyChar == (char)Keys.Escape)
{
if (currentAttempt == GameState.ViewingWord)
{
this.Close();
return;
}
else
{
helpGiven = true;
helpLetterTimer.Stop();
UpdateScoreWithPenalty();
DisplayOriginalWord();
return;
}
}
// If escape ' key was pressed display the
// word to be guessed [Silly easter egg ;)]
if (e.KeyChar == '7')
{
guess.Text = CurrentPuzzleWord;
return;
}
// If the user has finished off all the chances,
// do not allow to proceed without clicking the enter key
if (currentAttempt > GameState.LastAttempt && (e.KeyChar != (char)Keys.Enter))
{
guess.ForeColor = Color.Gray;
guess.Text = "Press ENTER";
return;
}
// If enter key has been pressed without entering a five letter word
// or backspace has been pressed, just return
if ((e.KeyChar == (char)Keys.Enter && guess.Text.Length != WordLength && currentAttempt < GameState.MaximumAttemptsOver) || e.KeyChar == (char)Keys.Back)
{
e.Handled = false;
return;
}
// Ignore any keys other than a-z and the enter key at this stage
if ((e.KeyChar.CompareTo('a') < 0 || e.KeyChar.CompareTo('z') > 0) && e.KeyChar != (char)Keys.Enter)
{
return;
}
// User has pressed a key after entering a five letter word
// and has chances left to be guessing
if (guess.Text.Length == WordLength && currentAttempt < GameState.MaximumAttemptsOver)
{
// If the key was not enter, return
if (e.KeyChar != (char)Keys.Enter && guess.SelectionLength == 0)
{
return;
}
if (guess.SelectionLength != 0)
{
e.Handled = false;
return;
}
// Check if the word is valid
if (!IsValidWord(guess.Text))
{
// If the word is not valid, the player
// will miss a chance. The letters in the word
// will not be processed
errorLabel.Visible = true;
guess.SelectAll();
messageLabel.Text = null;
#region User misses a chance
for (int i = 0; i < WordLength; i++)
{
layout.Controls[currentAttempt * WordLength + i].Text = guess.Text[i] + "";
layout.Controls[currentAttempt * WordLength + i].BackColor = Color.Gainsboro;
if (solved[i] && currentAttempt < GameState.LastAttempt)
{
layout.Controls[(
}
}
currentAttempt++;
#endregion
return;
}
else
{
// The word entered is valid
// save in the history
errorLabel.Visible = false;
// If the current word is not the same
// as the one entered, add it to the
// history list
if (history[historyIndex - 1] != guess.Text)
{
history.Add(guess.Text);
historyIndex = history.Count;
}
}
// Display the letters that were correct
DisplayCorrectLetters();
// Display the letters that are not in the right position
DisplayProbableLetters();
// Increment the count of attempts
currentAttempt++;
// If the word is correct, display it is
// and start the game all over again
if (guess.Text == CurrentPuzzleWord)
{
guess.Text = "Correct!";
for (int i = 0; i < WordLength && currentAttempt < GameState.MaximumAttemptsOver; i++)
{
layout.Controls[currentAttempt * WordLength + i].Text = "";
}
definitionLink.Text = "What's " + CurrentPuzzleWord + "?";
definitionLink.Visible = true;
UpdateScore();
currentAttempt = GameState.ViewingWord;
helpLetterTimer.Stop();
return;
}
// Clear the current entry
guess.Text = "";
helpLetterTimer.Start();
return;
}
else if (currentAttempt == GameState.MaximumAttemptsOver)
{
UpdateScoreWithPenalty();
// If all guesses have been exhausted, display what the
// right word was
DisplayOriginalWord();
return;
}
else if (currentAttempt > GameState.MaximumAttemptsOver)
{
// Start off a new game
StartGame();
return;
}
e.Handled = false;
}
/// <summary>
/// Event handler to control up and down key presses to display
/// attempt history
/// </summary>
private void ProcessPreviewKeys(object sender, PreviewKeyDownEventArgs e)
{
// Make sure we are in a game
if (currentAttempt<GameState.
return;
// If the up or down arrow keys are pressed
// populate from history
if (e.KeyCode == Keys.Up)
{
historyIndex = (history.Count + historyIndex - 1) % history.Count;
guess.Text = history[historyIndex];
guess.SelectionStart = guess.Text.Length;
return;
}
if (e.KeyCode == Keys.Down)
{
historyIndex = (historyIndex + 1) % history.Count;
guess.Text = history[historyIndex];
guess.SelectionStart = guess.Text.Length;
return;
}
}
/// <summary>
/// The moment a key up is detected, the help timer
/// will be restarted
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void guess_KeyUp(object sender, KeyEventArgs e)
{
if (!helpGiven && currentAttempt > GameState.FirstAttempt)
{
helpLetterTimer.Stop();
helpLetterTimer.Start();
}
}
#endregion
#region Highlighting letters routines
/// <summary>
/// Routine to mark letters in the guessed word that are
/// also in the original word, but not in the exact position
/// </summary>
private void DisplayProbableLetters()
{
// If the current letter is present elsewhere in
// the word to be guessed, we mark them out in red
int labelPosition = 0;
for (int i = 0; i < WordLength; i++)
{
if (marked[i] && guess.Text[i] == CurrentPuzzleWord[i])
{
continue;
}
for (int j = 0; j < WordLength; j++)
{
if (guess.Text[i] == CurrentPuzzleWord[j])
{