Skip to content

Instantly share code, notes, and snippets.

@Y0lan
Created March 22, 2018 17:18
Show Gist options
  • Save Y0lan/70e9583916fc014f317cded64863d566 to your computer and use it in GitHub Desktop.
Save Y0lan/70e9583916fc014f317cded64863d566 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
void CreatePlayground(int sizeWithBorder, char (*PlayingTab)[sizeWithBorder])
{
for (int i=0;i<sizeWithBorder;i++){
for(int j=0;j<sizeWithBorder;j++){
if(i == 0 || i == sizeWithBorder - 1){
PlayingTab[i][j]='-';
}
else if (j==0 || j==sizeWithBorder - 1) {
PlayingTab[i][j]='|';
}
else {
PlayingTab[i][j]=' ';
}
}
}
}
void DisplayPlayground(int sizeWithBorder, char (*PlayingTab)[sizeWithBorder])
{
for(int i = 0; i < sizeWithBorder; i++) {
for(int j = 0; j < sizeWithBorder; j++) {
printf("%c",PlayingTab[i][j]);
}
printf("\n");
}
}
void CreateFruit(int sizeWithoutBorder, int sizeWithBorder, char (*PlayingTab)[sizeWithBorder])
{
time_t t;
srand((unsigned) time(&t));
int fruitX = rand()%sizeWithoutBorder + 1;
int fruitY = rand()%sizeWithoutBorder + 1;
char fruitSymbole = '*';
PlayingTab[fruitX][fruitY] = fruitSymbole;
}
int main(int argc, char const *argv[])
{
int PlayerTurn=0;
int sizeWithoutBorder=0;
printf("Veuillez choisir la taille de la carte dans laquelle vous allez jouer \n");
scanf("%d",&sizeWithoutBorder);
while(sizeWithoutBorder<5||sizeWithoutBorder>26){
printf("Veuillez choisir une taille comprise entre 5x5 et 26x26 \n");
scanf("%d",&sizeWithoutBorder);
}
int sizeWithBorder = sizeWithoutBorder + 2;
char PlayingTab[sizeWithBorder][sizeWithBorder];
CreatePlayground(sizeWithBorder, PlayingTab);
CreateFruit(sizeWithoutBorder,sizeWithBorder,PlayingTab);
DisplayPlayground(sizeWithBorder, PlayingTab);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment