Before I Go Any Further...

I am planning on making a RTS-esque game from the DOS (thinking about it, it's like a variation of pen and paper game you would play). So this is what I have so far:
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
95
//main.cpp

#include <iostream>
#include <windows.h>
#include "rtsmenu.h"

int main()
{
    using namespace std;
    
    //Treasury
    int yMoney = 100;
    int cMoney = 100;
    //
    
    //Units    
    int ySwordsmen = 0;
    int cSwordsmen = 0;
    
    int yArchers = 0;
    int cArchers = 0;
    
    int yCavalary = 0;
    int cCavalary = 0;
    
    int ySoldiers = (ySwordsmen + yArchers + yCavalary);
    int cSoldiers = (cSwordsmen + cArchers + cCavalary);
    //    
    
    int action;
    
    cout << "Starting...\n";
    Sleep(250);
    cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
    
    action = menu(ySwordsmen, cSwordsmen, yArchers, cArchers, yCavalary, cCavalary, yMoney, cMoney);
    
    cout << "\n\n";
    
    if (action == 1)
    {
          cout << "What units do you want to buy?\n";
    }
    
    if (action == 2)
    {
          if (ySoldiers == 0)
          {
                cout << "You can't attack!\n";
          }
          else
          cout << "On guard!\n";
    }
    
    if (action == 3)
    {
          yMoney += 50;     
          cout << "Waiting for computer to finish...\n";
    }
    
    cin.get();         
    cin.get();
    return 0;
}

//rtsmenu.h

#ifndef RTSMENU_H
#define RTSMENU_H

#include <iostream>

int menu(int ySwordsmen, int cSwordsmen, int yArchers, int cArchers, int yCavalary, int cCavalary, int yMoney, int cMoney)
{
    using namespace std; 
     
    cout << "Your Army:\t\t\tOpposing Army:\n\n";
    cout << "Swordsmen:\t" << ySwordsmen << "\t\tSwordsmen:\t" << cSwordsmen << endl;
    cout << "Archers:\t" << yArchers << "\t\tArchers:\t" << cArchers << endl;
    cout << "Cavalary:\t" << yCavalary << "\t\tCavalary:\t" << cCavalary << endl;
    cout << "\nTreasury:\t" << yMoney << "\t\tTreasury:\t" << cMoney;
    
    cout << "\nWould you like to buy units (1), attack enemy(2), or do nothing (3)?";
    int action;
    cin >> action;
    while (action < 1 || action > 3)
    {
          cout << "Please try again\n";
          cin >> action;
    }
    
    return action;
}

#endif 


So before I go any further, should I create a class? Such as a player class? Where one is you and the other the computer or other player? I just don't if this would make it easier (or at least cleaner) or not. This is probably more opinionated but still I wouldn't mind the assistance.
closed account (Lv0f92yv)
Lines 77 thru 81 suggest a class-based implementation wouldn't hurt. Currently, you're distinguishing between friend and foe by variable names - which might be OK in a small (and guaranteed to stay-small project). If you want to be able to easily add on and make the project bigger, it would probably save you a headache if you used classes up front.

A player class would probably a good idea, in my opinion. You could optionally make two classes, in the case that your opponent is a computer-controlled one. This would allow you to add functionality specific to computer controlled opponents (threads, randomness, etc). Though to keep it generic and simple, one Player class should do fine.

Also, take a look at your parameter list on line 73. Pretty long? This could be shortened to 2 lines if you passed references to the objects instead. This would also make adding functionality to each class MUCH easier, since you would only have to edit the class - not everything dependent on them (excluding additional implementation). Would also save you time in the future.

Things like:
1
2
int ySoldiers = (ySwordsmen + yArchers + yCavalary);
    int cSoldiers = (cSwordsmen + cArchers + cCavalary);
could also be done much more easily conveniently with classes. Something generic like this can be done from within the class when creating the class or upon adding/removing units.
Last edited on
Topic archived. No new replies allowed.