Jump to content
  • Advertisement
Sign in to follow this  
Plasmarobo

Console I/O class Issues!

This topic is 4439 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have written a system for "drawing" a map to the console, but I have a problem. It doesn;t work right. I get no errors, and the functions return true! But they draw nothing to the screen. Could someone take a look at my code, and tell me what I have done horribly wrong? Thanks... Here it is... The h file
//String Pump .h
//This processes output to the screen,
//Holding Data in a tank waiting for output
//And geting user imput
//It also color codes the text
//CONSOL ONLY, DO NOT INCLUDE IN A WINDOWS PROJECT


#include <iostream>
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x500
#endif
#include <windows.h>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <fstream>

#ifndef _STRING_PUMP_H_
#define _STRING_PUMP_H_
#define CONS_HANDLE GetStdHandle(STD_OUTPUT_HANDLE)

enum
{
	BLACK,
	BLUE,
	GREEN,
	AQUA,
	RED,
	PURPLE,
	YELLOW,
	WHITE,
	GRAY,
	LIGHT_BLUE,
	LIGHT_GREEN,
	LIGHT_AQUA,
	LIGHT_RED,
	LIGHT_PURPLE,
	LIGHT_YELLOW,
	BRIGHT_WHITE
};




struct Screen8032
{
       char buffer[32][80]; //32 lines, 80 chars per line
       int colors[32][80];
       void Fillline(int line, char buf[80])
       {
           for(int a = 0; a == 79; a++)
           {
           buffer[line][a] = buf[a];
           colors[line][a] = WHITE;
           }
       }

       void Fill(char a)
       {
           for(int a = 0; a == 31; a++)
           {
               for(int b = 0; b == 79; b++)
               {
                   buffer[a] = a;
                   colors[a] = WHITE;
               }
           }
       }

       bool Map(char *filename)
       {
       	std::ifstream fobj;
		fobj.open(filename);
		if(fobj.fail() || !fobj.is_open())
			return false;

			std::string temp;
			for(int u = 0; u == 31; u++)
			{
            if(!getline(fobj, temp))
            return false;

            if(temp.size() != 80)
            return false;

            for(int s = 0; s == 79; s++)
            {
                buffer[s] = temp[s];
            }
			}


        }
    };



class StringPump
{
      private:
                std::queue<int> Clist;
                std::queue<std::string> Mlist;



public:

       int lines;

       StringPump();
       ~StringPump();

       bool SetColor(int color);

       bool Add(std::string text, int color);

       bool Send();

       bool Remove();

       bool Clear();

       bool Force();

       bool Sendx(int num);

      std::string Input(std::string Message, int color);

      int NInput(std::string Message, int color);

      int Getlines();

      bool Autoclear(bool on);

      void ClearScreen( HANDLE hCons= CONS_HANDLE);

      int GetLines( HANDLE hCons= CONS_HANDLE );

      int GetLength( HANDLE hCons= CONS_HANDLE );

      bool DrawScreenBuffer(Screen8032 *buffer, HANDLE hCons = CONS_HANDLE); //WARNING, BUFFER MUST BE A 2D ARRAY

      bool Out(char *buffer); //Writes a character buffer to the console output

      bool ScreenOut(Screen8032 *buffer);

      bool SizeScreen(int height, int width, COORD font);
};

most of these functions work fine. The problematics ones are: DrawScreenBuffer() ScreenOut() SizeScreen() - this one isn't as importaint, I just want to make sure the console size stays constant. Here is the abbridged expansions. I have cut out all the unessessary working functions:
//String Pump .cpp
//Class Definitions of stringpump.h
//This processes output to the screen,
//Holding Data in a tank waiting for output
//And geting user imput
//It also color codes the text
//CONSOL ONLY, DO NOT INCUDE WITH A WINDOWS PROJECT

#include <iostream>
#include <windows.h>
#include <cstdlib>

#include <cstring>
#include <string>
#include <vector>
#include <queue>

#include "StringPump.h"


using namespace std;



    StringPump::StringPump()
{

    SetConsoleMode( CONS_HANDLE, ENABLE_PROCESSED_INPUT );
   Clear();

   lines = 0;

}

      StringPump::~StringPump()
     {
     Clear();
     }




      

         

    
bool StringPump::DrawScreenBuffer(Screen8032 *buffer, HANDLE hCons)
{
if(buffer = NULL)
return false;

ClearScreen();
DWORD num;
char s;
for(int line = 0; line == 31; line++)
{

    for(int pos = 0; pos == 79; pos++)
    {
        SetColor(buffer->colors[line][pos]);
        s = buffer->buffer[line][pos];
        WriteConsole( hCons, &s, 1, &num, NULL);
    }
}
return true;

}



bool StringPump::Out(char *buffer)
{

DWORD num;

 WriteConsole( GetStdHandle(STD_OUTPUT_HANDLE), buffer, 80, &num, NULL);

 if(num == 80)
  return true;

  return false;
}





bool StringPump::ScreenOut(Screen8032 *buffer)
{
    char line[80];
    DWORD num;
    for(int x = 0; x == 31; x++)
    {
        for(int y = 0; y == 79; y++)
        {
            line[y] = buffer->buffer[x][y];
        }

        WriteConsole( GetStdHandle(STD_OUTPUT_HANDLE), line, 80, &num, NULL);
    }

    return true;
}


bool StringPump::SizeScreen(int height, int width, COORD font)
{

     SMALL_RECT rec;
     rec.Top = 0;
     rec.Left = 0;
     rec.Right = font.X * width; // 80 chars wide
     rec.Bottom = font.Y * height; //32 chars high
     SetConsoleWindowInfo(CONS_HANDLE, false, &rec);


}


Anyway, I am using Code::Blocks (for the first time) I am used to Visual C++ 2005, but someone told me you need to include extra libs with your package to run it.... so I am using this. I am using a hybred of Windows and C/C++ functions. I want to stay away from Windows completely, but since I need it for the color code I might as well use the console as well. Thanks...

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • 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!