bejewelled-board.C
00001
00002
00003
00004 #include "bejewelled-board.H"
00005 #include <vector>
00006 #include <iostream>
00007 #include <string>
00008 #include <stdio.h>
00009 #include <stdlib.h>
00010 #include <sstream>
00011 #include <time.h>
00012
00013 using namespace std ;
00014
00015 template <class T> Matrix<T>::Matrix(int row , int col , T** m)
00016 {
00017 mems = *m ;
00018 r = row ;
00019 c = col ;
00020 }
00021
00022
00023 template <class T> Matrix<T>::~Matrix()
00024
00025 {
00026 delete[] mems;
00027 }
00028
00029 template <class T> int Matrix<T>::getNumOfRows()
00030 {
00031 return r ;
00032 }
00033
00034 template <class T> int Matrix<T>::getNumOfColumns()
00035 {
00036 return c ;
00037 }
00038
00039 template <class T> void Matrix<T>::setNumOfRows(int nr)
00040 {
00041 r = nr ;
00042 }
00043
00044 template <class T> void Matrix<T>::setNumOfColumns(int nc)
00045 {
00046 c = nc ;
00047 }
00048
00049 template <class T> string Matrix<T>::toFormattedString()
00050 {
00051 string s("") ;
00052 for (int i = 0 ; i < r ; i++){
00053 s += "<" ;
00054 for(int j = 0 ; j < c ; j++){
00055 int index = i*c + j;
00056 T m = *(mems + index);
00057 s+=stringify(m)+" " ;
00058 }
00059 s += ">" ;
00060 }
00061 return s ;
00062 }
00063
00064 template <class T> string Matrix<T>::toString()
00065 {
00066 string s("") ;
00067 for (int i = 0 ; i < r ; i++){
00068 for(int j = 0 ; j < c ; j++){
00069 int index = i*c + j;
00070 T m = *(mems + index);
00071 s+=stringify(m)+" " ;
00072 }
00073 }
00074 return s ;
00075 }
00076
00077 template <class T> string Matrix<T>::stringify(T i)
00078 {
00079 ostringstream o ;
00080 o << i ;
00081 return o.str();
00082 }
00083
00084 template <class T> T* Matrix<T>::operator[](int row){
00085 return &mems[row*c];
00086 }
00087
00088 Cell::Cell(const uint row , const uint col) {
00089 r = row ;
00090 c = col ;
00091 }
00092
00093
00094
00095 Board::Board(Matrix<uint>& m){
00096 cstate = &m ;
00097 }
00098
00099 Board::~Board(){
00100 delete cstate;
00101 }
00102
00103 Board::getCurrentState(){
00104 cstate ;
00105 }
00106
00107 Board::getObjectAtCell(Cell& cell){
00108 return (*cstate)[cell.r][cell.c];
00109 }
00110
00111
00112
00113 int main(){
00114 float* a = new float[6] ;
00115 for (int i = 0 ; i < 6 ; i++){
00116 a[i] = i ;
00117 }
00118 Matrix<float> m(3,2,&a);
00119
00120 m[0][0] = 21.45 ;
00121 m[0][1] = 0.00001 ;
00122 m[1][0] = 13 ;
00123 for(int i = 0 ; i < 2 ; i++ ){
00124 for( int j = 0 ; j < 3 ; j++ ){
00125 cout<< m[i][j]<<endl ;
00126 }
00127 }
00128 cout<<m.toFormattedString()<<endl ;
00129 cout<<m.toString()<<endl;
00130 return 0 ;
00131 }
00132
00133