Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program hello
- implicit none
- character, allocatable :: table(:,:)
- integer :: n,a,b,player
- logical :: process
- logical :: player_win
- !
- write (*,'(a$)') 'Enter the size of the field:'
- read (*,*) n
- allocate(table(n,n))
- table(:,:) = '-'
- process = .true.
- player = 1
- !
- do while(process)
- if (player_win(table)) then
- write (*,'(a,1x,i1,1x,a)') 'Congrats! Player', player, 'won!'
- exit
- else
- do while (.true.)
- write (*,'(a,1x,i1,1x,a)') 'Player',player,'walks'
- write (*,'(a$)') 'Enter a row: '
- read (*,'(i5$)') a
- write (*,'(a$)') 'Enter a column: '
- read (*,'(i5$)') b
- if ( (.not.((a<=n).and.(1<=a))) .or. (.not.((b<=n).and.(1<=b))) ) then
- write (*,*) 'Enter the correct value!'
- cycle
- else if ( (table(a,b) == '0') .or. (table(a,b) == 'x') ) then
- write (*,*) 'Enter the correct value!'
- cycle
- else
- exit
- end if
- end do
- if (player == 1) then
- table(a,b) = 'x'
- player = 2
- else
- table(a,b) = '0'
- player = 1
- end if
- call draw(n,table)
- end if
- end do
- deallocate(table)
- end program
- subroutine draw(r,table_2)
- integer :: r, i, j, m
- character :: table_2(r,r)
- !
- do m =1,r
- if (m /= r) then
- write (*,'(1x,i2$)') m
- else
- write (*,'(1x,i2)') m
- end if
- end do
- do i =1,r
- do j =1,r-1
- write (*,'(2x,a$)') table_2(i,j)
- end do
- write (*,'(2x,a,1x,i2)') table_2(i,r), i
- end do
- end subroutine
- logical function player_win(table_3)
- player_win = .false.
- end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement