please help, i can't figure out what's wrong

This is a discussion on please help, i can't figure out what's wrong within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream.h> #include <windows.h> #include <conio.h> #include <fstream.h> #include <stdlib.h> #include <string> #include <stdio.h> int keypress=0; char message[50]; char ...

  1. #1
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753

    please help, i can't figure out what's wrong

    Code:
    #include <iostream.h>
    #include <windows.h>
    #include <conio.h>
    #include <fstream.h>
    #include <stdlib.h>
    #include <string>
    #include <stdio.h>
    
    int keypress=0;
    char message[50];
    char tempmessage[50];
    
    int count;
    
    int space1gone=0;
    int space2gone=0;
    
    void frame (int xmin,int ymin,int xmax,int ymax);
    void gotoxy(int,int);
    void printmove(char message[], char tempmessage[], int& space1gone, int& space2gone);
    void determinemessage(char message[], char tempmessage[], int& keypress);
    
    ///////////////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////////////////
    int main()
    {
    	frame(0,0,55,20); //Biggest box
    	frame(56,0,79,24); //Right-side box
    	frame(0,21,55,24); //Message Box
    
    	while(keypress!=27)
    	{
    		keypress=0;
    
    	    if(kbhit())
    		{
    		    keypress=_getch();
    			cout<<flush;
    			determinemessage(message, tempmessage, keypress); //Determine what to print
    			printmove(message, tempmessage, space1gone, space2gone); //print in correct spot
    		}
    	}
    	return 0;
    }
    ////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////
    
    void frame (int xmin, int ymin, int xmax, int ymax)
    {
       int count;
       gotoxy(xmin,ymin);
       putchar(218);
       gotoxy(xmax,ymin);
       putchar(191);
       gotoxy(xmin,ymax);
       putchar(192);
       gotoxy(xmax,ymax);
       putchar(217);
       gotoxy(xmin+1,ymin);
       for(count=xmin; count<xmax-1; count++)
          putchar(196);
       gotoxy(xmin+1,ymax);   
       for(count=xmin; count<xmax-1; count++)
          putchar(196);   
       for(count=ymin+1; count<=ymax-1; count++)
       {
          gotoxy(xmin,count);
          putchar(179);
       }   
       for(count=ymin+1; count<=ymax-1; count++)
       {
          gotoxy(xmax,count);
          putchar(179);
       }
    }
    
    void gotoxy(int x, int y)
    {
    	HANDLE hConsoleOutput;
    	COORD dwCursorPosition;
    
    	dwCursorPosition.X = x;
    	dwCursorPosition.Y = y;
    	hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
     	SetConsoleCursorPosition(hConsoleOutput,dwCursorPosition);
    }
    
    void printmove(char message[], char tempmessage[], int& space1gone, int& space2gone)
    {
    	switch(space2gone) //checks if first spot is open
    	{
    	    case 0:
    		    if(space1gone==0) //checks if second spot is open
    			{
    			    gotoxy(1,22);
    			    cout<<message;
    				gotoxy(1,22);
    			}
    		    else if(space1gone==1) //first spot is used, second is open
    			{
    			    gotoxy(1,23);
    			    cout<<message;
    				gotoxy(1,23);
    			}
    		    space1gone=1;
    		    break;
    	    case 1:
    		    gotoxy(1,22);
    			cout<<"                              ";
    			gotoxy(1,22);
    		    cout<<tempmessage;
    		    gotoxy(1,23);
    			cout<<"                              ";
    			gotoxy(1,23);
    		    cout<<message;
    			gotoxy(1,23);
    			break;
    	}
    	space2gone=1;
    
    }
    
    void determinemessage(char message[], char tempmessage[], int& keypress)
    {
    	strcpy(tempmessage, message);
    
    	strcpy(message, "Invalid move");
    
    	if(keypress==72)
    		strcpy(message, "You moved up");
    	if(keypress==75)
    		strcpy(message, "You moved left");
    	if(keypress==80)
    		strcpy(message, "You moved down");
    	if(keypress==77)
    		strcpy(message, "You moved right");
    }
    it's supposed to keep printing in one of two spots, that's why there are 'gotoxy's. It doesn't though. It's a bit odd, please help me. thanks in advance;

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    305
    im pretty sure i know whats happening, but i dont think i know how to fix it. i think when you use gotoxy() and go to a certain section of the screen, everything that was on there gets pushed up instead of staying there. try using curses or the like.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help! I cannot figure out what I'm doing wrong here!
    By chsindian595 in forum C Programming
    Replies: 2
    Last Post: 08-02-2008, 03:18 AM
  2. Any suggestions on whats wrong with this C Program?
    By thephreak6 in forum C Programming
    Replies: 3
    Last Post: 10-19-2002, 07:50 PM
  3. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM
  4. What is wrong here?????
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 05-23-2002, 10:51 AM
  5. What did i do wrong? Code inside
    By The Rookie in forum C Programming
    Replies: 2
    Last Post: 05-18-2002, 08:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21