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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
|
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <ctime>
#include "Board.h"
#include "Card.h"
using namespace std;
using namespace System;
Card::Card()
{
faceUp = 0;
number = 0;
xCord = 0;
yCord = 0;
};
int Card::getRow()
{
return xCord;
};
int Card::getCol()
{
return yCord;
};
int Card::setPosition(int x, int y)
{
xCord = x;
yCord = y;
return xCord, yCord;
};
int Card::putNumber(int num)
{
number = num;
return number;
};
bool Card::turnover()
{
faceUp = 1;
return faceUp;
};
bool Card::IsFaceUp()
{
return faceUp;
};
int Card::myNumber()
{
return number;
};
void Card::display()
{
cout << number;
};
bool Card::ChangeFace(bool i)
{
faceUp = i;
return faceUp;
};
Card & Card::operator=(Card &other)
{
faceUp = other.faceUp;
number = other.number;
xCord = other.xCord;
yCord = other.yCord;
return *this;
};
Board::Board()
{
x = 4;
y = 4;
int i,j;
while(i=0, i<=x, i++)
{
while(j=0, j<=y, j++)
{
cards[i][j].setPosition(i,j);
}
}
};
void Board::DeckSize(int n)
{
x = n;
y = n;
cards[x][y];
};
Board::Board(Board &other)
{
x = other.x;
y = other.y;
cards = other.cards;
};
int Board::getRows()
{
return x;
};
int Board::getCols()
{
return y;
};
int Board::Deal()
{
int i=0;
int j=0;
int k=(x/2);
std::vector<int> n;
for (int c = 1; c < ((x*y)/2)+1; c++)
n.push_back(c);
std::random_shuffle (n.begin(), n.end());
while(i <= ((x-k)-1), i++)
{
while(j <= (y-1), j++)
{
return cards[i][j].putNumber(n.at(i+j));
}
}
int l = k;
while(l=0, l<=((x-i)-1), k++)
{
while(j=0, j<=(y-1), j++)
{
return cards[k][j].putNumber(n.at(k+j));
}
}
return 0;
};
int Board::getFaceDown()
{
return faceDown;
};
int Board::getSize()
{
return x*y;
};
void Board::turnOver(int x, int y)
{
if (cards[x][y].IsFaceUp())
cards[x][y].ChangeFace(0);
else
cards[x][y].ChangeFace(1);
};
std::ostream& operator<<(std::ostream &out, Card& obj)
{
out << obj.myNumber();
return out;
};
void Board::printBoard()
{
int i, j;
while(i = 0, i <= x-1, i++)
{
while(j = 0, j <= y-1, j++)
{
if (cards[i][j].IsFaceUp())
{ cout << " ";
cout << cards[i][j];
cout << " ";
}
else
cout << " X ";
}
cout << "\n\n";
}
};
void Board::printAll()
{
int i, j;
while(i = 0, i <= x-1, i++)
{
while(j = 0, j <= y-1, j++)
{
cout << " ";
cout << cards[i][j];
cout << " ";
}
cout << "\n\n";
}
};
Board::~Board()
{};
int main()
{
std::srand(unsigned(std::time(0)));
bool ans;
Board playBoard;
playBoard.Deal();
Console::WriteLine("Do you want to play a 16-Card game (1), or choose a size for the card deck (0)?");
cin >> ans;
if (ans == true)
{
playBoard.printBoard();
}
else if (ans == false)
{
Console::WriteLine("Enter an even number of cards(up to 50) to play with.");
int total;
cin >> total;
}
return 0;
};
|