Welcome to Dream.In.Code
Become a C++ Expert!

Join 150,045 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,636 people online right now. Registration is fast and FREE... Join Now!




Making a connect4 game and need some advice

 
Reply to this topicStart new topic

Making a connect4 game and need some advice

Xeogen
2 Feb, 2008 - 09:21 AM
Post #1

New D.I.C Head
*

Joined: 2 Feb, 2008
Posts: 4


My Contributions
Hey there ive been given an assignment to make a connect4 game, i havent been using c++ long so i'm still not sure quite how everything works, so far i have been able to print a grid and i am currently stuck on how to start placing counters down on the grid, if anyone could point me in the right direction for doing this it would be much appreciated. the code ive come up with so far is:


CODE

#include <iostream>

using namespace std;

void print_grid(int arr[7][6]);


int main()
{
    int arr[7][6] = { {1,2,3,4,5,6},
                      {7,8,9,10,11,12},
                      {13,14,15,16,17,18},
                      {19,20,21,22,23,24},
                      {25,26,27,28,29,30},
                      {31,32,33,34,35,36},
                      {37,38,39,40,41,42}
                    };
    
    char Player1;
    char Player2;
    
    cout << "player one enter your name ";
    cin >> Player1;
    cout << "player two enter your name ";
    cin >> Player2;
    
    
    print_grid(arr);
    
    cout << "Player one's move";
    
    cin >> arr[7][6];

    
    int a = 0;
    cin >> a;
    return 0;
}

void print_grid(int arr[7][6])
{
      for(int i=0;i<7;i++)
      {
      for (int j=0; j<4; j++)
      {        
      
                cout<<"|_";
      }
      cout<<"|";
      cout<<endl;
      }
}



User is offlineProfile CardPM
+Quote Post

Jingle
RE: Making A Connect4 Game And Need Some Advice
2 Feb, 2008 - 01:52 PM
Post #2

D.I.C Regular
***

Joined: 20 Oct, 2007
Posts: 250


My Contributions
you could use a loop to fill your array. but either way


what do you mean I'm afraid i don't understand.
User is offlineProfile CardPM
+Quote Post

KYA
RE: Making A Connect4 Game And Need Some Advice
2 Feb, 2008 - 04:24 PM
Post #3

#include <nerd.h>
Group Icon

Joined: 14 Sep, 2007
Posts: 5,904



Thanked: 159 times
Dream Kudos: 1375
My Contributions
Well for starters I would have a flag that denotes if a certain space is filled. Each "turn" taken by a player could be sent to an outside method for "game logic" (i.e. checks to see if that space in the array is 'filled' and if it is a legal move). The tricky part I see here is having the board recognize the slots that are filled and to put it on top of them. Connect 4 is a up and down game rather then tic tac toe, so the aray spot [0][0] (assuming that's the bottom left corner) would be below [0][1], etc... or however you want to set it up.

Rather then having the player choose where to play you could have them pick a column (1-5) then update the board accordingly.

--KYA
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 10:02PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

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