Sunday, January 25, 2015

here is another program that i wrote when im bored, i created a F.L.A.M.E.S game using Java, if you don't know how to play with it, just take a look with this simple guide for you to know the basics of this game, and on the other hand, you can formulate your own logic and find some ways to improve this code. How to FLAMES

and to keep the ball rolling, here is my simple code;

package teamUndefined;

import java.io.*;

public class Flames {
   
    public static void main(String[] args)throws IOException{
       
        String[] _fName, _sName;   
        BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
       
        String[][] _flames = {{"F","Friends"},{"L","Lovers"},
                    {"A","Acquaintance"},{"M","Married"},{"E","Enemies"},{"S","Sweethearts"}};       
       
        String _fn, _sn;
       
        System.out.print("FLAMES throwback 90's\nEnter Name: ");   
        _fn = buff.readLine().toUpperCase().replace(" ", "");
       
        System.out.print("Enter Crush Name: ");   
        _sn = buff.readLine().toUpperCase().replace(" ", "");
       
/*setting array size*/
        _fNamenew String[_fn.length()];       
        _sName = new String[_sn.length()];
       
/*filling-up array*/
        for (int i = 0; i < _fn.length(); i++) {
            _fName[i] =_fn.substring(i, i + 1);
        }
        for (int i = 0; i < _sn.length(); i++) {
            _sName[i] = _sn.substring(i, i + 1);
        }       
/*comparing from F.L.A.M.E.S letters*/
        int _resA = 0, _resB = 0;       
        for (int i = 0; i < _fName.length; i++) {
            for (int j = 0; j < _flames.length; j++) {
                if (_fName[i].equals(_flames[j][0])) {               
                    _resA++;                   
                }
            }
        }                   
        int _x = (_fn.length() - _resA);
        for (int i = 0; i < _sName.length; i++) {
            for (int j = 0; j < _flames.length; j++) {
                if (_sName[i].equals(_flames[j][0])) {               
                    _resB++;               
                }
            }
        }           
/*iterating on F.L.A.M.E.S*/
        int _y = (_sn.length() - _resB) , _flamesRes = 0;           
        for (int i = 0; i < (_y + _x); i++) {                   
            if (_flamesRes == 5) {               
                _flamesRes = 0;
            }           
            else{
                _flamesRes++;
            }
        }               
/*Displaying the results*/
        System.out.print("Result: ".concat(_flames[_flamesRes][1]));   
    }   
}

i hope that you enjoy playing with F.L.A.M.E.S, and hoping to improve this code, like to shorten it, adding some functions, since theres a lot of repeated loops there, with the-same process, although its not the-same result  but the structure is similar. ENJOY



0 comments:

Post a Comment