Can life be like a program?
Sunday, 15. March 2009, 14:10:11
Program Life Basics; // Can life be like a program? Let's see!
Uses
LifeLib;
Var
Food, Sleep, Water As Needs;
Happiness As LifeStrength;
Love As SomethingNeeded(4);
Age, Death As Integer;
Junction Person
Begin
Health As Status;
End;
Const
GotoSchool;
Work;
StayInHome;
Begin
Death := Random(100); // We all know that the death is random.
Happiness := 2 + Random(5); // Happiness is random too.
Do
// Should I go to school, to work or stay in home?
If (Age < 18) Then
GotoSchool;
Else If (Age < 50)
GotoWork;
Else
StayInHome;
End;
// Let's try to survive...!
If Not Food Then
Person.Health := False
Happiness := Happiness - 2
Else
Happiness := Happiness + 5
End;
If Not Water Then
Person.Health = False
Happiness := Happiness - 2
Else
Happiness := Happiness + 5
End;
If Not Sleep Then
Person.Health := False
Happiness := Happiness - 2
Else
Happiness := Happiness + 5
End;
// Let's put some love in the game.
Read(Love);
Select Case (Love)
0 : Happiness := Happiness - 20; Break;
1 : Happiness := Happiness - 10; Break;
2 : Break;
3 : Happiness := Happiness + 10; Break;
4 : Happiness := Happiness + 15; Break;
End Case;
// Happy?
If (Happiness < -10) Then
Death := 0 // Suicide...
Else If (Happiness < 3) Then
Person.Health := False // Get Sick...
Else If (Happiness > 80) Then
Death := Death + 1 // Live longer!
Happiness := Happiness - 20
End;
// Am I sick?
If Not Person.Health Then
Hospital
End;
// Wow, time is going too fast!! A year has passed.
Age := Age + 1
While (Age <= Death);
// Oops... Game Over.
Write('Memento Mori...');
Readkey;
Write('Game Over');
End.
Procedure Hospital
Var
Methods As GoodOrBad;
Begin
// Can I be saved?
If (Methods = Good) Then
Happiness := Happiness + 2
Death := Death - 1
Else If (Methods = Bad) Then
Happiness = Happiness - 2
Death := Death - 5
End;
End;
Liệu ... cuộc sống có giống 1 chương trình?
Không! Cuộc sống của mình đang và sẽ không đơn giản như đoạn code chưa đến 200 dòng này!














Anonymous # 15. March 2009, 14:43
anh Tuấn tự viết hay copy paste ở đâu mà nhiều bài hay thế ^^.Hơi hâm mộ đó :d
Phạm Minh Tuấn # 15. March 2009, 14:49
Copy, paste hay tự viết thì quan trọng gì.
Quan trọng là làm sao để thể hiện ra cho mọi người cảm thấy hay thôi
Rear # 22. March 2009, 05:46
Sai # 31. March 2009, 04:25
đoạn này hình như còn thiếu ?
Phạm Minh Tuấn # 31. March 2009, 12:53
Anonymous # 7. April 2009, 02:40
có ai chạy thử, xem nó ra cái gì nhỉ? hihi :D