Friday, October 19, 2007

Text Fighter

Programming is fun, especially when programming games. Yet game programming often involves advanced graphics and complicated techniques, making it formidable to beginners.

So here comes the Text Fighter, the first homework assignment for our junior programmers in our introductory Java programming course ISM001. It is text-based with no fancy graphics at all, but (I hope) students still find it funny and inspiring.

The rules: [Read full text]

There are two players, each with an initial power of 100. One player attacks the other. The winner, determined by random, receives the difference between the power of the players before the attack. The loser, on the other hand, loses the same amount. If the difference is zero before the attack (i.e. both players have the same power), then use 1 as the difference. The process is repeated until one player is dead, which occurs when the power becomes negative. End the game and display the power of all the users.

Sample output:

Java Simple Text Fighter! v20070928

== Round 1 ==
Player Ho Yin's power = 100
Player Justin's power = 100
Justin attacks Ho Yin!
Justin wins
== Round 2 ==
Player Ho Yin's power = 99
Player Justin's power = 101
Justin attacks Ho Yin!
Justin wins
...
[Read more in the instructions]

Two players are not funny enough, so I've also included a challenge to add more players with human and computer interaction.

My works:

The simple Text Fighter:
Player.java: http://pastebin.ca/742515
How to run:
Compile the file (javac Player.java) and run it (java Player).

The advanced Text Fighter with 4 players:
TextFighter.java: http://pastebin.ca/739752
Player.java: http://pastebin.ca/739756
How to run:
Compile both files (javac *.java) and run TextFighter.java (java TextFighter).
Sample output: http://docs.google.com/Doc?id=dgn28fpv_64c6rhrx

You may also download all the source code as a zip file.

Students' works (ordered by last name):

I asked the students to put their works in a programming portfolio. Feel free to comment.
  1. Cham Hin Cheung: Java - Programming
  2. Chau Chung Yin: 不雨錄
  3. Ching Ho Yee: Works Portfolio
  4. Chu Ming Hei: http://tonycmh.blogspot.com
  5. Chu Po Ling: java_share_area's Xanga Site
  6. Fung Ting Pong: Fungtingpong’s Weblog
  7. Ho Ka Wai: Tom Ho's Program Blog
  8. Ieong Weng Tat: Testplayer (小字頭)
  9. Lau Wing Lok: CIT
  10. Law Mei Kwan: Likefunny2007’s Weblog
  11. Lee Cornwall: Lee Cornwall
  12. Lok Hey Young: http://lokhy-ism001.blogspot.com
  13. Ng Ho Lam: ngholam2007's Xanga Site
  14. Pang Wing In: Joey Pang’s Weblog
  15. Tsoi Chung Him: Yworkshop’s Weblog
  16. Wu Po Yu: Drara's Weblog
That's all. Enjoy the fighting!

No comments: