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