Versions - wlsdn2316/1-tetris- GitHub Wiki
Original Code
Split File tetris_origin.c => main.c function.h init.h
Refactoring Files : init.h main.c function.h 1. init.h
global variable : struct
2. function.h
According to init.h changes
refactoring codes
new function : get_UI_Position()
3. main.c
According to init.h changes
refactoring codes
1. function.h
clean code check_line and drop_block
new function : file_control(), init_reset(), setCurInfo()
Only defined and declared.
Functionalizes repeated file opening and closing => file_control()
Functionalizes initial variables in reset => init_reset()
Functionalizes repeated Cursor Info => setCurInfo()
modified codes : reset(), check_game_over(), setcursortype()
< modified >
reset() #137 : file_control();
reset () #139 : init_reset();
setCurInfo () #86 #89 #92 : CurInfo = setCurInfo();
check_game_over() #595 : file_control();
All of the previous codes have been replaced as above.
modifided codes: change struct member values to local value
< modified >
move_block(); #374~#377
(*block_info).b_type -> b_type
(*block_info).b_rotation -> b_rotation
Change struct variables to local value.
almost value name changed in move_block();.
Improve readability.
1 Function added , other variables changed
pause() #629: new function added
generateNextBlock() #633~651: This function works for generating next block.
{(*block_info).b_type_next} -> nextBlock: legibility improved.
new_block() #283: There was a statement that works same as generateNextBlock()
Therefore, it is replaced by generateNextBlock().
int i and y are not local variables anymore. They only work in for statement
add function : set_new_block()
Define and declare set_new_block().
set_new_block() is only setting a Block_info.
modified codes : file_control(), setcursortype(), check_key()
file_control() :
FILE * pfile = (*game_info).file; //add lines #60
(*game_info).file -> pfile
Add comment lines //#52~59
setcursortype() :
Add comment lines //#116~119
check_key() :
(*block_info).b_type-> b_type
(*block_info).b_rotation -> b_rotation
(*block_info).bx -> bx
(*block_info).by -> by
(*block_info).b_type_next -> b_type_next
Length of a structure variable is too long, replace it with a local variable.
modified code : draw_map()
< modified >
write original author and secondary author.
modified code #232 #233
modified codes : move_block()
< modified >
move_block(): #487 #506
1. (*block_info).b_rotation = ((*block_info).b_rotation + 1) % 4;
->
(*block_info).b_rotation = ((*block_info).b_rotation + 1) % 4;
b_rotation = (*block_info).b_rotation;
2. (*block_info).b_rotation -> b_rotation
Change struct variables to local value.
modified codes : move_block()
< modified >
move_block(): #492 #512
(*block_info).b_rotation -> b_rotation
Change struct variables to local value.
new function : move_left(), move_right(), move_up(), move_down(), move_bottom_rotation()
enum member : BOTTOM_ROTATOIN = 100
< function. h >
Move block to the left direction : move_left()
Move block to the right direction : move_right()
Move block to the down direction : move_ down()
Rotate the block : move_up()
Rotate the block when it touches the floor or block : move_bottom_rotation()
<init.h>
enum KEYCODE : add 'BOTTOM_ROTATOIN = 100'
modified codes : EXISTING_BLOCK
<init.h>
enum BLOCK_STATUS : add 'EXISTING_BLOCK == 1'
<function.h>
check_crush() -> non_crush
if (blocks[b_type][b_rotation][i][j] == 1)
->
if (blocks[b_type][b_rotation][i][j] == EXISTING_BLOCK)
modified codes : function name change
<main.c>
check_crush() ->non_crush() #29
only one function name change
modified codes : function name change
<main.c>
check_crush() ->non_crush() #29
only one function name change
Add function : set_map_main(),set_map_cpy(),get_map_main(),get_map_cpy()
set_map_main() : set main_org(map) status
set_map_cpy() : set main_cpy(map copy) status
get_map_main() : get main_org(map) status
get_map_cpy() : get main_cpy(map copy) status
Only define and declare.
modified codes : main_org -> set,get_map_main() , main_cpy -> set,get_map_cpy(), reset_main(), reset_main_cpy()
As add function set,get_map_main(), set,get_map_cpy(), changes as follow :
main_org -> set_map_main(), get_map_main()
main_cpy -> set_map_cpy(), get_map_cpy()
reset_main() : #192 set_map_cpy(map_info, i, j, 100) -> set_map_cpy(map_info, i, j, 999)
reset_main_cpy() : #214 set_map_cpy(map_info, i, j, 100) -> set_map_cpy(map_info, i, j, 999)
First map_copy must not match original status.
Add function : move_space()
move_space() : If input 'space' key, process it.
Only define and declare.
modified code : check_key()
check_key() : #369 , move_space().
Functionalized the codes.
modifided codes : change function name and modified comment
<modified>
check_line() : #7 #8 #13 #20
reset_main() -> Reset_main()
check_line() -> Check_line()
so on... clean code and comment modified
modifided codes : change function name and modified comment
<modified>
check_line() : #37
drop_main() -> Drop_main()
Add function : void Cal_score_line()
void Cal_score_line(): check ceiling line and down all lines one by one
modified codes : function names
All functions capitalize the first letter of the name.
Add functions : Init_Game(), Excute_Game()
Init_Game() : Initialization part at game.
Excute_Game() : Excute part at game.
Only define and declare
modified codes : main.c
As added the functions, it changed. //Init_Game() Excute_Game()
Refactoring check_level_up function
Check_levelup_popup #761 show level up and speed up popup
Game_Level_Up #749 change the game level
Everything looks good but need to work on the variables