Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help Making Battles
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Presto81




PostPosted: Mon Dec 19, 2016 10:53 am   Post subject: Help Making Battles

What is it you are trying to achieve?
Trying to make a battle template for later use, but it's really one-sided right now. need help making a turn-based battle, so the monster will fight back.


What is the problem you are having?
I only know how to make the monster exist and stand there. The only way I could make it fight back is if I programmed it to do so when I said so, and I want it to fight on it's own.

Here's some code that I had help with earlier. I need the monster to do something other than 'stand robotically.'





Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
%Attack simulator
var monsterHP:nat:=6
var monstermaxHP:int:=6
var monsterNAME:string:= "TEST MONSTER 01"

var attack:boolean
var damage:int:=2

put monsterNAME, " approaches."
loop
put "Shall you attack? true/false"
get attack
if attack= true then
put "You stabbed TEST MONSTER 01."
put monsterNAME, " is at ", monsterHP-2, "/", monstermaxHP
monsterHP:=monsterHP-2
end if
if attack= false then
put monsterNAME, " stands robotically."
end if
exit when monsterHP=0
end loop
put "You win!"

Turing:


<Add your code here>



Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Mon Dec 19, 2016 11:32 am   Post subject: RE:Help Making Battles

You're asking how to write an AI, which can be as simple or as complicated as you want, but before you can do anything, you need to define how you want your monster to behave. Do you want it to attack every turn? Does it have a variety of attacks or just one? Can it move? You can't program an AI without first knowing how you want it to behave.

As far as 'making it do stuff', that's really just changing variables and animation. To attack, you animate an attack, and take away some of the player's health.

I suggest you keep everything to do with player input separate from the AI. It should look something like this:

loop
%player stuff
choose action (ie get input)
play animation
apply damage
%end turn

%computer turn
choose action (apply AI)
play animation
apply damage
%end turn
end loop

Notice that the code for the player and the computer are almost exactly the same. The only difference is how they choose the action- the player inputs from the keyboard, and the AI chooses based on how you program it. Could be 'attack every time', could be 'flee if hp < 10, otherwise attack', or 'if mana > 5 then superattack, otherwise regular attack'. That's all up to you.
Presto81




PostPosted: Mon Dec 19, 2016 7:08 pm   Post subject: RE:Help Making Battles

Thanks. Currently I'm experimenting with text-based fights so I can make more complex things later. I'm planning on using a turn-based model. I'm looking for how to make different turns specifically so I can have the monster damage the player, or choose what to do based on current status.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: