Jump to content

I need a big favor with project for college

Okay i just needed to know if its possible in such way so i can find which part is failling apart there >.>... So lets say i have 2 timers one that is for all the fight and if he runs out the game is lost ofc after couple of tweaks . and there second timer that is for turns . so once every 40 sec for now the computer should make its move but i cant add method of the move to the timer cuz it requires a varriable that inside main body and class that is created in the main body too also that method uses this switch for a random move . Only what i manage to do is add in timer message and when i created in main body if with same argument as in timertask it does not work :S. And about debug yes i know kinda now how to use it so my while loop is working better and game can be beaten :P.

 

class Koniec_tury{     int tura_user = 0;           Scanner enterpress = new Scanner(System.in);     String enter ;    Timer tura_jedi = new Timer();    TimerTask koniectury = new TimerTask(){            public void run(){                       tura_user ++;            if (tura_user>=40){        System.out.println("tura rycerz sith");                tura_user =0;                    }        }    };    public  void start (){         tura_jedi.scheduleAtFixedRate(koniectury,1000,1000);    }}//timer for the turns  if (userturn.tura_user>=40){             LordVader.randommove(zycie);     }// if that should call method that makes computer a random move//its above this codeSystem.out.println("Zycie przeciwnika "+LordVader.zyciesith + "           " +" Mana "+ LordVader.manasith +"\n"+"\n"+"\n"+"\n"+"\n"+"\n"+"\n");                         System.out.println("twoje zycie "+zycie+"    "+"twoja mana " +mana +"\n");    System.out.println("Wybierz swoj ruch");    System.out.println("1. Podstawowy atak");    System.out.println("2. Podwojne ciecie mieczem");    System.out.println("3. uzycie umiejetnosci "+ userJedi.umiejetnosc);        b=user_input.nextInt();//and under switch that has player moves 

CPU i5 6600k 4,4Ghz , COOLER Dark Rock 3 from BQ, RAM 16 GB of ddr 4 2800MHz from corsair,

 PSU EVGA 750 W GOLD G2, MOBO Msi z170A Gaming M3, CASE NZXT H440 Black/Blue,

GPU Geforce GTX 980 Gigabyte G1 Gaming,

STORAGE 1 SSD Samsung 850 Evo 250 GB and 1 HDD 500GB WD, Windows 8.1.

Link to comment
Share on other sites

Link to post
Share on other sites

Okay i just needed to know if its possible in such way so i can find which part is failling apart there >.>... So lets say i have 2 timers one that is for all the fight and if he runs out the game is lost ofc after couple of tweaks . and there second timer that is for turns . so once every 40 sec for now the computer should make its move but i cant add method of the move to the timer cuz it requires a varriable that inside main body and class that is created in the main body too also that method uses this switch for a random move . Only what i manage to do is add in timer message and when i created in main body if with same argument as in timertask it does not work :S. And about debug yes i know kinda now how to use it so my while loop is working better and game can be beaten :P.

 

So to try to summarize and put this more concisely: You're not sure how to share state between threads in Java?

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

So to try to summarize and put this more concisely: You're not sure how to share state between threads in Java?

propably not. In javascript there were protocols or smth like that when you could make variable it could be empty use it in method 1 that is far in build and call the result of that method in the method in another place if i remember correctly but here i dont know to do such thing :c

CPU i5 6600k 4,4Ghz , COOLER Dark Rock 3 from BQ, RAM 16 GB of ddr 4 2800MHz from corsair,

 PSU EVGA 750 W GOLD G2, MOBO Msi z170A Gaming M3, CASE NZXT H440 Black/Blue,

GPU Geforce GTX 980 Gigabyte G1 Gaming,

STORAGE 1 SSD Samsung 850 Evo 250 GB and 1 HDD 500GB WD, Windows 8.1.

Link to comment
Share on other sites

Link to post
Share on other sites

propably not. In javascript there were protocols or smth like that when you could make variable it could be empty use it in method 1 that is far in build and call the result of that method in the method in another place if i remember correctly but here i dont know to do such thing :c

 

Sorry it's really not clear what you are trying to achieve at all... Can you try to generalise?

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

Well in short i cant figure out how to force computer to make random move that is placed in method in class and to make this move repeat once after 20 sec . When i try to call variable that is used in timer by the class that has this variable the if outcome does not work hence the computer does not launch method. Only what i did in TimerTask worked which was just message that its computer move time and than make variable of time to 0 so the circle repeats and works but method is still not launched. Oh and after message appears user needs to make move otherwise he is stuck in the message;p

CPU i5 6600k 4,4Ghz , COOLER Dark Rock 3 from BQ, RAM 16 GB of ddr 4 2800MHz from corsair,

 PSU EVGA 750 W GOLD G2, MOBO Msi z170A Gaming M3, CASE NZXT H440 Black/Blue,

GPU Geforce GTX 980 Gigabyte G1 Gaming,

STORAGE 1 SSD Samsung 850 Evo 250 GB and 1 HDD 500GB WD, Windows 8.1.

Link to comment
Share on other sites

Link to post
Share on other sites

Well in short i cant figure out how to force computer to make random move that is placed in method in class and to make this move repeat once after 20 sec . When i try to call variable that is used in timer by the class that has this variable the if outcome does not work hence the computer does not launch method. Only what i did in TimerTask worked which was just message that its computer move time and than make variable of time to 0 so the circle repeats and works but method is still not launched. Oh and after message appears user needs to make move otherwise he is stuck in the message;p

 

You're still not being clear enough and worse still is the language barrier unfortunately as a lot of that simply doesn't make any sense (to me at least)  :mellow:

 

When I asked if you could try to generalize I meant for you to try to remove your context i.e. describe/demonstrate your problem in general terms relating to the language and/or specific concept. For example: 'I have two threads and I need to share a variable between them' or 'I have a variable and I want to update it from a thread but I don't know how' - this sort of thing...

 

Now from reading your post it sounds to me like you have some class and you want to update it when a timer is fired but it's not working?

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

You're still not being clear enough and worse still is the language barrier unfortunately as a lot of that simply doesn't make any sense (to me at least)  :mellow:

 

When I asked if you could try to generalize I meant for you to try to remove your context i.e. describe/demonstrate your problem in general terms relating to the language and/or specific concept. For example: 'I have two threads and I need to share a variable between them' or 'I have a variable and I want to update it from a thread but I don't know how' - this sort of thing...

 

Now from reading your post it sounds to me like you have some class and you want to update it when a timer is fired but it's not working?

sort of. Okay slowly now. I got timer that has specific variable that stores second passed by timer (cuz its essential for timer to work) and by status of this variable i want it to fire a method by pre define argument (which is the right second for example 20 ) and than after calling method this varriable resets itself. So the variable sure does reset because the reset process is inside timer task but the variable status does not update to if so then if wont activate the method that i nested there. 

 

I assume you know how to make timer in java so the timer has its own class that is in fact nested in main code in order to run it  and in if statement i nested classname.variablename to get to variable but this seems to not work dunno why.

CPU i5 6600k 4,4Ghz , COOLER Dark Rock 3 from BQ, RAM 16 GB of ddr 4 2800MHz from corsair,

 PSU EVGA 750 W GOLD G2, MOBO Msi z170A Gaming M3, CASE NZXT H440 Black/Blue,

GPU Geforce GTX 980 Gigabyte G1 Gaming,

STORAGE 1 SSD Samsung 850 Evo 250 GB and 1 HDD 500GB WD, Windows 8.1.

Link to comment
Share on other sites

Link to post
Share on other sites

Okay after many combinations i finally archived what i looked for the computer takes rounds and live of the user !! :) not time to tweak things up and add additionall enemy just for science.

 

EDIT:

Okay i made a comparesement that takes hp of enemy sith lord and user and after time limit it will tell if user one on time out or not and its working finally 90% is working :P

CPU i5 6600k 4,4Ghz , COOLER Dark Rock 3 from BQ, RAM 16 GB of ddr 4 2800MHz from corsair,

 PSU EVGA 750 W GOLD G2, MOBO Msi z170A Gaming M3, CASE NZXT H440 Black/Blue,

GPU Geforce GTX 980 Gigabyte G1 Gaming,

STORAGE 1 SSD Samsung 850 Evo 250 GB and 1 HDD 500GB WD, Windows 8.1.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×