@@ -327,7 +327,7 @@ void redrawLetters(short term_maxx, short term_maxy, char playerLetters[7], uint
327327 term_resetColorPair ();
328328}
329329
330- void fillPlayerLetters (vector<char > letters, char playerLetters[7 ])
330+ void fillPlayerLetters (vector<char >& letters, char playerLetters[7 ])
331331{
332332 static mt19937 mt (time (nullptr ));
333333 for (int i = 0 , id; i<7 ; ++i)
@@ -346,14 +346,17 @@ int emptyLettersOnHand(char letters[7])
346346{
347347 int ret = 0 ;
348348 for (int i = 0 ; i<7 ; ++i)
349- ret += letters[i]==0 ;
349+ ret += ( letters[i]==0 ) ;
350350
351351 return ret;
352352}
353353
354354int game ()
355355{
356356 term_clear ();
357+
358+ term_setCursorVisibility (1 );
359+
357360 uint8_t input, x = 7 , y = 7 , direction = 0 ;
358361 // direction 0 - undecided, 1-x, 2-y
359362
@@ -686,7 +689,7 @@ int game()
686689 if ((letters.size ()+emptyLettersOnHand (playerLetters[turn]))==0 )
687690 {
688691 // if all letters are used
689- return playerScore[0 ]<playerScore[1 ];
692+ return ( playerScore[0 ]!=playerScore[ 1 ]?(playerScore[ 0 ] <playerScore[1 ])+ 1 : 0 ) ;
690693 }
691694
692695 turn = !turn;
@@ -730,8 +733,16 @@ int game()
730733
731734 fillPlayerLetters (letters, playerLetters[turn]);
732735
736+ term_moveCursor (20 , 3 );
737+ cout << (letters.size ()+emptyLettersOnHand (playerLetters[turn]));
738+ if ((letters.size ()+emptyLettersOnHand (playerLetters[turn]))==0 )
739+ {
740+ // if all letters are used
741+ return (playerScore[0 ]!=playerScore[1 ]?(playerScore[0 ]<playerScore[1 ])+1 :0 );
742+ }
743+
733744 term_moveCursor (COORDSX (-2 ), COORDSY (-5 ));
734- cout << " " ;
745+ cout << " " ;
735746
736747 turn = !turn;
737748
@@ -747,11 +758,12 @@ int game()
747758 }
748759 term_moveCursor (COORDSX (x), COORDSY (y));
749760 }
750- return playerScore[0 ]<playerScore[1 ];
761+ return ( playerScore[0 ]!=playerScore[ 1 ]?(playerScore[ 0 ] <playerScore[1 ])+ 1 : 0 ) ;
751762}
752763
753764int main () // menu
754765{
766+ term_setCursorVisibility (0 );
755767init:
756768 term_init ();
757769
@@ -813,35 +825,49 @@ int main() // menu
813825 case ' 1' :
814826 {
815827 result = game ();
828+ term_setCursorVisibility (0 );
816829 break ;
817830 }
818831 case ' 3' :
819832 {
820833 term_clear ();
834+ Sleep (100 );
821835 term_moveCursor (term_maxx/2 -4 , term_maxy/2 -10 );
822836 cout << " Scrabble" ;
837+ Sleep (100 );
823838 term_moveCursor (term_maxx/2 -20 , term_maxy/2 -8 );
824839 cout << " The goal of the game is to get points" ;
840+ Sleep (100 );
825841 term_moveCursor (term_maxx/2 -20 , term_maxy/2 -7 );
826842 cout << " by using the letters you have. You win" ;
843+ Sleep (100 );
827844 term_moveCursor (term_maxx/2 -20 , term_maxy/2 -6 );
828845 cout << " when there are no more letters left." ;
846+ Sleep (100 );
829847 term_moveCursor (term_maxx/2 -20 , term_maxy/2 -5 );
830848 cout << " You can move only to tiles with letters" ;
849+ Sleep (100 );
831850 term_moveCursor (term_maxx/2 -20 , term_maxy/2 -4 );
832851 cout << " in or next to them. You can see your" ;
852+ Sleep (100 );
833853 term_moveCursor (term_maxx/2 -20 , term_maxy/2 -3 );
834854 cout << " hand below the playfield. During your" ;
855+ Sleep (100 );
835856 term_moveCursor (term_maxx/2 -20 , term_maxy/2 -2 );
836857 cout << " turn, you can do either:" ;
858+ Sleep (100 );
837859 term_moveCursor (term_maxx/2 -20 , term_maxy/2 -1 );
838860 cout << " 1. Place one or more letters to form" ;
861+ Sleep (100 );
839862 term_moveCursor (term_maxx/2 -20 , term_maxy/2 );
840863 cout << " one or more words" ;
864+ Sleep (100 );
841865 term_moveCursor (term_maxx/2 -20 , term_maxy/2 +1 );
842866 cout << " 2. Pass the turn and get zero points" ;
867+ Sleep (100 );
843868 term_moveCursor (term_maxx/2 -20 , term_maxy/2 +2 );
844869 cout << " 3. Exchange some letters for new ones" ;
870+ Sleep (100 );
845871 term_moveCursor (term_maxx/2 -20 , term_maxy/2 +3 );
846872 cout << " Good luck and have fun!" ;
847873 term_getch ();
@@ -852,16 +878,22 @@ int main() // menu
852878 term_clear ();
853879 term_moveCursor (term_maxx/2 -15 , term_maxy/2 -3 );
854880 cout << " Arrow keys - move on the field" ;
881+ Sleep (100 );
855882 term_moveCursor (term_maxx/2 -15 , term_maxy/2 -2 );
856883 cout << " Letter - choose / place a letter" ;
884+ Sleep (100 );
857885 term_moveCursor (term_maxx/2 -15 , term_maxy/2 -1 );
858886 cout << " Enter - calculate score" ;
887+ Sleep (100 );
859888 term_moveCursor (term_maxx/2 -15 , term_maxy/2 );
860889 cout << " Space - pass your turn" ;
890+ Sleep (100 );
861891 term_moveCursor (term_maxx/2 -15 , term_maxy/2 +1 );
862892 cout << " Ctrl-R - exchange letters" ;
893+ Sleep (100 );
863894 term_moveCursor (term_maxx/2 -15 , term_maxy/2 +2 );
864895 cout << " Backspace - return a letter" ;
896+ Sleep (100 );
865897 term_moveCursor (term_maxx/2 -15 , term_maxy/2 +3 );
866898 cout << " Ctrl-C - finish the game" ;
867899 term_getch ();
@@ -870,31 +902,34 @@ int main() // menu
870902 case ' 5' :
871903 {
872904 term_clear ();
873- term_moveCursor (term_maxx/2 -16 , term_maxy/2 -2 );
874- cout << " Scrum Leader - SAKostin" ;
905+ term_moveCursor (term_maxx/2 -20 , term_maxy/2 -2 );
906+ cout << " Scrum Leader - SAKostin" ;
875907 Sleep (200 );
876- term_moveCursor (term_maxx/2 -16 , term_maxy/2 -1 );
908+ term_moveCursor (term_maxx/2 -20 , term_maxy/2 -1 );
877909 cout << " Backend Developer - SVRomanchenko" ;
878910 Sleep (200 );
879911
880- term_moveCursor (term_maxx/2 -16 , term_maxy/2 +1 );
912+ term_moveCursor (term_maxx/2 -20 , term_maxy/2 +1 );
881913 cout << " Frontend Developer - OVBondarenko" ;
882914 Sleep (200 );
883- term_moveCursor (term_maxx/2 -16 , term_maxy/2 +2 );
884- cout << " Designer - SAChapkina" ;
915+ term_moveCursor (term_maxx/2 -20 , term_maxy/2 +2 );
916+ cout << " Designer - SAChapkina" ;
885917 term_getch ();
886918 goto init;
887919 }
888920 default :
889921 {
890922 term_deinit ();
923+ term_setCursorVisibility (1 );
891924 return 0 ;
892925 }
893926 }
894927
895928 term_deinit ();
929+ term_setCursorVisibility (1 );
896930
897- cout << " Player " << result+1 << " won!\n " ;
931+ if (result) cout << " Player " << result << " won!\n " ;
932+ else cout << " Tie!\n " ;
898933 term_getch ();
899934 return 0 ;
900935}
0 commit comments