Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added OOP and ROS assignments. #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added OOP and ROS assignments.
  • Loading branch information
abinashmeher999 committed Mar 12, 2014
commit 8764454f72685eeaafb94c0e8ec364c776bc14d4
29 changes: 29 additions & 0 deletions Abinash/OOP_Assignment/Board.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "Board.h"
#include <cstdlib>
#include <ctime>

//void Board::mapped(Image img,int *x,int *y,chan *pa)
//{


//}

Board::Board()
{
srand((unsigned int)time(NULL));
Chan *x;
int i,j,k;
x=&A;
x->rn=99;
x->gn=99;
x->bn=99;//Board::mapped(img,&height,&width,&A);
for (i=0;i<99;i++)
{
x->r[i].x=rand()%640;
x->g[i].x=rand()%640;
x->b[i].x=rand()%640;
x->r[i].y=-(rand()%480);
x->g[i].y=-(rand()%480);
x->b[i].y=-(rand()%480);
}
}
28 changes: 28 additions & 0 deletions Abinash/OOP_Assignment/Board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef BOARD_H
#define BOARD_H
#include "Position.h"
#include "Image.h"

typedef struct{
char c;
Position p;
}pix;

struct Chan{
Position r[100];int rn;
Position g[100];int gn;
Position b[100];int bn;
};

class Board
{
public:
int height,width;
Chan A;
Board();
private:
//void mapped(Image,int*,int*,chan *pa);

};

#endif // BOARD_H
4 changes: 4 additions & 0 deletions Abinash/OOP_Assignment/Dice.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "Dice.h"
#include <ctime>
#include <cstdlib>

13 changes: 13 additions & 0 deletions Abinash/OOP_Assignment/Dice.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef DICE_H
#define DICE_H


class Dice
{
public:
virtual int roll()=0;
protected:
private:
};

#endif // DICE_H
10 changes: 10 additions & 0 deletions Abinash/OOP_Assignment/Dice6.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "Dice6.h"
#include <ctime>
#include <cstdlib>


int Dice6::roll()
{
srand((unsigned int)time(NULL));
return (rand()%6)+1;//ctor
}
15 changes: 15 additions & 0 deletions Abinash/OOP_Assignment/Dice6.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef DICE6_H
#define DICE6_H

#include "Dice.h"


class Dice6 : public Dice
{
public:
int roll();
protected:
private:
};

#endif // DICE6_H
63 changes: 63 additions & 0 deletions Abinash/OOP_Assignment/Game.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include "Game.h"
#include <conio.h>

void Game::get_players()
{
int i;
std::cout<<"Enter the number of players\n";
std::cin>>no_players;
Set=new Player [no_players];
winset=new Player* [no_players];
for (i=0;i<no_players;i++)
{
Set[i].id=i;
}
}

void Game::trialturn()
{
int i;
for (i=0;i<no_players;i++)
{
getch();
Set[i].Getdice(dice.roll(),&bd1);
std::cout<<"\tPlayer_"<<Set[i].id<<" @ "<<Set[i].pos.x<<","<<Set[i].pos.y<<" With score="<<Set[i].score<<"\n"<<std::endl;
}
return;
}

void Game::StartGame()
{
int j,k,l;

Player* tmpset=new Player [no_players];
for (l=0;l<no_players;l++)
{
tmpset[l]=Set[l];
}
for (j=0;no_winners==0;j++)
{
std::cout<<"Round--"<<j+1<<std::endl;
Game::trialturn();
for (k=0;k<no_players;k++)
{
if (tmpset[k].pos.x==Set[k].pos.x && tmpset[k].pos.x==Set[k].pos.x)
{

winset[no_winners++]=&Set[k];

}
}
for (l=0;l<no_players;l++)
{
tmpset[l]=Set[l];
}
}
return;
}

Game::Game()
{
no_winners=0;
}

27 changes: 27 additions & 0 deletions Abinash/OOP_Assignment/Game.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef GAME_H
#define GAME_H
#include "Player.h"
#include "Dice6.h"
#include "Board.h"
#include "Dice.h"


class Game
{
public:
void StartGame();
void get_players ();//takes no of players and makes players with unique ids
Player** winset;
int no_winners;
Game();
private:

int no_players;

void trialturn();//executes one turn for each player
Player *Set;
Dice6 dice;
Board bd1;
};

#endif // GAME_H
6 changes: 6 additions & 0 deletions Abinash/OOP_Assignment/Image.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "Image.h"

//Image::Image(IplImage *img)
//{
// pointer=img;
//}
17 changes: 17 additions & 0 deletions Abinash/OOP_Assignment/Image.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef IMAGE_H
#define IMAGE_H
//#include <cv.h>
//#include <cxcore.h>
//#include <highgui.h>


class Image
{
public:
// IplImage *pointer;
// Image(IplImage* );
protected:
private:
};

#endif // IMAGE_H
57 changes: 57 additions & 0 deletions Abinash/OOP_Assignment/OOPs PS.cbp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="OOPs PS" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/OOPs PS" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/OOPs PS" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename="Board.cpp" />
<Unit filename="Board.h" />
<Unit filename="Dice.cpp" />
<Unit filename="Dice.h" />
<Unit filename="Dice6.cpp" />
<Unit filename="Dice6.h" />
<Unit filename="Game.cpp" />
<Unit filename="Game.h" />
<Unit filename="Image.cpp" />
<Unit filename="Image.h" />
<Unit filename="Player.cpp" />
<Unit filename="Player.h" />
<Unit filename="Position.cpp" />
<Unit filename="Position.h" />
<Unit filename="main.cpp" />
<Extensions>
<code_completion />
<envvars />
<debugger />
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>
71 changes: 71 additions & 0 deletions Abinash/OOP_Assignment/OOPs PS.depend
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# depslib dependency file v1.0
1394618834 source:c:\users\abinash\skydrive\documents\code chef\new folder\oops ps\main.cpp
<iostream>
<ctime>
<cstdlib>
"Position.h"
"Board.h"
"Player.h"
"Image.h"
"Dice.h"
"Game.h"
"Dice6.h"

1394456855 c:\users\abinash\skydrive\documents\code chef\new folder\oops ps\position.h

1394456844 source:c:\users\abinash\skydrive\documents\code chef\new folder\oops ps\position.cpp
"Position.h"

1394456386 source:c:\users\abinash\skydrive\documents\code chef\new folder\oops ps\src\position.cpp
"Position.h"

1394456386 c:\users\abinash\skydrive\documents\code chef\new folder\oops ps\src\position.h

1394562841 source:c:\users\abinash\skydrive\documents\code chef\new folder\oops ps\board.cpp
"Board.h"
<cstdlib>
<ctime>

1394558684 c:\users\abinash\skydrive\documents\code chef\new folder\oops ps\board.h
"Position.h"
"Image.h"

1394556573 c:\users\abinash\skydrive\documents\code chef\new folder\oops ps\image.h

1394518589 source:c:\users\abinash\skydrive\documents\code chef\new folder\oops ps\dice.cpp
"Dice.h"
<ctime>
<cstdlib>

1394518570 c:\users\abinash\skydrive\documents\code chef\new folder\oops ps\dice.h

1394560446 source:c:\users\abinash\skydrive\documents\code chef\new folder\oops ps\dice6.cpp
"Dice6.h"
<ctime>
<cstdlib>

1394476911 c:\users\abinash\skydrive\documents\code chef\new folder\oops ps\dice6.h
"Dice.h"

1394619055 source:c:\users\abinash\skydrive\documents\code chef\new folder\oops ps\game.cpp
"Game.h"
<conio.h>

1394618834 c:\users\abinash\skydrive\documents\code chef\new folder\oops ps\game.h
"Player.h"
"Dice6.h"
"Board.h"
"Dice.h"

1394619179 c:\users\abinash\skydrive\documents\code chef\new folder\oops ps\player.h
"Position.h"
"Board.h"
<iostream>
<cmath>

1394556587 source:c:\users\abinash\skydrive\documents\code chef\new folder\oops ps\image.cpp
"Image.h"

1394619758 source:c:\users\abinash\skydrive\documents\code chef\new folder\oops ps\player.cpp
"Player.h"

Loading