Stratego game code

Trying to create the game Stratego

Page 1 of 1

2 Replies - 3031 Views - Last Post: 07 September 2008 - 10:13 AM Rate Topic: -----

#1 coolgymnast01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 26-March 08

Stratego game code

Posted 06 September 2008 - 05:13 PM

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

#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:



Any help would be greatly appreciated!!

This post has been edited by Martyr2: 06 September 2008 - 09:46 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Stratego game code

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4187
  • View blog
  • Posts: 11,847
  • Joined: 18-April 07

Re: Stratego game code

Posted 06 September 2008 - 09:47 PM

Did you have a specific problem with this or are you just looking for someone to help you develop it? :)
Was This Post Helpful? 0
  • +
  • -

#3 coolgymnast01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 26-March 08

Re: Stratego game code

Posted 07 September 2008 - 10:13 AM

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 :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1