Well, I’m working on a little game that I used to play with my cousins when I was 12. It is a game normally played with hands but I decided to make the same game to play against the computer. The game is played that you choose, shoot, block or reload. If you shoot, while they are reloading, they lose one life, you lose a bullet (and they gain one), if they block your shot, nothing happens (except you are down 1 bullet), if you shoot each other you both lose a life and a bullet, and it goes on. You get 5 lives. I’m not quite finished the script yet, but what I have so far should still work. I don’t know why I am getting [an] error.
property player_ammo : 1
property cpu_ammo : 1
property player_lives : 5
property cpu_lives : 5
on activated theObject
set player_name to text returned of (display dialog "Please enter your name" default answer "") as string
set the contents of text field "player_name" of window "mainWindow" to player_name
end activated
on clicked theObject
tell window "mainWindow"
set the contents of text field "player_lives" of box "playerlives_box" to player_lives as string
set the contents of text field "cpu_lives" of box "cpulives_box" to cpu_lives as string
set the contents of text field "player_ammo" of box "playerlives_box" to player_ammo as string
set the contents of text field "cpu_ammo" of box "cpulives_box" to cpu_ammo as string
end tell
if cpu_ammo is greater than 0 then
set sbr_list to {"Shoot", "Block", "Reload"}
set the list_count to the count of sbr_list
set pick to random number from 1 to list_count
set cpu_choice to item pick of sbr_list as string
else
set sbr_list to {"Block", "Reload"}
set the list_count to the count of sbr_list
set pick to random number from 1 to list_count
set cpu_choice to item pick of srb_list as string
if player_ammo is greater than 0 then
set enabled of button "shoot_button" of window "mainWindow" to true
else
set enabled of button "shoot_button" of window "mainWindow" to false
end if
if the name of theObject is equal to "shoot_button" and cpu_choice is equal to "Shoot" then
set player_ammo to player_ammo - 1
set cpu_ammo to cpu_ammo - 1
set player_lives to player_lives - 1
set cpu_lives to cpu_lives - 1
set the contents of text field game_text of window "mainWindow" to "You shot each other!"
else if the name of theObject is equal to "shoot_button" and cpu_choice is equal to "Block" then
set player_ammo to player_ammo - 1
set the contents of text field game_text of window "mainWindow" to "Bullet was blocked!"
else if the name of theObject is equal to "shoot_button" and cpu_choice is equal to "Reload" then
set player_ammo to player_ammo - 1
set cpu_ammo to cpu_ammo + 1
set cpu_lives to cpu_lives - 1
set the contents of text field game_text of window "mainWindow" to "That's a hit!"
else if the name of theObject is equal to "block_button" and cpu_choice is equal to "Shoot" then
set cpu_ammo to cpu_ammo - 1
set the contents of text field game_text of window "mainWindow" to "You blocked his shot!"
else if the name of theObject is equal to "block_button" and cpu_choice is equal to "Block" then
set the contents of text field game_text of window "mainWindow" to "Both of you blocked!"
else if the name of theObject is equal to "block_button" and cpu_choice is equal to "Reload" then
set cpu_ammo to cpu_ammo + 1
set the contents of text field game_text of window "mainWindow" to "You blocked, but he reloaded!"
else if the name of theObject is equal to "reload_button" and cpu_choice is equal to "Shoot" then
set cpu_ammo to cpu_ammo - 1
set player_ammo to player_ammo + 1
set player_lives to player_lives - 1
set the contents of text field game_text of window "mainWindow" to "You were shot!"
else if the name of theObject is equal to "reload_button" and cpu_choice is equal to "Block" then
set player_ammo to player_ammo + 1
set the contents of text field game_text of window "mainWindow" to "You reloaded, but he blocked!"
else if the name of theObject is equal to "reload_button" and cpu_choice is equal to "Reload" then
set cpu_ammo to cpu_ammo + 1
set player_ammo to player_ammo + 1
set the contents of text field game_text of window "mainWindow" to "You both reloaded!"
end if
end if
end clicked
on should quit after last window closed theObject
return true
end should quit after last window closed
on idle theObject
tell window "mainWindow"
set the contents of text field "player_lives" of box "playerlives_box" to player_lives as string
set the contents of text field "cpu_lives" of box "cpulives_box" to cpu_lives as string
set the contents of text field "player_ammo" of box "playerlives_box" to player_ammo as string
set the contents of text field "cpu_ammo" of box "cpulives_box" to cpu_ammo as string
end tell
end idle
on awake from nib theObject
tell window "mainWindow"
set the contents of text field "player_lives" of box "playerlives_box" to player_lives as string
set the contents of text field "cpu_lives" of box "cpulives_box" to cpu_lives as string
set the contents of text field "player_ammo" of box "playerlives_box" to player_ammo as string
set the contents of text field "cpu_ammo" of box "cpulives_box" to cpu_ammo as string
end tell
end awake from nib