C++ School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

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

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




Stratego game code

 

Stratego game code, Trying to create the game Stratego

coolgymnast01

6 Sep, 2008 - 04:13 PM
Post #1

New D.I.C Head
*

Joined: 26 Mar, 2008
Posts: 21

I am trying to create the game Stratego by using code. Here is what I have now and what I still have to do:

cpp

#include <iostream>
using namespace std;

enum color {red,blue};
const int ROWS=10;
const int COLS=10;

// this is the definition of what a 'piece' is

struct basicPiece{
color team;
int value;
};

void handlePlace(basicPiece *[ROWS][COLS]);
void handleMove(basicPiece *[ROWS][COLS]);
void handleDisplay(basicPiece *[ROWS][COLS]);

int main(){
int i,j;
// the following is the definition of the board
// for the assignment, it must be an array of pointers
basicPiece *board[ROWS][COLS]; //board



bool quittingTime = false;


// this array is used as a temporary place to
// store the first word of the input sequence
// that will be interpreted as a command.
// if all goes well with the input file,
// command will have "p" or "m" or "d" or
// "q" in it. I'm using an array here so as
// not to confuse cin. If I were to use a
// char, surrounding white space
// might or might not be ignored, depending on
// the input file. I am using an array of 256
// elements because, hey, memory is cheap.
char command[256];

for(i=0;i<ROWS;++i)for(j=0;j<COLS;++j)board[i][j]=0;


while(!quittingTime){
handleDisplay(board);
cin >> command;
switch(command[0]){
case 'p': handlePlace(board); break;
case 'm': handleMove(board); break;
case 'd': handleDisplay(board); break;
case 'q': quittingTime = true; break;

default: cout << "huh?" << endl;
}
}

cout << "I'm outta here!" << endl;
return 0;
}

// I'll even throw in a bonus function stub

void handlePlace(basicPiece * board[ROWS][COLS]){

char inputColor[256];
int inputVal, inputRow, inputCol;

// the "p" was gotten from the input in main()
// now, get the rest of the command
cin >> inputColor >> inputVal >> inputRow >> inputCol;

// todo: check for errors in the input values

// todo: check to see if the spot is occupied

// todo: make a new official piece and get the board to point to it

// todo: set the values of the piece correctly

// todo: notify the user of the result

// todo: return to main
return;
}

// todo: write more functions!

*edit: Please use code tags in the future, thanks! code.gif



Any help would be greatly appreciated!!

This post has been edited by Martyr2: 6 Sep, 2008 - 08:46 PM

User is offlineProfile CardPM
+Quote Post


Martyr2

RE: Stratego Game Code

6 Sep, 2008 - 08:47 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 7,246



Thanked: 820 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Did you have a specific problem with this or are you just looking for someone to help you develop it? smile.gif
User is offlineProfile CardPM
+Quote Post

coolgymnast01

RE: Stratego Game Code

7 Sep, 2008 - 09:13 AM
Post #3

New D.I.C Head
*

Joined: 26 Mar, 2008
Posts: 21

I just need some assistance developing it. I am not very good at structs and I would really like knowing how to make them work biggrin.gif

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic

Time is now: 11/8/09 04:15AM

Live C++ Help!

Be Social

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

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month