Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 135,961 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,570 people online right now. Registration is fast and FREE... Join Now!




C++ Connect Four

 
Reply to this topicStart new topic

C++ Connect Four, Dont know where to go next.

Gazz_mann
29 Mar, 2007 - 01:49 AM
Post #1

New D.I.C Head
*

Joined: 29 Mar, 2007
Posts: 2


My Contributions
Hi...

I have got this far but dont know where to go now.
Can anyone help me???
CODE

#include <iostream>

using namespace std;

struct player
{
    char playername[25];
    char PlayerCounter; // 'R' or 'B';
    char score [5];
};
struct col
{
    char rows[7];
    int add;
};

col frame [7];
player playerone;
player playertwo;



void get_player_info (player &p)
// this is where the player type in their names.
{
    cout << "Player's name: ";
//    cout<<endl;
    cin >> p.playername;
    cout << endl;
}

void get_players_info ()
// this is where the information goes and the player get set counters
{
    playerone.PlayerCounter = 'R';
    playertwo.PlayerCounter = 'B';

    get_player_info(playerone);
    get_player_info(playertwo);
}

void Clear_grid ()
{
    int row;
    int col;

    for ( row = 6; row >= 0; row -- )
    {
        for (col = 0; col < 7; col++);
        {
            frame[col].rows[row] = ' ';
        }
        frame[col].add = 0;
    }
}

void print_grid ()
{
    int row;
    int col;
    for ( row = 6; row >= 0; row -- ){
        cout << '|';
        for ( col = 0; col <= 6; col++ ){
            cout << frame[col].rows[row];
            cout << '|';
        }
        cout << endl;
        cout << '|';
        for ( col = 0; col <= 6; col ++ ) {
            cout << "-|";
        }
        cout << endl;
    }
}

void player_move ()

{
    player playerone;
    player playertwo;
    
    int selection;

    cout<< playerone.playername << " Vs " << playertwo.playername <<endl;
    cout<<endl;


    cout<< playerone.playername << " your counter is " << playerone.PlayerCounter<<endl;
    cout<<endl;
    cout<< playertwo.playername << " your counter is " << playertwo.PlayerCounter<<endl;
    cout<<endl;

    do {
        cout<< playerone.playername <<" Please choose a column from 1 to 7\n";
        cout<<endl;
        cin>>selection;
        cout<<endl;

        while ((selection <1) || (selection >7))
        {
            cout<< playerone.playername<<" illegal column please try agian";
            cout<<endl;
            cin>>selection;
        }
        selection--; // Now choice is range 0 to 6
        if (frame[selection].add >= 7) cout << "Full - choose another column!";
    } while (frame[selection].add >= 7);
    // Column selection is OK

    do {
        cout<<  playertwo.playername <<" Please choose a column from 1 to 7\n";
        cout<<endl;
        cin>>selection;
        cout<<endl;

        while ((selection <1) || (selection >7))
        {
            cout<< playertwo.playerame <<" illegal column please try agian";
            cout<<endl;
            cin>>selection;
        }
        selection--; // Now choice is range 0 to 6
        if (frame[selection].add >= 7) cout << "Full - choose another column!";
    } while (frame[selection].add >= 7);
    // Column selection is OK
}
void main()
{
    get_players_info ();
    Clear_grid ();
    print_grid ();
    player_move ();
}

User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: C++ Connect Four
29 Mar, 2007 - 01:20 PM
Post #2

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,009



Thanked: 5 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
Hi, I believe that there are members that could help, BUT
you need to share with us where are you heading.
hint: Describe what this code means so that someone could
help. wink2.gif
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: C++ Connect Four
29 Mar, 2007 - 02:52 PM
Post #3

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 48 times
Dream Kudos: 550
My Contributions
This is a very popular question. Here are some other topics that you might want to look though.

Connect 4, Finding a winner!!
Connect 4, confused...

if you can't find anything in these, ask a more specific question.
User is offlineProfile CardPM
+Quote Post

Gazz_mann
RE: C++ Connect Four
17 Apr, 2007 - 04:24 AM
Post #4

New D.I.C Head
*

Joined: 29 Mar, 2007
Posts: 2


My Contributions
Sorry i was away on holiday, what i am trying to do next to place the counters in the column, but i dont know
how to do that (or i have fogoten) so could someone please help me?
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 09:27AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month