Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <iostream>
- #import <conio.h>
- #include <stdlib.h>
- #include <ctime>
- using namespace std;
- //funktioner
- int move();
- int menu();
- int option();
- //---globala variabler---
- char key;
- //kordinater
- int y = 2;
- int x = 1;
- int coinX = 3;
- int coinY = 3;
- //random (score, steps osv)
- int score = 0;
- int steps = 100;
- char player = 'X';
- char scoreicon = 'O';
- int main() {
- srand(time(NULL));
- menu();
- int map[10][10] = {
- {1,1,1,1,1,1,1,1,1,1},
- {1,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,1},
- {1,1,1,1,1,1,1,1,1,1},
- };
- while(true) {
- move();
- cout << "Score: " << score << endl;
- cout << "Steps: " << steps << endl;
- for(int i=0; i<10; i++) {
- for(int i2=0; i2<10; i2++) {
- switch (map [i][i2]) {
- case 0:
- if(i==y && i2==x) {
- cout << player;
- } else if (i==coinY && i2==coinX) {
- cout << scoreicon;
- } else {
- cout << " ";
- }
- if(x == coinX && y == coinY) {
- score++;
- coinX = rand() % 8 + 1;
- coinY = rand() % 8 + 1;
- }
- break;
- case 1:
- cout << "#";
- break;
- }
- }
- cout << endl;
- }
- key = getch();
- if(steps <= 0) {
- system("cls");
- cout << "You loose!";
- getch();
- return 0;
- }
- }
- return 0;
- }
- int move() {
- if(key == 'w' && y > 1) {
- steps--;
- y--;
- }
- if(key == 's' && y < 8) {
- steps--;
- y++;
- }
- if(key == 'a' && x > 1) {
- steps--;
- x--;
- }
- if(key == 'd' && x < 8) {
- steps--;
- x++;
- }
- system("cls");
- }
- int menu() {
- while(true) {
- cout
- << "#######################################" << endl
- << "#-------------------------------------#" << endl
- << "#|Welcome to 'Get the point'! V 1.0.0|#" << endl
- << "#-------------------------------------#" << endl
- << "#######################################" << endl;
- cout << "1: Start" << endl
- << "2: Option" << endl;
- cout << "9: Exit";
- key = getch();
- system("cls");
- if(key == '1') {
- return 1;
- }
- else if(key == '2') {
- option();
- }
- else if(key == '9') {
- exit(1);
- }
- system("cls");
- }
- }
- int option() {
- while(true){
- system("cls");
- cout << "1: Choose steps" << endl
- << "2: Choose Player icon" << endl
- << "3: Choose Score icon" << endl
- << "9: exit option";
- key = getch();
- system("cls");
- if(key == '1') {
- cout << "How many steps?: ";
- cin >> steps;
- }
- else if(key == '2') {
- cout << "Which icon?: ";
- cin >> player;
- }
- else if(key == '3') {
- cout << "Wich icon?: ";
- cin >> scoreicon;
- }
- else if(key == '9') {
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment