can someone please help me here?!
jarv 13 Newbie Poster
i am using Vista Ultimate, does this matter?
GreenDay2001
Whats the code, so that we could see whats happening. Here's an MSDN link which show some common reason to this specific error.
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
i am using Vista Ultimate, does this matter?
No -- that error has nothing at all to do with the operating system. Without seeing your code I guess that you left out a semicolon somewhere.
jarv 13 Newbie Poster
// speedgame.cpp : main project file.
#include "stdafx.h"
#include "Form1.h"
using namespace speedgame;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}
jarv 13 Newbie Poster
and my main form code:
#pragma once
namespace speedgame {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::ToolTip^ tipControl;
private: System::Windows::Forms::Timer^ tmrControl;
private: System::Windows::Forms::TextBox^ txtDisplay;
private: System::Windows::Forms::TextBox^ txtEntry;
private: System::Windows::Forms::Label^ lblInstructions;
private: System::Windows::Forms::Label^ lblSourceText;
private: System::Windows::Forms::Label^ lblEntryText;
private: System::Windows::Forms::StatusStrip^ stsControl;
private: System::Windows::Forms::ToolStripStatusLabel^ stsLabel;
protected:
protected:
private: System::Windows::Forms::Button^ btnGo;
private: System::Windows::Forms::Button^ btnDone;
private: System::Windows::Forms::Button^ btnExit;
private: System::ComponentModel::IContainer^ components;
private:
/// <summary>
/// Required designer variable.
/// </summary>
Int16 intWrong; //Tracks number of strikes
Int16 intCount; //Tracks number of tries
Int16 intTimer; //Tracks elapsed time
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->components = (gcnew System::ComponentModel::Container());
this->tipControl = (gcnew System::Windows::Forms::ToolTip(this->components));
this->txtDisplay = (gcnew System::Windows::Forms::TextBox());
this->txtEntry = (gcnew System::Windows::Forms::TextBox());
this->btnGo = (gcnew System::Windows::Forms::Button());
this->btnDone = (gcnew System::Windows::Forms::Button());
this->btnExit = (gcnew System::Windows::Forms::Button());
this->tmrControl = (gcnew System::Windows::Forms::Timer(this->components));
this->lblInstructions = (gcnew System::Windows::Forms::Label());
this->lblSourceText = (gcnew System::Windows::Forms::Label());
this->lblEntryText = (gcnew System::Windows::Forms::Label());
this->stsControl = (gcnew System::Windows::Forms::StatusStrip());
this->stsLabel = (gcnew System::Windows::Forms::ToolStripStatusLabel());
this->stsControl->SuspendLayout();
this->SuspendLayout();
//
// txtDisplay
//
this->txtDisplay->Location = System::Drawing::Point(40, 55);
this->txtDisplay->Name = L"txtDisplay";
this->txtDisplay->ReadOnly = true;
this->txtDisplay->Size = System::Drawing::Size(675, 20);
this->txtDisplay->TabIndex = 0;
this->tipControl->SetToolTip(this->txtDisplay, L"Displays source text string");
//
// txtEntry
//
this->txtEntry->Location = System::Drawing::Point(40, 121);
this->txtEntry->Name = L"txtEntry";
this->txtEntry->ReadOnly = true;
this->txtEntry->Size = System::Drawing::Size(675, 20);
this->txtEntry->TabIndex = 1;
this->tipControl->SetToolTip(this->txtEntry, L"Type your text here");
//
// btnGo
//
this->btnGo->Location = System::Drawing::Point(43, 216);
this->btnGo->Name = L"btnGo";
this->btnGo->Size = System::Drawing::Size(75, 23);
this->btnGo->TabIndex = 6;
this->btnGo->Text = L"GO";
this->tipControl->SetToolTip(this->btnGo, L"Display new text string");
this->btnGo->UseVisualStyleBackColor = true;
this->btnGo->Click += gcnew System::EventHandler(this, &Form1::btnGo_Click);
//
// btnDone
//
this->btnDone->Enabled = false;
this->btnDone->Location = System::Drawing::Point(639, 216);
this->btnDone->Name = L"btnDone";
this->btnDone->Size = System::Drawing::Size(75, 23);
this->btnDone->TabIndex = 7;
this->btnDone->Text = L"Done";
this->tipControl->SetToolTip(this->btnDone, L"Check typing");
this->btnDone->UseVisualStyleBackColor = true;
this->btnDone->Click += gcnew System::EventHandler(this, &Form1::btnDone_Click);
//
// btnExit
//
this->btnExit->Location = System::Drawing::Point(639, 9);
this->btnExit->Name = L"btnExit";
this->btnExit->Size = System::Drawing::Size(75, 23);
this->btnExit->TabIndex = 8;
this->btnExit->Text = L"Exit";
this->tipControl->SetToolTip(this->btnExit, L"Exit game");
this->btnExit->UseVisualStyleBackColor = true;
//
// tmrControl
//
this->tmrControl->Interval = 1000;
this->tmrControl->Tick += gcnew System::EventHandler(this, &Form1::tmrControl_Tick);
//
// lblInstructions
//
this->lblInstructions->AutoSize = true;
this->lblInstructions->Location = System::Drawing::Point(12, 9);
this->lblInstructions->Name = L"lblInstructions";
this->lblInstructions->Size = System::Drawing::Size(511, 13);
this->lblInstructions->TabIndex = 2;
this->lblInstructions->Text = L"Click Go to begin. You have 15 seconds to type the text displayed in the source t"
L"ext field exactly as shown.";
//
// lblSourceText
//
this->lblSourceText->AutoSize = true;
this->lblSourceText->Location = System::Drawing::Point(40, 39);
this->lblSourceText->Name = L"lblSourceText";
this->lblSourceText->Size = System::Drawing::Size(68, 13);
this->lblSourceText->TabIndex = 3;
this->lblSourceText->Text = L"Source Text:";
//
// lblEntryText
//
this->lblEntryText->AutoSize = true;
this->lblEntryText->Location = System::Drawing::Point(40, 105);
this->lblEntryText->Name = L"lblEntryText";
this->lblEntryText->Size = System::Drawing::Size(79, 13);
this->lblEntryText->TabIndex = 4;
this->lblEntryText->Text = L"Enter text here:";
//
// stsControl
//
this->stsControl->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->stsLabel});
this->stsControl->Location = System::Drawing::Point(0, 270);
this->stsControl->Name = L"stsControl";
this->stsControl->Size = System::Drawing::Size(773, 22);
this->stsControl->TabIndex = 5;
this->stsControl->Text = L"statusStrip1";
//
// stsLabel
//
this->stsLabel->Name = L"stsLabel";
this->stsLabel->Size = System::Drawing::Size(118, 17);
this->stsLabel->Text = L"toolStripStatusLabel1";
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(773, 292);
this->Controls->Add(this->btnExit);
this->Controls->Add(this->btnDone);
this->Controls->Add(this->btnGo);
this->Controls->Add(this->stsControl);
this->Controls->Add(this->lblEntryText);
this->Controls->Add(this->lblSourceText);
this->Controls->Add(this->lblInstructions);
this->Controls->Add(this->txtEntry);
this->Controls->Add(this->txtDisplay);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
this->Name = L"Form1";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = L"The Speed Game";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->stsControl->ResumeLayout(false);
this->stsControl->PerformLayout();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
//set begginning data values
intWrong = 0;
intCount = 0;
intTimer = 0;
}
private: System::Void btnGo_Click(System::Object^ sender, System::EventArgs^ e) {
//Display game sentences according to level
if( intCount == 0 )
txtDisplay->Text = "Once upon a time there where three little pigs.";
if( intCount == 1 )
txtDisplay->Text = "In days gone by times where hard but the people were strong.";
if( intCount == 2 )
txtDisplay->Text = "Once in awhile something speacial happens even to the worst of people.";
if( intCount == 3 )
txtDisplay->Text = "When injustice rears its ugly hea, it is the duty of all good.";
if( intCount == 4 )
txtDisplay->Text = "It has been said that in the end there can only be one. Let that one be mighty Molly!";
btnDone->Enabled = true; //Activate done button
btnGo->Enabled = false; //Disable Go button
//Allow text to be entered
txtEntry->ReadOnly = false;
//Activate Timer
tmrControl->Enabled = true;
intTimer = 0;
txtEntry->Focus();
}
private: System::Void btnDone_Click(System::Object^ sender, System::EventArgs^ e) {
//Clear out status bar text
stsControl->Text = "";
//Deactivate Timer so it doesn't keep going
tmrControl->Enabled = false;
//Make sure player entered something
if( String::IsNullOrEmpty( txtEntry->Text ) )
{
//Show error
MessageBox::Show( "Error: You must enter something!" );
//reset game
txtDisplay->Text = "";
btnDone->Enabled = false;
btnGo->Enabled = true;
txtEntry->ReadOnly = true;
intTimer = 0;
btnGo->Focus;
return;
}
if( String::Compare( txtEntry->Text, txtDisplay->Text ) == 0 )
{
//handle Correct answer
MessageBox::Show( "Match! You typed the string in correctly!" );
intCount += 1;
intTimer = 0;
}
else
{
//handle incorrect answer
MessageBox::Show( String::Concat( "Strike ",
intWrong.ToString(), "! You made at least",
" one typo." ) );
intTimer = 0;
}
//get set up for the next level
txtEntry->Text = "";
txtDisplay->Text = "";
btnDone->Enabled = false;
btnGo->Enabled = true;
txtEntry->ReadOnly = true;
intTimer = 0;
btnGo->Focus();
//handle 3 strikes
if( intWrong == 3 )
{
//inform play he/she is a begginer
if( intCount < 2 )
{
MessageBox::Show( "Game Over! Your "
"typing skill level is Beginner. "
"Please play again!" );
intCount = 0;
intWrong = 0;
return;
}
//inform play he/she is intermediate
if( intCount < 4 )
{
MessageBox::Show( "Game Over! Your "
"typing skill level is intermediate. "
"Please play again!" );
intCount = 0;
intWrong = 0;
return;
}
//inform play he/she is advanced
if( intCount < 5 )
{
MessageBox::Show( "Game Over! Your "
"typing skill level is advanced. "
"Please play again!" );
intCount = 0;
intWrong = 0;
return;
}
}
private: System::Void btnExit_Click(System::Object^ sender,
System::EventArgs^ e) {
this->Close();
}
}
private: System::Void tmrControl_Tick(System::Object^ sender, System::EventArgs^ e) {
//update timer value
intTimer += 1;
int16 intTimeRemain = 15 - intTimer;
stsLabel->Text = "Seconds remaining: ";
stsLabel->Text = String::Concat( stsLabel,
intTimeRemain.ToString() );
//handle running out of time
if( intTimer == 15 )
{
intWrong += 1;
tmrControl->Enabled = false;
stsLabel->Text = "";
MessageBox::Show( String::Concat( "Strike ",
intWrong.ToString(), " - Time is up! Please",
" try again." ) );
//reset game
txtEntry->Text = "";
txtDisplay->Text = "";
btnDone->Enabled = false;
btnGo->Enabled = true;
txtEntry->ReadOnly = true;
intTimer = 0;
btnGo->Focus;
//handle 3 strikes
if( intWrong == 3 )
{
//inform play he/she is a begginer
if( intCount < 2 )
{
MessageBox::Show( "Game Over! Your "
"typing skill level is Beginner. "
"Please play again!" );
intCount = 0;
intWrong = 0;
return;
}
//inform play he/she is intermediate
if( intCount < 4 )
{
MessageBox::Show( "Game Over! Your "
"typing skill level is intermediate. "
"Please play again!" );
intCount = 0;
intWrong = 0;
return;
}
//inform play he/she is advanced
if( intCount < 5 )
{
MessageBox::Show( "Game Over! Your "
"typing skill level is advanced. "
"Please play again!" );
intCount = 0;
intWrong = 0;
return;
}
}
//player is an expert!
if( intCount >= 5 )
{
intCount = 0;
intWrong = 0;
MessageBox::Show( "Game Complete! Your "
"typing skill level is Expert! "
"Please try again!" );
}
}
}
iamthwee commented: Not true c++ -2
Narue commented: C++/CLI is close enough +15
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
without attempting to compile the code you posted there is probably at least one semicolon missing at the last brace in the header file.
jarv 13 Newbie Poster
can anyone help?
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ok I loaded your code in a new project with VC++ 2005 Express and found that your Form1.h is missing some braces somewhere. You need to start at the top of the file and count the number of open/close brace pairs and insert the missing one(s). Put your cursor on the closing brace at the bottom of the file then press Ctrl + [ keys and the cursor will jump to the matching open brace.
After adding two closing braces at the bottom of the file (probably in the wrong place I might add) the compiler now spits out a lot of other errors in Form1.h. My suggestion is to begain all over again, create a new CLR Windows project and gradually add the code you posted here a little bit at a time, compile to get clean compile, then add some more.
Salem 5,199 Posting Sage
An approach to writing code
Writing 5(*) lines at a time, then pressing "compile" to see how you're doing is a sustainable development strategy.
Dumping 100's of lines on a message board for someone else to fix is not.
The same goes for testing, when you've finished a function, then try running the code to make sure it's doing what you want.
Never code beyond your ability to deal with the consequence of the compiler spitting it straight back at you.
(*) or however many you feel confident about writing without errors.
jarv 13 Newbie Poster
can someone please help?!
I am very new to this!
Narue 5,707 Bad Cop Team Colleague
>can someone please help?!
Two very qualified people have already given you good advice. Are you ignoring their suggestions and hoping that someone does all of the work for you? If not, explain what you've done to troubleshoot and how it didn't work.
jarv 13 Newbie Poster
it says:
1>c:\users\john\documents\visual studio 2005\projects\speedgame\speedgame\Form1.h(23) : error C2143: syntax error : missing ',' before '}'
so i think it's line 23 where it goes }{
jarv 13 Newbie Poster
>can someone please help?!
Two very qualified people have already given you good advice. Are you ignoring their suggestions and hoping that someone does all of the work for you? If not, explain what you've done to troubleshoot and how it didn't work.
I have gone through the { and the } and looked for where to put a ;
i wrote this code from a book and i am double checking it!
Salem 5,199 Posting Sage
Like I said, the problem was how you approached the problem from the beginning.
This is your post.
"It's the 4th down and 50 yards to go, with 20 seconds remaining on the clock, and you need 7 points for the win".
In essence, a "hail mary" pass into the end zone in the hopes that you'll strike lucky.
IMO, you need to create a new project and build up slowly this time, copy/pasting small sections of this project to it, along with lots of compile and test as you go.
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
forget about the semicolon for now, just concentrate on finding the mismatches braces. Books sometimes contain errors due to poor or inadequate proofreading -- or more likely you copied it wrong.
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
IMO, you need to create a new project and build up slowly this time, copy/pasting small sections of this project to it, along with lots of compile and test as you go.
Yup, I suggested that too, but I suppose some people don't take suggestions like that.
Narue 5,707 Bad Cop Team Colleague
You had quite a few transcription errors. In other words, unless the book is absolutely horrid, you introduced syntax errors on your own when typing the code in. I've cleaned it up for you and fixed the syntax errors. Don't expect me to do it again:
#pragma once
namespace speedgame {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public ref class Form1: public System::Windows::Forms::Form {
public:
Form1()
{
InitializeComponent();
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if ( components )
delete components;
}
private:
System::Windows::Forms::ToolTip^ tipControl;
System::Windows::Forms::Timer^ tmrControl;
System::Windows::Forms::TextBox^ txtDisplay;
System::Windows::Forms::TextBox^ txtEntry;
System::Windows::Forms::Label^ lblInstructions;
System::Windows::Forms::Label^ lblSourceText;
System::Windows::Forms::Label^ lblEntryText;
System::Windows::Forms::StatusStrip^ stsControl;
System::Windows::Forms::ToolStripStatusLabel^ stsLabel;
System::Windows::Forms::Button^ btnGo;
System::Windows::Forms::Button^ btnDone;
System::Windows::Forms::Button^ btnExit;
System::ComponentModel::IContainer^ components;
Int16 intWrong; //Tracks number of strikes
Int16 intCount; //Tracks number of tries
Int16 intTimer; //Tracks elapsed time
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->components = (gcnew System::ComponentModel::Container());
this->tipControl = (gcnew System::Windows::Forms::ToolTip(this->components));
this->txtDisplay = (gcnew System::Windows::Forms::TextBox());
this->txtEntry = (gcnew System::Windows::Forms::TextBox());
this->btnGo = (gcnew System::Windows::Forms::Button());
this->btnDone = (gcnew System::Windows::Forms::Button());
this->btnExit = (gcnew System::Windows::Forms::Button());
this->tmrControl = (gcnew System::Windows::Forms::Timer(this->components));
this->lblInstructions = (gcnew System::Windows::Forms::Label());
this->lblSourceText = (gcnew System::Windows::Forms::Label());
this->lblEntryText = (gcnew System::Windows::Forms::Label());
this->stsControl = (gcnew System::Windows::Forms::StatusStrip());
this->stsLabel = (gcnew System::Windows::Forms::ToolStripStatusLabel());
this->stsControl->SuspendLayout();
this->SuspendLayout();
//
// txtDisplay
//
this->txtDisplay->Location = System::Drawing::Point(40, 55);
this->txtDisplay->Name = L"txtDisplay";
this->txtDisplay->ReadOnly = true;
this->txtDisplay->Size = System::Drawing::Size(675, 20);
this->txtDisplay->TabIndex = 0;
this->tipControl->SetToolTip(this->txtDisplay, L"Displays source text string");
//
// txtEntry
//
this->txtEntry->Location = System::Drawing::Point(40, 121);
this->txtEntry->Name = L"txtEntry";
this->txtEntry->ReadOnly = true;
this->txtEntry->Size = System::Drawing::Size(675, 20);
this->txtEntry->TabIndex = 1;
this->tipControl->SetToolTip(this->txtEntry, L"Type your text here");
//
// btnGo
//
this->btnGo->Location = System::Drawing::Point(43, 216);
this->btnGo->Name = L"btnGo";
this->btnGo->Size = System::Drawing::Size(75, 23);
this->btnGo->TabIndex = 6;
this->btnGo->Text = L"GO";
this->tipControl->SetToolTip(this->btnGo, L"Display new text string");
this->btnGo->UseVisualStyleBackColor = true;
this->btnGo->Click += gcnew System::EventHandler(this, &Form1::btnGo_Click);
//
// btnDone
//
this->btnDone->Enabled = false;
this->btnDone->Location = System::Drawing::Point(639, 216);
this->btnDone->Name = L"btnDone";
this->btnDone->Size = System::Drawing::Size(75, 23);
this->btnDone->TabIndex = 7;
this->btnDone->Text = L"Done";
this->tipControl->SetToolTip(this->btnDone, L"Check typing");
this->btnDone->UseVisualStyleBackColor = true;
this->btnDone->Click += gcnew System::EventHandler(this, &Form1::btnDone_Click);
//
// btnExit
//
this->btnExit->Location = System::Drawing::Point(639, 9);
this->btnExit->Name = L"btnExit";
this->btnExit->Size = System::Drawing::Size(75, 23);
this->btnExit->TabIndex = 8;
this->btnExit->Text = L"Exit";
this->tipControl->SetToolTip(this->btnExit, L"Exit game");
this->btnExit->UseVisualStyleBackColor = true;
//
// tmrControl
//
this->tmrControl->Interval = 1000;
this->tmrControl->Tick += gcnew System::EventHandler(this, &Form1::tmrControl_Tick);
//
// lblInstructions
//
this->lblInstructions->AutoSize = true;
this->lblInstructions->Location = System::Drawing::Point(12, 9);
this->lblInstructions->Name = L"lblInstructions";
this->lblInstructions->Size = System::Drawing::Size(511, 13);
this->lblInstructions->TabIndex = 2;
this->lblInstructions->Text = L"Click Go to begin. You have 15 seconds to type the text displayed in the source t"
L"ext field exactly as shown.";
//
// lblSourceText
//
this->lblSourceText->AutoSize = true;
this->lblSourceText->Location = System::Drawing::Point(40, 39);
this->lblSourceText->Name = L"lblSourceText";
this->lblSourceText->Size = System::Drawing::Size(68, 13);
this->lblSourceText->TabIndex = 3;
this->lblSourceText->Text = L"Source Text:";
//
// lblEntryText
//
this->lblEntryText->AutoSize = true;
this->lblEntryText->Location = System::Drawing::Point(40, 105);
this->lblEntryText->Name = L"lblEntryText";
this->lblEntryText->Size = System::Drawing::Size(79, 13);
this->lblEntryText->TabIndex = 4;
this->lblEntryText->Text = L"Enter text here:";
//
// stsControl
//
this->stsControl->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->stsLabel});
this->stsControl->Location = System::Drawing::Point(0, 270);
this->stsControl->Name = L"stsControl";
this->stsControl->Size = System::Drawing::Size(773, 22);
this->stsControl->TabIndex = 5;
this->stsControl->Text = L"statusStrip1";
//
// stsLabel
//
this->stsLabel->Name = L"stsLabel";
this->stsLabel->Size = System::Drawing::Size(118, 17);
this->stsLabel->Text = L"toolStripStatusLabel1";
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(773, 292);
this->Controls->Add(this->btnExit);
this->Controls->Add(this->btnDone);
this->Controls->Add(this->btnGo);
this->Controls->Add(this->stsControl);
this->Controls->Add(this->lblEntryText);
this->Controls->Add(this->lblSourceText);
this->Controls->Add(this->lblInstructions);
this->Controls->Add(this->txtEntry);
this->Controls->Add(this->txtDisplay);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
this->Name = L"Form1";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = L"The Speed Game";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->stsControl->ResumeLayout(false);
this->stsControl->PerformLayout();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
System::Void Form1_Load ( System::Object^ sender, System::EventArgs^ e )
{
//set begginning data values
intWrong = 0;
intCount = 0;
intTimer = 0;
}
System::Void btnGo_Click ( System::Object^ sender, System::EventArgs^ e )
{
//Display game sentences according to level
if( intCount == 0 )
txtDisplay->Text = "Once upon a time there where three little pigs.";
if( intCount == 1 )
txtDisplay->Text = "In days gone by times where hard but the people were strong.";
if( intCount == 2 )
txtDisplay->Text = "Once in awhile something speacial happens even to the worst of people.";
if( intCount == 3 )
txtDisplay->Text = "When injustice rears its ugly hea, it is the duty of all good.";
if( intCount == 4 )
txtDisplay->Text = "It has been said that in the end there can only be one. Let that one be mighty Molly!";
btnDone->Enabled = true; //Activate done button
btnGo->Enabled = false; //Disable Go button
//Allow text to be entered
txtEntry->ReadOnly = false;
//Activate Timer
tmrControl->Enabled = true;
intTimer = 0;
txtEntry->Focus();
}
System::Void btnDone_Click ( System::Object^ sender, System::EventArgs^ e )
{
//Clear out status bar text
stsControl->Text = "";
//Deactivate Timer so it doesn't keep going
tmrControl->Enabled = false;
//Make sure player entered something
if ( String::IsNullOrEmpty ( txtEntry->Text ) ) {
//Show error
MessageBox::Show ( "Error: You must enter something!" );
//reset game
txtDisplay->Text = "";
btnDone->Enabled = false;
btnGo->Enabled = true;
txtEntry->ReadOnly = true;
intTimer = 0;
btnGo->Focus();
return;
}
if ( String::Compare ( txtEntry->Text, txtDisplay->Text ) == 0 ) {
//handle Correct answer
MessageBox::Show ( "Match! You typed the string in correctly!" );
intCount += 1;
intTimer = 0;
}
else {
//handle incorrect answer
MessageBox::Show ( String::Concat ( "Strike ",
intWrong.ToString(), "! You made at least",
" one typo." ) );
intTimer = 0;
}
//get set up for the next level
txtEntry->Text = "";
txtDisplay->Text = "";
btnDone->Enabled = false;
btnGo->Enabled = true;
txtEntry->ReadOnly = true;
intTimer = 0;
btnGo->Focus();
//handle 3 strikes
if ( intWrong == 3 ) {
//inform play he/she is a begginer
if ( intCount < 2 ) {
MessageBox::Show ( "Game Over! Your "
"typing skill level is Beginner. "
"Please play again!" );
intCount = 0;
intWrong = 0;
return;
}
//inform play he/she is intermediate
if ( intCount < 4 ) {
MessageBox::Show ( "Game Over! Your "
"typing skill level is intermediate. "
"Please play again!" );
intCount = 0;
intWrong = 0;
return;
}
//inform play he/she is advanced
if ( intCount < 5 ) {
MessageBox::Show ( "Game Over! Your "
"typing skill level is advanced. "
"Please play again!" );
intCount = 0;
intWrong = 0;
return;
}
}
}
System::Void btnExit_Click ( System::Object^ sender, System::EventArgs^ e )
{
this->Close();
}
System::Void tmrControl_Tick ( System::Object^ sender, System::EventArgs^ e )
{
//update timer value
intTimer += 1;
Int16 intTimeRemain = 15 - intTimer;
stsLabel->Text = "Seconds remaining: ";
stsLabel->Text = String::Concat( stsLabel, intTimeRemain.ToString() );
//handle running out of time
if ( intTimer == 15 ) {
intWrong += 1;
tmrControl->Enabled = false;
stsLabel->Text = "";
MessageBox::Show ( String::Concat ( "Strike ",
intWrong.ToString(), " - Time is up! Please",
" try again." ) );
//reset game
txtEntry->Text = "";
txtDisplay->Text = "";
btnDone->Enabled = false;
btnGo->Enabled = true;
txtEntry->ReadOnly = true;
intTimer = 0;
btnGo->Focus();
//handle 3 strikes
if ( intWrong == 3 ) {
//inform play he/she is a begginer
if ( intCount < 2 ) {
MessageBox::Show ( "Game Over! Your "
"typing skill level is Beginner. "
"Please play again!" );
intCount = 0;
intWrong = 0;
return;
}
//inform play he/she is intermediate
if ( intCount < 4 ) {
MessageBox::Show ( "Game Over! Your "
"typing skill level is intermediate. "
"Please play again!" );
intCount = 0;
intWrong = 0;
return;
}
//inform play he/she is advanced
if( intCount < 5 ) {
MessageBox::Show ( "Game Over! Your "
"typing skill level is advanced. "
"Please play again!" );
intCount = 0;
intWrong = 0;
return;
}
}
//player is an expert!
if ( intCount >= 5 ) {
intCount = 0;
intWrong = 0;
MessageBox::Show ( "Game Complete! Your "
"typing skill level is Expert! "
"Please try again!" );
}
}
}
};
}
Here are a few C++ tips:
1) Classes always end with a semicolon.
2) public, private, and protected are groupings. You don't have to specify an access modifier for every single member.
3) C++ is case sensitive. int16 is quite different from Int16.
4) Every opening { has to have a corresponding closing }.
jarv 13 Newbie Poster
thankyou so much!
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.