Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Platform Game in pure C++
#1
What I mean by pure is no graphics such as shapes and images and stuff. Its not much of a game. You could just jump in it and hit the wall and find exploits.

Here's my code:
Code:
#include<iostream>
   #include<windows.h>
   #include <conio.h>
   using namespace std;
   HANDLE hconsole = GetStdHandle(STD_OUTPUT_HANDLE);
   char map[11][11]={{'Û','Û','Û','Û','Û','Û','Û','Û','Û'},
      {'Û',' ',' ',' ',' ',' ',' ',' ','Û'},
      {'Û',' ',' ',' ',' ',' ',' ',' ','Û'},
      {'Û',' ',' ',' ',' ',' ',' ',' ','Û'},
      {'Û',' ',' ',' ',' ',' ',' ',' ','Û'},
      {'Û',' ',' ',' ',' ',' ',' ',' ','Û'},
      {'Û',' ',' ',' ',' ',' ',' ',' ','Û'},
      {'Û',' ',' ',' ',' ',' ',' ',' ','Û'},
      {'Û','Û','Û','Û','Û','Û','Û','Û','Û'}};
   int main() {
      COORD pos;
      pos.X = 3;
      pos.Y = 7;
      char kbinput;
      while (true) {
         system("cls");
         int x;
         int y;
         for(x = 0; x <= 11; x++) {
            for (y = 0; y <= 11; y++)
            cout << map[x][y];
            cout << endl;
         }
         SetConsoleCursorPosition(hconsole, pos);
         cout << "@";
         kbinput = _getch();
         switch(kbinput) {
         case 'd':
            if(map[pos.X+1][pos.Y]==' ') {
               pos.X += 1;
               break;
            }
         case 'a':
            if(map[pos.X-1][pos.Y]==' ') {
               pos.X -= 1;
               break;
            }
         case 'w':
            system("cls");
            SetConsoleCursorPosition(hconsole, pos);
            cout << "@";
            while(pos.Y > 3) {
               if(map[pos.X][pos.Y-1]==' ') {
                  system("cls");
                  
                  for(x = 0; x <= 11; x++) {
                     for (y = 0; y <= 11; y++)
                     cout << map[x][y];
                     cout << endl;
                  }
                  pos.Y--;
                  SetConsoleCursorPosition(hconsole, pos);
                  cout << "@";
               }
            }
            pos.X += 1;
            while(pos.Y <= 6) {
                    if(pos.X >= 7)break;
               if(map[pos.X][pos.Y+1]==' ') {
                  system("cls");
                  for(x = 0; x <= 11; x++) {
                     for (y = 0; y <= 11; y++)
                     cout << map[x][y];
                     cout << endl;
                  }
                  pos.Y++;
                  SetConsoleCursorPosition(hconsole, pos);
                  cout << "@";
               }
            }
            
            break;
         case 's':
            system("cls");
            SetConsoleCursorPosition(hconsole, pos);
            cout << "@";
            while(pos.Y > 3) {
               if(map[pos.X][pos.Y-1]==' ') {
                  system("cls");
                  for(x = 0; x <= 11; x++) {
                     for (y = 0; y <= 11; y++)
                     cout << map[x][y];
                     cout << endl;
                  }
                  pos.Y--;
                  SetConsoleCursorPosition(hconsole, pos);
                  cout << "@";
               }
            }
            pos.X -= 1;
            while(pos.Y <= 6) {
                    if(pos.X <= 3) break;
               if(map[pos.X][pos.Y+1]==' ') {
                  system("cls");
                  for(x = 0; x <= 11; x++) {
                     for (y = 0; y <= 11; y++)
                     cout << map[x][y];
                     cout << endl;
                  }
                  pos.Y++;
                  SetConsoleCursorPosition(hconsole, pos);
                  cout << "@";
               }
            }
            
            break;
         }
      }
   }
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)