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

Overview
Comment:End game
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:9cb3cdd267a5d999905f1f88f4434402ac2192cd49565b178c0602b6c6c4d83d
User & Date: sarah 2018-05-18 22:54:27
Context
2018-05-18
23:06
Figuring out eaten cookie issue check-in: ac75da0465 user: sarah tags: trunk
22:54
End game check-in: 9cb3cdd267 user: sarah tags: trunk
22:21
cookie stuff check-in: 2c0c33b7ee user: zie tags: trunk
Changes

Changes to finalproject/finalproject.cpp.

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
...
228
229
230
231
232
233
234
235

236
237
238
239
240
241
242
243
244
                  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 createCookies()
      {
            
            CookieNumber = 1 + rand() % 10;
           
            for (int i=0; i < CookieNumber; i++)

            { int RandomxPos ;
            RandomxPos= rand()%19 ;    
            int RandomyPos;
            RandomyPos= rand()%39;     

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

            }
      }
      // check to see if there is a cookie laying about at the user position.
      // returns bool
      bool checkCookies(int x, int y) {

            char c;
            c = Screen[x][y];
            cout << "checkCookies: " << c << "\n";
            if (c == 'o') {

                  cout << "COOKIE HERE!!" << x << y << "\n";
                   return true;
            }
            return false;
      }
      void endgame()
      {
            cout<< "congrats you picked up "<< CookieNumber<<". Feel free to play again.";
            exit(0);
      }
      void MyMove(char 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
                  if (checkCookies(xPos, yPos)) {
                        cout << "COOKIE MONSTER";


                  }
                  Screen[xPos][yPos] = '^'; //Move the users cursor
                  break;
            case 66: //Down arrow
                  // cout << "Down\n";
                  Screen[xPos][yPos] = ' ';
                  xPos++;
                  if (checkCookies(xPos, yPos)) {
                        cout << "COOKIE MONSTER";


                  }
                  Screen[xPos][yPos] = 'v';
                  break;
            case 68: //Left arrow
                     // cout << "Left\n";
                  Screen[xPos][yPos] = ' ';
                  yPos--;
                  if (checkCookies(xPos, yPos)) {
                        cout << "COOKIE MONSTER";


                  }
                  Screen[xPos][yPos] = '<';
                  break;
            case 67: //Right arrow
                  // cout << "Right\n";
                  Screen[xPos][yPos] = ' ';
                  yPos++;
                  if (checkCookies(xPos, yPos)) {
                        cout << "COOKIE MONSTER";


                  }
                  Screen[xPos][yPos] = '>';
                  break;
            }
      }













      void BoundedMove(char UserMove)
      {
            cout << "\nbefore usernove:"
                 << "xPos=" << xPos << " yPos=" << yPos << "\n";
            MyMove(UserMove);
            cout << "after usernove:"
................................................................................
            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;
}







<


<
<
>




|
<


|

|
<




|
<












|
>


|

|
|
>
|
|
|
|

|
|
|
|
|
|
<




|
>



|
>

|



<
|
<
<
<
|
>
>






|
<
>
>







|
<
>
>







|
<
>
>







|
<
>
>





>
>
>
>
>
>
>
>
>
>
>
>







 







|
>









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
...
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
                  cout << endl; //After each row is printed, print a newline character
            }
      }

      //Take in user input to move around the grid
      void Move(char Direction)
      {

            switch (static_cast<int>(Direction)) //Don't know the ASCII characters for the arrow keys so use the ASCII numbers
            {


            case 72:                        //Up arrow
                  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 80: //Down arrow

                  Screen[xPos][yPos] = ' ';
                  xPos++;
                  Screen[xPos][yPos] = 'V';
                  break;
            case 75: //Left arrow

                  Screen[xPos][yPos] = ' ';
                  yPos--;
                  Screen[xPos][yPos] = '<';
                  break;
            case 77: //Right arrow

                  Screen[xPos][yPos] = ' ';
                  yPos++;
                  Screen[xPos][yPos] = '>';
                  break;
            }
      }
};
// DO NOT ALTER OR DELETE THIS CODE (END)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

class MyPickUpGame : public PickUpGame
{
    public:
      int CookieNumber;
      int EatanCookies;
      void createCookies()
      {

            CookieNumber = 1 + rand() % 10;

            for (int i = 0; i < CookieNumber; i++)
            {
                  int RandomxPos;
                  RandomxPos = rand() % 19;
                  int RandomyPos;
                  RandomyPos = rand() % 39;

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

            }
      }
      // check to see if there is a cookie laying about at the user position.
      // returns bool
      bool checkCookies(int x, int y)
      {
            char c;
            c = Screen[x][y];
            cout << "checkCookies: " << c << "\n";
            if (c == 'o')
            {
                  cout << "COOKIE HERE!!" << x << y << "\n";
                  return true;
            }
            return false;
      }





      void MyMove(char Direction)
      {
            EatanCookies = 0;
            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
                  if (checkCookies(xPos, yPos))

                  {
                        endgame();
                  }
                  Screen[xPos][yPos] = '^'; //Move the users cursor
                  break;
            case 66: //Down arrow
                  // cout << "Down\n";
                  Screen[xPos][yPos] = ' ';
                  xPos++;
                  if (checkCookies(xPos, yPos))

                  {
                        endgame();
                  }
                  Screen[xPos][yPos] = 'v';
                  break;
            case 68: //Left arrow
                     // cout << "Left\n";
                  Screen[xPos][yPos] = ' ';
                  yPos--;
                  if (checkCookies(xPos, yPos))

                  {
                        endgame();
                  }
                  Screen[xPos][yPos] = '<';
                  break;
            case 67: //Right arrow
                  // cout << "Right\n";
                  Screen[xPos][yPos] = ' ';
                  yPos++;
                  if (checkCookies(xPos, yPos))

                  {
                        endgame();
                  }
                  Screen[xPos][yPos] = '>';
                  break;
            }
      }

      void endgame()
      {
            cout << "COOKIE MONSTER";
            EatanCookies = EatanCookies + 1;
            cout << EatanCookies << "\n";
            if (EatanCookies = CookieNumber)
            {
                  cout << "You ate " << CookieNumber << "cookie(s)";
                  exit(0);
            }
      }

      void BoundedMove(char UserMove)
      {
            cout << "\nbefore usernove:"
                 << "xPos=" << xPos << " yPos=" << yPos << "\n";
            MyMove(UserMove);
            cout << "after usernove:"
................................................................................
            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;
}