The scientific field of Artificial Intelligence is trying to do just that- build rational agents that can infer, reason and act like humans. Computers have already defeated humans in the game of chess. Intelligent agents in software, intelligent robots for assistance are being developed and improved. Oral-B cross action toothbrush was invented by a computer software called Creativity Machine. Similarly, intelligent software is being used to invent many new things and solve various problems- it is the age of Artificial Invention. Robots are also being trained to guess the emotions of people around from their facial expression, body language and such other characteristics that may reveal your mood/attitude. Imparting emotions to software/robots will be the next step. If the machines derive a consciousness because of memory, intelligence and emotions, we never know what they might do- they would be completely autonomous beings- equipped with all the know-how and resources- Maybe they will feel suppressed by the inferior human beings who treat them like slaves- maybe they will become ambitious and greedy and feel like becoming the masters of the universe… Anything is possible in that scenario.. Will humans win in the war? I would say if we reach a point where machines will rise against us, that itself would be an utterly frightening moment! Watch movies like Matrix, Terminator and Transformers for further details :P
Artificial Intelligence movie by Steven Spielberg is also an interesting alternative take on this issue- its about the bond between humans and emotional robots rather than enemy machines seeking to overpower humanity.