Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    570
  • comments
    2427
  • views
    216941

Entry #50

Sign in to follow this  
Mushu

92 views

  • Random Observation of the Day!!
    Even Nazis take vacations!

CODE DUMP (compile at own risk):
#include "main.h"

int main() {
dispBanner();
//mainMenu();

sizeBoard();
drawBoard();

int foo;
cin >> foo;

setSquare(foo, -1);

drawBoard();
cin >> foo;

return 0;
}


#include "board.h"

int xBound;
int yBound;
int maxLen;

vector<int> board;
vector pieces;

bool checkWin(int x, int y, int reqLen) {

}

int rowLen(int x, int y, int ix, int iy, int val, int incri) {
if (x < 0 || x > xBound || y < 0 || y > yBound)
return incri;

if (getSquare(x, y) == val)
return rowLen(x+ix, y+iy, ix, iy, val, incri+1);
else
return incri;
}

void iniBoard(int x, int y) {
xBound = x;
yBound = y;

board.reserve(x*y);

//std::vector::iterator i = board.begin();
int i2;

for (i2 = 0; i2 < x*y; ++i2)
board.push_back(i2);

if (i2 > 99) {
maxLen = 3;
} else if(i2 > 9) {
maxLen = 2;
} else {
maxLen = 1;
}
}

void iniBoard(int x, int y, string p1, string p2) {
iniBoard(x,y);
iniBoard(p1,p2);
}

void iniBoard(string p1, string p2) {
pieces.clear();
pieces.push_back(" ");
pieces.push_back(p1);
pieces.push_back(p2);
}

void setSquare(int x, int y, int value) {
setSquare(y * xBound + x, value);
}

void setSquare(int index, int value) {
board[index] = value;
}

void drawBoard() {
int x, y;

if (getSquare(0,0) >= 0)
cout << "\n" << string(maxLen-1, ' ') << board[0];
else
cout << "\n" << string(maxLen-1, ' ') << pieces[abs(board[0])];

for (x = 1; x != xBound; ++x)
if (getSquare(x,0) >= 0)
cout << "|" << string(maxLen-getLen(x), ' ') << board[x];
else
cout << "|" << string(maxLen-1, ' ') << pieces[abs(getSquare(x,0))];

for (y = 1; y != yBound; ++y) {

cout << "\n" << string(maxLen, '-');

for (x = 1; x != xBound; ++x)
cout << "+" << string(maxLen, '-');

if (getSquare(0, y) >= 0)
cout << "\n" << string(maxLen-getLen(y*xBound), ' ') << board[y * xBound];
else
cout << "\n" << string(maxLen-1, ' ') << pieces[abs(getSquare(0,y))];

for (x = 1; x != xBound; ++x)
if (getSquare(x,y) >= 0)
cout << "|" << string(maxLen-getLen(y*xBound + x), ' ') << board[y*xBound + x];
else
cout << "|" << string(maxLen-1, ' ') << pieces[abs(getSquare(x,y))];
}

cout << "\n";
}

int getLen(int value) {
if (value > 99) {
return 3;
} else if(value > 9) {
return 2;
} else {
return 1;
}
}

int getSquare(int x, int y) {
return board[y*xBound + x];
}

#include "menus.h"

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

void menu1Player() {}
void menu2Player() {}
void menuOptions() {}

void mainMenu() {
cout << "1. 1-Player Game\n";
cout << "2. 2-Player Game\n";
cout << "3. Options\n";
cout << "4. Exit\n";

int foo;
cin >> foo;

if (foo == 1) {
// 1-Player Game
menu1Player();

} else if (foo == 2) {
// 2-Player Game
menu2Player();

} else if (foo == 3) {
// 3-Player Game
menuOptions();

} else {
exit(0);
}
}

void dispBanner() {
cout << " __ _ _ _ __ " << "\n";
cout << "|\\ /| || || / _| | |_| | || || \\| / _|" << "\n";
cout << "| \\/ | | \\/ | \\__\\ | _ | | \\/ | \\__\\" << "\n";
cout << "||\\/|| \\__/ |__/ |_| |_| \\__/ |__/" << "\n";

cout << "\n" << "TIC TAC TOE" << "\n\n";
}

void sizeBoard() {
int x, y;

cout << "Enter board x-Bounds. (3~20) ";
cin >> x;
cout << "Enter board y-Bounds. (3~12) ";
cin >> y;

if (x > 20) x = 20;
if (y > 12) y = 12;
if (x < 3) x = 3;
if (y < 3) y = 3;

iniBoard(x,y, "X", "O");
}

#include "OP_string.h"

std::string makeString(int len, std::string character) {
std::string ret;

for (len = len; len != 0; --len)
ret += character;

return ret;
}

using std::string; using std::vector;

vector split(string source, string target) {
vector ret;
string tempStr;

string::size_type i;

for (i = 0; i != source.size(); ++i) {
if (source == target[0]) {
ret.push_back(tempStr);
tempStr = "";
} else {
tempStr += source;
}
}

if (tempStr != "") ret.push_back(tempStr);

return ret;
}


#include "OP_vector.h"

using std::string; using std::vector;

string join(vector& source, string target) {
std::vector::iterator i;
string ret;

for (i = source.begin(); i != source.end(); ++i)
ret += *i + target;

return ret;
}

string join(vector& source) {
return join(source, "");
}




Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!