Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Working on Cookies
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:689de052ff76a8a52edf73159adf4a1def448207aa3ed7c8cc22e522a1ee1308
User & Date: sarah 2018-05-18 19:36:18
Context
2018-05-18
19:42
for loop correct check-in: e7db9f3a92 user: sarah tags: trunk
19:36
Working on Cookies check-in: 689de052ff user: sarah tags: trunk
18:49
xPos fixed check-in: f08571ec15 user: sarah tags: trunk
Changes

Changes to finalproject/finalproject.cpp.

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
96
97

98
99

100
101
102
103

104
105
106
107
108

109
110
111
112
113

114
115
116
117
118

119
120
121
122
123
124

125
126
127
128
129
130
131
132
133
134
135
136
137

138
139
140
141

142
143

144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// #include <conio.h> //For getche()
// #include <curses.h>
#include <time.h>
using namespace std;

//You can modify these numbers but don't delete these constants or this starting code will not work
const int MAX_HEIGHT = 20; //The height of the grid
const int MAX_WIDTH = 40; //The width of the grid

// DO NOT ALTER OR DELETE THIS CODE (START)!!!!!!!!!!!!!!!!!!!!!!!!!!!
/********************************************************************
 * Class: PickUpGame
 * Purpose: To store the grid and the current x and y position of the
 * user. Also has memeber functions to intialize the grid and print it.
 * Allows the user to move around the grid but provides no out of
 * bounds checking.
 ********************************************************************/
class PickUpGame
{
protected:
      char Screen[MAX_HEIGHT][MAX_WIDTH]; //The grid to print to the screen
      int xPos, yPos; //The current x and y position of the users cursor on the grid

public:
      //Constructor that will intialize the screen and x and y positions
      PickUpGame() : xPos(0), yPos(MAX_WIDTH - 1)
      {
           SetupScreen(); //Initalize the grid
      }

      //Initialize the screen with all '.' characters and set the intial user cursor position on the grid
      void SetupScreen()
      {
           for(int height = 0; height < MAX_HEIGHT; height++) {

                for(int width = 0; width < MAX_WIDTH; width++) {

                     Screen[height][width] = '.'; //Initialize each grid position
                }
           }
           Screen[xPos][yPos] = '<'; //Set the users initial cursor position
      }

      //Print the grid to the screen
      void Print()
      {
           for(int height = 0; height < MAX_HEIGHT; height++) {

                for(int width = 0; width < MAX_WIDTH; width++) {

                     cout << Screen[height][width]; //Print the character at this location in the grid
                }
                cout << endl; //After each row is printed, print a newline character
           }
      }

      //Take in user input to move around the grid
      void Move(char Direction)
      {
            // cout << "char: " << static_cast<int>(Direction);
           switch(static_cast<int>(Direction)) //Don't know the ASCII characters for the arrow keys so use the ASCII numbers
           {
                case 65: //Up arrow
                     // cout << "UP\n";
                     Screen[xPos][yPos] = ' '; //Wipe out the users current cursor
                     xPos--; //Move the users x position on the grid
                     Screen[xPos][yPos] = '^'; //Move the users cursor
                     break;
                case 66: //Down arrow
                     // cout << "Down\n";
                     Screen[xPos][yPos] = ' ';
                     xPos++;
                     Screen[xPos][yPos] = 'v';
                     break;
                case 68: //Left arrow
                      // cout << "Left\n";
                     Screen[xPos][yPos] = ' ';
                     yPos--;
                     Screen[xPos][yPos] = '<';
                     break;
                case 67: //Right arrow
                     // cout << "Right\n";
                     Screen[xPos][yPos] = ' ';
                     yPos++;
                     Screen[xPos][yPos] = '>';
                     break;
           }
      }
};
// DO NOT ALTER OR DELETE THIS CODE (END)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

class MyPickUpGame: public PickUpGame

{ public:  


      



























void BoundedMove(char UserMove)
{ 

cout<< "\nbefore usernove:" << "xPos="<<xPos<<" yPos="<<yPos << "\n";

Move(UserMove);
cout<< "after usernove:" << "xPos="<<xPos<<" yPos="<<yPos << "\n";


// When you reset a xPos, you have to clear the character at the old location first.
// you are not doing that here... yet :)
if(xPos<0)

 {cout << "xPos <1, resetting back to 1\n";
       xPos=0;
       Screen[xPos][yPos] = '^';
 }
 if(xPos>19)

{cout << "xPos > 19, resetting back to 19\n";
      xPos=19;
      Screen[xPos][yPos] = 'v';
}
if(yPos<0)

{cout << "yPos< 0, resetting back to 0\n";
      yPos=0;
      Screen[xPos][yPos] = '<';
}
if(yPos>39)

{cout << "yPos > 39, resetting back to 39\n";
      yPos=39;
      Screen[xPos][yPos] = '>';
}
     
cout << "move end" <<"xPos="<<xPos<<" yPos="<<yPos << "\n";

     
}




};

//You can modify and change main()
int main()
{
      system("clear"); //Clear the screen before printing anything


      MyPickUpGame* Game = new MyPickUpGame; //Create a new game object and store it in a object pointer

      char UserMove = ' '; //This is used to store the users input
      do {

           cout << "Welcome to cookie pickup. You will move to the cookies by using the arrow keys." << endl; //Program intro
           Game->Print(); //Print the grid out

           cout << "What direction would you like to move in? \n(Move using the arrow keys or type q to quit.) "; //Instructions to the user
           //UserMove = getche(); //Get one character from the user (some compilers have "getche()")
            system("/bin/stty raw"); 
           UserMove = getchar(); //Get one character from the user (Visual Studio 2010 "_getche()" is the new version of "getche()")
     	      system("/bin/stty cooked");
           Game->BoundedMove(UserMove); //Process the users input
      } while(UserMove != 'Q' && UserMove != 'q'); //Keep running the program until the user types in a Q or q

      // system("clear"); //Clear the screen
      cout << endl;
      Game->Print(); //Print the final grid out to the user
      cout << endl;

      
      return 0;
}







|











|

|

|



|





|
>
|
>
|
|
|
|





|
>
|
>
|
|
|
|






|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|




|
>
|
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|

|
>
|
|
>

|
|
|
>
|
|
|
|
|
>
|
|
|
|
|
>
|
|
|
|
|
>
|
|
|
|
|
|
>
|
<
<
<
<
<






<
>
|


|
>
|
<
>
|
|
|
|
|
|
|






<


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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166





167
168
169
170
171
172

173
174
175
176
177
178
179

180
181
182
183
184
185
186
187
188
189
190
191
192
193

194
195
// #include <conio.h> //For getche()
// #include <curses.h>
#include <time.h>
using namespace std;

//You can modify these numbers but don't delete these constants or this starting code will not work
const int MAX_HEIGHT = 20; //The height of the grid
const int MAX_WIDTH = 40;  //The width of the grid

// DO NOT ALTER OR DELETE THIS CODE (START)!!!!!!!!!!!!!!!!!!!!!!!!!!!
/********************************************************************
 * Class: PickUpGame
 * Purpose: To store the grid and the current x and y position of the
 * user. Also has memeber functions to intialize the grid and print it.
 * Allows the user to move around the grid but provides no out of
 * bounds checking.
 ********************************************************************/
class PickUpGame
{
    protected:
      char Screen[MAX_HEIGHT][MAX_WIDTH]; //The grid to print to the screen
      int xPos, yPos;                     //The current x and y position of the users cursor on the grid

    public:
      //Constructor that will intialize the screen and x and y positions
      PickUpGame() : xPos(0), yPos(MAX_WIDTH - 1)
      {
            SetupScreen(); //Initalize the grid
      }

      //Initialize the screen with all '.' characters and set the intial user cursor position on the grid
      void SetupScreen()
      {
            for (int height = 0; height < MAX_HEIGHT; height++)
            {
                  for (int width = 0; width < MAX_WIDTH; width++)
                  {
                        Screen[height][width] = '.'; //Initialize each grid position
                  }
            }
            Screen[xPos][yPos] = '<'; //Set the users initial cursor position
      }

      //Print the grid to the screen
      void Print()
      {
            for (int height = 0; height < MAX_HEIGHT; height++)
            {
                  for (int width = 0; width < MAX_WIDTH; width++)
                  {
                        cout << Screen[height][width]; //Print the character at this location in the grid
                  }
                  cout << endl; //After each row is printed, print a newline character
            }
      }

      //Take in user input to move around the grid
      void Move(char Direction)
      {
            // cout << "char: " << static_cast<int>(Direction);
            switch (static_cast<int>(Direction)) //Don't know the ASCII characters for the arrow keys so use the ASCII numbers
            {
            case 65: //Up arrow
                  // cout << "UP\n";
                  Screen[xPos][yPos] = ' '; //Wipe out the users current cursor
                  xPos--;                   //Move the users x position on the grid
                  Screen[xPos][yPos] = '^'; //Move the users cursor
                  break;
            case 66: //Down arrow
                  // cout << "Down\n";
                  Screen[xPos][yPos] = ' ';
                  xPos++;
                  Screen[xPos][yPos] = 'v';
                  break;
            case 68: //Left arrow
                     // cout << "Left\n";
                  Screen[xPos][yPos] = ' ';
                  yPos--;
                  Screen[xPos][yPos] = '<';
                  break;
            case 67: //Right arrow
                  // cout << "Right\n";
                  Screen[xPos][yPos] = ' ';
                  yPos++;
                  Screen[xPos][yPos] = '>';
                  break;
            }
      }
};
// DO NOT ALTER OR DELETE THIS CODE (END)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

class MyPickUpGame : public PickUpGame
{
    public:
    int CookieNumber;
      void cookies()
      {
            
            CookieNumber = 1 + rand() % 10;
           
            for(int CookieNumber)
            { int RandomxPos ;
            RandomxPos= rand()%19 ;    
            int RandomyPos;
            RandomyPos= rand()%39;     

            Screen[RandomxPos][RandomyPos]='o';
            if(Screen[RandomxPos][RandomyPos]='o')
            {
                  RandomxPos=rand()%19;
                  RandomyPos=rand()%39;
                  Screen[RandomxPos][RandomyPos]='o';
            }

            }
      }

      void endgame()
      {
            if( )
            cout<< "congrats you picked up "<< CookieNumber<<". Feel free to play again.";
            exit(0);
      }

      void BoundedMove(char UserMove)
      {

            cout << "\nbefore usernove:"
                 << "xPos=" << xPos << " yPos=" << yPos << "\n";
            Move(UserMove);
            cout << "after usernove:"
                 << "xPos=" << xPos << " yPos=" << yPos << "\n";

            // When you reset a xPos, you have to clear the character at the old location first.
            // you are not doing that here... yet :)
            if (xPos < 0)
            {
                  cout << "xPos <1, resetting back to 1\n";
                  xPos = 0;
                  Screen[xPos][yPos] = '^';
            }
            if (xPos > 19)
            {
                  cout << "xPos > 19, resetting back to 19\n";
                  xPos = 19;
                  Screen[xPos][yPos] = 'v';
            }
            if (yPos < 0)
            {
                  cout << "yPos< 0, resetting back to 0\n";
                  yPos = 0;
                  Screen[xPos][yPos] = '<';
            }
            if (yPos > 39)
            {
                  cout << "yPos > 39, resetting back to 39\n";
                  yPos = 39;
                  Screen[xPos][yPos] = '>';
            }

            cout << "move end"
                 << "xPos=" << xPos << " yPos=" << yPos << "\n";
      }





};

//You can modify and change main()
int main()
{
      system("clear"); //Clear the screen before printing anything

      srand(time(0));
      MyPickUpGame *Game = new MyPickUpGame; //Create a new game object and store it in a object pointer

      char UserMove = ' '; //This is used to store the users input
      do
      {
            cout << "Welcome to cookie pickup. You will move to the cookies by using the arrow keys." << endl;     //Program intro

            Game->Print();                                                                                         //Print the grid out
            cout << "What direction would you like to move in? \n(Move using the arrow keys or type q to quit.) "; //Instructions to the user
                                                                                                                   //UserMove = getche(); //Get one character from the user (some compilers have "getche()")
            system("/bin/stty raw");
            UserMove = getchar(); //Get one character from the user (Visual Studio 2010 "_getche()" is the new version of "getche()")
            system("/bin/stty cooked");
            Game->BoundedMove(UserMove);            //Process the users input
      } while (UserMove != 'Q' && UserMove != 'q'); //Keep running the program until the user types in a Q or q

      // system("clear"); //Clear the screen
      cout << endl;
      Game->Print(); //Print the final grid out to the user
      cout << endl;


      return 0;
}