Here is my source code. I am really new at programming so ANY help that could assist would be awesome.
//Zach Adams
//CSCI 1300
//Project 4
//Several "fish" sprites move once across the screen and user must "catch" them with the net, which is the mouse clicking on them.
//COMMENTS
//I have not been able to figure out how to include the catching of the fish and the keeping track of total points, which is what I am going to have in the final program. I also plan to make the fish look more fish-like, perhaps with .GIF's if making a complicated fish exclusively with C++ coding is too complicated.
#include <winbgim.h>
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include "Fish.h"
#include <cstdlib>
using namespace std;
const int WINDOW_SIZE = 700;
//Program
int main ()
{
int N;
cout << "How many fish do you want to release?" << endl;
cin >> N;
int S;
cout << "How fast do you want them to move? 1=Fast 100=Slow" << endl;
cin >> S;
initwindow (WINDOW_SIZE, WINDOW_SIZE, "Fish Tank");
setbkcolor (BLUE);
setcolor (BLACK);
cleardevice ();
vector<fish> fishies
while (I < N)
{
fishies.push_back(fish());
}
while (S > 100)
{
cout << "That's just not possible. Re-enter.";
cin >>S;
}
while (S < 1)
{
cout << "That's ludicrous speed. Don't go to plaid. Re-enter.";
cin >>S;
}
cout << "CATCH FISH!" << endl;
srand (time (NULL));
Fish b();
b.move();
b.draw();
fishies[0].draw();
//The delay multiplied by the user-defined variable S cause the game to go slower for higher numbers entered.
delay (10*S);
return EXIT_SUCCESS;
}
// vector<fish> fishies
///////////////////////////////////////////////////////////////////
Header file for fish object
class Fish
{
public:
// constructors
Fish (); //"default" constructor, no arguments
Fish (int r, int g, int b);
// "accessor" functions, not used in this example
int getx ();
int gety ();
int getdx ();
int getdy ();
// "mutator" functions, not used in this example
void setx (int _x);
void sety (int _y);
void setdx (int _dx);
void setdy (int _dy);
// other member functions
void move ();
void draw ();
private:
int x;
int y;
int dx;
int dy;
int red;
int green;
int blue;
};
/////////////////////////////////////////////////////////////////////////
fish class
#include <winbgim.h>
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include "fish.h"
using namespace std;
Fish::Fish ()
{
x = 200 + rand () % 10;
y = 10 - rand () % 10;
dx = 4 + rand () % 20;
dy = 16 - rand () % 16;
red = rand () % 256;
green = rand () % 256;
blue = rand () % 256;
}
//Fish::Fish (int r, int g, int b)
// x = 10 + rand () % 10;
// y = WINDOW_SIZE - 10 - rand () % 10;
// red = r;
// green = g;
// blue = b;
int Fish::getx ()
{
return x;
}
int Fish::gety ()
{
return y;
}
int Fish::getdx ()
{
return dx;
}
int Fish::getdy ()
{
return dy;
}
void Fish::setx (int _x)
{
x = _x;
}
void Fish::sety (int _y)
{
y = _y;
}
void Fish::setdx (int _dx)
{
dx = _dx;
}
void Fish::setdy (int _dy)
{
dy = _dy;
}
void Fish::move ()
{
x += dx;
y += dy;
dy++;
}
void Fish::draw ()
{
setfillstyle (SOLID_FILL, COLOR (red, green, blue));
fillellipse (x, y, 16, 8);
//These lines are meant to color in the eye for the fish.
setcolor (BLACK);
setfillstyle (SOLID_FILL, BLACK);
fillellipse (x+6, y-2, 4, 4);
}
The window opens but the fish do not appear. I am trying to solve that problem before I focus on making it so when a fish is clicked it changes into a skelleton. If anyone feels like helping I would be indebt for eternity.
Last edited by cscgal; Apr 30th, 2004 at 2:19 pm.