i made this last summer in windows visual studio express... can you alter the code so that it works in xcode?
here is the code:
here is the code:
Code:
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <ctime>
#include <conio.h>
#include <string>
/*
skeleton for ascii games: displays an array of ascii art, refreshing every N milliseconds(n=300 in the example);
also checks for keypresses every refresh.
*/
using namespace std;
//display array:
const int x=40, y=40;
char display[x][y];
int personx=20;
int persony=20;
string blocks[y]={
" V V V ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "
};
int score=0;
void redraw();//redraw screen
int main()
{
system("color 06");
srand((unsigned int)time(0));// random number seed
while (true)
{
int timestep=30;//timestep in miliseconds
//initialize screen:
for(int i=0; i<x; i++)
for(int j=0; j<y; j++)
display[i][j]=' ';
for(int i=0; i<x; i++)
for(int j=0; j<y; j++)
blocks[j][i]=' ';
//console size setup:
COORD bufferSize = {110+1, x+1};
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), bufferSize);
SMALL_RECT WinRect = {0, 0, 100, x};
SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), true, &WinRect);
bool displayText = true;
while(!_kbhit()){
clock_t waketime=clock()+300;
while(clock()<waketime);//wait until taking the next step
system("cls");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " ::: ::::::::::: ::::::::: :::::::: ::::::::::: ::::::::: ::::::::::: ::: ::: :::::::::: " << endl;
cout << " :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: " << endl;
cout << " +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ " << endl;
cout << "+#++:++#++: +#+ +#++:++#: +#++:++#++ +#+ +#++:++#: +#+ +#++:++ +#++:++# " << endl;
cout << "+#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ " << endl;
cout << "#+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# #+# " << endl;
cout << "### ### ########### ### ### ######## ### ### ### ########### ### ### ########## " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " 1st player 2nd player " << endl;
cout << " A --> left J --> left don't get hit by the missiles --> V " << endl;
cout << " D --> right L --> left made by Sean Panayi " << endl;
if (displayText==true)
{
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " Press 1 For Single Player or 2 for Multiplayer " << endl;
}
displayText = !displayText;
}
bool twoplayer=true;
if(_getch()=='1')
{
twoplayer = false;
}
else
{
twoplayer = true;
}
system ("cls");
cout << " " << endl;
cout << " " << endl;
cout << " __ __ _ _ " << endl;
cout << " / |_ _ _ _ _ \\_/_ _ | \\.(_(_. _ ||_ " << endl;
cout << " \\__| )(_)(_)_)(- |(_)|_|| |__/|| | |(_|_|||_\\/ " << endl;
cout << " / " << endl;
cout << " " << endl;
cout << " beginner --> 1 intermediate --> 2 advanced --> 3 " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
while(!kbhit){};
char level = _getch();
if (level=='1') timestep=100;
if (level=='2') timestep=35;
if (level=='3') timestep=10;
//some code that lets the user pick one or two player goes here.
if(twoplayer)
{
personx=1;
persony=39;
}
else
{
personx=20;
}
//console size setup:
COORD bufferSize2 = {x+1, y+1};
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), bufferSize2);
SMALL_RECT WinRect2 = {0, 0, x, y};
SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), true, &WinRect2);
//main loop:
while(true)
{
score=score+1;
if (level=='1') score=score+1;
if (level=='2') score=score+2;
if (level=='3') score=score+3;
clock_t waketime=clock()+timestep;
while(clock()<waketime);//wait until taking the next step
//process keypress, if any:
if(_kbhit())//if there was a key press
{
char key=(char)_getch();//get which key it was
switch(key)
{
case 'a':
personx=personx-1;
break;
case 'd':
personx=personx+1;
break;
case 'j':
persony=persony-1;
break;
case 'l':
persony=persony+1;
}
}
//process game logic here
int g=rand() % x;
blocks[0][g]='V';
for(int i=0; i<x; i++)
for(int j=0; j<y; j++)
display[i][j]=blocks[j][i];
if(display [personx][39]==' ' || display [personx][39]=='Y' )
{
display [personx][39]='T';
}
else
{
break;
}
if(twoplayer)
{
if(display [persony][39]==' ' || display [persony][39]=='T' )
{
display [persony][39]='Y';
}
else
{
break;
}
}
redraw();
for (int i=y-1; i>0; i--)
{
blocks [i]=blocks [i-1];
}
blocks [0]=" ";
}
system("cls");
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " _______ ___ .___ ___. _______ " << endl;
cout << " / _____| / \\ | \\/ | | ____| " << endl;
cout << "| | __ / ^ \\ | \\ / | | |__ " << endl;
cout << "| | |_ | / /_\\ \\ | |\\/| | | __| " << endl;
cout << "| |__| | / _____ \\ | | | | | |____ " << endl;
cout << " \\______| /__/ \\__\\ |__| |__| |_______| " << endl;
cout << " " << endl;
cout << " ______ ____ ____ _______ .______ " << endl;
cout << " / __ \\ \\ \\ / / | ____|| _ \\ " << endl;
cout << "| | | | \\ \\/ / | |__ | |_) | " << endl;
cout << "| | | | \\ / | __| | / " << endl;
cout << "| `--' | \\ / | |____ | |\\ \\----. " << endl;
cout << " \\______/ \\__/ |_______|| _| `._____| " << endl;
cout << " " << endl;
cout << " " << endl;
cout << " your score is "<< score << endl;
cout << " " << endl;
cout << " " << endl;
cout << " press spacebar to continue " << endl;
cout << " " << endl;
score=0;
while(!_kbhit() || _getch()!=' ' ){
}
}
}
void redraw()
{
system("cls");
for(int i=0; i<y; i++)
{
for(int j=0; j<x; j++)
{
cout << display[j][i];
}
cout << endl;
}
cout << score;
Last edited by a moderator: