Over Break

let's write a game

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 1944 Views - Last Post: 02 January 2002 - 03:44 PM Rate Topic: -----

#1 nighthawk  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 1,269
  • Joined: 11-April 01

Over Break

Posted 12 December 2001 - 08:33 PM

i don't know about the rest of you programmers out there, but i want to be able to retain my knowledge of what i've learned (little as it may be) over the semester...

i think that i have enough knowledge to work on a simple rpg, i can use classes to make modifications easier, i can write to files and call from files, arrays will work nicely to hold information about enemies...

if anyone would like to add to this please do, like ideas or anything, of course, this will be the simple, text, old school, rpg type thing...


Is This A Good Question/Topic? 0
  • +

Replies To: Over Break

#2 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4503
  • View blog
  • Posts: 28,410
  • Joined: 21-March 01

Re: Over Break

Posted 12 December 2001 - 08:43 PM

i need some ideas so i can do programs that require classes and the sort, i learn by doing, got any ideas, maybe some requirements from your class at unm you happen to still have....
Was This Post Helpful? 0
  • +
  • -

#3 nighthawk  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 1,269
  • Joined: 11-April 01

Re: Over Break

Posted 13 December 2001 - 10:25 AM

if you want to do some programs that require classes i suggest trying to write the game of connect four, i had to do this assignment...ummm, i'll look through my notes and whatnot and see if i can dig up some guidelines for you.
Was This Post Helpful? 0
  • +
  • -

#4 nighthawk  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 1,269
  • Joined: 11-April 01

Re: Over Break

Posted 13 December 2001 - 10:33 AM

ok, here it is, this was my first assignment for the semester, it was the first thing i ever had to write to impliment classes...now, i don't know how you would do this because all my programs are run on unix machines, but i can tell you that i needed a board.C board.h connect4.C and a makefile...but in anycase, here's the original assignment that i was given:

Quote

ASSIGNMENT #1 --- Connect-4 referee

This assignment is to write a C++ program that allows two human
players to play Connect-4 against each other.  This game is a variant
of tic-tac-toe in which players drop pieces down a column (the usual
board has 7 columns, each of which has room for 6 pieces) and try to
form four in a row, vertically, horizontally, or diagonally.  Once a
column is full neither player can go there, and if the entire board
fills with pieces without either player winning, it's a draw.

It calls for three files, board.h, board.C, and connect4.C.

The first thing for you to do is design a class called "board" that
keeps track of what pieces are already on the board, whose turn it is,
whether someone has already won, and so on.  For instance, my board
class has a data member which is a two-dimensional array of chars

class board {
private:
 char grid[WIDTH][HEIGHT];
 ...

(where WIDTH and HEIGHT are #defined earlier) and its most important
member function is

public:
 bool move(int i);
};

board::move takes input i and modifies the board by having the current
player add a piece in the i'th column.  It returns a bool, true if
this move is legal and false if it is not.  It also checks to see if
that's a winning move (this is the hardest part).

My connect4.C program fits onto one page, and simply calls member
functions of the board inside a simple loop that asks who goes first,
what their move is, and so on.  In fact, you could change the rules of
the game by just modifying board.C and board.h, and my connect4.C
could remain identical!  This is the advantage of object-oriented
programming.

To get full credit, remember to check for illegal moves (moving in a
column that doesn't exist, or which is already full) and for draws (in
which there's no room on the board left to play).

hope this helps you a little :)

Was This Post Helpful? 0
  • +
  • -

#5 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4503
  • View blog
  • Posts: 28,410
  • Joined: 21-March 01

Re: Over Break

Posted 13 December 2001 - 04:06 PM

thank ya much
Was This Post Helpful? 0
  • +
  • -

#6 nighthawk  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 1,269
  • Joined: 11-April 01

Re: Over Break

Posted 13 December 2001 - 04:17 PM

no problem, if you can figure that out you should also try to do the 1 player version of the game (although i must warn you, it's complicated)
Was This Post Helpful? 0
  • +
  • -

#7 arcturus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 14-December 01

Re: Over Break

Posted 14 December 2001 - 09:07 AM

if you want to make a game, i suggest that you at least let them build their character instead of just having them wonder through a forest type thing. let them have stats as if this were a normal rpg...like Dungeons and Dragons.
Was This Post Helpful? 0
  • +
  • -

#8 EnKRYpTeD  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 128
  • Joined: 11-May 01

Re: Over Break

Posted 14 December 2001 - 09:41 AM

Well, i don't know classes and all of that yet and i, too, learn by doing. Ill try that assignment you did when i get some free time though i would love to help ya write up an rpg. I personaly play A large amount of RPG`s and im in 2 Dungeons and Dragons games as we speak. It would be fun, count me in! Just say the word and drop me an email (morbidangel767@hotmail.com)

(Edited by EnKRYpTeD at 11:42 am on Dec. 14, 2001)

Was This Post Helpful? 0
  • +
  • -

#9 malkiri  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 3
  • View blog
  • Posts: 364
  • Joined: 29-March 01

Re: Over Break

Posted 14 December 2001 - 01:13 PM

I found a cool site today:

http://www.topcoder.com

Looks pretty interesting. Check it out.

Was This Post Helpful? 0
  • +
  • -

#10 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4503
  • View blog
  • Posts: 28,410
  • Joined: 21-March 01

Re: Over Break

Posted 14 December 2001 - 03:09 PM

thanx i signed up, sounds kool.
Was This Post Helpful? 0
  • +
  • -

#11 arcturus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 14-December 01

Re: Over Break

Posted 15 December 2001 - 10:42 AM

here's an example of the set-up for some stats of characters

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <time.h>

using namespace std;

//FUNCTIONS void Gender();        //Function to select gender void Race();        //Function to select race void Occupation();//Function to select occupation void Attributes();//Function to roll attributes void getchar();         //Function to get the ready made character

//GLOBAL VARIABLES int str=0;    //strength int vit=0;    //vitality int dex=0;    //dexterity int spd=0;    //speed int intel=0;  //intelligence int wil=0;    //willpower int per=0;    //perception int pre=0;    //presence int hp=0;     //hit points int thrd=0;   //threshold int eva=0;    //evade

//GLOBAL NAMES string username;    //string for username string gender;    //string for gender string race;    //string for race string occupation;  //string for occupation

main() {

 string charactercreate;

 ifstream in_stream;  ofstream out_stream;    cout <<"What is your character's name: ";  cin >> username;  cout << endl;    in_stream.open(username.c_str());    if(in_stream.fail()){

   cout << "This character hasn't been created yet.  Would you like "         << "to create it? Yes or No: ";    cin >> charactercreate;

   Gender();    Race();    Occupation();    Attributes();        out_stream.open(username.c_str());          out_stream << username << endl       << gender << endl       << race << endl       << occupation << endl       << str << endl       << vit << endl       << dex << endl       << spd << endl       << intel << endl       << wil << endl       << per << endl       << pre << endl       << hp << endl       << thrd << endl       << eva << endl;          out_stream.close();  }  else {      getchar();  }  return 0; }

void Gender() {    do {    cout <<"What is your character's gender, choose from the following:" << endl <<"Male" << endl <<"Female" << endl <<"What would you like to be, please type it now (Nothing other than the" << endl <<"above will be accepted. Please use all lowercase letters.): ";    cin >> gender;    cout << endl << endl << endl;  } while ((gender != "male")&&(gender != "female")); }

void Race() {

 do {    cout <<"What is your character's race, choose from the following:" << endl <<"Badger" << endl <<"Cat" << endl <<"Fox" << endl <<"Hare" << endl <<"Mouse" << endl <<"Mole" << endl <<"Otter" << endl <<"Rat" << endl <<"Shrew" << endl <<"Sparrow" << endl <<"Squarrel" << endl <<"Weasel" << endl <<"What would you like to be, please type it now (Nothing other than the" << endl <<"above will be accepted. Please use all lowercase letters.): ";    cin >> race;    cout << endl << endl << endl;  } while ((race != "badger")&&(race != "cat")&&(race !="fox")&&(race != "hare")&&(race != "mouse")   &&(race != "mole")&&(race != "otter")&&(race != "rat")&&(race != "shrew")&&   (race != "sparrow")&&(race != "squarrel")&&(race != "weasel"));

}

void Occupation() {

 do {    cout <<"What is your character's occupation, choose from the following:" << endl <<"Abbott" << endl <<"Abbess" << endl <<"Gate Keeper" << endl <<"Sentry" << endl <<"Dibbon" << endl <<"Friar" << endl <<"Cook" << endl <<"Infirmary Keeper " << endl <<"Cellar Keeper" << endl <<"Abbey Warrior" << endl <<"What would you like to be, please type it now (Nothing other than the" << endl <<"above will be accepted. Please use all lowercase letters.): ";    getline(cin, occupation);    cout << endl << endl << endl;  } while ((occupation != "abbott")&&(occupation != "abbess")&&(occupation !="gate keeper")&&   (occupation != "sentry")&&(occupation != "dibbon")&&(occupation != "friar")&&   (occupation != "cook")&&(occupation != "infirmary keeper")&&   (occupation != "abbey warrior"));

}

void Attributes() {    bool doagain;    string again;

   srand((unsigned int)time(0));

   do {            str = rand() % 20 + 5;  // sets strength b/w 5 and 20      vit = rand() % 20 + 5;  //sets vitality b/w 5 and 20      dex = rand() % 20 + 5;  //sets dexterity b/w 5 and 20      spd = rand() % 20 + 5;  //sets speed b/w 5 and 20      intel = rand() % 20 + 5;  //sets intelligence b/w 5 and 20      wil = rand() % 20 + 5;  //sets willpower b/w 5 and 20      per = rand() % 20 + 5;  //sets perception  b/w 5 and 20      pre = rand() % 20 + 5;  //sets presence b/w 5 and 20      hp = (str+vit)*3;  //sets hit points      thrd = (str * 2)+wil;  //sets threshold      eva = dex + spd + per;  //sets evade

     cout << "Name: " << username << endl;      cout << "Race: " << race << endl;      cout << "Gender: " << gender << endl;      cout << "Occupation: " << occupation << endl;      cout << "------------------------------------" << endl;      cout << "Strength: " << str << endl;      cout << "Vitality: " << vit << endl;      cout << "Dexterity: " << dex << endl;      cout << "Speed: " << spd << endl;      cout << "Intelligence: " << intel << endl;      cout << "Willpower: " << wil << endl;      cout << "Perception: " << per << endl;      cout << "Presence: " << pre << endl;      cout << "-----------------------------------" << endl;      cout << "Hit Points: " << hp << endl;      cout << "Threshold: " << thrd << endl;      cout << "Evade: " << eva << endl;      cout << endl << endl << endl << "Would you like to ..." << endl;      cout << "Reroll or Accept: ";      cin >> again;  

     if( again == "r" )   // if you press r doagain = 1;           // sets the do again flag on      else                 // otherwise set to off doagain = 0;    }    while( doagain == 1 );    // if the flag is on do the whole thing again

}

void getchar() {    ifstream fin;

 fin.open(username.c_str());

 fin >> username      >> gender      >> race      >> occupation      >> str      >> vit      >> dex      >> spd      >> intel      >> wil      >> per      >> pre      >> hp      >> thrd      >> eva;  fin.close();

 cout << "Name: " << username << endl;  cout << "Race: " << race << endl;  cout << "Gender: " << gender << endl;  cout << "Occupation: " << occupation << endl;  cout << "------------------------------------" << endl;  cout << "Strength: " << str << endl;  cout << "Vitality: " << vit << endl;  cout << "Dexterity: " << dex << endl;  cout << "Speed: " << spd << endl;  cout << "Intelligence: " << intel << endl;  cout << "Willpower: " << wil << endl;  cout << "Perception: " << per << endl;  cout << "Presence: " << pre << endl;  cout << "-----------------------------------" << endl;  cout << "Hit Points: " << hp << endl;  cout << "Threshold: " << thrd << endl;  cout << "Evade: " << eva << endl << endl;

}


Was This Post Helpful? 0
  • +
  • -

#12 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4503
  • View blog
  • Posts: 28,410
  • Joined: 21-March 01

Re: Over Break

Posted 15 December 2001 - 11:26 AM

very nice arcturus. :)
Was This Post Helpful? 0
  • +
  • -

#13 arcturus  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 14-December 01

Re: Over Break

Posted 15 December 2001 - 11:28 AM

thanks, i was just playing around, and i figured that animals would be more fun than the usual, elf, ogre, type stuff, of course, that's just a beginning, and it's nothing fancy.
Was This Post Helpful? 0
  • +
  • -

#14 nighthawk  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 1,269
  • Joined: 11-April 01

Re: Over Break

Posted 15 December 2001 - 11:34 AM

hmm, interesting, what about perks, and minus, for being of a certain race or occupation?

[note]
those look like races and occupations of redwall characters.
[/note]

Was This Post Helpful? 0
  • +
  • -

#15 VxJasonxV  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 201
  • Joined: 03-October 01

Re: Over Break

Posted 15 December 2001 - 01:36 PM

hey arcturus, you want them to enter the word in all lowercase, why don't you look up case conversions, that way they can type MaLE and it can still be accepted as male.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2