Kaktusen

Get_the_point

May 13th, 2011
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.16 KB | None | 0 0
  1. #import <iostream>
  2. #import <conio.h>
  3. #include <stdlib.h>
  4. #include <ctime>
  5.  
  6. using namespace std;
  7.  
  8. //funktioner
  9. int move();
  10. int menu();
  11. int option();
  12.  
  13. //---globala variabler---
  14. char key;
  15.  
  16. //kordinater
  17. int y = 2;
  18. int x = 1;
  19. int coinX = 3;
  20. int coinY = 3;
  21.  
  22. //random (score, steps osv)
  23. int score = 0;
  24. int steps = 100;
  25. char player = 'X';
  26. char scoreicon = 'O';
  27.  
  28.  
  29. int main() {
  30.     srand(time(NULL));
  31.  
  32.     menu();
  33.  
  34.     int map[10][10] = {
  35.         {1,1,1,1,1,1,1,1,1,1},
  36.         {1,0,0,0,0,0,0,0,0,1},
  37.         {1,0,0,0,0,0,0,0,0,1},
  38.         {1,0,0,0,0,0,0,0,0,1},
  39.         {1,0,0,0,0,0,0,0,0,1},
  40.         {1,0,0,0,0,0,0,0,0,1},
  41.         {1,0,0,0,0,0,0,0,0,1},
  42.         {1,0,0,0,0,0,0,0,0,1},
  43.         {1,0,0,0,0,0,0,0,0,1},
  44.         {1,1,1,1,1,1,1,1,1,1},
  45.     };
  46.  
  47.     while(true) {
  48.  
  49.  
  50.                 move();
  51.  
  52.                 cout << "Score: " << score << endl;
  53.                 cout << "Steps: " << steps << endl;
  54.  
  55.                 for(int i=0; i<10; i++) {
  56.                         for(int i2=0; i2<10; i2++) {
  57.  
  58.                                 switch (map [i][i2]) {
  59.  
  60.                                        case 0:
  61.                                             if(i==y && i2==x) {
  62.                                                 cout << player;
  63.                                             } else if (i==coinY && i2==coinX) {
  64.                                                 cout << scoreicon;
  65.                                             } else {
  66.                                                 cout << " ";
  67.                                             }
  68.  
  69.                                             if(x == coinX && y == coinY) {
  70.                                                 score++;
  71.                                                 coinX = rand() % 8 + 1;
  72.                                                 coinY = rand() % 8 + 1;
  73.                                             }
  74.  
  75.                                             break;
  76.                                        case 1:
  77.                                             cout << "#";
  78.                                             break;
  79.                                 }
  80.  
  81.                         }
  82.  
  83.                         cout << endl;
  84.                 }
  85.  
  86.                 key = getch();
  87.  
  88.             if(steps <= 0) {
  89.                 system("cls");
  90.                 cout << "You loose!";
  91.                 getch();
  92.                 return 0;
  93.             }
  94.  
  95.     }
  96.  
  97.  
  98.  
  99.  
  100.     return 0;
  101. }
  102.  
  103.  
  104.  
  105. int move() {
  106.  
  107.     if(key == 'w' && y > 1) {
  108.         steps--;
  109.         y--;
  110.     }
  111.  
  112.     if(key == 's' && y < 8) {
  113.         steps--;
  114.         y++;
  115.     }
  116.  
  117.     if(key == 'a' && x > 1) {
  118.         steps--;
  119.         x--;
  120.     }
  121.  
  122.     if(key == 'd' && x < 8) {
  123.         steps--;
  124.         x++;
  125.     }
  126.  
  127.     system("cls");
  128. }
  129.  
  130. int menu() {
  131.  
  132.     while(true) {
  133.         cout
  134.         << "#######################################" << endl
  135.         << "#-------------------------------------#" << endl
  136.         << "#|Welcome to 'Get the point'! V 1.0.0|#" << endl
  137.         << "#-------------------------------------#" << endl
  138.         << "#######################################" << endl;
  139.  
  140.         cout << "1: Start" << endl
  141.         << "2: Option" << endl;
  142.         cout << "9: Exit";
  143.  
  144.         key = getch();
  145.         system("cls");
  146.  
  147.         if(key == '1') {
  148.             return 1;
  149.         }
  150.  
  151.         else if(key == '2') {
  152.             option();
  153.         }
  154.  
  155.         else if(key == '9') {
  156.             exit(1);
  157.         }
  158.  
  159.         system("cls");
  160.     }
  161. }
  162.  
  163.  
  164. int option() {
  165.     while(true){
  166.         system("cls");
  167.         cout << "1: Choose steps" << endl
  168.         << "2: Choose Player icon" << endl
  169.         << "3: Choose Score icon" << endl
  170.         << "9: exit option";
  171.  
  172.         key = getch();
  173.         system("cls");
  174.  
  175.         if(key == '1') {
  176.             cout << "How many steps?: ";
  177.             cin >> steps;
  178.         }
  179.  
  180.         else if(key == '2') {
  181.             cout << "Which icon?: ";
  182.             cin >> player;
  183.         }
  184.  
  185.         else if(key == '3') {
  186.             cout << "Wich icon?: ";
  187.             cin >> scoreicon;
  188.         }
  189.  
  190.         else if(key == '9') {
  191.             return 0;
  192.         }
  193.     }
  194. }
Advertisement
Add Comment
Please, Sign In to add comment