refactor
This commit is contained in:
		
							parent
							
								
									41aae0832c
								
							
						
					
					
						commit
						35d9e91598
					
				
							
								
								
									
										67
									
								
								w/w.c
								
								
								
								
							
							
						
						
									
										67
									
								
								w/w.c
								
								
								
								
							| 
						 | 
					@ -350,17 +350,13 @@ void dumpstate()
 | 
				
			||||||
		state.location.orientation);
 | 
							state.location.orientation);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void firstgame()
 | 
					void clearscreen()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	printf("Welcome to space dungeons.\n\nEnter your name: ");
 | 
					#ifdef _WIN32
 | 
				
			||||||
	fgets(state.name, sizeof(state.name), stdin);
 | 
						system("cls");
 | 
				
			||||||
	state.name[strcspn(state.name, "\n")] = 0; // remove last lf
 | 
					#else
 | 
				
			||||||
 | 
						system("clear");
 | 
				
			||||||
	// start at station
 | 
					#endif
 | 
				
			||||||
	strcpy(state.location.place, "st");
 | 
					 | 
				
			||||||
	state.location.x = 1;
 | 
					 | 
				
			||||||
	state.location.y = 1;
 | 
					 | 
				
			||||||
	state.location.orientation = 'n';
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void init()
 | 
					void init()
 | 
				
			||||||
| 
						 | 
					@ -368,7 +364,11 @@ void init()
 | 
				
			||||||
	loadstate();
 | 
						loadstate();
 | 
				
			||||||
	if (strlen(state.name) == 0)
 | 
						if (strlen(state.name) == 0)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		firstgame();
 | 
							// start at station
 | 
				
			||||||
 | 
							strcpy(state.location.place, "st");
 | 
				
			||||||
 | 
							state.location.x = 1;
 | 
				
			||||||
 | 
							state.location.y = 1;
 | 
				
			||||||
 | 
							state.location.orientation = 'n';
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -396,19 +396,31 @@ void update(char command)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		updatepov();
 | 
							updatepov();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							if (command == 'n')
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								strcpy(state.location.place, "f1"); 
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void draw()
 | 
					void draw()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						clearscreen();
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
#ifdef _WIN32
 | 
						if (strlen(state.name) == 0)
 | 
				
			||||||
	system("cls");
 | 
						{
 | 
				
			||||||
#else
 | 
							printf("\n\n      La légende des dongeons de l'espace\n\n\n");
 | 
				
			||||||
	system("clear");
 | 
							printf("Bonjour.\n");
 | 
				
			||||||
#endif
 | 
							printf("Bienvenue la station spaciale intergalactique.\n");
 | 
				
			||||||
 | 
							printf("Veuillez saisir votre nom:\n");
 | 
				
			||||||
 | 
							printf("> ");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (inmap())
 | 
						}
 | 
				
			||||||
 | 
						else if (inmap())
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		int shift = 10;
 | 
							int shift = 10;
 | 
				
			||||||
		for (int i = 0; i < shift; i++) printf("\n");
 | 
							for (int i = 0; i < shift; i++) printf("\n");
 | 
				
			||||||
| 
						 | 
					@ -433,10 +445,11 @@ void draw()
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		printf("%s is in the space station.\n\n", state.name, state.location.place);
 | 
							printf("%s est à la station intergalactique.\n\n", state.name);
 | 
				
			||||||
		printf("g: go to space dungeon\n");
 | 
							printf("n: prendre la navette pour le dongeon de l'espace\n");
 | 
				
			||||||
		printf("r: reach a rest pod\n");
 | 
							printf("r: aller dans une capsule de repos\n");
 | 
				
			||||||
		printf("s: shop at the interstellar marketplace\n\n");
 | 
							printf("m: aller au grand marché hyperspatial\n");
 | 
				
			||||||
 | 
							printf("i: consulter l'intercom\n\n");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -474,7 +487,17 @@ int main()
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		update(command);
 | 
							update(command);
 | 
				
			||||||
		draw();
 | 
							draw();
 | 
				
			||||||
		command = getchar();
 | 
							
 | 
				
			||||||
 | 
							// to refactor in a "getcommand" function or sumfin
 | 
				
			||||||
 | 
							if (strlen(state.name) == 0)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								fgets(state.name, sizeof(state.name), stdin);
 | 
				
			||||||
 | 
								state.name[strcspn(state.name, "\n")] = 0;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								command = getchar();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	savestate();
 | 
						savestate();
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue