Would anyone like to give me some insight?

closed account (L6b7X9L8)
I want to try and wrap my head around OOP and start planning out my programs before I dive in to it half arsed and end up with projects being unfinished after unfinished.

My project this time is BattleBots. A user creates a robot by adding(buying) different modules to it ( Motherboard, Armor, Weapon etc). The user also gets to 'Program' it's robot with a simple syntax. however, just like they have to watch the weight of the added modules, they also have to watch how much RAM they can allocate for the main program.

Each module is it's own class. I'm trying to get my head around OOP and how different objects can work with each other. I can't seem to graps all these Foo/Bar examples and I am hoping some coding guru's out there could take my idea and give me some code snippets to point me in the right direction.

These are very rough notes which I have written down in notepad for the past half an hour. If anyone disagree's with what I have wrote I am happy to shorten my idea's and make it more basic until I understand the concept!

Thanks to anyone in advance for replies, and code snippets of how all this would work together would be very much appreciated.

My notes:

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
BATTLEBOTS NOTES -


CPU:
string name; Name of the CPU
int threads; Number of processes it can do at a time (Move/Turn/Shoot/Sense - Move & Shoot/Turn & Shoot/Sense & Move/Turn & Sense) etc
int speed; How fast it can perform processes (Unsure how to do this)

RAM:
string name; Name of the RAM module
int space; How much space to store module programs; 16 - 32 - 64 - 128 etc 

MOTHERBOARD(CPU, RAM):
string name; Name of motherboard;
const int MaxWeight; Max weight of modules it can hold


BATTLEBOT:

- MOTHERBOARD(CPU, RAM) 
- ARMOR(Name, int defense, int weight)
- TYRES(Name, int speed, int weight) 
- WEAPON(Name, int damage, int weight)
- SENSOR(Name, int range, int weight)

BATTLEBOT(Motherboard(CPU, RAM), Armor, Tyres, Weapon, Sensor)


///////////////////////////////////////////////////////////////////////////

BATTLEBOTS must be programmed before each fight. Exisiting programs can be saved/loaded before a fight ( Allows people to save good programs or try and create better ones according to how much RAM they have )

An easy to read and use syntax must be used, i.e:

MoveForward 						- 1 byte
Sense							- 1 byte	
if(Sense.Enemy): turnTowardsEnemy and FireWeapon	- 2 bytes + 1 byte + 1 byte
if(Sense.HitWall): Reverse and TurnLeft			- 2 bytes + 1 byte + 1 byte
if(Sense.BeenHit): Reverse				- 2 bytes + 1 byte
Repeat							- 1 byte
						Total	- 14 bytes
Last edited on
closed account (L6b7X9L8)
Anyone?
closed account (j3Rz8vqX)
Something to help you jump start:
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
#include <iostream>
using namespace std;
class CPU{
public:
    string name;    //Name of the CPU
    int threads;    //Number of processes it can do at a time (Move/Turn/Shoot/Sense - Move & Shoot/Turn & Shoot/Sense & Move/Turn & Sense) etc
    int speed;      //How fast it can perform processes (Unsure how to do this)
};
class RAM{
public:
    string name;    //Name of the RAM module
    int space;      //How much space to store module programs; 16 - 32 - 64 - 128 etc
};
class Motherboard{
public:
    CPU cpu;
    RAM ram;
    string name;            //Name of motherboard;
    const int MaxWeight;    //Max weight of modules it can hold
};
/*
    Create Tires class
    Create Weapons class
    Create Sensors class
*/
class BattleBot{
public:
    Motherboard mobo;
    //Tires tires;
    //Weapons weapons;
    //Sensors sensors;
    void setCpuRam(CPU c, RAM r)
    {
        mobo.cpu = c;
        mobo.ram = r;
    }
};
int main()
{
    return 0;
}

Your next goal would be to consider each objects relationship.
closed account (L6b7X9L8)
So you wouldn't pass each module to the BattleBot class but create them inside? Same for the motherboard?

I had in mind something like:

1
2
3
4
5
CPU basicCPU;
RAM basicRAM;
MotherBoard basicMotherBoard(basicCPU, basicRAM);

BattleBot *player = new BattleBot(basicMotherBoard, Armor, Tyres, Weapon);


EDIT:

Also for the relationship between modules, how would I figure that out exactly?


From what I have planned the MotherBoard class has relationship between the CPU and RAM, while the BattleBot has relationship to the MotherBoard, Armor, Tyres and Weapon classes. Also it will have relationship to the Map class I will add when I get the logic to the BattleBot down.
Last edited on
closed account (j3Rz8vqX)
So you wouldn't pass each module to the BattleBot class but create them inside? Same for the motherboard?
Stack versus heap, whatever works best for you.

Also for the relationship between modules, how would I figure that out exactly?
As of right now, it seems you've got a collection of objects; which is good, but since you were focusing your
head around OOP
I mentioned relationship because there could be a possible change of a based class?

Every object seems to have
weight

Maybe SENSOR is a weapons? just kidding.

Have fun.
closed account (L6b7X9L8)
Could you explain a little of the Stack vs Heap paradigm?

I'm guessing the base class would be Polymorphism?

1
2
3
4
5
6
7
8
9
10
11
class Module
{
    int weight;
}

class Weapon: public Module
{
    int Damage;
}

Weapon Laser(5,5);
closed account (j3Rz8vqX)
http://www.learncpp.com/cpp-tutorial/79-the-stack-and-the-heap/
closed account (L6b7X9L8)
Thanks for the info!

I now have the CPU and RAM classes working inside the Motherboard class with the correct output. I had a minor problem where I made the CPU and RAM objects inside the Motherboard class a pointer, so when I passed the CPU and RAM to the Motherboard, after I deleted them, the CPU and RAM inside of the Motherboard also messed up. So i had to make them normal objects and copied the passed objects, so when I deleted the passed CPU and RAM, the objects inside of the Motherboard gave me the right values!

All works perfectly now, thank you.

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
#include "Module.h"

#include <iostream>

using std::cin;
using std::cout;

int main()
{
	CPU *cpuv01 = new CPU("Inzel I", 100, 1, 1);
	RAM *ramv01 = new RAM("Kingron mk16", 50, 16);

	Motherboard *mv01 = new Motherboard("Xerox 4001A", 250, cpuv01, ramv01, 200);

	delete cpuv01;
	delete ramv01;

	cout << "Motherboard name:		" << mv01->getName() << "\n"
		 << "Motherboard cost:		" << mv01->getCost() << "\n"
		 << "Motherboard Weight:		" << mv01->getMaxWeight() << "\n\n"
		 << "Motherboard CPU name:		" << mv01->mCPU.getName() << "\n"
		 << "Motherboard CPU cost:		" << mv01->mCPU.getCost() << "\n"
		 << "Motherboard CPU Threads:	" << mv01->mCPU.getThreads() << "\n"
		 << "Motherboard CPU Speed:		" << mv01->mCPU.getSpeed() << "\n\n"
		 << "Motherboard RAM name:		" << mv01->mRAM.getName() << "\n"
		 << "Motherboard RAM cost:		" << mv01->mRAM.getCost() << "\n"
		 << "Motherboard RAM space:		" << mv01->mRAM.getSpace() << "\n";

	delete mv01;

	cin.get();

	return 0;
}
Topic archived. No new replies allowed.