-+-+-+-+-+-+-+-+ START OF PART 4 -+-+-+-+-+-+-+-+ XMult := 2**7; `7B 2 ** Number of PLayers - 1`7D XNum_Players := 0; X X`7B Examine Each Bit In Mult To See If You Are Playing `7D XMax_player_number := 0; XFor Play := Max_Num_PLayers downto 1 do begin X If ( Who_Is_PLaying div Mult ) = 1 Then begin X Name_Get(Name`5BPlay`5D,Play); X Num_Players := Num_PLayers + 1; X Quit`5Bplay`5D := False; `7B Bit Set You Are Playing `7D X Who_is_Playing := Who_is_Playing - Mult; X If Max_player_number = 0 Then`20 X Max_player_number := play ;`7B The Highest Numbered Player `7D X end else begin X Quit`5BPlay`5D := True; `7B Bit Not Set Not Playing ie Quit `7D X end; X Mult := Mult div 2; Xend; X XNum_Moved_Last_Round := 0; X X`7B If You are PLaying Then You Havnt Died `7D XFor Play := 1 to Max_Num_Players Do Begin X If Not Quit`5BPlay`5D Then Begin X Died`5BPlay`5D := False; X Num_Moved_Last_Round := Num_Moved_Last_Round + 1; X end else X Died`5Bplay`5D := True; X responce`5BPlay`5D := ' '; `7B Initalise First Responce Should Not BE N Veeded `7D Xend; XFor PLay := 1 to Max_Num_PLayers do`20 X Game`5BPLay`5D := Game`5BPLay`5D + 1; XFor X := 1 To Screen_Dim_X do`20 X For Y := 1 to Screen_Dim_Y do X Screen`5BX,y`5D := '`7E'; XFor Y := 1 To Screen_Dim_Y do Begin X Screen`5B1,Y`5D := 'q'; X Screen`5BScreen_Dim_X,Y`5D := 'q'; Xend; XFor X := 1 To Screen_Dim_X Do Begin X Screen`5BX,1`5D := 'x'; X Screen`5BX,Screen_Dim_Y`5D := 'x';`20 Xend; XScreen`5B1,1`5D := 'l'; XScreen`5B1,Screen_Dim_Y`5D := 'k'; XScreen`5BScreen_Dim_X,1`5D := 'm'; XScreen`5BScreen_Dim_X,Screen_Dim_y`5D := 'j'; XHead_Sym`5B1`5D := chr(128+ord('1')); `7B Set The Bits In The Chars `7D XHead_Sym`5B2`5D := chr(128+ord('2')); XHead_Sym`5B3`5D := chr(128+ord('3')); XHead_Sym`5B4`5D := chr(128+ord('4')); XHead_Sym`5B5`5D := chr(128+ord('5')); XHead_Sym`5B6`5D := chr(128+ord('6')); XHead_Sym`5B7`5D := chr(128+ord('7')); XHead_Sym`5B8`5D := chr(128+ord('8')); X XFor Play := 1 to Max_Num_PLayers do`20 X If Not Quit`5Bplay`5D Then`20 X Screen`5BHead_X`5BPlay`5D,Head_Y`5BPlay`5D`5D := 'O'; X`7B Note If This Procedure Is Only Called When You Are Master Snake`20 X Draw Screen Should Be In The Mainlkine Before Init_pos X And The Writing Of The PLayers Pos Should Be To The Buffer`20 X And Then Written To All Who Are PLaying `7D X XDraw_screen; `20 X X`7B Pos Inital Player Positions `7D XFor Play := 1 to Max_Num_PLayers do `20 X If ( Not Quit`5BPlay`5D ) Then `20 X Writeln(at(Head_X`5BPlay`5D,Head_Y`5BPlay`5D),Head_sym`5BPlay`5D); Xend; X XProcedure Initalise_Mainline; X XVar Zero,Init_Rep,PLay,Name_pos,Game_Going : Integer; X XProcedure Verify_name(VAr Name : Name_Line ); X XVar I : INteger; X X XBegin X For I := 1 to Max_Name_length do `7B Remove All Invalid Chars From The V Name`7D X If ( Name`5Bi`5D < ' ' ) or ( Name`5Bi`5D > '`7E' ) Then Begin X Write(chr(7)); X Name`5Bi`5D := ' '; X end; Xend; X X XBegin X Esc := Chr(27); X Seed := Clock; X TT_Len := 0; X `20 X X `7B set where Each Player Starts `7D X X Init_pos_X`5B1`5D := 2; X Init_pos_Y`5B1`5D := 2; X `20 X Init_pos_X`5B2`5D := Screen_dim_x - 1; X Init_pos_Y`5B2`5D := Screen_dim_Y - 1; X `20 X Init_pos_X`5B3`5D := 2; X Init_pos_Y`5B3`5D := Screen_dim_y - 1; X `20 X Init_pos_X`5B4`5D := Screen_dim_x - 1; X Init_pos_Y`5B4`5D := 2; X `20 X Init_pos_X`5B5`5D := 2; X Init_pos_Y`5B5`5D := Screen_dim_Y div 2; X `20 X Init_pos_X`5B6`5D := Screen_dim_x - 1 ; X Init_pos_Y`5B6`5D := Screen_dim_Y div 2; X `20 X Init_pos_X`5B7`5D := Screen_dim_x div 2; X Init_pos_Y`5B7`5D := 2; X `20 X Init_pos_X`5B8`5D := Screen_dim_x div 2; X Init_pos_Y`5B8`5D := Screen_dim_Y - 1; X X Writeln(Esc,'<'); `7B Vt52 Mode `7D X Writeln(Esc,'`5B1;1H',Esc,'`5BJ'); `7B Clear Screen `7D X Init_rep := Snake_Init(You,Game_going); X You := You + 1; `20 X If Init_rep = 1 Then Begin X `7B you are the First Person to play zero all the scores `7D X For Play := 1 to Max_Num_PLayers do begin X Zero := 0; X Score_Set(Play,Zero,zero,zero); X end; X Help_Screen; X Writeln(esc,'`5B1;1H',Esc,'`5B?2l'); X Writeln(at(22,3),' Please Enter Your Name Player #',You:1); X Write(at(22,51)); X Readln(Name`5BYou`5D); X Verify_Name(Name`5BYou`5D); X Name_set(Name`5BYou`5D); X Write(at(22,3), ' Hit < Return > When Others Ready '); X Readln; X Writeln; X Write(at(22,3), ' Please Wait For Game To Start '); X Writeln; X end Else Begin X If You = 0 Then Begin X Writeln(esc,'`5B1;18H',Esc,'#3SNAKE'); X Writeln(esc,'`5B2;18H',Esc,'#4SNAKE'); X Writeln(esc,'`5B4;8H' ,Esc,'#6Sorry No Snakes Available'); X`09 Sleep(3); X goto 9999; X end else begin `7B Init_rep = 0 `7D`20 X Help_Screen; X Writeln(esc,'`5B1;1H',Esc,'`5B?2l'); X Writeln(at(22,3),' Please Enter Your Name Player # ',You:1); X Write(at(22,51)); X Readln(Name`5BYou`5D); X Verify_name(Name`5BYou`5D); X Name_set(Name`5BYou`5D); X Writeln; X Write(at(22,3), ' Please Wait For Game To Start '); X Writeln; X If Game_Going = 1 Then`20 X Snake_Game_End; X end; X end; X Game`5BYou`5D := 0; Xend `7B Initalise Mainline `7D; X XFunction Correct_Sym(Last_Move_X,Last_Move_Y,Move_X,Move_Y:Integer):Char; X XBegin `7B Calculates The Correct symbol To Write Given The Dir You Were In V `7D X Case (Last_Move_X+1) + (Last_Move_Y+1)*4 Of`20 X 6 : `7B Down `7D X Case (Move_X+1) + (Move_Y+1)*4 Of`20 X 6 : `7B Down `7D X Correct_Sym := 'x'; X 9 : `7B Right `7D X Correct_Sym := 'm'; X 1 : `7B Left `7D X Correct_Sym := 'j'; X 4 : `7B Up Note : This Is Poss On First Move `7D X Correct_Sym := 'x'; X end `7B Case `7D; X 4 : `7B Up `7D X Case (Move_X+1) + (Move_Y+1)*4 Of`20 X 6 : `7B Down `7D X Correct_Sym := 'x'; X 4 : `7B Up `7D X Correct_Sym := 'x'; `20 X 9 : `7B Right `7D X Correct_Sym := 'l'; X 1 : `7B Left `7D X Correct_Sym := 'k'; `20 X end `7B Case `7D; X `20 X 9 : `7B Right `7D X Case (Move_X+1) + (Move_Y+1)*4 Of`20 X 6 : `7B Down `7D X Correct_Sym := 'k'; `20 X 4 : `7B Up `7D X Correct_Sym := 'j'; `20 X 9 : `7B Right `7D X Correct_Sym := 'q'; X 1 : `7B Left `7D X Correct_Sym := 'q'; `20 X end `7B Case `7D; X X 1 : `7B Left `7D X Case (Move_X+1) + (Move_Y+1)*4 Of`20 X 9 : `7B Right `7D X Correct_Sym := 'q'; X 6 : `7B Down `7D X Correct_Sym := 'l'; `20 X 4 : `7B Up `7D X Correct_Sym := 'm'; `20 X 1 : `7B Left `7D X Correct_Sym := 'q'; `20 X end `7B Case `7D; X X end `7B Case `7D; Xend; `7B Correct Sym `7D X X`5BGLOBAL`5D Function Add_head( Var Responce : Player_responce ):Integer; X XVar Play, Num_Moved, Dir_X, Dir_Y, Pos_x, Pos_Y : Integer; X X X XProcedure Remove_tail( Var STail_X , STail_Y : Integer ); X XVar Last_X,Last_Y : Integer; X XBegin `7B removes the Tail of the snake whose tail is at StailX,Y `7D X`7B The Character To Move is determined by the Char at the tail X and if a character joins up to it `7D X X Last_X := STail_X; X Last_Y := STail_Y; X Pos(STail_X,STail_Y,'`7E'); X Case Screen`5BSTail_X,STail_Y`5D of`20 X 'l' : If Screen`5BStail_X,STail_Y+1`5D In `5B'k','j','q'`5D Then`20 X STail_Y := STail_Y + 1 X Else X STail_X := STail_X + 1; X 'k' : If Screen `5BSTail_X,STail_Y-1`5D In `5B'l','m','q'`5D Then`2 V0 X STail_Y := STail_Y - 1 X Else X Stail_X := STail_X + 1 ; X 'm' : If Screen`5BSTail_X,STail_Y+1`5D In `5B'k','j','q'`5D Then X Stail_Y := STail_Y + 1 X Else X Stail_X := Stail_X - 1 ; X 'j' : If Screen`5BSTail_X,STail_Y-1`5D In `5B'm','l','q'`5D Then`20 X STail_Y := STail_Y - 1 X Else X STail_X := STail_X - 1; X 'x' : If Screen`5BSTail_X-1,STail_Y`5D In `5B'l','k','x'`5D Then`20 X STail_X := STail_X - 1 X Else X STail_X := STail_X + 1; X 'q' : If Screen`5BSTail_X,STail_Y - 1 `5D In `5B 'l','m','q'`5D The Vn`20 X STail_Y := STail_Y - 1 X Else X STail_Y := STail_Y + 1; X end `7B CAse `7D; X Screen`5BLast_X,Last_Y`5D := '`7E'; Xend `7B remove_Tail`7D; X X XProcedure Remove_Players_tail( play : Integer ); X XVar X,Y : Integer; X XBegin `7B Removed Odd Players Tails Of Play = 1 Even If 2 `7D X While Play <= Max_PLayer_Number do Begin X If Not Died`5BPlay`5D Then `20 X Remove_tail(Tail_X`5BPLay`5D,Tail_Y`5BPLay`5D); X Play := Play + 2; X end; Xend; X X XProcedure Add_This_Players_Head; X Xbegin X If Not Quit`5BPlay`5D And (Ord(Responce`5BPLay`5D) = 0 ) Then begin X Died`5BPLay`5D := True; `7B If PLayer quit Then`20 X Quit`5BPLay`5D := True; Initalise all Variables `7D X Game`5BPlay`5D := 0; X Score`5BPlay`5D := 0; X Games_Won`5BPLay`5D := 0; X Score_Set(Play,Score`5BPlay`5D,Game`5BPLay`5D,Games_Won`5BPLay`5D); X end else`20 X If Not Died`5BPlay`5D Then Begin X Dir_X := Move_X`5BPlay`5D; X Dir_Y := Move_Y`5BPLay`5D; X`09 Pos_X := Head_X`5BPlay`5D; X Pos_Y := Head_Y`5BPlay`5D; X `7B Change Direction Of The Position You Move To is Not A Wall ie = V '.' `7D X Case Ord(responce`5BPlay`5D) Of`20 X 8 : If Screen`5BPos_x-1,Pos_Y`5D = '`7E' Then Begin X Dir_X := -1 ; X Dir_Y := 0 ; `7B Moving Up `7D X end; X 2 : If Screen`5BPos_X+1,Pos_Y`5D = '`7E' Then Begin X Dir_X := 1; X Dir_Y := 0; `7B Moving Down `7D X end; X 4 : If Screen`5BPos_X,Pos_Y-1`5D = '`7E' Then Begin X Dir_X := 0; `7B Moving Left `7D X Dir_Y := -1; X end; X 6 : If Screen`5BPos_X,Pos_Y+1`5D = '`7E' Then Begin X Dir_X := 0; `7B Moving Right `7D X Dir_Y := 1; X end; X otherwise `7B Do Nothing Same Dir As Before `7D X end `7B Case `7D; X `7B Given LAst Direction Or New Direction `7D X If Screen`5BPos_X + Dir_X , Pos_Y + Dir_Y `5D = '`7E' Then Begin `2 V0 X`09 `7B Going into a Blank square ok to move `7D X Num_Moved := Num_Moved + 1; X Screen`5BPos_X ,Pos_Y `5D :=`20 X Correct_sym(Move_X`5BPlay`5D,Move_Y`5BPLay`5D,Dir_X,Dir_Y) V; X pos(Pos_X,Pos_Y,Screen`5BPos_X,Pos_Y`5D); X Pos_X := Pos_X + Dir_X; X Pos_Y := Pos_Y + Dir_Y; X Screen`5BPos_X,Pos_Y`5D := 'O'; X Pos(Pos_X,Pos_Y,Head_Sym`5BPLay`5D); X end else begin `7B You HAve Died Hit Into A Non Blank Square `7D X Died`5BPlay`5D := True; X If Num_PLayers <> Num_Moved_Last_Round Then `20 X Score`5BPlay`5D := Score`5BPlay`5D +`20 X (( Num_PLayers - Num_Moved_Last_Round + 1 )**2 * 100 ) V`20 X div ( NUm_Players**2); X pos(Pos_X,Pos_Y,Correct_sym(Move_X`5BPlay`5D,Move_Y`5BPLay`5D,Di Vr_X,Dir_Y)); X Pos_X := Pos_X + Dir_X; X Pos_Y := Pos_Y + Dir_Y; X`09 Snake_Dead(play);`20 X end; X Move_X`5BPlay`5D := Dir_X; X Move_Y`5BPLay`5D := Dir_Y; X`09 Head_X`5BPlay`5D := pos_X; X Head_Y`5BPlay`5D := Pos_Y; X end; Xend; X Xbegin X Num_Moved := 0; `7B Iniotalise Counter For The Number Who Move Vd `7D X If Players_reMoving = 1 Then Begin `7B If 1 Then Loop Clockwise `7D X For Play := 1 to Max_Player_number do`20 X add_This_Players_head; X Remove_players_tail(1); `7B Remove Odd Players Tail `7D X PLayers_ReMoving := 2; `7B Next Round Shall remove Even V Ones `7D X end else`20 X If Players_removing = 2 Then Begin X For Play := Max_Player_Number downto 1 do`20 X add_This_Players_head; `7B Go Clockwise In Updatin Vg `7D X Remove_Players_tail(2); X PLayers_ReMoving := 1; X end else begin X For Play := Max_Player_Number downto 1 do `7B First Few Moves Don't V remove Tail `7D X add_This_Players_head; `7B Go Clockwise In Updatin Vg `7D X Players_removing := Players_removing + 1; X end; X If Num_Moved <= 1 Then Begin `7B Ie There IS Only 1 or 0 V PLayers Left `7D X For PLay := 1 to Max_player_Number do Begin X`09If Not Quit`5BPlay`5D Then Begin X If Not Died`5BPLay`5D Then Begin X Score`5BPLay`5D := Score`5BPlay`5D + 100; `7B One Hundred V If You Last Left `7D X Games_Won`5BPLay`5D := Games_Won`5BPLay`5D + 1; X end; X Score_set(Play,Score`5BPlay`5D,Game`5BPlay`5D,Games_Won`5BPLay`5 VD); X end; X end; X Add_head := 0; `7B Return 0 To Stop The Game `7D X end else`20 X Add_Head := 1; `7B 1 To Comtinue `7D X Num_Moved_Last_Round := Num_Moved; X Break_Buff; `7B does not write the buffer just says To`20 X Write this buffer to all the players when add_head exits V `7D Xend `7B add_Head`7D; X X XProcedure Snake_PLay;extern; X X XBegin `7B Mainline `7D X LineLimit(Output,MaxInt); X Initalise_Mainline; X While True Do Begin +-+-+-+-+-+-+-+- END OF PART 4 +-+-+-+-+-+-+-+-