Commit 978225ea authored by Jakub Čirip's avatar Jakub Čirip
Browse files

inicializacia projektu

parents
#include <ctype.h>
#include "ui.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "k.h"
void add_random_tile(struct game *game){
int row, col;
// find random, but empty tile
do{
row = rand() % 4;
col = rand() % 4;
}while(game->board[row][col] != ' ');
// place to the random position 'A' or 'B' tile
int tile = 'A' + (rand() % 2);
game->board[row][col] = tile;
}
bool is_game_won(const struct game game){
{
char win;
for(int i=0; i<4; i++){
for(j=0; j<4; j++){
if(game.board[i][j]==k)
wim=k;
}
}
if(win == k)
return 1;
else
return 0;
}
}
bool update(struct game *game, int dy, int dx){
char word[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'};
int num[] = {2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048};
int chang=0, a=0,
if(dy==1 && dx==0)
{
for(int i=0; i<4; i++)
{
for(int j=3; j>0;j--)
{
if((game->board[j][i]==game->board[j-+1][i]) &&(game->board[j][i]!=' '))
{
while(word[a]!=game->board[j][i]){j++;}
a++;
game->board[j][i]=word[a];
game->score+=num[a];
game->board[j-1][i]=' ';
chang++;
}
else if ((game->board[j][i]==game->board[j][i])&&(j==3)&& (game->board[j][i]!=' ')&& (game->board[j-2][i])&& (game->board[j-1][i]==' '))
{
a=0;
while(word[a]!=game->board[j][i])
{
a++;
}
a++;
game->board[j][i]=word[a];
Please register or sign in to reply
game->score+=num[a];
game->board[j-3][i]=' ';
chang++;
}
else if((game->board[j][i]==game->board[j-2][i])&& (j>1)&& (game->board[j][i]!=' ')&& (game->board[j-1][i]==' ')){
a=0;
while(word[y]!=game->board[j][i])
{
a++;
}
a++;
game->board[j][i]=word[a];
game->score+=num[a];
game->board[j-2][i]=' ';
chang++;
}
}
for(int z=0; 4>z; z++)
{
for(int v=3; 0<v; v--)
{
if(game->board[v][i]==' '&& game->board[v-1][i]!=' ')
{
game->board[v][i]=game->board[v-1][i];
game->board[v-1][i]=' ';
change++;
}
}
}
}
}else if(dy==0 && dx==1)
{
//V PRAVO
chang=0;
for(int i=0; i<4; i++){
for(int j=3; 0<j; j--)
{
if((game->board[i][j]==game->board[i][j-1])&& (game->board[i][j]!=' '))
{
a=0;
while(word[a]!=game->board[i][j])
{
a++;
}
a++;
game->board[i][j]=word[a];
game->score=game->score+num[a];
game->board[i][j-1]=' ';
chang++;
}else if((game->board[i][j]==game->board[i][j-3])&&(game->board[i][j-1]==' ')&&(game->board[i][j]!=' ')&&(j==3)&&(game->board[i][j-2]==' '))
{
a=0;
while(znaky[y]!=game->board[indx][r])
{
a++;
}
a++;
game->board[i][j]=word[a];
game->score+=num[a];
game->board[i][j-3]=' ';
chang++;
}
else if((game->board[i][j]==game->board[i][j-2])&&(1<j)&&(game->board[i][j]!=' ')&&(game->board[i][j-1]==' '))
{
a=0;
while(v[y]!=game->board[i][j])
{
a++;
}
a++;
game->board[i][j]=word[a];
game->score+=num[a];
game->board[i][j-2]=' ';
chang++;
}
else if((game->board[i][j-2]==' ')&&(game->board[i][j]==game->board[i][j-3])&&(j==3)&&(game->board[i][j-1]==' ')&&(game->board[i][j]!=' '))
{
a=0;
while(word[a]!=game->board[i][j])
{
a++;
}
a++;
game->board[i][j]=word[a];
game->score+=num[a];
game->board[i][j-3]=' ';
chang++;
}
}
for(int z=0; 4>z; z++)
{
for(int v=3; 0<v;v--)
{
if(game->board[i][z]==' '&& game->board[i][v-1]!=' ')
{
game->board[i][v]=game->board[i][v-1];
game->board[i][v-1]=' ';
chang++;
}
}
}
}
}
else if(dy==0 && dx==-1)
{
//V LAVO
chang=0;
for(int i=0;4>i;i++)
{
for(int j=0;3>j;j++)
{
if((game->board[i][j]==game->board[i][j+1])&&(game->board[i][j]!=' '))
{
a=0;
while(word[a]!=game->board[i][j])
{
a++;
}
a++;
game->board[i][j]=word[a];
game->score+=num[a];
game->board[i][j+1]=' ';
chang++;
}
else if((j==0)&&(game->board[i][j]==game->board[i][j+3])&&(game->board[i][j]!=' ')&&(game->board[i][j+2]==' ')&&(game->board[i][j+1]==' '))
{
a=0;
while(word[a]!=game->board[i][j])
{
a++;
}
a++;
game->board[i][j]=word[a];
game->score+=num[a];
game->board[i][j+3]=' ';
chang++;
}
else if((j<2)&&(game->board[i][j]!=' ')&& (game->board[i][j+1]==' ')&&(game->board[i][j]==game->board[i][j+2]))
{
a=0;
while(word[a]!=game->board[i][j])
{
a++;
}
a++;
game->board[i][j]=word[a];
game->score=game->score+num[a];
game->board[i][j+2]=' ';
chang++;
}
}
for(int z=0; 4>z; z++)
{
for(int v=0; 3>v;v++)
{
if(game->board[i][v]==' '&&game->board[i][v+1]!=' ')
{
game->board[i][v]=game->board[i][v+1];
game->board[i][v+1]=' ';
chang++;
}
}
}
}
}
else if(dy==-1&& dx==0)
{
chang=0;
for(int i=0;4>i;i++)
{
for(int j=0; 3>j; j++)
{
if((game->board[j][i]==game->board[j+2][i])&&(2>j)&&(game->board[j][i]!=' ')&&(game->board[j+1][i]==' '))
{
a=0;
while(word[a]!= game->board[j][i])
{
a++;
}
a++;
game->board[j][i]=word[a];
game->score= game->score+num[a];
game->board[j+2][i]=' ';
chang++;
}
else if((game->board[j][i]!=' ')&& (game->board[j][i]==game->board[j+1][i]))
{
a=0;
while(word[a]!=game->board[j][i])
{
a++;
}
a++;
game->board[j][i]=word[a];
game->board[j+1][i]=' ';
game->score= game->score+num[a];
chang++;
}
else if((j==0)&&(game->board[j+3][i]==game->board[j][i])&&(game->board[j+2][i]==' ')&& (game->board[j][i]!=' ')&&(game->board[j+1][i]==' '))
{
a=0;
while(word[a]!=game->board[j][i])
{
a++;
}
a++;
game->board[j][i]=word[a];
game->board[j+3][i]=' ';
game->score= game->score+num[a];
chang++;
}
}
for(int z=0; 4>z; z++)
{
for(int v=0; 3>v; v++)
{
if(game->board[v+1][i]!=' '&&game->board[v][i]==' ')
{
game->board[v][i]=game->board[v+1][i];
game->board[v+1][i]=' ';
chang++;
}
}
}
}
}
else{
return 0;
}
if(chang==0){
return 0;
}
else{
return 1;
}
}
bool is_move_possible(const struct game game){
char word[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'};
int num[] = {2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048};
int b=0;
for(int t=0;4>t;t++){
if(game.board[0][t]==game.board[1][t] || game.board[1][t]==game.board[2][t] || game.board[2][t]==game.board[3][t]){
return 1;
}
}
for(int u=0;4>u;u++){
if(game.board[u][0]==game.board[u][1] || game.board[u][1]==game.board[u][2] || game.board[u][2]==game.board[u][3]){
return 1;
}
else if(!isalpha(game.board[b][u]))
{
return 1;
}
b++;
}
return 0;
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include "bmp.h"
#include "playfair.h"
char* reverse(const char* text)
{
int ls = 0;
int ps = strlen(text) - 1;
if(text!=NULL)
{
while (ls < ps)
{
char a = text[ls];
text[ls] = text[ps];
text[ps] = a;
ls++;
ps--;
}
// printf("%s", text);
return text;
}
else
return NULL;
}
char* vigenere_encrypt(const char* key, const char* text)
{
char encrypt[100];
int number[26]={ 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25};
for(int i=0; i<=strlen(text); i++)
{
int result=0, resultt=0;
int pocet=0, pocett=0;
while(text[i]!=ALPHA[pocet]){
pocet++;
}
while(key[i]!=ALPHA[pocett]){
pocett++;
}
result = number[pocet]+number[pocett];
if(result>26){
resultt= result-26;
}
else{
resultt = result;
}
ALPHA[resultt] = encrypt[i];
}
return encrypt;
}
char* vigenere_decrypt(const char* key, const char* encrypt)
{
char dencrypt[100];
int number[26]={ 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25};
for(int i=0; i<=strlen(encrypt); i++)
{
int result=0, resultt=0;
int pocet=0, pocett=0;
while(encrypt[i]!=ALPHA[pocet]){
pocet++;
}
while(key[i]!=ALPHA[pocett]){
pocett++;
}
result = number[pocet]-number[pocett];
if(result<0){
resultt= result+26;
}
else{
resultt = result;
}
ALPHA[resultt] = dencrypt[i];
}
return dencrypt;
}
unsigned char* bit_encrypt(const char* text)
{
}
char* bit_decrypt(const unsigned char* text)
{
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment