Título: Programa para bases de datos de objetos
Publicado por: crazykenny en 21 Diciembre 2016, 22:38 pm
Hola; ante todo, no se si el titulo es el mas apropiado para este tema, pero aun asi, quisiera aprovechar para compartir el codigo de un programa que he estado haciendo esta tarde. Entonces, sobre la funcion del programa, la funcion es simple, ya que realiza es crear una pequeña base de datos enfocada para videojuegos, especificamente para los diversos objetos, y, por otra parte, el añadir que objetos se necesitan para conseguir otro mejor/diferente. En resumen, una base de datos para una opcion que aparece en juegos como "Resident Evil" donde, si combinas 2 o mas objetos, obtienes uno nuevo. Dicho sea de paso, el codigo lo he creado en "Blitz 3D", un compilador de finales de los años '90, y, bueno, comentar que si voy viendo algun error de programacion lo ire arreglando, y, bueno, agradeceria comentarios si creeis que debo añadir/mejorar alguna cosa (y, exceptuando con permiso, quitar la interfaz de "solo texto tipo MS-Dos"), claro esta. :D Entonces, aqui publico el codigo (eso si, puede ser algo largo): Graphics 800,600,32,2 Cls Locate 0,0 dir_base$=CurrentDir()+"database_list\" If FileType(dir_base$)=0 CreateDir dir_base$ EndIf .lista_BD Cls Locate 0,0 Print "Inserte el nombre de la base de datos." dat$=Input() If dat$="" .salida_inicial Cls Locate 0,0 Print "Ha insertado un nombre no valido." Print "¿Desea salir del programa?. (S/N)" dat$=Input() If dat$="S" Or dat$="s" End EndIf If dat$="N" Or dat$="n" Goto lista_BD EndIf Goto salida_inicial EndIf file_base_b$=dir_base$+dat$ If FileType(file_base_b$)=1 Cls Locate 0,0 Print "Ya existe un archivo con el nombre indicado." Print "Pulse una tecla para cargar los datos." WaitKey() fileout=ReadFile(file_base_b$) num_objetos#=ReadFloat(fileout) If num_objetos#=0 Goto fin_actualizacion_00 EndIf num_objetos#=num_objetos#-1 Dim lista_objetos$(num_objetos#) Dim lista_creacion_objetos#(num_objetos#,num_objetos#) For tr#=0 To num_objetos# daty$=ReadString(fileout) lista_objetos$(tr#)=daty$ For trr#=0 To num_objetos# opciones#=ReadFloat(fileout) lista_creacion_objetos#(tr#,trr#)=opciones# Next Next num_objetos#=num_objetos#+1 .fin_actualizacion_00 CloseFile(fileout) Cls Locate 0,0 Print "La base de datos se ha cargado." Print "Pulse una tecla para continuar al menu principal." WaitKey() Goto inicio EndIf .inicio Cls Locate 0,0 Print "¿Que desea hacer?." Print "1) Añadir un nuevo objeto a la BD, o bien" Print " modificar el nombre de un objeto existente." Print "2) Añadir/quitar objetos para crear un" Print " objeto especifico." Print "3) Ver todos los objetos." Print "4) Ver todos los objetos con los objetos" Print " necesarios para crearlos. Print "5) Buscar un objeto con todos los objetos." Print " necesarios para crearlo." Print "6) Ver una lista de objetos que se pueden Print " crear con uno o mas objetos." Print "7) Salir del programa." opciones#=Input() If opciones#=1 Cls Locate 0,0 Print "Inserte el nombre del nuevo objeto:" dat$=Input() If dat$="" Cls Locate 0,0 Print "No ha insertado ningun nombre." Print "Pulse una tecla para volver al menu inicial." WaitKey() Goto inicio EndIf If num_objetos#=0 Dim lista_objetos$(num_objetos#) Dim lista_creacion_objetos#(num_objetos#,num_objetos#) lista_objetos$(num_objetos#)=dat$ num_objetos#=num_objetos#+1 Cls Locate 0,0 Print "Se ha añadido el objeto a la base de datos." Print "Pulse una tecla para volver al menu inicial." WaitKey() Goto inicio EndIf If num_objetos#>0 num_objetos#=num_objetos#-1 For tr#=0 To num_objetos# If dat$=lista_objetos$(tr#) Cls Locate 0,0 Print "El objeto indicado ya existe." Print "Inserte el nuevo nombre para el objeto actual:" Print "(No inserte nada para descartar los datos y" Print " volver al menu inicial)." dat$=Input() If dat$="" num_objetos#=num_objetos#+1 Goto inicio EndIf For txz#=0 To num_objetos# If dat$=lista_objetos$(txz#) Cls Locate 0,0 Print "El nombre indicado no se puede añadir," Print "ya esta en uso." Print "Pulse una tecla para volver al menu inicial." num_objetos#=num_objetos#+1 WaitKey() Goto inicio EndIf Next lista_objetos$(tr#)=dat$ num_objetos#=num_objetos#+1 Cls Locate 0,0 Print "El nombre del objeto se ha modificado." Print "Pulse una tecla para volver al menu inicial." WaitKey() Goto inicio EndIf Next Dim lista_objetos_b$(num_objetos#) Dim lista_creacion_objetos_b#(num_objetos#,num_objetos#) For tr#=0 To num_objetos# dat_b$=lista_objetos$(tr#) lista_objetos_b$(tr#)=dat_b$ For trr#=0 To num_objetos# dat_b$=lista_creacion_objetos#(tr#,trr#) lista_creacion_objetos_b#(tr#,trr#)=dat_b$ Next Next num_objetos#=num_objetos#+1 Dim lista_objetos$(num_objetos#) Dim lista_creacion_objetos#(num_objetos#,num_objetos#) num_objetos#=num_objetos#-1 For tr#=0 To num_objetos# dat_b$=lista_objetos_b$(tr#) lista_objetos$(tr#)=dat_b$ For trr#=0 To num_objetos# dat_b$=lista_creacion_objetos_b#(tr#,trr#) lista_creacion_objetos#(tr#,trr#)=dat_b$ Next Next num_objetos#=num_objetos#+1 lista_objetos$(num_objetos#)=dat$ num_objetos#=num_objetos#+1 Cls Locate 0,0 Print "Se ha añadido el objeto a la base de datos." Print "Pulse una tecla para volver al menu inicial." WaitKey() Goto inicio EndIf EndIf If opciones#=2 Cls Locate 0,0 If num_objetos#=0 Print "No ha creado ningun objeto." Print "Debe crear 2 objetos antes de acceder a esta opcion." Print "Pulse una tecla para volver al menu inicial." WaitKey() Goto inicio EndIf If num_objetos#<1 Print "Solo ha creado 1 objeto." Print "Debe crear 2 o mas uno antes de acceder a esta opcion." Print "Pulse una tecla para volver al menu inicial." WaitKey() Goto inicio EndIf Print "Inserte el nombre del objeto principal:" dat$=Input() If dat$="" Cls Locate 0,0 Print "No ha insertado ningun nombre." Print "Pulse una tecla para volver al menu inicial." WaitKey() Goto inicio EndIf num_objetos#=num_objetos#-1 For tr#=0 To num_objetos# If dat$=lista_objetos$(tr#) Cls Locate 0,0 Print "Se ha encontrado el objeto indicado." Print "Pulse una tecla para seguir." Dim lista_objetos_temp#(num_objetos#) For trn#=0 To num_objetos# val#=lista_creacion_objetos#(tr#,trn#) lista_objetos_temp#(trn#)=val# Next WaitKey() .add_quit_object Cls Locate 0,0 Print "¿Que desea hacer?." Print "1) Ver una lista de todos los objetos." Print "2) Ver la lista inicial de objetos necesarios para" Print " poder crear el objeto principal." Print "3) Ver la lista actual de objetos necesarios para" Print " poder crear el objeto principal." Print "4) Anadir/quitar un objeto para poder crear" Print " el objeto principal." Print "5) Volver al menu inicial descartando los datos. Print "6) Volver al menu inicial guardando los datos. opciones#=Input() If opciones#=1 Cls Locate 0,0 trx#=0 For trn#=0 To num_objetos# num_objetosx#=trn#+1 Print "Objeto no. " + num_objetosx# Print lista_objetos$(trn#) trx#=trx#+1 If trx#=10 Print "" Print "Inserte R o r para volver al menu anterior." daty$=Input() If daty$="R" Or daty$="r" Goto add_quit_object EndIf Cls Locate 0,0 trx#=0 EndIf Next Print "" Print "Ya se han mostrado todos los objetos." Print "Pulse una tecla para volver al menu anterior." WaitKey() Goto add_quit_object EndIf If opciones#=2 Cls Locate 0,0 Print "Nombre del objeto principal:" Print lista_objetos$(tr#) Print "Objetos necesarios para crear este objeto:" trx#=0 For trn#=0 To num_objetos# val#=lista_creacion_objetos#(tr#,trn#) If val#=1 num_objetosx#=trn#+1 Print lista_objetos$(trn#) trx#=trx#+1 If trx#=10 Print "" Print "Inserte R o r para volver al menu anterior." daty$=Input() If daty$="R" Or daty$="r" Goto add_quit_object EndIf Cls Locate 0,0 Print "Nombre del objeto principal:" Print lista_objetos$(tr#) Print "Objetos necesarios para crear este objeto:" trx#=0 EndIf EndIf Next Print "" Print "Ya se han mostrado todos los objetos." Print "Pulse una tecla para volver al menu anterior." WaitKey() Goto add_quit_object EndIf If opciones#=3 Cls Locate 0,0 Print "Nombre del objeto principal:" Print lista_objetos$(tr#) Print "Objetos necesarios para crear este objeto:" trx#=0 For trn#=0 To num_objetos# val#=lista_objetos_temp#(trn#) If val#=1 num_objetosx#=trn#+1 Print lista_objetos$(trn#) trx#=trx#+1 If trx#=10 Print "" Print "Inserte R o r para volver al menu anterior." daty$=Input() If daty$="R" Or daty$="r" Goto add_quit_object EndIf Cls Locate 0,0 Print "Nombre del objeto principal:" Print lista_objetos$(tr#) Print "Objetos necesarios para crear este objeto:" trx#=0 EndIf EndIf Next Print "" Print "Ya se han mostrado todos los objetos." Print "Pulse una tecla para volver al menu anterior." WaitKey() Goto add_quit_object EndIf If opciones#=4 Cls Locate 0,0 Print "Inserte el nombre del objeto que desea añadir/quitar" Print "para crear el objeto principal:" daty$=Input() For trn#=0 To num_objetos# If tr#=trn# Cls Locate 0,0 Print "Ha insertado un nombre no valido, ya que es" Print "el nombre del objeto principal." Print "Pulse una tecla para volver al menu anterior." WaitKey() Goto add_quit_object EndIf If daty$=lista_objetos$(trn#) val#=lista_objetos_temp#(trn#) .select_add_or_quit Cls Locate 0,0 If val#=1 Print "¿Realmente desea quitar este objeto para poder" Print " crear el objeto principal? (S/N)." val_b#=0 EndIf If val#=0 Print "¿Realmente desea añadir este objeto para poder" Print " crear el objeto principal? (S/N)." val_b#=1 EndIf datx$=Input() If datx$="S" Or datx$="s" lista_objetos_temp#(trn#)=val_b# If val_b#=1 Cls Locate 0,0 Print "Objeto añadido." EndIf If val_b#=0 Cls Locate 0,0 Print "Objeto descartado/quitado." EndIf Print "Pulse una tecla para volver al menu anterior." WaitKey() Goto add_quit_object EndIf If datx$="N" Or datx$="n" Goto add_quit_object EndIf EndIf Next Cls Locate 0,0 Print "No se ha encontrado el objeto indicado." Print "Pulse una tecla para volver al menu anterior." WaitKey() Goto add_quit_object EndIf If opciones#=5 .return_without_saving Cls Locate 0,0 Print "¿Realmente desea volver al menu inicial guardando los cambios? (S/N)." dat$=Input() If dat$="S" Or dat$="s" num_objetos#=num_objetos#+1 Goto inicio EndIf If dat$="N" Or dat$="n" Goto add_quit_object EndIf Goto return_without_saving EndIf If opciones#=6 .return_saving Cls Locate 0,0 Print "¿Realmente desea volver al menu inicial guardando los cambios? (S/N)." dat$=Input() If dat$="S" Or dat$="s" For trn#=0 To num_objetos# val#=lista_objetos_temp#(trn#) lista_creacion_objetos#(tr#,trn#)=val# Next Cls Locate 0,0 Print "Se han aplicado los cambios." Print "Pulse una tecla para volver al menu inicial." num_objetos#=num_objetos#+1 WaitKey() Goto inicio EndIf If dat$="N" Or dat$="n" Goto add_quit_object EndIf Goto return_saving EndIf Goto add_quit_object EndIf Next EndIf If opciones#=3 Cls Locate 0,0 If num_objetos#=0 Print "No ha creado ningun objeto." Print "Debe crear uno antes de acceder a esta opcion." Print "Pulse una tecla para volver al menu inicial." WaitKey() Goto inicio EndIf trx#=0 num_objetos#=num_objetos#-1 For trn#=0 To num_objetos# num_objetosx#=trn#+1 Print "Objeto no. " + num_objetosx# Print lista_objetos$(trn#) trx#=trx#+1 If trx#=10 Print "" Print "Inserte R o r para volver al menu anterior." daty$=Input() If daty$="R" Or daty$="r" num_objetos#=num_objetos#+1 Goto inicio EndIf Cls Locate 0,0 trx#=0 EndIf Next num_objetos#=num_objetos#+1 Print "" Print "Ya se han mostrado todos los objetos." Print "Pulse una tecla para volver al menu anterior." WaitKey() Goto inicio EndIf If opciones#=4 Cls Locate 0,0 If num_objetos#=0 Print "No ha creado ningun objeto." Print "Debe crear uno antes de acceder a esta opcion." Print "Pulse una tecla para volver al menu inicial." WaitKey() Goto inicio EndIf trx#=0 num_objetos#=num_objetos#-1 For tr#=0 To num_objetos# num_objetosx#=trn#+1 Print "Objeto no. " + num_objetosx# Print lista_objetos$(tr#) Print "" trx#=trx#+1 Print "Objetos necesarios para crear este objeto:" For trn#=0 To num_objetos# val#=lista_creacion_objetos#(tr#,trn#) If val#=1 num_objetosx#=trn#+1 Print lista_objetos$(trn#) trx#=trx#+1 If trx#=10 Print "" Print "Inserte R o r para volver al menu anterior." daty$=Input() If daty$="R" Or daty$="r" num_objetos#=num_objetos#+1 Goto inicio EndIf Cls Locate 0,0 Print "Nombre del objeto principal:" Print lista_objetos$(tr#) Print "Objetos necesarios para crear este objeto:" Cls Locate 0,0 trx#=0 EndIf EndIf Next Print "" Print "Inserte R o r para volver al menu anterior y" Print "dejar de ver mas objetos." daty$=Input() If daty$="R" Or daty$="r" num_objetos#=num_objetos#+1 Goto inicio EndIf Cls Locate 0,0 Next num_objetos#=num_objetos#+1 Print "Ya se han mostrado todos los objetos." Print "Pulse una tecla para volver al menu anterior." WaitKey() Goto inicio EndIf If opciones#=5 Cls Locate 0,0 If num_objetos#=0 Print "No ha creado ningun objeto." Print "Debe crear uno antes de acceder a esta opcion." Print "Pulse una tecla para volver al menu inicial." WaitKey() Goto inicio EndIf Print "Inserte el nombre del objeto a buscar:" dat$=Input() Cls Locate 0,0 If dat$="" Cls Locate 0,0 Print "Ha insertado un nombre no valido." Print "Pulse una tecla para volver al menu inicial." WaitKey() Goto inicio EndIf num_objetos#=num_objetos#-1 For tr#=0 To num_objetos# If dat$=lista_objetos$(tr#) Cls Locate 0,0 Print "Nombre del objeto principal:" Print lista_objetos$(tr#) Print "Objetos necesarios para crear este objeto:" For trn#=0 To num_objetos# val#=lista_creacion_objetos#(tr#,trn#) If val#=1 num_objetosx#=trn#+1 Print lista_objetos$(trn#) trx#=trx#+1 If trx#=10 Print "" Print "Inserte R o r para volver al menu anterior." daty$=Input() If daty$="R" Or daty$="r" num_objetos#=num_objetos#+1 Goto inicio EndIf Cls Locate 0,0 Print "Nombre del objeto principal:" Print lista_objetos$(tr#) Print "Objetos necesarios para crear este objeto:" Cls Locate 0,0 trx#=0 EndIf EndIf Next Print "" Print "Ya se ha mostrado el objeto junto a todos" Print "los objetos necesarios para crearlo." Print "Pulse una tecla para volver al menu inicial." num_objetos#=num_objetos#+1 WaitKey() Goto inicio EndIf Next Cls Locate 0,0 Print "No se ha encontrado ningun objeto con el nombre indicado." Print "Pulse una tecla para volver al menu inicial." num_objetos#=num_objetos#+1 WaitKey() Goto inicio EndIf If opciones#=6 Cls Locate 0,0 If num_objetos#=0 Print "No ha creado ningun objeto." Print "Debe crear 2 objetos antes de acceder a esta opcion." Print "Pulse una tecla para volver al menu inicial." WaitKey() Goto inicio EndIf If num_objetos#<1 Print "Solo ha creado 1 objeto." Print "Debe crear 2 o mas uno antes de acceder a esta opcion." Print "Pulse una tecla para volver al menu inicial." WaitKey() Goto inicio EndIf num_objetos#=num_objetos#-1 Dim lista_objetos_c#(num_objetos#) .obj_base Cls Locate 0,0 Print "¿Que desea hacer?." Print "1) Añadir/quitar un objeto base de la lista" Print " para crear otro objeto. Print "2) Buscar objetos que se puedan crear con" Print " todos los objetos indicados." Print "3) Volver al menu inicial." opciones#=Input() If opciones#=1 Cls Locate 0,0 Print "Inserte el objeto que desea añadir/eliminar" Print "para crear otro objeto:" dat$=Input() For tr#=0 To num_objetos# If dat$=lista_objetos$(tr#) .i_o_object Cls Locate 0,0 If lista_objetos_c#(tr#)=0 Print "¿Realmente desea añadir el objeto indicado de la" Print " lista para crear otro objeto? (S/N)." EndIf If lista_objetos_c#(tr#)=1 Print "¿Realmente desea eliminar el objeto indicado de la" Print " lista para crear otro objeto? (S/N)." EndIf dat$=Input() If dat$="S" Or dat$="s" If lista_objetos_c#(tr#)=1 lista_objetos_c#(tr#)=0 Cls Locate 0,0 Print "Objeto eliminado." Print "Pulse una tecla para volver al menu anterior." WaitKey() Goto obj_base EndIf If lista_objetos_c#(tr#)=0 lista_objetos_c#(tr#)=1 Cls Locate 0,0 Print "Objeto añadido." Print "Pulse una tecla para volver al menu anterior." WaitKey() Goto obj_base EndIf EndIf If dat$="N" Or dat$="n" Goto obj_base EndIf Goto i_o_object EndIf Next Cls Locate 0,0 Print "No se ha encontrado el objeto indicado." Print "Pulse una tecla para volver al menu anterior." WaitKey() Goto obj_base EndIf If opciones#=2 .total_objs Cls Locate 0,0 Print "¿Los objetos que se van a mostrar deben incluir" Print " todos los objetos que se acaban de añadir? (S/N)." daty$=Input() vary#=0 var_03#=0 If daty$="S" Or daty$="s" For tr#=0 To num_objetos# vary#=0 varz#=0 For trr#=0 To num_objetos# If lista_objetos_c#(trr#)=1 vary#=vary#+1 EndIf Next Print vary# For trr#=0 To num_objetos# If lista_objetos_c#(trr#)=1 If lista_creacion_objetos#(tr#,trr#)=1 varz#=varz#+1 EndIf EndIf Next Print varz# WaitKey() If vary#=varz# var_03#=1 Cls Locate 0,0 Print "Nombre del objeto encontrado:" Print "" Print lista_objetos$(tr#) Print "" Print "Lista de objetos necesitados para crear este objeto:" var_02#=0 For trn#=0 To num_objetos# var_00#=lista_objetos_c#(trn#) var_01#=lista_creacion_objetos#(tr#,trn#) If var_01#=1 If var_00#=1 Print lista_objetos$(trn#) + " (Objeto indicado en la busqueda)" EndIf If var_00#=0 Print lista_objetos$(trn#) + " (Objeto no indicado en la busqueda)" EndIf EndIf var_02#=var_02#+1 If var_02#=10 Print "" Print "Inserte R o r para volver al menu anterior." daty$=Input() If daty$="R" Or daty$="r" Goto obj_base EndIf var_02#=0 Cls Locate 0,0 Print "Nombre del objeto encontrado:" Print "" Print lista_objetos$(tr#) Print "" Print "Lista de objetos necesitados para crear este objeto:" EndIf Next Print "" Print "No hay mas datos que mostrar de este objeto." Print "Inserte R o r para volver al menu anterior, o bien" Print "otra cosa para seguir." daty$=Input() If daty$="R" Or daty$="r" Goto obj_base EndIf EndIf Next Goto mensaje_fin_busquedas_0x0 EndIf If daty$="N" Or daty$="n" For tr#=0 To num_objetos# For trr#=0 To num_objetos# var_00#=lista_objetos_c#(trr#) var_01#=lista_creacion_objetos#(tr#,trr#) If var_00#=1 If var_00#=var_01# var_03#=1 Cls Locate 0,0 Print "Nombre del objeto encontrado:" Print "" Print lista_objetos$(tr#) Print "" Print "Lista de objetos necesitados para crear este objeto:" var_02#=0 For trn#=0 To num_objetos# var_00#=lista_objetos_c#(trn#) var_01#=lista_creacion_objetos#(tr#,trn#) If var_01#=1 If var_00#=1 Print lista_objetos$(trn#) + " (Objeto indicado en la busqueda)" EndIf If var_00#=0 Print lista_objetos$(trn#) + " (Objeto no indicado en la busqueda)" EndIf EndIf var_02#=var_02#+1 If var_02#=10 Print "" Print "Inserte R o r para volver al menu anterior." daty$=Input() If daty$="R" Or daty$="r" Goto obj_base EndIf var_02#=0 Cls Locate 0,0 Print "Nombre del objeto encontrado:" Print "" Print lista_objetos$(tr#) Print "" Print "Lista de objetos necesitados para crear este objeto:" EndIf Next Print "" Print "No hay mas datos que mostrar de este objeto." Print "Inserte R o r para volver al menu anterior, o bien" Print "otra cosa para seguir." daty$=Input() If daty$="R" Or daty$="r" Goto obj_base EndIf Goto obj_base_nn EndIf EndIf Next .obj_base_nn Next .mensaje_fin_busquedas_0x0 If var_03#=1 Cls Locate 0,0 Print "Ya se han mostrado todos los objetos que se" Print "pueden crear con los objetos indicados." Print "Pulse una tecla para volver al menu anterior." EndIf If var_03#=0 Print "No se puede crear ningun objeto con los que" Print "se han indicado." Print "Pulse una tecla para volver al menu anterior." EndIf WaitKey() Goto obj_base EndIf Goto total_objs EndIf If opciones#=3 .return_op_05 Cls Locate 0,0 Print "¿Realmente desea volver al menu inicial? (S/N)." dat$=Input() If dat$="S" Or dat$="s" num_objetos#=num_objetos#+1 Goto inicio EndIf If dat$="N" Or dat$="n" Goto obj_base EndIf Goto return_op_05 EndIf Goto obj_base EndIf If opciones#=7 .salida Cls Locate 0,0 Print "¿Desea actualizar la base de datos (BD) de objetos? (S/N)." dat$=Input() If dat$="N" Or dat$="n" End EndIf If dat$="S" Or dat$="s" If FileType(file_base_b$)=1 DeleteFile file_base_b$ EndIf fileout=WriteFile(file_base_b$) WriteFloat(fileout,num_objetos#) If num_objetos#=0 Goto fin_actualizacion EndIf num_objetos#=num_objetos#-1 For tr#=0 To num_objetos# daty$=lista_objetos$(tr#) WriteString(fileout,daty$) For trr#=0 To num_objetos# opciones#=lista_creacion_objetos#(tr#,trr#) WriteFloat(fileout,opciones#) Next Next num_objetos#=num_objetos#+1 .fin_actualizacion CloseFile(fileout) Cls Locate 0,0 Print "La base de datos se ha actualizado." Print "Pulse una tecla para salir del programa." WaitKey() End EndIf Goto salida EndIf Goto inicio
Muchas gracias por vuestra atencion, y, bueno, saludos.
|