Hey,
If don't know anything about tennis you will hate this snippet, and I hope it's okay to post something here that is over 200 lines too!
Anyway, I'm all hyped about the French Open and Wimbledon tennis tourneys. I made this program to simulation a match between 2 randomly picked tennis players. (Like Roger Federer and Andy Murray) Don't get to excited. All it shows is just the score as if you were watching the scoreboard of a real match with no TV.
I think it follows pretty much all the rules of tennis scoring. Except there is no tiebreakers. But the players still have to win each set by 2 games.
I've speed the game speed up a little so it doesn't take hours to finish one match. You can slow it down or speed it up by changing the "speed" variable on line 6 if you want.
`Tennis Scoreboard
`Daygamer (I'm excited about the French Open right now)
`Saturday, May 29, 2010
`set speed (the smaller the number the faster the program)
speed = 1000
`players
dim player$(10)
player$(1)="#1 Roger Federer"
player$(2)="#2 Refeal Nadal"
player$(3)="#3 Novak Djokovic"
player$(4)="#4 Andy Murray"
player$(5)="#5 Nikolay Davydenko"
player$(6)="#6 Juan Martin del Potro"
player$(7)="#7 Robin Soderling"
player$(8)="#8 Andy Roddick"
player$(9)="#9 Fernando Verdasco"
player$(10)="#10 Jo-Wilfried Tsonga"
`set up set score data
dim set_score1(5)
dim set_score2(5)
`set the program which players will be playing
player1 = rnd(9)+1
player2 = rnd(9)+1
`the player_skill varible (0-100) will detirmine the percentage that the player will win a point on their own serve
if player1 = 1 then player_skill1 = 70
if player1 = 2 then player_skill1 = 69
if player1 = 3 then player_skill1 = 67
if player1 = 4 then player_skill1 = 66
if player1 = 5 then player_skill1 = 64
if player1 = 6 then player_skill1 = 63
if player1 = 7 then player_skill1 = 62
if player1 = 8 then player_skill1 = 62
if player1 = 9 then player_skill1 = 61
if player1 = 10 then player_skill1 = 61
if player2 = 1 then player_skill2 = 70
if player2 = 2 then player_skill2 = 69
if player2 = 3 then player_skill2 = 67
if player2 = 4 then player_skill2 = 66
if player2 = 5 then player_skill2 = 64
if player2 = 6 then player_skill2 = 63
if player2 = 7 then player_skill2 = 62
if player2 = 8 then player_skill2 = 62
if player2 = 9 then player_skill2 = 61
if player2 = 10 then player_skill2 = 61
`tell the program to start in the first set
current_set = 1
`select one of the players to start the serve with
serve = rnd(1)+1
`set up text data
set text size 20
set text font "arial"
set text to bold
do
gosub screen_display
sync
gosub randomize_point
loop
`screen display
screen_display:
`detirmine the point length
point_length = rnd(speed)+speed/4
do
cls
box 0,0,640,480,rgb(0,192,255),rgb(255,255,255),rgb(255,255,255),rgb(0,192,255)
ink 0,0
line 80,200,560,200
line 80,250,560,250
line 80,300,560,300
line 80,200,80,300
line 560,200,560,300
line 300,200,300,300
line 360,200,360,300
line 400,200,400,300
line 440,200,440,300
line 480,200,480,300
line 520,200,520,300
`screen text
`print the players' name
if game_set_match = 1 then ink RGB(255,0,0),0
set cursor 110,215
print player$(player1)
ink 0,0
if game_set_match = 2 then ink RGB(255,0,0),0
set cursor 110,265
print player$(player2)
ink 0,0
`print the score of the current game
if game_set_match = 1 then ink RGB(255,0,0),0
set cursor 320,215
print game_score1
ink 0,0
if game_set_match = 2 then ink RGB(255,0,0),0
set cursor 320,265
print game_score2
ink 0,0
`print the score of the set
if game_set_match = 1 or game_set_match = 2 then dec current_set
if game_set_match = 1 then ink RGB(255,0,0),0
set cursor 375,215
if current_set >= 1 then print set_score1(1)
set cursor 415,215
if current_set >= 2 then print set_score1(2)
set cursor 455,215
if current_set >= 3 then print set_score1(3)
set cursor 495,215
if current_set >= 4 then print set_score1(4)
set cursor 535,215
if current_set >= 5 then print set_score1(5)
ink 0,0
if game_set_match = 2 then ink RGB(255,0,0),0
set cursor 375,265
if current_set >= 1 then print set_score2(1)
set cursor 415,265
if current_set >= 2 then print set_score2(2)
set cursor 455,265
if current_set >= 3 then print set_score2(3)
set cursor 495,265
if current_set >= 4 then print set_score2(4)
set cursor 535,265
if current_set >= 5 then print set_score2(5)
ink 0,0
if game_set_match = 1 or game_set_match = 2 then inc current_set
`tell who's serving
if game_set_match = 1 then ink RGB(255,0,0),0
if serve = 1 then circle 95,225,5
ink 0,0
if game_set_match = 2 then ink RGB(255,0,0),0
if serve = 2 then circle 95,275,5
ink 0,0
`print stuff like "Break Point" below the scoreboard at the correct time
if serve = 1 and game_score1 < 40 and game_score2 = 40 then set cursor 100,300 : print "Break Point"` : wait key
if serve = 2 and game_score2 < 40 and game_score1 = 40 then set cursor 100,300 : print "Break Point"` : wait key
if game_set_match = 1 or game_set_match = 2 then wait key : end
`wait for a while to make it seem like the point is being played out
count = count+1
if count = point_length
count = 0
exit
endif
sync
loop
return
`give one of the players a point.
randomize_point:
`make one of the players get a point
`(I will have to do some weird stuff because the tennis point system goes (0,15,30,40,game)(Crazy! but I love it!)
point_number = rnd(100)
if serve = 1
if point_number < player_skill1 then point_winner = 1 else point_winner = 2
endif
if serve = 2
if point_number < player_skill2 then point_winner = 2 else point_winner = 1
endif
`if player 1 wins point
if point_winner = 1
if game_score1 = 0 or game_score1 = 15
inc game_score1, 15
return
endif
if game_score1 = 30
inc game_score1, 10
return
endif
if game_score1 = 40
`if deuce (score is 40-40)
if game_score2 = 40
game_score2 = 30
return
endif
`since the player has won this game increase their score in the set
inc set_score1(current_set)
`if the set if over then move to the next set
if set_score1(current_set) > 5 and set_score1(current_set) > set_score2(current_set)+1
inc current_set
inc sets_won1
`when someone wins!
if sets_won1 = 3 then game_set_match = 1 : return
endif
`reset the score of the game
game_score1 = 0
game_score2 = 0
`change the server
if serve = 1 then inc serve else dec serve
return
endif
endif
`if player 2 wins point
if point_winner = 2
if game_score2 = 0 or game_score2 = 15
inc game_score2, 15
return
endif
if game_score2 = 30
inc game_score2, 10
return
endif
if game_score2 = 40
`if deuce (score is 40-40)
if game_score1 = 40
game_score1 = 30
return
endif
`since the player has won this game increase their score in the set
inc set_score2(current_set)
`if the set if over then move to the next set
if set_score2(current_set) > 5 and set_score2(current_set) > set_score1(current_set)+1
inc current_set
inc sets_won2
`when someone wins!
if sets_won2 = 3 then game_set_match = 2 : return
endif
`reset the score of the game
game_score1 = 0
game_score2 = 0
`change the server
if serve = 1 then inc serve else dec serve
return
endif
endif
return
P.S.
Go Roger Federer in the French! (Good luck to Andy Murray who probably most coders here like because he's British)
Have a nice day, God Bless You!