Notes
![]() ![]() Notes - notes.io |
#include <time.h>
#include <stdlib.h>
#include <conio.h>
#include<time.h>
#include <ctype.h>
#include <time.h>
#include <windows.h>
#include <process.h>
#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77
#define SIZE 4
#define BORDER 218
#define ESC 57
#define PR 2
int Matrix[5][5]={0};
int score=0;
int last=0;
void Display();
void print_ever();
void Action(int);
void Random_creator();
void Starting_Random();
int Temp_counter();
void ending();
void record();
void Down();
void Up();
void Left();
void Right();
void Starting_Random(){
Matrix[0][0]=2;
Display();
}
void Action(int Arrow)
{
switch(Arrow){
case UP:{
Up();
break;
}
case DOWN:{
Down();
break;
}
case LEFT:{
Left();
break;
}
case RIGHT:{
Right();
break;
}
default:{
return;
}
}
score++;
Random_creater();
Display();
}
void Random_creater()
{
int temp1,temp2,add,y,x;
srand(time(NULL));
temp1=rand()%SIZE; // y2
srand(time(NULL));
temp2=rand()%SIZE; // x3
if((temp1+temp2)%2==0)
add=2;
else
add=4;
for(y=0;y<temp1;y++)
{
for(x=temp2;x<SIZE;x++)
{
if(Matrix[y][x]==0)
{
Matrix[y][x]=add;
return;
}
}
}
}
void Display(){
int y,x;
system("cls");
printf("SCORE : %dnnnn",score);
printf(" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%cn",BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER);
for(y=0;y<SIZE;y++)
{
printf(" %c",BORDER);
for(x=0;x<SIZE;x++)
{
if(Matrix[y][x]==0)
{
printf(" ");
}
else
printf(" %4d ",Matrix[y][x]);
}
printf("%cn %c %cn",BORDER,BORDER,BORDER);
}
printf(" %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%cnn",BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER,BORDER);
}
void record(){
char plname[20],nplname[20],cha,c;
int y,x;
FILE *info;
info=fopen("record.txt","a+");
getch();
system("cls");
printf("Enter your namen");
scanf("%[^n]",plname);
//************************
for(x=0;plname[x]!=' ';x++){ //to convert the first letter after space to capital
nplname[0]=toupper(plname[0]);
if(plname[x-1]==' '){
nplname[x]=toupper(plname[x]);
nplname[x-1]=plname[x-1];}
else nplname[x]=plname[x];
}
nplname[x]=' ';
//*****************************
//sdfprintf(info,"tttPlayers Listn");
fprintf(info,"Player Name :%sn",nplname);
//for date and time
time_t mytime;
mytime = time(NULL);
fprintf(info,"Played Date:%s",ctime(&mytime));
//**************************
fprintf(info,"Score:%dn",score);//call score to display score
//fprintf(info,"nLevel:%dn",10);//call level to display level
for(y=0;y<=50;y++)
fprintf(info,"%c",'_');
fprintf(info,"n");
fclose(info);
printf("wanna see past records press 'y'n");
cha=getch();
system("cls");
if(cha=='y'){
info=fopen("record.txt","r");
do{
putchar(c=getc(info));
}while(c!=EOF);}
fclose(info);
printf("nnnttttPRESS ANY KEY TO EXITn");
while(!kbhit());
system("attrib +h +s record.txt");
}
void Down()
{
int y,x;
for(x=0;x<SIZE;x++){
y=2;
while(1){
while(Matrix[y][x]==0)
{
//sayinin üstünde sayi var mi diye kontrol ediyor
if(y==-1){
break;
}
y--;
}
if(y==-1){
break;
}
while(y<SIZE-1 && (Matrix[y+1][x]==0 || Matrix[y][x]==Matrix[y+1][x])) //alttaki sayı kendine eşitse veya altı boşsa ve y 3 değilse çalışır
{
Matrix[y+1][x]+=Matrix[y][x];
Matrix[y][x]=0;
y++;
}
y--;
}
}
}
void Up()
{
int y,x;
for(x=0;x<SIZE;x++)
{
y=1;
while(1)
{
while(Matrix[y][x]==0)
{
if(y==SIZE){
break;
}
y++;
}
if(y==SIZE){
break;
}
while(y>0 && (Matrix[y-1][x]==0 || Matrix[y][x]==Matrix[y-1][x]))
{
Matrix[y-1][x]+=Matrix[y][x];
Matrix[y][x]=0;
y--;
}
y++;
}
}
}
void Right()
{
int y,x;
for(y=0;y<SIZE;y++)
{
x=2;
while(1)
{
while(Matrix[y][x]==0)
{
if(x==-1)
break;
x--;
}
if(x==-1)
break;
while(x<SIZE-1 && (Matrix[y][x+1]==0 || Matrix[y][x]==Matrix[y][x+1]))
{
Matrix[y][x+1]+=Matrix[y][x];
Matrix[y][x]=0;
x++;
}
x--;
}
}
}
void Left()
{
int y,x;
for(y=0;y<SIZE;y++)
{
x=1;
while(1)
{
while(Matrix[y][x]==0)
{
if(x==SIZE)
break;
x++;
}
if(x==SIZE)
break;
while(x>0 && (Matrix[y][x-1]==0 || Matrix[y][x]==Matrix[y][x-1]))
{
Matrix[y][x-1]+=Matrix[y][x];
Matrix[y][x]=0;
x--;
}
x++;
}
}
}
int resultFinder(){
/* IT SHOULD FIND MAX VALUE FROM WHOLE MATRIX */
int temp=0,y,x;
for(y=0;y<SIZE;y++)
{
for(x=0;x<SIZE;x++)
{
if(Matrix[y][x]==2048)
return(1);
if(Matrix[y][x]==0)
temp=1;
}
}
if(temp==1)
{
last=0;
return(-99);
}
else
{
if(last==1){
return(0);
}
last=1;
return(-99);
}
}
int main(){
int aro;
char Arrow;
int result;
Starting_Random();
//Arrow=DOWN;
while(Arrow!=ESC) {
Arrow=getch();
aro=Arrow;
Action(Arrow);
result=resultFinder();
if(result==1){
printf("ntttYOU WON");
printf("nnttttYOUR SCORE is : %d",score);
record();
break;
}
if(result==0){
printf("ntttSORRY ! GAME OVERn");
break;
}
}
return 0;
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team