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[Read more in the instructions]
== 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
...
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.
- Cham Hin Cheung: Java - Programming
- Chau Chung Yin: 不雨錄
- Ching Ho Yee: Works Portfolio
- Chu Ming Hei: http://tonycmh.blogspot.com
- Chu Po Ling: java_share_area's Xanga Site
- Fung Ting Pong: Fungtingpong’s Weblog
- Ho Ka Wai: Tom Ho's Program Blog
- Ieong Weng Tat: Testplayer (小字頭)
- Lau Wing Lok: CIT
- Law Mei Kwan: Likefunny2007’s Weblog
- Lee Cornwall: Lee Cornwall
- Lok Hey Young: http://lokhy-ism001.blogspot.com
- Ng Ho Lam: ngholam2007's Xanga Site
- Pang Wing In: Joey Pang’s Weblog
- Tsoi Chung Him: Yworkshop’s Weblog
- Wu Po Yu: Drara's Weblog