Text Based Game

This is a discussion on Text Based Game within the C++ Programming forums, part of the General Programming Boards category; I'm using Borland C++. I'm creating a game based on text. For all of you that don't know, it's a ...

  1. #1
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Question Text Based Game

    I'm using Borland C++. I'm creating a game based on text. For all of you that don't know, it's a game that is based on your input, all you see is what you read. I start with an opening sequence, an animation of a conversation... don't ask. Then I have an input space. The compiler comes up with two errors... I'll show you the code and the errors below:

    //Filename: txtgm.cpp
    //Function: Text Based Game
    #include <iostream.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <fstream.h>
    #include <stdio.h>
    #include <time.h>
    void Sleep(int MilliSeconds)
    {
    // CLOCKS_PER_SEC / 1000 gives the number of system clock ticks per millisecond
    int TicksPerMilliSec = CLOCKS_PER_SEC / 1000;

    // Set the desired looping time value
    int LoopingTime = clock() / TicksPerMilliSec + MilliSeconds;

    // loop until the desired amount of milliseconds has passed
    while(LoopingTime > clock() / TicksPerMilliSec)
    {
    // just keep looping
    }
    }

    int main()
    {
    cout << "SAT-ELITE" << endl;
    cout << "USERNAME: ";
    Sleep(100);
    cout << "A";
    Sleep(100);
    cout << "S";
    Sleep(100);
    cout << "T";
    Sleep(100);
    cout << "E";
    Sleep(100);
    cout << "R";
    Sleep(100);
    cout << "I";
    Sleep(100);
    cout << "S";
    Sleep(100);
    cout << "K" << endl;
    cout << "PASSWORD: ";
    Sleep(100);
    cout << "*";
    Sleep(100);
    cout << "*";
    Sleep(100);
    cout << "*";
    Sleep(100);
    cout << "*";
    Sleep(100);
    cout << "*";
    Sleep(500);
    clrscr();
    Sleep(2000);
    cout << "INCOMING SIGNAL: HELP, ASTERISK" << endl;
    Sleep(2000);
    cout << "INCOMING SIGNAL: SCAN THIS LINE" << endl;
    Sleep(2000);
    cout << "INCOMING SIGNAL: HURRY, ASTERISK" << endl;
    Sleep(2000);
    cout << "INCOMING SIGNAL: I DON'T HAVE MUCH TIME" << endl;
    int lp1=1;
    while(lp1!=0)
    {
    unsigned char sl[]="SCAN LINE";
    unsigned char chc1;
    cin >> chc1;
    if(chc1==sl)
    {
    cout << "SCANNING LINE" << endl;
    Sleep(100);
    cout << "SCANNING OUTCOME: SOUTHERN HEMISPHERE" << endl;
    Sleep(100);
    cout << "SCANNING OUTCOME: SOUTH WESTERN HEMISPHERE" << endl;
    Sleep(100);
    cout << "SCANNING OUTCOME: AUSTRALIA" << endl;
    Sleep(100);
    cout << "SCANNING OUTCOME: WESTERN AUSTRALIA" << endl;
    Sleep(100);
    cout << "ENDING TRANSMISSION" << endl;
    Sleep(100);
    cout << "SCAN INTERUPTED" << endl;
    lp1=0;
    }
    cout << "I DON'T UNDERSTAND" << endl;
    }
    return 0;
    }

    The errors are:
    1. Cannot convert unsigned char to unsigned char in function main.

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    49
    You have :
    unsigned char sl[]="SCAN LINE";
    unsigned char chc1;
    cin >> chc1;
    if(chc1==sl)

    chc1 is a char and sl a pionter to an array.

    Since chc1 is A char you are expecting a single letter input

    You can try if(chc1=='S')

    But if you want a word input :


    unsigned char chc1[20];
    and with #include <string.h>
    if(!strcmp(chc1,sl))

  3. #3
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Thanks

    Thanks GertFaller, that worked completely. Now I can continue at my game. Thanks again, Dr. Droid.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Text based game
    By wipeout4wh in forum C Programming
    Replies: 12
    Last Post: 03-26-2009, 04:39 PM
  2. Text based game
    By beene in forum Game Programming
    Replies: 10
    Last Post: 05-12-2008, 07:52 PM
  3. New Project, text game, design stage.
    By Shamino in forum Game Programming
    Replies: 9
    Last Post: 05-23-2007, 06:39 AM
  4. easiest way to make text based game?
    By oceanrats in forum C++ Programming
    Replies: 7
    Last Post: 08-13-2005, 02:17 PM
  5. Saving a text game
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 03-27-2002, 12:33 PM

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