DonnyYangR |
05-15-2008 02:49 AM |
I cant draw a ASCII table in c++ shell console
i cant seem to display my ASCII tables using a function which takes a RECT class as a argument using these codes:
the function is "void tables::sdraw(RECT tmp){/*do stuff*/}"
function.cpp:
Code:
#include "header.h"
// regular functions
int randint()
{
return ((int)(rand()*rand()*time(NULL)));
}
BOOL gotoxy(int x,int y) // somebody plz tell me how this function works!
{
HANDLE hConsole = GetStdHandle ( STD_OUTPUT_HANDLE );
if ( INVALID_HANDLE_VALUE != hConsole )
{
COORD pos = {x,y};
return SetConsoleCursorPosition(hConsole,pos);
}
}
// end regular functions
// class coin functions
coin::coin()
{
topface = HEAD;
}
face coin::getTopFace(void)
{
return topface;
}
void coin::tossCoin(void)
{
int tmp;
tmp = 1+(randint()%2);
if (tmp==1)
topface = HEAD;
else
topface = TAIL;
}
// end class coin functions
// class player functions
player::player()
{
wins = 0;
points = 100;
bet = 0;
side = HEAD;
loss = 0;
}
// end class player functions
// class tables functions
void tables::draw(player *tmp,int stage)
{
if(stage==1)
{
gotoxy(0,0);
cout << "+------------------------------------------------------------------------------+";
gotoxy(0,1);
cout << "| Press ENTER to play or press ESCAPE to quit! |";
gotoxy(0,2);
cout << "| WARNING: Your points and your status will not be saved |";
gotoxy(0,3);
cout << "+------------------+-----------------------------------------------------------+";
gotoxy(0,4);
cout << "| Status: | Results: |";
gotoxy(0,5);
cout << "| | |";
gotoxy(0,6);
cout << "| | |";
gotoxy(0,7);
cout << "| | |";
gotoxy(0,8);
cout << "| | |";
gotoxy(0,9);
cout << "| | |";
gotoxy(0,10);
cout << "| | |";
gotoxy(0,11);
cout << "| | |";
gotoxy(0,12);
cout << "| | |";
gotoxy(0,13);
cout << "| | |";
gotoxy(0,14);
cout << "| | |";
gotoxy(0,15);
cout << "| | |";
gotoxy(0,16);
cout << "| | |";
gotoxy(0,17);
cout << "| | |";
gotoxy(0,18);
cout << "+------------------+ |";
gotoxy(0,19);
cout << "| Credits: +-----------------------------------------------------------+";
gotoxy(0,20);
cout << "| | You currently have: "; gotoxy(62,20); cout << "Points |";
gotoxy(0,21);
cout << "| Made By: +-----------------------------------------------------------+";
gotoxy(0,22);
cout << "| Donny Corp. | Current Player: 1 Total Players: 1 |";
gotoxy(0,23);
cout << "| | +--------+";
gotoxy(0,24);
cout << "+------------------+--------------------------------------------------+ DUMP: ";
showpoint(tmp->getPoints());
}
gotoxy(78,24);
}
inline void tables::showpoint(int tmp)
{
gotoxy(52,20);
printf("%9d",tmp);
}
void tables::showerr(string tmp)
{
RECT tmp2;
tmp2.bottom = 15;
tmp2.top = 11;
tmp2.left = 8;
tmp2.right = 68;
sdraw(tmp2);
gotoxy(35,12);
cout << "ERROR:";
gotoxy(9,13);
cout << tmp;
}
void tables::sdraw(RECT tmp)
{
int x,y;
for(x=0;!x>(tmp.right-tmp.left);x++)
{
if(x==0||x==(tmp.right-tmp.left))
{
gotoxy(tmp.left+x,tmp.top);
cout << "+";
}
else
{
gotoxy(tmp.left+x,tmp.top);
cout << "-";
}
}
for(y=1;!y==(tmp.bottom-tmp.top);y++)
{
for(x=0;!x>(tmp.right-tmp.left);x++)
{
if(x==0||x==(tmp.right-tmp.left))
{
gotoxy(tmp.left+x,tmp.top+y);
cout << "|";
}
else
{
gotoxy(tmp.left+x,tmp.top+y);
cout << " ";
}
}
}
for(x=0;!x>(tmp.right-tmp.left);x++)
{
if(x==0||x==(tmp.right-tmp.left))
{
gotoxy(tmp.left+x,tmp.bottom);
cout << "+";
}
else
{
gotoxy(tmp.left+x,tmp.bottom);
cout << "-";
}
}
}
// end class tables functions
header.h:
Code:
#ifndef HEADER_H
#define HEADER_H
#include <windows.h>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <time.h>
#include <iostream>
using namespace std;
#define FALSE 0
#define TRUE !FALSE
#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77
#define ESC 27
#define ENTER 13
typedef unsigned short int tinyint;
enum face {HEAD,TAIL};
int randint(void);
BOOL gotoxy(int x,int y);
class coin
{
public:
coin();
face getTopFace(void);
void tossCoin(void);
private:
face topface;
};
class player
{
public:
player();
int getWins(void)
{
return wins;
}
int getPoints(void)
{
return points;
}
int getBet(void)
{
return bet;
}
face getSide(void)
{
return side;
}
int getLoss(void)
{
return loss;
}
void setWins(int tmp)
{
wins = tmp;
}
void setPoints(int tmp)
{
points = tmp;
}
void setBet(int tmp)
{
bet = tmp;
}
void setSide(face tmp)
{
side = tmp;
}
void setLoss(int tmp)
{
loss = tmp;
}
private:
tinyint wins;
unsigned int points;
unsigned int bet;
face side;
tinyint loss;
};
class tables
{
public:
static void draw(player *tmp,int stage);
static void showerr(string tmp);
static void sdraw(RECT tmp);
//static void showcre(int tmp);
static void showpoint(int tmp);
};
#endif
test.cpp:
Code:
#include "header.h"
int main()
{
player *player1;
player1 = new player;
tables::draw(player1,1);
_getche();
tables::showerr("TEST");
delete player1;
return 0;
}
im using VC++ 2008 express
|