: .NET Compact Framework

13.1.

13.1.

//--------------------------------------------------------------------------
// , ,
//--------------------------------------------------------------------------
private enum GameUIState {
startScreen = 1,
waitForNextQuestion = 2,
waitForUserToStateKnowledge = 4,
waitForUserToAnswerMultipleChoice = 8
}
//
private GameUIState m_GameUIState;
//==========================================================================
// ,
//==========================================================================
private void StateChangeForGameUI(GameUIState newGameUIState) {
m_GameUIState = newGameUIState;
switch (newGameUIState) {
case GameUIState.startScreen:
buttonAskQuestion.Visible = true;
buttonAskQuestion.Text = "Start";
//
textBoxAskQuestion.Visible = false;
SetAnswerButtonVisibility(false);
SetDifficultyButtonVisibility(false);
break;
case GameUIState.waitForNextQuestion:
setQuestionText("List answer details here... rn" +
"Lots of space to write...rn" +
"Waiting for user to select next question...");
textBoxAskQuestion.Visible = true;
buttonAskQuestion.Text = "Next";
buttonAskQuestion.Visible = true;
// ,
buttonAskQuestion.BringToFront();
SetAnswerButtonVisibility(false);
SetDifficultyButtonVisibility(false);
#if PLAYFIELD ON_BOTTOM //
//
textBoxAskQuestion.Height = pictureBoxGameBoard.Top - 2;
#else //
//
textBoxAskQuestion.Top = pictureBoxGameBoard.Top + pictureBoxGameBoard.Height + 2;
textBoxAskQuestion.Height = this.Height - textBoxAskQuestion.Top;
#endif
break;
case GameUIState.waitForUserToStateKnowledge:
SetTextForVocabularyQuestion();
textBoxAskQuestion.Visible = true;
buttonAskQuestion.Visible = false;
SetAnswerButtonVisibility(false);
SetDifficultyButtonVisibility(true);
#if PLAYFIELD_ON_BOTTOM //
//
textBoxAskQuestion.Height = buttonShowAnswers_AdvancedVersion.Top - 2;
#else //
//
textBoxAskQuestion.Top = buttonShowAnswers_AdvancedVersion.Top + buttonShowAnswers_AdvancedVersion.Height + 2;
textBoxAskQuestion.Height = this.Height - textBoxAskQuestion.Top;
#endif
break;
case GameUIState.waitForUserToAnswerMultipleChoice:
buttonAskQuestion.Visible = false;
SetDifficultyButtonVisibility(false);
// ,
SetAnswerButtonEnabled(true);
SetAnswerButtonVisibility(true);
#if PLAYFIELD_ON_BOTTOM //
//
textBoxAskQuestion.Height = buttonAnswer0.Top - 2;
#else //
// .
// ,
//
textBoxAskQuestion.Top = buttonAnswer5.Top + buttonAnswer5.Height + 2;
textBoxAskQuestion.Height =this.Height - textBoxAskQuestion.Top;
#endif
break;
//======================================================================
// .
// , .
//
//
//======================================================================
private void SetStartControlPositionAndState() {
pictureBoxGameBoard.Width = 240;
pictureBoxGameBoard.Height = 176;
//
const int answerButtons_dx = 117;
const int answerButtons_dy = 18;
buttonAnswer0.Width = answerButtons_dx;
buttonAnswer0.Height = answerButtons_dy;
buttonAnswer1.Size = buttonAnswer0.Size;
buttonAnswer2.Size = buttonAnswer0.Size;
buttonAnswer3.Size = buttonAnswer0.Size;
buttonAnswer4.Size = buttonAnswer0.Size;
buttonAnswer5.Size = buttonAnswer0.Size;
buttonShowAnswers_AdvancedVersion.Width = answerButtons_dx;
buttonShowAnswers_AdvancedVersion.Height = 24;
buttonShowAnswers_SimpleVersion.Size = buttonShowAnswers_AdvancedVersion.Size;
// ( )
const int dx_betweenButtons = 3;
const int dy_betweenButtons = 2;
const int answerbuttons_beginX = 3;
// ,
//
System.Drawing.Bitmap gameBoard;
gameBoard = new System.Drawing.Bitmap(pictureBoxGameBoard.Width, pictureBoxGameBoard.Height);
System.Drawing.Graphics gameboard_gfx;
gameboard_gfx = System.Drawing.Graphics.FromImage(gameBoard);
gameboard_gfx.Clear(System.Drawing.Color.Yellow);
System.Drawing.Pen myPen = new System.Drawing.Pen(System.Drawing.Color.Blue);
gameboard_gfx.DrawRectangle(myPen, 2, 2, gameBoard.Width-4, gameBoard.Height-6);
myPen.Dispose();
gameboard_gfx.Dispose();
pictureBoxGameBoard.Image = gameBoard;
// , ,
//a
textBoxAskQuestion.Left = 0;
textBoxAskQuestion.Width = 240;
buttonAskQuestion.Width = 64;
buttonAskQuestion.Height = 20;
#if PLAYFIELD_ON_BOTTOM //
//
const int answerbuttons_beginY = 42;
const int showanswers_beginY = 77;
//--------------------------------------------------------
// Easy Hard
//--------------------------------------------------------
buttonShowAnswers_AdvancedVersion.Top = showanswers_beginY;
buttonShowAnswers_SimpleVersion.Top = showanswers_beginY;
//------------------------------
//
//------------------------------
// ,
//
buttonAnswer0.Top = answerbuttons_beginY;
// PictureBox
pictureBoxGameBoard.Top = (answerButtons_dy + dy_betweenButtons) * 3 + answerbuttons beginY;
buttonAskQuestion.Top = 0;
buttonAskQuestion.Left = 174;
textBoxAskQuestion.Top = 0;
#else //
//
const int answerbuttons_beginY = 174;
//--------------------------------------------------------
// Easy Hard
//--------------------------------------------------------
buttonShowAnswers_AdvancedVersion.Top = answerbuttons_beginY;
buttonShowAnswers_SimpleVersion.Top = answerbuttons_beginY;
//-----------------------------
//
//-----------------------------
// ,
//
buttonAnswer0.Top = answerbuttons_beginY;
pictureBoxGameBoard.Top = 0;
buttonAskQuestion.Top = answerbuttons_beginY;
buttonAskQuestion.Left = 174;
#endif
buttonShowAnswers_AdvancedVersion.Left = answerbuttons_beginX;
buttonShowAnswers_SimpleVersion.Left = buttonShowAnswers_AdvancedVersion.Left + answerButtons_dx + dx betweenButtons;
pictureBoxGameBoard.Left = 0;
pictureBoxGameBoard.Width = 240;
pictureBoxGameBoard.Height = 172;
buttonAnswer0.Left = answerbuttons_beginX;
buttonAnswer1.Left = buttonAnswer0.Left + answerButtons_dx + dx_betweenButtons;
buttonAnswer1.Top = buttonAnswer0.Top;
//
buttonAnswer2.Left = buttonAnswer0.Left;
buttonAnswer2.Top = buttonAnswer0.Top + answerButtons_dy + dy_betweenButtons;
buttonAnswer3.Left = buttonAnswer2.Left + answerButtons_dx + dx_betweenButtons;
buttonAnswer3.Top = buttonAnswer2.Top;
//
buttonAnswer4.Left = buttonAnswer2.Left;
buttonAnswer4.Top = buttonAnswer2.Top + answerButtons_dy + dy_betweenButtons;
buttonAnswer5.Left = buttonAnswer4.Left + answerButtons_dx + dx_betweenButtons;
buttonAnswer5.Top = buttonAnswer4.Top;
}
//-------------------------------------------------------------
// ,
// ,
//-------------------------------------------------------------
private void SetAnswerButtonVisibility(bool visibleState) {
buttonAnswer0.Visible = visibleState;
buttonAnswer1.Visible = visibleState;
buttonAnswer2.Visible = visibleState;
buttonAnswer3.Visible = visibleState;
buttonAnswer4.Visible = visibleState;
buttonAnswer5.Visible = visibleState;
}
//-----------------------------------------------------------------
// ,
//
//-----------------------------------------------------------------
private void SetDifficultyButtonVisibility(bool visibleState) {
buttonShowAnswers_AdvancedVersion.Visible = visibleState;
buttonShowAnswers_SimpleVersion.Visible = visibleState;
}
//-------------------------------------------------------------
// ,
// ,
//-------------------------------------------------------------
private void SetAnswerButtonEnabled(bool enabledState) {
buttonAnswer0.Enabled = enabledState;
buttonAnswer1.Enabled = enabledState;
buttonAnswer2.Enabled = enabledState;
buttonAnswer3.Enabled = enabledState;
buttonAnswer4.Enabled = enabledState;
buttonAnswer5.Enabled = enabledState;
}
//-----------------------------------------------------------------
// ,
// .
//
//B
//
//-----------------------------------------------------------------
private void SetTextForVocabularyQuestion() {
setQuestionText("What is the English word for 'der Mensch'?");
buttonAnswer0.Text = "Four";
buttonAnswer1.Text = "Person";
buttonAnswer2.Text = "Three";
buttonAnswer3.Text = "To Jump";
buttonAnswer4.Text = "Newspaper";
buttonAnswer5.Text = "Brother";
}
// ,
private void evaluateMultipleChoiceAnswer(Button buttonClicked, int selection) {
//:
// " 1"
// ,
//
if (selection ! = 1) {
//
buttonClicked.Enabled = false;
} else {
// ,
StateChangeForGameUI(GameUIState.waitForNextQuestion);
}
}
//,
void setQuestionText(string textIn) {
textBoxAskQuestion.Text = textIn;
}
//----------------------------------------------------------------
// :
//----------------------------------------------------------------
private void buttonAskQuestion_Click(object sender, System.EventArgs e) {
SetTextForVocabularyQuestion();
StateChangeForGameUI(GameUIState.waitForUserToStateKnowledge);
}
//---------------------------------------------------------------------
// :
// ,
//
//---------------------------------------------------------------------
private void buttonShowAnswers_AdvancedVersion_Click(object sender, System.EventArgs e) {
//
StateChangeForGameUI(GameUIState.waitForUserToAnswerMultipleChoice);
}
//---------------------------------------------------------------------
// :
// ,
//
//---------------------------------------------------------------------
private void buttonShowAnswers_SimpleVersion_Click(object sender, System.EventArgs e) {
//
StateChangeForGameUI(GameUIState.waitForUserToAnswerMultipleChoice);
}
// :
private void buttonAnswer0_Click(object sender, System.EventArgs e) {
evaluateMultipleChoiceAnswer(buttonAnswer0, 0);
}
// :
private void buttonAnswer1_Click(object sender, System.EventArgs e) {
evaluateMultipleChoiceAnswer(buttonAnswer1, 1);
}
// :
private void buttonAnswer2_Click(object sender, System.EventArgs e) {
evaluateMultipleChoiceAnswer(buttonAnswer2, 2);
}
// :
private void buttonAnswer3_Click(object sender, System.EventArgs e) {
evaluateMultipleChoiceAnswer(buttonAnswer3, 3);
}
// :
private void buttonAnswer4_Click(object sender, System.EventArgs e) {
evaluateMultipleChoiceAnswer(buttonAnswer4, 4);
}
// :
private void buttonAnswer5_Click(object sender, System.EventArgs e) {
evaluateMultipleChoiceAnswer(buttonAnswer5, 5);
}
//-------------------------------------------------
// :
//-------------------------------------------------
private void Form1_Load(object sender, System.EventArgs e) {
//
SetStartControlPositionAndState();
// , ,
//
StateChangeForGameUI(GameUIState.startScreen);
}


: 0.050. /Cache: 0 / 0