Skip to content

Instantly share code, notes, and snippets.

@erayarslan
Created July 17, 2014 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erayarslan/64e61b3fa4606063dee5 to your computer and use it in GitHub Desktop.
Save erayarslan/64e61b3fa4606063dee5 to your computer and use it in GitHub Desktop.
Console Palette
#include <iostream>
#include <conio.h>
#include <time.h>
#include <windows.h>
//buyukluk
#define bx 10
#define by 50
char bos=' ';
char dolu='O';
using namespace std;
char palet[bx][by];
int kx,ky;
void sifirla();
int onaylandi(int,int);
void goruntule();
void koordinatogren();
// tuslar
char ileri='W';
char geri='S';
char sol='A';
char sag='D';
char baski='X';
int main()
{
int hamle=0;
char c;
sifirla();
palet[bx/2][by/2]=dolu;
while(1)
{
goruntule();
koordinatogren();
c=getch();
if(c==ileri+32|| c==ileri)
{
if(onaylandi(kx-1,ky)==1)
{
palet[kx][ky]=bos;
palet[kx-1][ky]=dolu;
hamle++;
}
}
else if(c==sol+32|| c==sol)
{
if(onaylandi(kx,ky-1)==1)
{
palet[kx][ky]=bos;
palet[kx][ky-1]=dolu;
hamle++;
}
}
else if(c==geri+32 || c==geri)
{
if(onaylandi(kx+1,ky)==1)
{
palet[kx][ky]=bos;
palet[kx+1][ky]=dolu;
hamle++;
}
}
else if(c==sag+32 || c==sag)
{
if(onaylandi(kx,ky+1)==1)
{
palet[kx][ky]=bos;
palet[kx][ky+1]=dolu;
hamle++;
}
}
else if(c==baski+32 || c==baski)
{
if(onaylandi(kx,ky+1)==1)
{
palet[kx][ky]='x';
palet[kx][ky+1]=dolu;
hamle++;
}
}
}
}
void sifirla()
{
for(int i=0;i<=bx-1;i++)
{
for(int j=0;j<=by-1;j++)
{
palet[i][j]=bos;
}
}
}
void goruntule()
{
system("cls");
for(int i=0;i<=bx-1;i++)
{
for(int j=0;j<=by-1;j++)
{
cout<<palet[i][j];
}
cout<<endl;
}
}
void koordinatogren()
{
for(int i=0;i<=bx-1;i++)
{
for(int j=0;j<=by-1;j++)
{
if(palet[i][j]==dolu)
{
kx=i;
ky=j;
}
}
}
}
int onaylandi(int x,int y)
{
// ust basla
for(int i=0;i<=by-1;i++)
{
if(x==-1 && i==y)
{
return 0;
}
}
// ust bit
//
// alt basla
for(int i=0;i<=by-1;i++)
{
if(x==bx && i==y)
{
return 0;
}
}
// alt bit
//
// sol basla
for(int i=0;i<=bx-1;i++)
{
if(y==by && i==x)
{
return 0;
}
}
// sol bit
//
// sag basla
for(int i=0;i<=bx-1;i++)
{
if(y==-1 && i==x)
{
return 0;
}
}
//sag bit
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment