Advertisement
Gabriel_Rofl

got.c

Nov 22nd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.63 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include "got.h"
  6. #include <string.h>
  7.  
  8. int contador_no = 0;
  9.  
  10. t_node* node_create(){
  11.  
  12.     t_node* ptr = malloc(sizeof(t_node));/*aloca dinamicamente um no depois coloca NULL nos ponteiros de Character right e left */
  13.  
  14.     ptr->character = NULL;
  15.  
  16.     ptr->right = NULL;
  17.  
  18.     ptr->left = NULL;
  19.  
  20.     return(ptr);
  21. }
  22.  
  23. t_node* tree_create(){
  24.     t_node* raiz = malloc(sizeof(t_node));/*aloca memoria para o no raiz*/
  25.     raiz = node_create();
  26.     return raiz;
  27. }
  28.  
  29. t_node* tree_node(t_node* raiz){
  30.     if(raiz == NULL){
  31.         return node_create();
  32.     }
  33.     else{
  34.         raiz->left = tree_node(raiz->left);
  35.         raiz->right = tree_node(raiz->right);
  36.     }
  37.     return raiz;
  38. }
  39.  
  40. int height(t_node* h){/*Checa a altura da arvore*/
  41.     int hl, hr;
  42.  
  43.     if(h == NULL){
  44.         return 0;
  45.     }
  46.     hl = height(h->left)+1;
  47.     hr = height(h->right)+1;
  48.  
  49.     if(hr >= hl){
  50.         return hr;
  51.     }
  52.     else{
  53.         return hl;
  54.     }
  55. }
  56.  
  57. Character* character_create(char* _name, char* _house, int _agility, int _strength, int _intelligence, int _health){
  58.  
  59.     Character* character = (Character *) malloc(sizeof(Character));
  60.      
  61.     character->name = _name;
  62.     character->house = _house;
  63.     character->agility = _agility;
  64.     character->strength = _strength;
  65.     character->intelligence = _intelligence;
  66.     character->health = _health;
  67.  
  68.     return character;
  69. }
  70.    
  71. void inserir_character(Character* character, lista* l){
  72.     if(l->begin == NULL && l->end == NULL){
  73.         element* personagem = aloca_element(character);
  74.         l->begin = personagem;
  75.         l->end = personagem;
  76.     }
  77.     else{
  78.         element* aux = aloca_element(character);
  79.         l->end->proximo = aux;
  80.         aux->anterior = l->end;
  81.         l->end = aux;
  82.         l->end->proximo = NULL;
  83.  
  84.     }
  85. }
  86.  
  87. lista* aloca_lista(){
  88.     lista* ptr = (lista *) malloc(sizeof(lista));
  89.  
  90.     ptr->begin = NULL;
  91.     ptr->end = NULL;
  92.  
  93.     return ptr;
  94. }
  95.  
  96. element* aloca_element(Character* character){
  97.     element* personagem_fila = (element *) malloc(sizeof(element));
  98.     personagem_fila->character = character;
  99.  
  100.     return personagem_fila;
  101. }
  102.  
  103. int display(){
  104.     char mat[17][45];
  105.     int i, j, gamemode;
  106.     i = j = 0;
  107.     FILE *menu;
  108.     menu = fopen("menu.txt", "r");
  109.     while(!feof(menu)){
  110.         for(i = 0; i < 17; i++){
  111.             for(j = 0; j < 45; j++){
  112.                 fscanf(menu, "%c", &mat[i][j]);
  113.             }
  114.         }
  115.     }
  116.     for(i = 0; i < 17; i++){
  117.         for(j = 0; j < 45; j++){
  118.             printf("%c", mat[i][j]);
  119.         }
  120.     }
  121.         printf("################");
  122.         printf("\n\n");
  123.     fclose(menu);
  124.  
  125.     printf("[1] Start New Game\n[2] Quit Game\n");
  126.     scanf("%d", &gamemode);
  127.     return gamemode;
  128. }
  129.  
  130.  
  131. void print_list(lista* l){
  132.     element* aux = l->begin;
  133.     while(aux != NULL){
  134.         printf("%s -> ", aux->character->name);
  135.         aux = aux->proximo;
  136.     }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement