Androne

Monday, December 04, 2006

Long tiring weekless week

met teddy after sch on fri b4 cg. kinda missed most of e cg..but im glad he came :) and thanks bro for the cab lift home after dat XD

ive not had the mood to blog lately too..

dat day after cg, something struck me which im not gonna talk about. its so obvious...

u mean u didnt know? but its so obvious? but u dont know abt it? thats the point..=/

its pretty rare for me to get angry..in fact..i dont even think anyone has seen me angry. or even see me with 'attitude'. cus im a man of a few words and i dont express myself completely, im a 'filtered expressor' if i can put it tt way.

for someone with high tolerance like me, its hard to actually get angry. but sometimes the hurt is so much that it turns into anger and a volcano erupts inside. tts wad been happening for days. it accumulates. i dont want to burn people so i end up burning myself.

sat service was great. but i wasnt feeling normal for that day. i was still struggling. it felt as if i lost everyone, and that every bond was severed, broken and gone. it felt as if i had to start from scratch again..

today PM was great..then after that a similar incident happened again. i think im confusing u guys. good...=/

didnt sleep at all last night..i couldnt afford to be late for class this morning at 9. i know im overdoing it, but im desperately tired. id rather fail than to get debarred. didnt sleep for 40hours now..

and guess what happened..when i reached class at 850am. class started at 915 cus wait for latecomers then mark attendance. class ended at 940am!! wth man. make me have a sleepless night so that i can be early and u frigging dismiss us after like 20 minutes? whack u ah.

did e-learning tutorial after tt, then went home. bored to death man! common test coming and i cant stand it. i hate fixing things, id rather replace them. urrgh. so disgusting! was talking to LP on the phone for like an hour i think. talking abt what im gd at talking best.."CRAP"...=/

then, not surprised, i dozed off..and missed DSA class AGAIN! dang i think im gonna get another DB letter =/ thats 3..:O

i miss sec sch..those days when i would go LANshops with my frens..those were e most fun times. everyday talk to the comp, at home also talk to e comp. in class also talk to e comp.

yes i have no social life and do you think i care? no i dont actually. ive been 'trained' for 3 years to live a life with me and my comp. 3 years of java...its worse than 10 years of amaths!!!!!! id rather have 10 years of amaths than 3 years of frickin java..so sucky. at least amaths every thing is different and exciting..

java is different..yes..but still, its still java. worse if u have a teacher that talks like a compiler. =/ the moment he open his mouth:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.text.*;
import java.net.*;

class TeachCrap extends JFrame implements CrappyMouth {

System.out.println("I am crap. Hear my crap and be crapped.");

...

heck i dont even wanna continue..=/

fine..you want codes? ill give you codes!


// TicTacToe - GUI Version
import javax.swing.*;import java.awt.*;import java.awt.event.*;
public class TicTacToe extends JFrame implements ActionListener { private JButton[][] cells = new JButton[3][3]; private JLabel header; private JLabel status; private JButton newButton; private JPanel panel1, panel2, panel3; private String player = "X"; // constructor public TicTacToe() { Container c = getContentPane(); c.setLayout(new BorderLayout());
// Panel 1 - to display the header panel1 = new JPanel(); header = new JLabel("Tic Tac Toe"); panel1.add(header); c.add(panel1, BorderLayout.NORTH);
// Panel 2 - to dislay the game (board) JPanel panel2 = new JPanel(); panel2.setLayout(new GridLayout(3,3)); panel2.setLayout(new GridLayout(3,3)); for (int row=0; row<3; row++) for (int col=0; col<3; col++) { cells[row][col] = new JButton(""); cells[row][col].addActionListener(this); panel2.add(cells[row][col]); } c.add(panel2, BorderLayout.CENTER);
// Panel 3 - to dislay status amd new game button panel3 = new JPanel(); panel3.setLayout(new BorderLayout()); status = new JLabel("Welcome! 'X' starts first"); newButton = new JButton("New Game"); newButton.setVisible(false); newButton.addActionListener(this); panel3.add(status, new BorderLayout().CENTER); panel3.add(newButton, new BorderLayout().EAST); c.add(panel3, BorderLayout.SOUTH); }
/* * When a player makes a move, the program need to : * 1. Update the cell * 2. Check the result * 3. Check if the board is full * 4. Proceed to next player if game not over */ public void actionPerformed(ActionEvent e) { JButton currentButton = (JButton) e.getSource(); if (currentButton == newButton) // new game { resetGame(); status.setText("New game "); } else // a new move { updateMove(currentButton); // 1. update move if ( isWon(player) ) // 2. check the result { status.setText(player + " wins"); disableButtons(); newButton.setVisible(true); } else if ( isFull() ) // 3. check if board is full { status.setText("The board is full, game over!"); disableButtons(); newButton.setVisible(true); } else // 4. proceed to next player { if (player.equals("X")) player = "O"; else player = "X"; status.setText(player + "'s turn."); } } } // method to update move public void updateMove(JButton currentButton) { currentButton.setText(player); // update cell currentButton.setEnabled(false); // disable button }
// method to check if the current player wins public boolean isWon(String token) { // check the rows for (int r=0; r<3; r++) if ( (cells[r][0].getText().equals(token)) && (cells[r][1].getText().equals(token)) && (cells[r][2].getText().equals(token))) return true; // check the columns for (int c=0; c<3; c++) if ((cells[0][c].getText().equals(token)) && (cells[1][c].getText().equals(token)) && (cells[2][c].getText().equals(token))) return true;
// check forward diagonal if ((cells[0][0].getText().equals(token)) && (cells[1][1].getText().equals(token)) && (cells[2][2].getText().equals(token))) return true;
// check backward diagonal if ((cells[0][2].getText().equals(token)) && (cells[1][1].getText().equals(token)) && (cells[2][0].getText().equals(token))) return true;
return false; }
// method to check if a the board is full public boolean isFull() { for (int i=0; i<3; i++) for (int j=0; j<3; j++) if ( cells[i][j].getText().equals("") ) return false; return true; } // method to reset the game public void resetGame() { for (int r=0; r<3; r++) for (int c=0; c<3; c++) cells[r][c].setText("");
enableButtons(); player = "X"; status.setText("Welcome! 'X' starts first"); }
// method to enable the buttons public void enableButtons() { for (int i=0; i<3; i++) for (int j=0; j<3; j++) cells[i][j].setEnabled(true); } // method to disable the buttons public void disableButtons() { for (int i=0; i<3; i++) for (int j=0; j<3; j++) cells[i][j].setEnabled(false); } public static void main(String[] args) { TicTacToe frame = new TicTacToe(); frame.setTitle("TicTacToe"); frame.setSize(300, 320); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }}

yes its a tictactoe game and it works! i jus copy and paste frm my practicals. i didnt even bother to do the paragraph lining and indents! and oh..its one of the 'simple and SMALLEST' programs!

hope you love and appreciate java...

because if you dont..

congratulations! you're normal =

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]



<< Home