text games(for beginner)

Hello, i was wondering if any of you know any text based games i can make. I am a beginner. All i know is cin,cout,loops,if and switch statements and some other little things. I don't really know strings and pointers but i guess this a good opertunity to learn them - thanks.
the folowing link may help you to get the ideas

http://xoax.net/comp/cpp/console/
im trying to make a trying to make the tic tac toe board but there r errors....


C:\Users\Neil\Desktop\c++\main.cpp|18|error: expected ';' before 'cout'|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
    char box1('1');
    char box2('2');
    char box3('3');
    char box4('4');
    char box5('5');
    char box6('6');
    char box7('7');
    char box8('8');
    char box9('9');

    cout << box1 << "|" cout << box2 << "|" << box3 << endl;
    cout << "------" << endl;

    cin.get();
    return 0;
}
Take the second cout, out of line 18:
cout << box1 << "|" cout << box2 << "|" << box3 << endl;
On line 18 you shouldn't be using cout twice in 1 line.

Change it from
cout << box1 << "|" cout << box2 << "|" << box3 << endl;

to
cout << box1 << "|" << box2 << "|" << box3 << endl;

Also I would think it would be easier to hold each of the grid areas in an array instead of seperate char's.
Also I would think it would be easier to hold each of the grid areas in an array instead of seperate char's.

He's doing the above tutorial, that's how it is on the video. I just had a look at a few of them. (:
ok im have alot of trouble...i used the tutorial to help me make the grid but im trying to do the rest without the tutorial but im stuck and dont know what to do next? can you help?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
    char box1('1');
    char box2('2');
    char box3('3');
    char box4('4');
    char box5('5');
    char box6('6');
    char box7('7');
    char box8('8');
    char box9('9');
    int player;
    int what_grid;
    
    do{
    cout << box1 << "|" << box2 << "|" << box3 << endl;
    cout << "-----" << endl;
    cout << box4 << "|" << box5 << "|" << box6 << endl;
    cout << "-----" << endl;
    cout << box7 << "|" << box8 << "|" << box9 << endl;
    
    cout << "enter 1 if it is player 1's turn or 2 if it is player 2's turn: ";
    cin >> player;
    
    if (player == 1){
        cout << "Enter the number of the grid you want to put an X in: ";
        cin >> what_grid;
    

    cin.get();
    return 0;
}
I have just fixed this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <conio.h>
#include <string.h>
using namespace std;
//Initialize keyboard function
int keyboard_key() {if (kbhit()) {return getch();} else {return 0;} }

int main()
{
    int x=0,y=0,key;
    char plr=2;
    //Intro:
    cout<<"You use arrow keys to move\nReady?\n";
    system("pause");
    //Loop
    while (1) {
          //Keyboard checking
          key=keyboard_key();
          if (key==77) {x+=1;}
          if (key==75) {x-=1;}
          if (key==72) {y-=1;}
          if (key==80) {y+=1;}
          //Write to a console
          cout<<string(y,'\n')<<string(x,' ')<<plr;
          system("cls"); //Clear screen
          }
    return 0;
}
Last edited on
is there any more easy way cause i dont know what half of that means
is there any more easy way cause i dont know what half of that means
1 line: <iostream> standard input/output library for console.
2 line: <conio.h> is the library i used to check the what keyboard key was pressed
3 line: <string.h> is to handle strings
4 line: std namespace so I don't write "std::cout" but just "cout"
5 line: COMMENT
6 line: a function that returns what keyboard key was pressed
7 line: EMPTY SPACE
8 line: main function initialize
9 line: {
10 line: initialize some variables. x,y,key
11 line: plr character init.
12 line: COMMENT
13 line: Just an intro message
14 line: pausing until the user presses some key...
15 line: COMMENT
16 line: WHILE LOOP
17 line: COMMENT
18 line: Check what key was pressed and store the key in "key" variable
19 line: check if RIGHT was pressed
20 line: check if LEFT was pressed
21 line: check if UP was pressed
22 line: check if DOWN was pressed
23 line: COMMENT
24 line: write where player is. making y break lines and x spaces
25 line: Clear Screen
26 line: }
27 line: return value of main
28 line: }
29 line:
visit tic-tac-toe source code in ANSI C++

you will find easy to understand code for beginners

http://www.cppforschool.com/project/tic-tac-toe-project.html
Topic archived. No new replies allowed.