rouge-like game not working

Apr 6, 2012 at 6:09pm
Ive been coding this all night and for the life of me i cant get it to work, it gets stuck in a loop.
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
///////////////////////////////////
//      Console application      //
//            for                //
//        Rouge! RPG             //
//	This program is under the//
//GPL Public License you may mod //
//it as you see fit. -Noah Klabo //
///////////////////////////////////


//standard librarys 
#include <iostream>  
#include <fstream>   
#include <iomanip>  
#include <string>
#include <cstdlib>

//program headers
#include "map.h"
#include "navigation.h"
#include "render.h"
using namespace std;

int command()//basic Quit commands // oh gosh its late at nite and Im going to have to tarnsfer the commands to there own  function "command()"
{
screen();//FIXME //put navigate() inside the "screen" function
if (input == "exit")
  {                                           // __________
   //cout << Quit();                             | 1| 2| 3|
  }                                           // |__|__|__|
   if (input == "quit")                       // | 4| 5| 6|
     {                                        // |__|__|__|
      cout << "Quiting...NOW!\n";             // | 7| 8| 9|
     return 0;                                // |__|__|__|   
     }
//Direction commands
if (input == "north")
  {
   location - map_width; //would be only ten units for this demo but adding this will give the engine more flexability
  }
   if (input == "east")
     {
      //location + 1;
     }
      if (input == "south")
        {
         //location + map_width; //would be only ten units for this demo but adding this will give the engine more flexability
        } 
         if (input == "west")
          {
           location - 1;
          }
else
 {
 command();
 }


 return 0; //program must always return a value DUH
}

int main() //main function
{
cout << " ___       ___      _   _     ___      ____        ___ \n";
cout << "| ___\\    / __ \\   | | | |   / __ \\   / ___\\      |   |\n";
cout << "| |__||  | |  | |  | | | |  | |  | | | |___||     |   |\n";
cout << "|  _  |  | |__| |  | \\_/ |  | |__| | |  ____|      |_| \n";
cout << "|_| \\_\\   \\___ /    \\___/    \\___  |  \\ \\___        _  \n";
cout << "                                 | |   '____|      |_| \n";
cout << "                              __/ /                    \n";
cout << "                             |___/                     \n";

 cout << "Welcome, User"; //could use "endl" but I prefer newline 
 cin.ignore();//ignore function!
cout << command();
return 0;
}





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
38
///////////////////////////////////
//        Map rendition          //
//            for                //
//         rouge RPG             //
//	This program is under the//
//GPL Public License you may mod //
//it as you see fit. -Noah Klabo //
///////////////////////////////////

//standard librarys 
#include <iostream>  
#include <fstream>   
#include <iomanip>  
#include <string>
#include <cstdlib>
         
#ifndef _RENDER_
#define _RENDER_
using namespace std;

///////VARIABLES///////
string input;

int refresh() 
{
system("clear");//this is a linux command, I have no idea what the Windows equivalent is
}


int screen() //screen function displays,revives and clears the screen.
{
 cout << drawmap();
 getline(cin, input);
 navigate(); 
 refresh();
}
//day one finished!
#endif 




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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
///////////////////////////////////
//      Map format reference     //
//            for                //
//         rouge RPG             //
//	This program is under the//
//GPL Public License you may mod //
//it as you see fit. -Noah Klabo //
///////////////////////////////////

//standard librarys 
#include <iostream>  
#include <fstream>   
#include <iomanip>  
#include <string>
#include <cstdlib>

#ifndef _MAP_
#define _MAP_
using namespace std;

///////VARIABLES///////
int map_width = 10; 
//line 1
int pix1 = 0;
int pix2 = 0;
int pix3 = 0;
int pix4 = 0;
int pix5 = 0;
int pix6 = 0;
int pix7 = 0;
int pix8 = 0;
int pix9 = 0;
int pix10 = 0;

//line 2
int pix11 = 0;
int pix12 = 0;
int pix13 = 0;
int pix14 = 0;
int pix15 = 0;
int pix16 = 0;
int pix17 = 0;
int pix18 = 0;
int pix19 = 0;
int pix20 = 0;

//line 3
int pix21 = 0;
int pix22 = 0;
int pix23 = 0;
int pix24 = 0;
int pix25 = 0;
int pix26 = 0;
int pix27 = 0;
int pix28 = 0;
int pix29 = 0;
int pix30 = 0;

//line 4
int pix31 = 0;
int pix32 = 0;
int pix33 = 0;
int pix34 = 0;
int pix35 = 0;
int pix36 = 0;
int pix37 = 0;
int pix38 = 0;
int pix39 = 0;
int pix40 = 0;

//line 5
int pix41 = 0;
int pix42 = 0;
int pix43 = 0;
int pix44 = 0;
int pix45 = 0;
int pix46 = 0;
int pix47 = 0;
int pix48 = 0;
int pix49 = 0;
int pix50 = 0;

double magic_number = 0.1; //demo map format 10x10

int drawmap() //draws all the characters (pixles) on the screen
 {
    cout << pix1 << pix2 << pix3 << pix4 << pix5 << pix6 << pix7 << pix8 << pix9 << pix10 << endl 
<< pix11 << pix12 << pix13 << pix14 << pix15 << pix16 << pix17 << pix18 << pix19 << pix20 << endl 
<< pix21 << pix22 << pix23 << pix24 << pix25 << pix26 << pix27 << pix28 << pix29 << pix30 << endl 
<< pix31 << pix32 << pix33 << pix34 << pix35 << pix36 << pix37 << pix38 << pix39 << pix40 << endl;
return 0; 
}
#endif

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
///////////////////////////////////
//     Navigation subroutines    //
//            for                //
//         rouge RPG             //
//	This program is under the//
//GPL Public License you may mod //
//it as you see fit. -Noah Klabo //
///////////////////////////////////

//standard librarys 
#include <iostream>  
#include <fstream>   
#include <iomanip>  
#include <string>
#include <cstdlib>
         
#ifndef _NAVIGATION_
#define _NAVIGATION_
using namespace std;

///////VARIABLES///////
int location = 1;

int navigate() //I am aware of how crude this navigation system is, but it works.
{
cin >> location;
if (location == 1)
 {
  pix1 = 1;
 }
  if (location == 2)
    {
     pix2 = 1;
    }
     if (location == 3)
       {
        pix3 = 1;
       }
        if (location == 4)
          {
           pix4 = 1;
          }
           if (location == 5)
             {
              pix5 = 1;
             }
              if (location == 6)
                {
                 pix6 = 1;
                }
                 if (location == 7)
                   {
                    pix7 = 1;
                   }
                    if (location == 8)
                   {
                    pix8 = 1;
                   }
else
{
cout<< "Could you repeat that?";
}
}//FIXME //not finished
#endif
Last edited on Apr 6, 2012 at 6:12pm
Apr 6, 2012 at 7:45pm
The first thing you need to look up is arrays. That should shrink all this code down to about a dozen lines, then you can worry about any other errors if they still exist after the fix.
May 6, 2012 at 11:49am
Updated and made all map variables arrays added SFML to handle PNG tiles
Topic archived. No new replies allowed.