Thread: C++ Classes

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    3

    C++ Classes

    Hi Im having trouble creating a class for the scoring system of a game i have been given. its called the weakest link. i have created ENUM states for the enabled and disabled properties of all the buttons and i have had a go at creating a class. it is a very simple set up and i have coded the game to work as it should but i still needs classes in it.

    It would be much appreciated if someone could have a look at what i have done and give me some idea on how i can get over this problem

    Thanks

    Phil

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Forget anything?

  3. #3
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Quote Originally Posted by 03191993
    It would be much appreciated if someone could have a look at what i have done and give me some idea on how i can get over this problem.
    Sure. Take a look at my answer.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  4. #4
    Registered User
    Join Date
    Apr 2005
    Posts
    3

    Code

    Here is the code. this code executes perfectaly but I need a class system for btnCorrect, btnWrong, btnBank. if anyone wants to see how the game works at the moment i can send it you

    Thanks

    Sorry if the code is not good to read this is the first time i have used these tags





    #include <vcl.h>
    #pragma hdrstop

    #include "WeakestLinkTestUnit1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TfrmWeakestLinkTest *frmWeakestLinkTest;
    //---------------------------------------------------------------------------
    __fastcall TfrmWeakestLinkTest::TfrmWeakestLinkTest(TComponen t* Owner)
    : TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    Code:
    void __fastcall TfrmWeakestLinkTest::btnStartClick(TObject *Sender)
    Code:
    {   controlSettings(Start);
    
       memTrace->Lines->Add("Clock Started");
    
        tmrClock->Enabled = True;
    
        btnStart->Enabled=False;
       {
    //!tmrClock->Enabled;
    //if (btnStart->Caption == "Start")
    // {
    // btnStart->Caption = "Stop";
    // }//end if
    //else
    // {
    // btnStart->Caption = "Start";
    // }//end else
    }

    }
    //---------------------------------------------------------------------------
    Code:
    void __fastcall TfrmWeakestLinkTest::btnCorrectClick(TObject *Sender)
    Code:
    {
    
    if (edtCurrentWinnings->Text==IntToStr(0))
    {
     edtCurrentWinnings->Text=IntToStr(50);
    
    }
    else
    {
     edtCurrentWinnings->Text=IntToStr(StrToInt(edtCurrentWinnings->Text)*2);
    
    }
    Code:
      memTrace->Lines->Add("Correct Answer: "+edtCurrentWinnings->Text);
      }
    //---------------------------------------------------------------------------
    Code:
    void __fastcall TfrmWeakestLinkTest::btnWrongClick(TObject *Sender)
    Code:
    {
    
      if (edtCurrentWinnings->Text>=IntToStr(0))
      {
       edtCurrentWinnings->Text=IntToStr(0);
      }
      memTrace->Lines->Add("Wrong Answer");
    }
    //---------------------------------------------------------------------------
    Code:
    void __fastcall TfrmWeakestLinkTest::btnBankClick(TObject *Sender)
    {
      controlSettings(bank);
    
       edtGuaranteed->Text=IntToStr(StrToInt( edtGuaranteed->Text)
    
       + StrToInt(edtCurrentWinnings->Text));
    
      memTrace->Lines->Add("Bank: "+edtGuaranteed->Text);
    
      edtCurrentWinnings->Text=IntToStr(0);
    }
    //---------------------------------------------------------------------------
    Code:
    void __fastcall TfrmWeakestLinkTest::btnResetClick(TObject *Sender)
    {
      memTrace->Lines->Add("Reset");
      controlSettings(setUp);
    
    }
    //---------------------------------------------------------------------------
    Code:
    void __fastcall TfrmWeakestLinkTest::FormCreate(TObject *Sender)
    {
    controlSettings(setUp);
    }
    //---------------------------------------------------------------------------
    Code:
    void __fastcall TfrmWeakestLinkTest::controlSettings(states gameState)
    {
    
    switch (gameState)
    {
            case setUp:
            {
            btnStart->Enabled=True;
            gpbWinnings->Enabled=False;
            gpbClock->Enabled =True;
            btnBank->Visible=False;
            btnReset->Visible=False;
            btnWrong->Visible=False;
            btnCorrect->Visible=False;
            gpbTest->Visible=False;
            edtClock->Text=IntToStr(60);
            edtCurrentWinnings->Text=IntToStr(0);
            edtGuaranteed->Text=IntToStr(0);
            }
            break;
            case Start:
            {
            gpbTest->Visible=True;
            btnCorrect->Visible=True;
            btnCorrect->Enabled=True;
            btnWrong->Visible=True;
            btnWrong->Enabled=True;
            btnBank->Visible=True;
            btnBank->Enabled=True;
            }
            break;
            case wrong :
            {
            btnStart->Enabled=False;
            gpbWinnings->Enabled=True;
            gpbClock->Enabled  =True;
            gpbTest->Enabled=True;
            btnReset->Enabled=False;
            }
            break;
             case correct:
            {
            btnStart->Enabled=False;
            gpbWinnings->Enabled=True;
            gpbClock->Enabled  =True;
            gpbTest->Enabled=True;
            btnReset->Enabled=False;
            }
            break;
            case bank:
            {
            btnStart->Enabled=False;
            gpbWinnings->Enabled=True;
            gpbClock->Enabled  =True;
            gpbTest->Enabled=True;
            btnReset->Enabled=False;
            }
            break;
            case gameOver:
            {
            btnStart->Enabled=False;
            gpbWinnings->Enabled=False;
            gpbClock->Enabled  =False;
            gpbTest->Enabled=False;
            btnReset->Enabled=True;
            }
            break;
            }
    
    
    
    }
    //-----------------------------------------------------------
    Code:
    void __fastcall TfrmWeakestLinkTest::tmrClockTimer(TObject *Sender)
    {
    edtClock->Text=IntToStr(StrToInt(edtClock->Text)-1);
    if (edtClock->Text<=IntToStr(0))
    {
    edtClock->Text=IntToStr(0);
    
    edtGuaranteed->Text= IntToStr(StrToInt( edtGuaranteed->Text)
    
    + StrToInt(edtCurrentWinnings->Text));
    
    edtCurrentWinnings->Text= IntToStr(0);
    
    memTrace->Lines->Add("Clock Stopped");
    
    memTrace->Lines->Add("You Won: " + edtGuaranteed->Text);
    
    btnReset->Visible=True;
    
     btnReset->Enabled=True;
    
            //btnCorrect->Visible=False;
            btnCorrect->Enabled=False;
            //btnWrong->Visible=False;
            btnWrong->Enabled=False;
            //btnBank->Visible=False;
            btnBank->Enabled=False;
            tmrClock->Enabled=False;
    }
    }

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Quote Originally Posted by pianorain
    Sure. Take a look at my answer.


    Code:
    this code executes perfectaly but I need a class system for btnCorrect, btnWrong, btnBank.
    ...then start studying. No one here will do your homework for you, so unless you have some specific questions??

  6. #6
    Registered User
    Join Date
    Apr 2005
    Posts
    3

    Thumbs down Chill out

    All i wanted was a little help, a fat lot of good you all were not mentioning any names. Ive finished it now and i had done all my homework fcuking sad'os

  7. #7
    Let's do some coding! Welshy's Avatar
    Join Date
    Mar 2005
    Location
    Staffordshire University, UK
    Posts
    168
    lol?

  8. #8
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Quote Originally Posted by 03191993
    All i wanted was a little help, a fat lot of good you all were not mentioning any names. Ive finished it now and i had done all my homework.
    Congratulations on solving the problem yourself. Next time give us some questions, and you may get some answers.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you Initialize all classes once with New?
    By peacerosetx in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2008, 10:47 AM
  2. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 09:04 AM
  3. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  4. Exporting VC++ classes for use with VB
    By Helix in forum Windows Programming
    Replies: 2
    Last Post: 12-29-2003, 05:38 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM